Ejemplo n.º 1
0
 def test_get_bdm_image_metadata__basic_property(self):
     block_device_mapping = [{
         'id': 1,
         'device_name': 'vda',
         'no_device': None,
         'virtual_name': None,
         'snapshot_id': None,
         'volume_id': '1',
         'delete_on_termination': False,
     }]
     fake_volume = {
         'volume_image_metadata': {
             'min_ram': 256,
             'min_disk': 128,
             'foo': 'bar',
         },
     }
     with mock.patch.object(
             self.compute_api.volume_api,
             'get',
             return_value=fake_volume,
     ):
         meta = block_device.get_bdm_image_metadata(
             self.context, self.compute_api.image_api,
             self.compute_api.volume_api, block_device_mapping)
         self.assertEqual(256, meta['min_ram'])
         self.assertEqual(128, meta['min_disk'])
         self.assertEqual('active', meta['status'])
         self.assertEqual('bar', meta['properties']['foo'])
Ejemplo n.º 2
0
    def _test_get_bdm_image_metadata__bootable(self, is_bootable=False):
        block_device_mapping = [{
            'id': 1,
            'device_name': 'vda',
            'no_device': None,
            'virtual_name': None,
            'snapshot_id': None,
            'volume_id': '1',
            'delete_on_termination': False,
        }]

        expected_meta = {
            'min_disk': 0, 'min_ram': 0, 'properties': {}, 'size': 0,
            'status': 'active',
        }

        def get_vol_data(*args, **kwargs):
            return {'bootable': is_bootable}

        with mock.patch.object(
            self.compute_api.volume_api, 'get', side_effect=get_vol_data,
        ):
            if not is_bootable:
                self.assertRaises(
                    exception.InvalidBDMVolumeNotBootable,
                    block_device.get_bdm_image_metadata,
                    self.context,
                    self.compute_api.image_api,
                    self.compute_api.volume_api,
                    block_device_mapping)
            else:
                meta = block_device.get_bdm_image_metadata(
                    self.context, self.compute_api.image_api,
                    self.compute_api.volume_api, block_device_mapping)
                self.assertEqual(expected_meta, meta)