예제 #1
0
    def test_s3_parse_manifest(self):
        self.set_mock_db_items(fakes.DB_IMAGE_AKI_1, fakes.DB_IMAGE_ARI_1)
        self.db_api.get_item_by_id.return_value = None
        self.glance.images.get.side_effect = (
            tools.get_by_1st_arg_getter({
                fakes.ID_OS_IMAGE_AKI_1: fakes.OSImage(fakes.OS_IMAGE_AKI_1),
                fakes.ID_OS_IMAGE_ARI_1: fakes.OSImage(fakes.OS_IMAGE_ARI_1)}))

        metadata, image_parts, key, iv = image_api._s3_parse_manifest(
            base.create_context(), AMI_MANIFEST_XML)

        expected_metadata = {
            'disk_format': 'ami',
            'container_format': 'ami',
            'properties': {'architecture': 'x86_64',
                           'kernel_id': fakes.ID_OS_IMAGE_AKI_1,
                           'ramdisk_id': fakes.ID_OS_IMAGE_ARI_1,
                           'mappings': [
                                {"device": "sda1", "virtual": "ami"},
                                {"device": "/dev/sda1", "virtual": "root"},
                                {"device": "sda2", "virtual": "ephemeral0"},
                                {"device": "sda3", "virtual": "swap"}]}}
        self.assertThat(metadata,
                        matchers.DictMatches(expected_metadata,
                                             orderless_lists=True))
        self.assertThat(image_parts,
                        matchers.ListMatches(['foo']))
        self.assertEqual('foo', key)
        self.assertEqual('foo', iv)
        self.db_api.get_items_ids.assert_any_call(
            mock.ANY, 'aki', item_ids=(fakes.ID_EC2_IMAGE_AKI_1,),
            item_os_ids=None)
        self.db_api.get_items_ids.assert_any_call(
            mock.ANY, 'ari', item_ids=(fakes.ID_EC2_IMAGE_ARI_1,),
            item_os_ids=None)
예제 #2
0
    def test_s3_parse_manifest(self):
        db_api = self.mock_db()
        glance = self.mock_glance()
        db_api.set_mock_items(fakes.DB_IMAGE_AKI_1, fakes.DB_IMAGE_ARI_1)
        glance.images.get.side_effect = (tools.get_by_1st_arg_getter({
            fakes.ID_OS_IMAGE_AKI_1:
            fakes.OSImage(fakes.OS_IMAGE_AKI_1),
            fakes.ID_OS_IMAGE_ARI_1:
            fakes.OSImage(fakes.OS_IMAGE_ARI_1)
        }))

        metadata, image_parts, key, iv = image_api._s3_parse_manifest(
            base.create_context(), AMI_MANIFEST_XML)

        expected_metadata = {
            'disk_format': 'ami',
            'container_format': 'ami',
            'properties': {
                'architecture':
                'x86_64',
                'kernel_id':
                fakes.ID_OS_IMAGE_AKI_1,
                'ramdisk_id':
                fakes.ID_OS_IMAGE_ARI_1,
                'mappings': [{
                    "device": "sda1",
                    "virtual": "ami"
                }, {
                    "device": "/dev/sda1",
                    "virtual": "root"
                }, {
                    "device": "sda2",
                    "virtual": "ephemeral0"
                }, {
                    "device": "sda3",
                    "virtual": "swap"
                }]
            }
        }
        self.assertThat(
            metadata,
            matchers.DictMatches(expected_metadata, orderless_lists=True))
        self.assertThat(image_parts, matchers.ListMatches(['foo']))
        self.assertEqual('foo', key)
        self.assertEqual('foo', iv)
        db_api.get_items_ids.assert_any_call(
            mock.ANY,
            'aki',
            item_ids=(fakes.ID_EC2_IMAGE_AKI_1, ),
            item_os_ids=None)
        db_api.get_items_ids.assert_any_call(
            mock.ANY,
            'ari',
            item_ids=(fakes.ID_EC2_IMAGE_ARI_1, ),
            item_os_ids=None)