示例#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)
示例#2
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),
                         matchers.IsSubDictOf(new))
示例#3
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.assertEquals(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.assertEquals(len(image_bdms), 1)
        self.assertEquals(len(boot_bdms), 1)
        self.assertEquals(image_bdms[0]['boot_index'], 0)
        self.assertEquals(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.assertEquals(len(image_bdms), 0)
        self.assertEquals(len(boot_bdms), 1)
        self.assertEquals(boot_bdms[0]['boot_index'], 0)
        self.assertEquals(boot_bdms[0]['source_type'], 'volume')
示例#4
0
class TestDictMatches(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),
         ]
示例#5
0
    def _test_network_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')
        rpcapi = network_rpcapi.NetworkAPI()
        expected_retval = 'foo' if method == 'call' else None
        expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
        expected_topic = CONF.network_topic
        expected_msg = rpcapi.make_msg(method, **kwargs)
        if 'source_compute' in expected_msg['args']:
            # Fix up for migrate_instance_* calls.
            args = expected_msg['args']
            args['source'] = args.pop('source_compute')
            args['dest'] = args.pop('dest_compute')
        targeted_methods = [
            'lease_fixed_ip', 'release_fixed_ip', 'rpc_setup_network_on_host',
            '_rpc_allocate_fixed_ip', 'deallocate_fixed_ip', 'update_dns',
            '_associate_floating_ip', '_disassociate_floating_ip',
            'lease_fixed_ip', 'release_fixed_ip', 'migrate_instance_start',
            'migrate_instance_finish',
            'allocate_for_instance', 'deallocate_for_instance',
        ]
        if method in targeted_methods and 'host' in kwargs:
            if method not in ['allocate_for_instance',
                              'deallocate_for_instance',
                              'deallocate_fixed_ip']:
                del expected_msg['args']['host']
            host = kwargs['host']
            if CONF.multi_host:
                expected_topic = rpc.queue_get_for(ctxt, CONF.network_topic,
                                                   host)
        expected_msg['version'] = expected_version

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, expected_topic, expected_msg]
        for arg, expected_arg in zip(self.fake_args, expected_args):
            try:
                self.assertEqual(arg, expected_arg)
            except AssertionError:
                # actual_args may contain optional args, like the one that
                # have default values; therefore if arg and excepted_arg
                # do not match verify at least that the required ones do
                if isinstance(arg, dict) and isinstance(expected_arg, dict):
                    actual_args = arg.get('args')
                    required_args = expected_arg.get('args')
                    if actual_args and required_args:
                        self.assertThat(required_args,
                                        matchers.IsSubDictOf(actual_args))
示例#6
0
    def test_describe_instances_bdm(self):
        """Make sure describe_instances works with root_device_name and
        block device mappings
        """
        (inst1, inst2, volumes) = self._setUpBlockDeviceMapping()

        result = self._assertInstance(inst1['id'])
        self.assertThat(self._expected_instance_bdm1,
                        matchers.IsSubDictOf(result))
        self._assertEqualBlockDeviceMapping(
            self._expected_block_device_mapping0, result['blockDeviceMapping'])

        result = self._assertInstance(inst2['id'])
        self.assertThat(self._expected_instance_bdm2,
                        matchers.IsSubDictOf(result))

        self._tearDownBlockDeviceMapping(inst1, inst2, volumes)
示例#7
0
 def _assertEqualBlockDeviceMapping(self, expected, result):
     self.assertEqual(len(expected), len(result))
     for x in expected:
         found = False
         for y in result:
             if x['deviceName'] == y['deviceName']:
                 self.assertThat(x, matchers.IsSubDictOf(y))
                 found = True
                 break
         self.assertTrue(found)
示例#8
0
    def test_format_instance_bdm(self):
        (inst1, inst2, volumes) = self._setUpBlockDeviceMapping()

        result = {}
        self.cloud._format_instance_bdm(self.context, inst1['uuid'],
                                        '/dev/sdb1', result)
        self.assertThat(
            {'rootDeviceType': self._expected_instance_bdm1['rootDeviceType']},
            matchers.IsSubDictOf(result))
        self._assertEqualBlockDeviceMapping(
            self._expected_block_device_mapping0, result['blockDeviceMapping'])

        result = {}
        self.cloud._format_instance_bdm(self.context, inst2['uuid'],
                                        '/dev/sdc1', result)
        self.assertThat(
            {'rootDeviceType': self._expected_instance_bdm2['rootDeviceType']},
            matchers.IsSubDictOf(result))

        self._tearDownBlockDeviceMapping(inst1, inst2, volumes)
示例#9
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))
示例#10
0
 def test_legacy(self):
     for legacy, new in zip(self.legacy_mapping, self.new_mapping):
         self.assertThat(legacy, matchers.IsSubDictOf(new.legacy()))
示例#11
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))