Ejemplo n.º 1
0
 def test_legacy_source_image(self):
     for legacy, new in zip(self.legacy_mapping_source_image,
                            self.new_mapping_source_image):
         if new['destination_type'] == 'volume':
             self.assertThat(legacy, matchers.IsSubDictOf(new.legacy()))
         else:
             self.assertRaises(exception.InvalidBDMForLegacy, new.legacy)
Ejemplo n.º 2
0
    def test_from_legacy_mapping(self):
        def _get_image_bdms(bdms):
            return [bdm for bdm in bdms if bdm['source_type'] == 'image']

        def _get_bootable_bdms(bdms):
            return [bdm for bdm in bdms if bdm['boot_index'] >= 0]

        new_no_img = block_device.from_legacy_mapping(self.legacy_mapping)
        self.assertEqual(len(_get_image_bdms(new_no_img)), 0)

        for new, expected in zip(new_no_img, self.new_mapping):
            self.assertThat(new, matchers.IsSubDictOf(expected))

        new_with_img = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref')
        image_bdms = _get_image_bdms(new_with_img)
        boot_bdms = _get_bootable_bdms(new_with_img)
        self.assertEqual(len(image_bdms), 1)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(image_bdms[0]['boot_index'], 0)
        self.assertEqual(boot_bdms[0]['source_type'], 'image')

        new_with_img_and_root = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref', 'sda1')
        image_bdms = _get_image_bdms(new_with_img_and_root)
        boot_bdms = _get_bootable_bdms(new_with_img_and_root)
        self.assertEqual(len(image_bdms), 0)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(boot_bdms[0]['boot_index'], 0)
        self.assertEqual(boot_bdms[0]['source_type'], 'volume')

        new_no_root = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref', 'sda1', no_root=True)
        self.assertEqual(len(_get_image_bdms(new_no_root)), 0)
        self.assertEqual(len(_get_bootable_bdms(new_no_root)), 0)
Ejemplo n.º 3
0
 def test_from_api(self):
     for api, new in zip(self.api_mapping, self.new_mapping):
         new['connection_info'] = None
         if new['snapshot_id']:
             new['volume_id'] = None
         self.assertThat(
             block_device.BlockDeviceDict.from_api(api, False),
             matchers.IsSubDictOf(new))
Ejemplo n.º 4
0
    def test_legacy_mapping_source_image(self):
        got_legacy = block_device.legacy_mapping(self.new_mapping)

        for legacy, expected in zip(got_legacy, self.legacy_mapping):
            self.assertThat(expected, matchers.IsSubDictOf(legacy))
Ejemplo n.º 5
0
 def test_legacy(self):
     for legacy, new in zip(self.legacy_mapping, self.new_mapping):
         self.assertThat(
             legacy,
             matchers.IsSubDictOf(new.legacy()))
Ejemplo n.º 6
0
 def test_from_legacy(self):
     for legacy, new in zip(self.legacy_mapping, self.new_mapping):
         self.assertThat(
             block_device.BlockDeviceDict.from_legacy(legacy),
             matchers.IsSubDictOf(new))
Ejemplo n.º 7
0
class TestIsSubDictOf(testtools.TestCase, helpers.TestMatchersInterface):

    matches_matcher = matchers.IsSubDictOf({
        'foo': 'bar',
        'baz': 'DONTCARE',
        'cat': {
            'tabby': True,
            'fluffy': False
        }
    })

    matches_matches = [{
        'foo': 'bar',
        'baz': 'noox',
        'cat': {
            'tabby': True,
            'fluffy': False
        }
    }, {
        'foo': 'bar',
        'baz': 'quux'
    }]

    matches_mismatches = [
        {
            'foo': 'bop',
            'baz': 'qux',
            'cat': {
                'tabby': True,
                'fluffy': False
            }
        },
        {
            'foo': 'bar',
            'baz': 'quux',
            'cat': {
                'tabby': True,
                'fluffy': True
            }
        },
        {
            'foo': 'bar',
            'cat': {
                'tabby': True,
                'fluffy': False
            },
            'dog': None
        },
    ]

    str_examples = [
        ("IsSubDictOf({'foo': 'bar', 'baz': 'DONTCARE',"
         " 'cat': {'fluffy': False, 'tabby': True}})", matches_matcher),
    ]

    describe_examples = [
        ("Dictionaries do not match at fluffy. d1: False d2: True", {
            'foo': 'bar',
            'baz': 'quux',
            'cat': {
                'tabby': True,
                'fluffy': True
            }
        }, matches_matcher),
        ("Dictionaries do not match at foo. d1: bar d2: bop", {
            'foo': 'bop',
            'baz': 'quux',
            'cat': {
                'tabby': True,
                'fluffy': False
            }
        }, matches_matcher),
    ]