def setUp(self): locations = [{'url': '%s/%s' % (BASE_URI, UUID1), 'metadata': {}, 'status': 'active'}] self.image_stub = ImageStub(UUID1, 'active', locations) self.store_api = unit_test_utils.FakeStoreAPI() self.store_utils = unit_test_utils.FakeStoreUtils(self.store_api) super(TestStoreImage, self).setUp()
def _get_image(self, location_count=1, image_size=10): context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = 'xyz' base_image.size = image_size image = glance.quota.ImageProxy(base_image, context, db_api, store) locations = [] for i in range(location_count): locations.append({ 'url': 'file:///g/there/it/is%d' % i, 'metadata': {}, 'status': 'active' }) image_values = { 'id': 'xyz', 'owner': context.owner, 'status': 'active', 'size': image_size, 'locations': locations } db_api.image_create(context, image_values) return image
def setUp(self): super(TestImageFactory, self).setUp() store_api = unit_test_utils.FakeStoreAPI() store_utils = unit_test_utils.FakeStoreUtils(store_api) self.image_factory = glance.location.ImageFactoryProxy( ImageFactoryStub(), glance.context.RequestContext(user=USER1), store_api, store_utils)
def setUp(self): super(TestImagesController, self).setUp() self.config(verbose=True, debug=True) self.controller = glance.api.v2.image_data.ImageDataController( db_api=unit_test_utils.FakeDB(), store_api=unit_test_utils.FakeStoreAPI())
def setUp(self): super(TestStoreImageRepo, self).setUp() self.store_api = unit_test_utils.FakeStoreAPI() self.image_stub = ImageStub(UUID1) self.image = glance.store.ImageProxy(self.image_stub, {}, self.store_api) self.image_repo_stub = ImageRepoStub() self.image_repo = glance.store.ImageRepoProxy(self.image_repo_stub, {}, self.store_api)
def setUp(self): super(TestTasksController, self).setUp() self.db = unit_test_utils.FakeDB() self.policy = unit_test_utils.FakePolicyEnforcer() self.notifier = unit_test_utils.FakeNotifier() self.store = unit_test_utils.FakeStoreAPI() self._create_tasks() self.controller = glance.api.v2.tasks.TasksController( self.db, self.policy, self.notifier, self.store)
def setUp(self): self.store_api = unit_test_utils.FakeStoreAPI() self.store_utils = unit_test_utils.FakeStoreUtils(self.store_api) self.enabled_backends = { "ceph1": "rbd", "ceph2": "rbd" } super(TestStoreMultiBackends, self).setUp() self.config(enabled_backends=self.enabled_backends)
def setUp(self): super(TestImageMemberQuotas, self).setUp() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) context = FakeContext() self.image = mock.Mock() self.base_image_member_factory = mock.Mock() self.image_member_factory = glance.quota.ImageMemberFactoryProxy( self.base_image_member_factory, context, db_api, store)
def setUp(self): super(TestImagesController, self).setUp() self.config(verbose=True, debug=True) self.notifier = unit_test_utils.FakeNotifier() self.controller = glance.api.v2.image_data.ImageDataController( db_api=unit_test_utils.FakeDB(), store_api=unit_test_utils.FakeStoreAPI(), policy_enforcer=unit_test_utils.FakePolicyEnforcer(), notifier=self.notifier)
def setUp(self): super(TestImagesController, self).setUp() conf = glance.tests.utils.TestConfigOpts({ 'verbose': True, 'debug': True, }) self.controller = glance.api.v2.image_data.ImageDataController(conf, db_api=test_utils.FakeDB(), store_api=test_utils.FakeStoreAPI())
def setUp(self): super(TestImageMembersController, self).setUp() self.db = unit_test_utils.FakeDB() self.store = unit_test_utils.FakeStoreAPI() self.policy = unit_test_utils.FakePolicyEnforcer() self.notifier = unit_test_utils.FakeNotifier() self._create_images() self._create_image_members() self.controller = glance.api.v2.image_members.ImageMembersController( self.db, self.policy, self.notifier, self.store) glance_store.create_stores()
def setUp(self): super(TestMultiBackendImagesController, self).setUp() self.config(debug=True) self.image_repo = FakeImageRepo() db = unit_test_utils.FakeDB() policy = unit_test_utils.FakePolicyEnforcer() notifier = unit_test_utils.FakeNotifier() store = unit_test_utils.FakeStoreAPI() self.controller = glance.api.v2.image_data.ImageDataController() self.controller.gateway = FakeGateway(db, store, notifier, policy, self.image_repo)
def setUp(self): self.store_api = unit_test_utils.FakeStoreAPI() self.store_utils = unit_test_utils.FakeStoreUtils(self.store_api) ts = datetime.now() self.artifact_stub = ArtifactStub(id=UUID2, state='creating', created_at=ts, updated_at=ts, version='1.0', owner='me', name='foo') super(TestStoreArtifact, self).setUp()
def _test_quota_allowed_unit(self, data_length, config_quota): self.config(user_storage_quota=config_quota) context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = 'id' image = glance.quota.ImageProxy(base_image, context, db_api, store) data = '*' * data_length base_image.set_data(data, size=None) image.set_data(data) self.assertEqual(data_length, base_image.size)
def setUp(self): super(TestImageActionsController, self).setUp() self.db = unit_test_utils.FakeDB(initialize=False) self.policy = unit_test_utils.FakePolicyEnforcer() self.notifier = unit_test_utils.FakeNotifier() self.store = unit_test_utils.FakeStoreAPI() for i in range(1, 4): self.store.data['%s/fake_location_%i' % (BASE_URI, i)] = ('Z', 1) self.store_utils = unit_test_utils.FakeStoreUtils(self.store) self.controller = image_actions.ImageActionsController( self.db, self.policy, self.notifier, self.store) self.controller.gateway.store_utils = self.store_utils store.create_stores()
def test_quota_allowed(self): quota = 10 self.config(user_storage_quota=str(quota)) context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = 'id' image = glance.quota.ImageProxy(base_image, context, db_api, store) data = '*' * quota base_image.set_data(data, size=None) image.set_data(data) self.assertEqual(quota, base_image.size)
def test_iadd_location_for_queued_image(self): context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = str(uuid.uuid4()) image = glance.quota.ImageProxy(base_image, context, db_api, store) self.assertIsNone(image.size) self.mock_object(store_api, 'get_size_from_backend', unit_test_utils.fake_get_size_from_backend) image.locations += [{'url': 'file:///fake.img.tar.gz', 'metadata': {}}] self.assertIn({'url': 'file:///fake.img.tar.gz', 'metadata': {}}, image.locations)
def setUp(self): super(TestStoreImageRepo, self).setUp() self.store_api = unit_test_utils.FakeStoreAPI() store_utils = unit_test_utils.FakeStoreUtils(self.store_api) self.image_stub = ImageStub(UUID1) self.image = glance.location.ImageProxy(self.image_stub, {}, self.store_api, store_utils) self.image_repo_stub = ImageRepoStub() self.image_repo = glance.location.ImageRepoProxy( self.image_repo_stub, {}, self.store_api, store_utils) patcher = mock.patch("glance.location._get_member_repo_for_store", self.get_fake_member_repo) patcher.start() self.addCleanup(patcher.stop) self.fake_member_repo = FakeMemberRepo(self.image, [TENANT1, TENANT2]) self.image_member_repo = glance.location.ImageMemberRepoProxy( self.fake_member_repo, self.image, {}, self.store_api)
def test_image_set_data_location_metadata(self): context = glance.context.RequestContext(user=USER1) image_stub = ImageStub(UUID2, status='queued', locations=[]) loc_meta = {'key': 'value5032'} store_api = unit_test_utils.FakeStoreAPI(store_metadata=loc_meta) image = glance.store.ImageProxy(image_stub, context, store_api) image.set_data('YYYY', 4) self.assertEqual(image.size, 4) location_data = image.locations[0] self.assertEqual(location_data['url'], UUID2) self.assertEqual(location_data['metadata'], loc_meta) self.assertEqual(image.checksum, 'Z') self.assertEqual(image.status, 'active') image.delete() self.assertEqual(image.status, 'deleted') self.assertRaises(exception.NotFound, self.store_api.get_from_backend, {}, image.locations[0]['url'])
def setUp(self): super(TestImageMembersController, self).setUp() self.db = unit_test_utils.FakeDB(initialize=False) self.store = unit_test_utils.FakeStoreAPI() self.policy = unit_test_utils.FakePolicyEnforcer() self.notifier = unit_test_utils.FakeNotifier() self._create_images() self._create_image_members() self.controller = glance.api.v2.image_members.ImageMembersController( self.db, self.policy, self.notifier, self.store) glance_store.register_opts(CONF) self.config(default_store='filesystem', filesystem_store_datadir=self.test_dir, group="glance_store") glance_store.create_stores()
def setUp(self): super(TestImagesController, self).setUp() self.config(debug=True) self.image_repo = FakeImageRepo() db = unit_test_utils.FakeDB() policy = unit_test_utils.FakePolicyEnforcer() notifier = unit_test_utils.FakeNotifier() store = unit_test_utils.FakeStoreAPI() self.controller = glance.api.v2.image_data.ImageDataController() self.controller.gateway = FakeGateway(db, store, notifier, policy, self.image_repo) # FIXME(abhishekk): Everything is fake in this test, so mocked the # image mutable_check, Later we need to fix these tests to use # some realistic data patcher = mock.patch('glance.api.v2.policy.check_is_image_mutable') patcher.start() self.addCleanup(patcher.stop)
def _quota_exceeded_size(self, quota, data, deleted=True, size=None): self.config(user_storage_quota=quota) context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = 'id' image = glance.quota.ImageProxy(base_image, context, db_api, store) if deleted: with patch.object(store_utils, 'safe_delete_from_backend'): store_utils.safe_delete_from_backend(context, image.image_id, base_image.locations[0]) self.assertRaises(exception.StorageQuotaFull, image.set_data, data, size=size)
def test_quota_exceeded_keystone_quotas(self): # Set our global limit to a tiny ten bytes self.config(user_storage_quota='10B') context = FakeContext() db_api = unit_test_utils.FakeDB() store_api = unit_test_utils.FakeStoreAPI() store = unit_test_utils.FakeStoreUtils(store_api) base_image = FakeImage() base_image.image_id = 'id' image = glance.quota.ImageProxy(base_image, context, db_api, store) # With keystone quotas disabled, a 100 byte image should fail the # global limit. data = '*' * 100 self.assertRaises(exception.StorageQuotaFull, image.set_data, data, size=len(data)) # If we turn on keystone quotas, the global limit gets ignored # so the same image no longer fails. self.config(use_keystone_limits=True) image.set_data(data, size=len(data))
def setUp(self): locations = ['%s/%s' % (BASE_URI, UUID1)] self.image_stub = ImageStub(UUID1, 'active', locations) self.store_api = unit_test_utils.FakeStoreAPI() super(TestStoreImage, self).setUp()
def setUp(self): super(TestImageFactory, self).setUp() self.image_factory = glance.store.ImageFactoryProxy( ImageFactoryStub(), glance.context.RequestContext(user=USER1), unit_test_utils.FakeStoreAPI())