コード例 #1
0
 def setUp(self):
     super(TestImportToStoreTask, self).setUp()
     self.gateway = gateway.Gateway()
     self.context = context.RequestContext(user_id=TENANT1,
                                           project_id=TENANT1,
                                           overwrite=False)
     self.img_factory = self.gateway.get_image_factory(self.context)
コード例 #2
0
    def setUp(self):
        super(TestConvertImageTask, self).setUp()

        glance_store.register_opts(CONF)
        self.config(default_store='file',
                    stores=['file', 'http'],
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")
        self.config(output_format='qcow2', group='image_conversion')
        glance_store.create_stores(CONF)

        self.work_dir = os.path.join(self.test_dir, 'work_dir')
        utils.safe_mkdirs(self.work_dir)
        self.config(work_dir=self.work_dir, group='task')

        self.context = mock.MagicMock()
        self.img_repo = mock.MagicMock()
        self.task_repo = mock.MagicMock()
        self.image_id = UUID1

        self.gateway = gateway.Gateway()
        self.task_factory = domain.TaskFactory()
        self.img_factory = self.gateway.get_image_factory(self.context)
        self.image = self.img_factory.new_image(image_id=self.image_id,
                                                disk_format='raw',
                                                container_format='bare')

        task_input = {
            "import_from": "http://cloud.foo/image.raw",
            "import_from_format": "raw",
            "image_properties": {
                'disk_format': 'raw',
                'container_format': 'bare'
            }
        }

        task_ttl = CONF.task.task_time_to_live

        self.task_type = 'import'
        request_id = 'fake_request_id'
        user_id = 'fake_user'
        self.task = self.task_factory.new_task(self.task_type,
                                               TENANT1,
                                               self.image_id,
                                               user_id,
                                               request_id,
                                               task_time_to_live=task_ttl,
                                               task_input=task_input)

        self.image.extra_properties = {
            'os_glance_import_task': self.task.task_id
        }
        self.wrapper = import_flow.ImportActionWrapper(self.img_repo,
                                                       self.image_id,
                                                       self.task.task_id)
コード例 #3
0
    def setUp(self):
        super(TestImportTask, self).setUp()

        glance_store.register_opts(CONF)
        self.config(default_store='file',
                    stores=['file', 'http'],
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")
        glance_store.create_stores(CONF)

        self.work_dir = os.path.join(self.test_dir, 'work_dir')
        utils.safe_mkdirs(self.work_dir)
        self.config(work_dir=self.work_dir, group='task')

        self.context = context.RequestContext(user_id=TENANT1,
                                              project_id=TENANT1,
                                              overwrite=False)
        self.img_repo = mock.MagicMock()
        self.task_repo = mock.MagicMock()

        self.gateway = gateway.Gateway()
        self.task_factory = domain.TaskFactory()
        self.img_factory = self.gateway.get_image_factory(self.context)
        self.image = self.img_factory.new_image(image_id=UUID1,
                                                disk_format='qcow2',
                                                container_format='bare')

        task_input = {
            "import_from": "http://cloud.foo/image.qcow2",
            "import_from_format": "qcow2",
            "image_properties": {
                'disk_format': 'qcow2',
                'container_format': 'bare'
            }
        }
        task_ttl = CONF.task.task_time_to_live

        self.task_type = 'import'
        request_id = 'fake_request_id'
        user_id = 'fake_user'
        self.task = self.task_factory.new_task(self.task_type,
                                               TENANT1,
                                               UUID1,
                                               user_id,
                                               request_id,
                                               task_time_to_live=task_ttl,
                                               task_input=task_input)
コード例 #4
0
ファイル: test_image_cache.py プロジェクト: crowdy/glance
    def _test_prefetcher(self, mock_get_db):
        self.config(enabled_backends={'cheap': 'file'})
        store.register_store_opts(CONF)
        self.config(filesystem_store_datadir='/tmp', group='cheap')
        store.create_multi_stores(CONF)

        tempf = tempfile.NamedTemporaryFile()
        tempf.write(b'foo')

        db = unit_test_utils.FakeDB(initialize=False)
        mock_get_db.return_value = db

        ctx = context.RequestContext(is_admin=True, roles=['admin'])
        gateway = glance_gateway.Gateway()
        image_factory = gateway.get_image_factory(ctx,
                                                  authorization_layer=False)
        image_repo = gateway.get_repo(ctx, authorization_layer=False)
        fetcher = prefetcher.Prefetcher()

        # Create an image with no values set and queue it
        image = image_factory.new_image()
        image_repo.add(image)
        fetcher.cache.queue_image(image.image_id)

        # Image is not active, so it should fail to cache, but remain queued
        self.assertFalse(fetcher.run())
        self.assertFalse(fetcher.cache.is_cached(image.image_id))
        self.assertTrue(fetcher.cache.is_queued(image.image_id))

        # Set the disk/container format and give it a location
        image.disk_format = 'raw'
        image.container_format = 'bare'
        image.status = 'active'
        loc = {'url': 'file://%s' % tempf.name, 'metadata': {'store': 'cheap'}}
        with mock.patch('glance.location._check_image_location'):
            # FIXME(danms): Why do I have to do this?
            image.locations = [loc]
        image_repo.save(image)

        # Image is now active and has a location, so it should cache
        self.assertTrue(fetcher.run())
        self.assertTrue(fetcher.cache.is_cached(image.image_id))
        self.assertFalse(fetcher.cache.is_queued(image.image_id))
コード例 #5
0
    def test_get_repo_member_property(self):
        """Test that the image.member property is propagated all the way from
        the DB to the top of the gateway repo stack.
        """
        db_api = unit_test_utils.FakeDB()
        gw = gateway.Gateway(db_api=db_api)

        # Get the UUID1 image as TENANT1
        ctxt = context.RequestContext(tenant=unit_test_utils.TENANT1)
        repo = gw.get_repo(ctxt)
        image = repo.get(unit_test_utils.UUID1)
        # We own the image, so member is None
        self.assertIsNone(image.member)

        # Get the UUID1 image as TENANT2
        ctxt = context.RequestContext(tenant=unit_test_utils.TENANT2)
        repo = gw.get_repo(ctxt)
        image = repo.get(unit_test_utils.UUID1)
        # We are a member, so member is our tenant id
        self.assertEqual(unit_test_utils.TENANT2, image.member)
コード例 #6
0
 def test_get_catalog_search_repo_no_es_api(self):
     gate = gateway.Gateway()
     self.assertRaises(exception.SearchNotAvailable,
                       gate.get_catalog_search_repo,
                       context.get_admin_context())
コード例 #7
0
ファイル: test_gateway.py プロジェクト: takanattie/glance
 def setUp(self):
     super(TestGateway, self).setUp()
     self.gateway = gateway.Gateway()
     self.context = mock.sentinel.context