

@mock.patch('glance_store._drivers.swift.utils.is_multiple_swift_store_accounts_enabled', mock.Mock(return_value=True))
def test_add_no_container_and_multiple_containers_no_create(self):
    '\n        Tests that adding an image with a non-existing container while using\n        multiple containers raises an appropriate exception\n        '
    conf = copy.deepcopy(SWIFT_CONF)
    conf['swift_store_user'] = 'tenant:user'
    conf['swift_store_create_container_on_put'] = False
    conf['swift_store_container'] = 'randomname'
    conf['swift_store_multiple_containers_seed'] = 2
    self.config(**conf)
    moves.reload_module(swift)
    self.mock_keystone_client()
    expected_image_id = str(uuid.uuid4())
    expected_container = ('randomname_' + expected_image_id[:2])
    self.store = Store(self.conf)
    self.store.configure()
    image_swift = six.BytesIO(b'nevergonnamakeit')
    global SWIFT_PUT_OBJECT_CALLS
    SWIFT_PUT_OBJECT_CALLS = 0
    exception_caught = False
    try:
        self.store.add(expected_image_id, image_swift, 0)
    except BackendException as e:
        exception_caught = True
        expected_msg = 'container %s does not exist in Swift'
        expected_msg = (expected_msg % expected_container)
        self.assertIn(expected_msg, encodeutils.exception_to_unicode(e))
    self.assertTrue(exception_caught)
    self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 0)

dataset/ETHPy150Open openstack/glance_store/glance_store/tests/unit/test_swift_store.py SwiftTests.test_add_no_container_and_multiple_containers_no_create/original