Пример #1
0
    def _test_driver_device(self, name):
        db_bdm = getattr(self, "%s_bdm" % name)
        test_bdm = self.driver_classes[name](db_bdm)
        self.assertThat(
            test_bdm,
            matchers.DictMatches(getattr(self, "%s_driver_bdm" % name)))

        for k, v in db_bdm.items():
            field_val = getattr(test_bdm._bdm_obj, k)
            if isinstance(field_val, bool):
                v = bool(v)
            self.assertEqual(field_val, v)

        self.assertThat(
            test_bdm.legacy(),
            matchers.DictMatches(getattr(self, "%s_legacy_driver_bdm" % name)))

        # Test passthru attributes
        for passthru in test_bdm._proxy_as_attr:
            self.assertEqual(getattr(test_bdm, passthru),
                             getattr(test_bdm._bdm_obj, passthru))

        # Make sure that all others raise _invalidType
        for other_name, cls in self.driver_classes.items():
            if other_name == name:
                continue
            self.assertRaises(driver_block_device._InvalidType, cls,
                              getattr(self, '%s_bdm' % name))

        # Test the save method
        with mock.patch.object(test_bdm._bdm_obj, 'save') as save_mock:
            for fld, alias in test_bdm._update_on_save.items():
                # We can't set fake values on enums, like device_type,
                # so skip those.
                if not isinstance(test_bdm._bdm_obj.fields[fld],
                                  fields.BaseEnumField):
                    test_bdm[alias or fld] = 'fake_changed_value'
            test_bdm.save()
            for fld, alias in test_bdm._update_on_save.items():
                self.assertEqual(test_bdm[alias or fld],
                                 getattr(test_bdm._bdm_obj, fld))

            save_mock.assert_called_once_with()

        def check_save():
            self.assertEqual(set([]), test_bdm._bdm_obj.obj_what_changed())

        # Test that nothing is set on the object if there are no actual changes
        test_bdm._bdm_obj.obj_reset_changes()
        with mock.patch.object(test_bdm._bdm_obj, 'save') as save_mock:
            save_mock.side_effect = check_save
            test_bdm.save()
    def test_get_flavor_with_default_limit(self):
        self.stub_out('nova.api.openstack.common.get_limit_and_marker',
                      fake_get_limit_and_marker)
        self.flags(max_limit=1, group='api')
        req = fakes.HTTPRequest.blank('/v2/fake/flavors?limit=2')
        response = self.controller.index(req)
        response_list = response["flavors"]
        response_links = response["flavors_links"]

        expected_flavors = [{
            "id":
            fakes.FLAVORS['1'].flavorid,
            "name":
            fakes.FLAVORS['1'].name,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/flavors/1",
            }, {
                "rel": "bookmark",
                "href": "http://localhost/fake/flavors/1",
            }]
        }]

        self.assertEqual(response_list, expected_flavors)
        self.assertEqual(response_links[0]['rel'], 'next')
        href_parts = urlparse.urlparse(response_links[0]['href'])
        self.assertEqual('/v2/fake/flavors', href_parts.path)
        params = urlparse.parse_qs(href_parts.query)
        self.assertThat({
            'limit': ['2'],
            'marker': ['1']
        }, matchers.DictMatches(params))
Пример #3
0
    def test_get_image_meta(self, mock_get):
        mock_get.return_value = objects.Flavor(extra_specs={})
        image_meta = compute_utils.get_image_metadata(
            self.ctx, self.mock_image_api, 'fake-image', self.instance_obj)

        self.image['properties'] = 'DONTCARE'
        self.assertThat(self.image, matchers.DictMatches(image_meta))
Пример #4
0
    def test_build_limits_empty_limits(self):
        expected_limits = {"limits": {"rate": [],
                           "absolute": {}}}

        quotas = {}
        output = self.view_builder.build(self.req, quotas)
        self.assertThat(output, matchers.DictMatches(expected_limits))
Пример #5
0
    def test_cloudpipe_list(self):
        def network_api_get(context, network_id):
            self.assertEqual(context.project_id, project_id)
            return {'vpn_public_address': '127.0.0.1', 'vpn_public_port': 22}

        def fake_get_nw_info_for_instance(instance):
            return fake_network.fake_get_instance_nw_info(self)

        self.stubs.Set(compute_utils, "get_nw_info_for_instance",
                       fake_get_nw_info_for_instance)
        self.stubs.Set(self.controller.network_api, "get", network_api_get)
        self.stubs.Set(self.controller.compute_api, "get_all",
                       compute_api_get_all)
        res_dict = self.controller.index(self.req)
        response = {
            'cloudpipes': [{
                'project_id': project_id,
                'internal_ip': '192.168.1.100',
                'public_ip': '127.0.0.1',
                'public_port': 22,
                'state': 'running',
                'instance_id': uuid,
                'created_at': '1981-10-20T00:00:00Z'
            }]
        }
        self.assertThat(res_dict, matchers.DictMatches(response))
Пример #6
0
 def create(*args, **kwargs):
     self.assertFalse(kwargs['legacy_bdm'])
     for expected, received in zip(bdm_expected,
                                   kwargs['block_device_mapping']):
         self.assertThat(block_device.BlockDeviceDict(expected),
                         matchers.DictMatches(received))
     return old_create(*args, **kwargs)
Пример #7
0
    def test_multi_choice_image(self):
        req = webob.Request.blank('/images/1')
        req.accept = "application/json"
        res = req.get_response(fakes.wsgi_app())
        self.assertEqual(res.status_int, 300)
        self.assertEqual(res.content_type, "application/json")

        expected = {
            "choices": [
                {
                    "id":
                    "v2.0",
                    "status":
                    "CURRENT",
                    "links": [
                        {
                            "href": "http://localhost/v2/images/1",
                            "rel": "self",
                        },
                    ],
                    "media-types": [
                        {
                            "base":
                            "application/xml",
                            "type":
                            "application/vnd.openstack.compute+xml"
                            ";version=2"
                        },
                        {
                            "base":
                            "application/json",
                            "type":
                            "application/vnd.openstack.compute+json"
                            ";version=2"
                        },
                    ],
                },
                {
                    "id":
                    "v2.1",
                    "status":
                    "EXPERIMENTAL",
                    "links": [
                        {
                            "href": "http://localhost/v2/images/1",
                            "rel": "self",
                        },
                    ],
                    "media-types": [{
                        "base":
                        "application/json",
                        "type":
                        "application/vnd.openstack.compute+json;version=2.1",
                    }],
                },
            ],
        }

        self.assertThat(jsonutils.loads(res.body),
                        matchers.DictMatches(expected))
Пример #8
0
    def test_dict_from_dotted_str(self):
        in_str = [('BlockDeviceMapping.1.DeviceName', '/dev/sda1'),
                  ('BlockDeviceMapping.1.Ebs.SnapshotId', 'snap-0000001c'),
                  ('BlockDeviceMapping.1.Ebs.VolumeSize', '80'),
                  ('BlockDeviceMapping.1.Ebs.DeleteOnTermination', 'false'),
                  ('BlockDeviceMapping.2.DeviceName', '/dev/sdc'),
                  ('BlockDeviceMapping.2.VirtualName', 'ephemeral0')]
        expected_dict = {
            'block_device_mapping': {
                '1': {
                    'device_name': '/dev/sda1',
                    'ebs': {
                        'snapshot_id': 'snap-0000001c',
                        'volume_size': 80,
                        'delete_on_termination': False
                    }
                },
                '2': {
                    'device_name': '/dev/sdc',
                    'virtual_name': 'ephemeral0'
                }
            }
        }
        out_dict = ec2utils.dict_from_dotted_str(in_str)

        self.assertThat(out_dict, matchers.DictMatches(expected_dict))
    def test_show_console(self):
        def fake_get_console(cons_self, context, instance_id, console_id):
            self.assertEqual(instance_id, self.uuid)
            self.assertEqual(console_id, 20)
            pool = dict(console_type='fake_type',
                        public_hostname='fake_hostname')
            return dict(id=console_id,
                        password='******',
                        port='fake_port',
                        pool=pool,
                        instance_name='inst-0001')

        expected = {
            'console': {
                'id': 20,
                'port': 'fake_port',
                'host': 'fake_hostname',
                'password': '******',
                'instance_name': 'inst-0001',
                'console_type': 'fake_type'
            }
        }

        self.stubs.Set(console.api.API, 'get_console', fake_get_console)

        req = fakes.HTTPRequest.blank(self.url + '/20')
        res_dict = self.controller.show(req, self.uuid, '20')
        self.assertThat(res_dict, matchers.DictMatches(expected))
Пример #10
0
    def test_build_limits_empty_limits(self):
        expected_limits = {"limits": {"rate": [], "absolute": {}}}

        abs_limits = {}
        rate_limits = []
        output = self.view_builder.build(rate_limits, abs_limits)
        self.assertThat(output, matchers.DictMatches(expected_limits))
Пример #11
0
 def test_get_flavor_list_with_marker(self):
     self.maxDiff = None
     url = self._prefix + '/flavors?limit=1&marker=1'
     req = self.fake_request.blank(url)
     flavor = self.controller.index(req)
     expected = {
         "flavors": [
             {
                 "id":
                 fakes.FLAVORS['2'].flavorid,
                 "name":
                 fakes.FLAVORS['2'].name,
                 "links": [
                     {
                         "rel":
                         "self",
                         "href":
                         "http://localhost/" + self._rspv + "/flavors/2",
                     },
                     {
                         "rel": "bookmark",
                         "href":
                         "http://localhost" + self._fake + "/flavors/2",
                     },
                 ],
             },
         ],
         'flavors_links': [{
             'href':
             'http://localhost/' + self._rspv + '/flavors?limit=1&marker=2',
             'rel': 'next'
         }]
     }
     self.assertThat(flavor, matchers.DictMatches(expected))
Пример #12
0
    def test_build_limits(self):
        expected_limits = {"limits": {
                "rate": [{
                      "uri": "*",
                      "regex": ".*",
                      "limit": [{"value": 10,
                                 "verb": "POST",
                                 "remaining": 2,
                                 "unit": "MINUTE",
                                 "next-available": "2011-07-21T18:17:06Z"}]},
                   {"uri": "*/servers",
                    "regex": "^/servers",
                    "limit": [{"value": 50,
                               "verb": "POST",
                               "remaining": 10,
                               "unit": "DAY",
                               "next-available": "2011-07-21T18:17:06Z"}]}],
                "absolute": {"maxServerMeta": 1,
                             "maxImageMeta": 1,
                             "maxPersonality": 5,
                             "maxPersonalitySize": 5}}}

        output = self.view_builder.build(self.rate_limits,
                                         self.absolute_limits)
        self.assertThat(output, matchers.DictMatches(expected_limits))
Пример #13
0
    def test_refresh_connection(self):
        test_bdm = self.driver_classes['snapshot'](self.snapshot_bdm)

        instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
        connector = {'ip': 'fake_ip', 'host': 'fake_host'}
        connection_info = {'data': {'multipath_id': 'fake_multipath_id'}}
        expected_conn_info = {
            'data': {
                'multipath_id': 'fake_multipath_id'
            },
            'serial': 'fake-volume-id-2'
        }

        self.mox.StubOutWithMock(test_bdm._bdm_obj, 'save')

        self.virt_driver.get_volume_connector(instance).AndReturn(connector)
        self.volume_api.initialize_connection(
            self.context, test_bdm.volume_id,
            connector).AndReturn(connection_info)
        test_bdm._bdm_obj.save().AndReturn(None)

        self.mox.ReplayAll()

        test_bdm.refresh_connection_info(self.context, instance,
                                         self.volume_api, self.virt_driver)
        self.assertThat(test_bdm['connection_info'],
                        matchers.DictMatches(expected_conn_info))
Пример #14
0
    def test_get_all_host_states(self):

        context = 'fake_context'

        self.mox.StubOutWithMock(objects.ServiceList, 'get_by_topic')
        self.mox.StubOutWithMock(objects.ComputeNodeList, 'get_all')
        self.mox.StubOutWithMock(host_manager.LOG, 'warning')

        objects.ServiceList.get_by_topic(
            context, CONF.compute_topic).AndReturn(fakes.SERVICES)
        objects.ComputeNodeList.get_all(context).AndReturn(fakes.COMPUTE_NODES)
        # node 3 host physical disk space is greater than database
        host_manager.LOG.warning("Host %(hostname)s has more disk space "
                                 "than database expected (%(physical)sgb >"
                                 " %(database)sgb)",
                                 {'physical': 3333, 'database': 3072,
                                  'hostname': 'node3'})
        # Invalid service
        host_manager.LOG.warning("No service record found for host %(host)s "
                                 "on %(topic)s topic",
                                 {'host': 'fake', 'topic': CONF.compute_topic})
        self.mox.ReplayAll()
        self.host_manager.get_all_host_states(context)
        host_states_map = self.host_manager.host_state_map

        self.assertEqual(len(host_states_map), 4)
        # Check that .service is set properly
        for i in xrange(4):
            compute_node = fakes.COMPUTE_NODES[i]
            host = compute_node['host']
            node = compute_node['hypervisor_hostname']
            state_key = (host, node)
            self.assertEqual(host_states_map[state_key].service,
                    obj_base.obj_to_primitive(fakes.get_service_by_host(host)))
        self.assertEqual(host_states_map[('host1', 'node1')].free_ram_mb,
                         512)
        # 511GB
        self.assertEqual(host_states_map[('host1', 'node1')].free_disk_mb,
                         524288)
        self.assertEqual(host_states_map[('host2', 'node2')].free_ram_mb,
                         1024)
        # 1023GB
        self.assertEqual(host_states_map[('host2', 'node2')].free_disk_mb,
                         1048576)
        self.assertEqual(host_states_map[('host3', 'node3')].free_ram_mb,
                         3072)
        # 3071GB
        self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb,
                         3145728)
        self.assertThat(
                objects.NUMATopology.obj_from_db_obj(
                        host_states_map[('host3', 'node3')].numa_topology
                    )._to_dict(),
                matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict()))
        self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb,
                         8192)
        # 8191GB
        self.assertEqual(host_states_map[('host4', 'node4')].free_disk_mb,
                         8388608)
Пример #15
0
    def test_get_image_meta(self):
        image_meta = compute_utils.get_image_metadata(self.ctx,
                                                      self.mock_image_api,
                                                      'fake-image',
                                                      self.instance_obj)

        self.image['properties'] = 'DONTCARE'
        self.assertThat(self.image, matchers.DictMatches(image_meta))
Пример #16
0
    def test_availability_zone_detail_no_services(self, mock_get_az):
        expected_response = {'availabilityZoneInfo':
                                 [{'zoneState': {'available': True},
                             'hosts': {},
                             'zoneName': 'nova'}]}
        resp_dict = self.controller.detail(self.req)

        self.assertThat(resp_dict,
                        matchers.DictMatches(expected_response))
Пример #17
0
 def test_aggregate_metadata_delete(self):
     result = _create_aggregate(self.context, metadata=None)
     metadata = deepcopy(_get_fake_metadata(1))
     aggregate_obj._metadata_add_to_db(self.context, result['id'], metadata)
     aggregate_obj._metadata_delete_from_db(self.context, result['id'],
                                        list(metadata.keys())[0])
     expected = _aggregate_metadata_get_all(self.context, result['id'])
     del metadata[list(metadata.keys())[0]]
     self.assertThat(metadata, matchers.DictMatches(expected))
Пример #18
0
 def test_failed_action(self):
     body = dict(fail=dict(name="test"))
     url = "/fake/servers/abcd/action"
     response = self._send_server_action_request(url, body)
     self.assertEqual(400, response.status_int)
     self.assertEqual('application/json', response.content_type)
     body = jsonutils.loads(response.body)
     expected = {"badRequest": {"message": "Tweedle fail", "code": 400}}
     self.assertThat(expected, matchers.DictMatches(body))
Пример #19
0
 def test_aggregate_update_zone_with_existing_metadata(self):
     result = _create_aggregate(self.context)
     new_zone = {'availability_zone': 'fake_avail_zone_2'}
     metadata = deepcopy(_get_fake_metadata(1))
     metadata.update(new_zone)
     aggregate_obj._aggregate_update_to_db(self.context, result['id'],
                                           new_zone)
     expected = _aggregate_metadata_get_all(self.context, result['id'])
     self.assertThat(metadata, matchers.DictMatches(expected))
Пример #20
0
    def test_build_limits(self):
        expected_limits = {"limits": {
                "rate": [],
                "absolute": {"maxServerMeta": 1,
                             "maxImageMeta": 1,
                             "maxPersonality": 5,
                             "maxPersonalitySize": 5}}}

        output = self.view_builder.build(self.req, self.absolute_limits)
        self.assertThat(output, matchers.DictMatches(expected_limits))
Пример #21
0
 def test_get_image_details_next_link(self, get_all_mocked):
     request = self.http_request.blank(
         self.url_base + 'images/detail?limit=1')
     response = self.controller.detail(request)
     response_links = response['images_links']
     href_parts = urlparse.urlparse(response_links[0]['href'])
     self.assertEqual(self.url_base + '/images/detail', href_parts.path)
     params = urlparse.parse_qs(href_parts.query)
     self.assertThat({'limit': ['1'], 'marker': [IMAGE_FIXTURES[0]['id']]},
                     matchers.DictMatches(params))
Пример #22
0
 def test_aggregate_update_with_existing_metadata(self):
     result = _create_aggregate(self.context)
     values = deepcopy(_get_fake_aggregate(1, result=False))
     values['metadata'] = deepcopy(_get_fake_metadata(1))
     values['metadata']['fake_key1'] = 'foo'
     expected_metadata = deepcopy(values['metadata'])
     aggregate_obj._aggregate_update_to_db(self.context, result['id'],
                                           values)
     metadata = _aggregate_metadata_get_all(self.context, result['id'])
     self.assertThat(metadata, matchers.DictMatches(expected_metadata))
Пример #23
0
 def test_aggregate_metadata_add_and_update(self):
     result = _create_aggregate(self.context)
     metadata = deepcopy(_get_fake_metadata(1))
     key = list(metadata.keys())[0]
     new_metadata = {key: 'foo', 'fake_new_key': 'fake_new_value'}
     metadata.update(new_metadata)
     aggregate_obj._metadata_add_to_db(self.context, result['id'],
                                       new_metadata)
     expected = _aggregate_metadata_get_all(self.context, result['id'])
     self.assertThat(metadata, matchers.DictMatches(expected))
Пример #24
0
    def _test_driver_device(self, name):
        db_bdm = getattr(self, "%s_bdm" % name)
        test_bdm = self.driver_classes[name](db_bdm)
        self.assertThat(
            test_bdm,
            matchers.DictMatches(getattr(self, "%s_driver_bdm" % name)))

        for k, v in db_bdm.iteritems():
            field_val = getattr(test_bdm._bdm_obj, k)
            if isinstance(field_val, bool):
                v = bool(v)
            self.assertEqual(field_val, v)

        self.assertThat(
            test_bdm.legacy(),
            matchers.DictMatches(getattr(self, "%s_legacy_driver_bdm" % name)))

        # Test passthru attributes
        for passthru in test_bdm._proxy_as_attr:
            self.assertEqual(getattr(test_bdm, passthru),
                             getattr(test_bdm._bdm_obj, passthru))

        # Make sure that all others raise _invalidType
        for other_name, cls in self.driver_classes.iteritems():
            if other_name == name:
                continue
            self.assertRaises(driver_block_device._InvalidType, cls,
                              getattr(self, '%s_bdm' % name))

        # Test the save method
        with mock.patch.object(test_bdm._bdm_obj, 'save') as save_mock:
            test_bdm.save(self.context)
            for fld, alias in test_bdm._update_on_save.iteritems():
                self.assertEqual(test_bdm[alias or fld],
                                 getattr(test_bdm._bdm_obj, fld))

            save_mock.assert_called_once_with(self.context)

        # Test the save method with no context passed
        with mock.patch.object(test_bdm._bdm_obj, 'save') as save_mock:
            test_bdm.save()
            save_mock.assert_called_once_with()
Пример #25
0
 def test_aggregate_metadata_update(self):
     result = _create_aggregate(self.context)
     metadata = deepcopy(_get_fake_metadata(1))
     key = list(metadata.keys())[0]
     aggregate_obj._metadata_delete_from_db(self.context, result['id'], key)
     new_metadata = {key: 'foo'}
     aggregate_obj._metadata_add_to_db(self.context,
                                       result['id'], new_metadata)
     expected = _aggregate_metadata_get_all(self.context, result['id'])
     metadata[key] = 'foo'
     self.assertThat(metadata, matchers.DictMatches(expected))
Пример #26
0
    def _test_get_image_meta_exception(self, error):
        self.mock_image_api.get.side_effect = error

        image_meta = compute_utils.get_image_metadata(
            self.ctx, self.mock_image_api, 'fake-image', self.instance_obj)

        self.image['properties'] = 'DONTCARE'
        # NOTE(danms): The trip through system_metadata will stringify things
        for key in self.image:
            self.image[key] = str(self.image[key])
        self.assertThat(self.image, matchers.DictMatches(image_meta))
Пример #27
0
    def test_multi_choice_server(self):
        uuid = str(stdlib_uuid.uuid4())
        req = webob.Request.blank('/servers/' + uuid)
        req.accept = "application/json"
        res = req.get_response(fakes.wsgi_app())
        self.assertEqual(res.status_int, 300)
        self.assertEqual(res.content_type, "application/json")

        expected = {
            "choices": [
                {
                    "id":
                    "v2.0",
                    "status":
                    "SUPPORTED",
                    "links": [
                        {
                            "href": "http://localhost/v2/servers/" + uuid,
                            "rel": "self",
                        },
                    ],
                    "media-types": [
                        {
                            "base":
                            "application/json",
                            "type":
                            "application/vnd.openstack.compute+json"
                            ";version=2"
                        },
                    ],
                },
                {
                    "id":
                    "v2.1",
                    "status":
                    "CURRENT",
                    "links": [
                        {
                            "href": "http://localhost/v2.1/servers/" + uuid,
                            "rel": "self",
                        },
                    ],
                    "media-types": [{
                        "base":
                        "application/json",
                        "type":
                        "application/vnd.openstack.compute+json;version=2.1",
                    }],
                },
            ],
        }

        self.assertThat(jsonutils.loads(res.body),
                        matchers.DictMatches(expected))
Пример #28
0
    def test_multi_choice_image(self):
        req = fakes.HTTPRequest.blank('/images/1', base_url='')
        req.accept = "application/json"
        res = req.get_response(self.wsgi_app)
        self.assertEqual(300, res.status_int)
        self.assertEqual("application/json", res.content_type)

        expected = {
            "choices": [
                {
                    "id":
                    "v2.0",
                    "status":
                    "SUPPORTED",
                    "links": [
                        {
                            "href": "http://localhost/v2/images/1",
                            "rel": "self",
                        },
                    ],
                    "media-types": [
                        {
                            "base":
                            "application/json",
                            "type":
                            "application/vnd.openstack.compute+json"
                            ";version=2"
                        },
                    ],
                },
                {
                    "id":
                    "v2.1",
                    "status":
                    "CURRENT",
                    "links": [
                        {
                            "href": "http://localhost/v2.1/images/1",
                            "rel": "self",
                        },
                    ],
                    "media-types": [{
                        "base":
                        "application/json",
                        "type":
                        "application/vnd.openstack.compute+json;version=2.1",
                    }],
                },
            ],
        }

        self.assertThat(jsonutils.loads(res.body),
                        matchers.DictMatches(expected))
    def test_get_all_host_states(self):

        context = 'fake_context'

        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        self.mox.StubOutWithMock(host_manager.LOG, 'warn')

        db.compute_node_get_all(context).AndReturn(fakes.COMPUTE_NODES)
        # node 3 host physical disk space is greater than database
        host_manager.LOG.warn(
            _LW("Host %(hostname)s has more disk space than "
                "database expected (%(physical)sgb > "
                "%(database)sgb)"), {
                    'physical': 3333,
                    'database': 3072,
                    'hostname': 'node3'
                })
        # Invalid service
        host_manager.LOG.warn(_LW("No service for compute ID %s"), 5)

        self.mox.ReplayAll()
        self.host_manager.get_all_host_states(context)
        host_states_map = self.host_manager.host_state_map

        self.assertEqual(len(host_states_map), 4)
        # Check that .service is set properly
        for i in xrange(4):
            compute_node = fakes.COMPUTE_NODES[i]
            host = compute_node['service']['host']
            node = compute_node['hypervisor_hostname']
            state_key = (host, node)
            self.assertEqual(host_states_map[state_key].service,
                             compute_node['service'])
        self.assertEqual(host_states_map[('host1', 'node1')].free_ram_mb, 512)
        # 511GB
        self.assertEqual(host_states_map[('host1', 'node1')].free_disk_mb,
                         524288)
        self.assertEqual(host_states_map[('host2', 'node2')].free_ram_mb, 1024)
        # 1023GB
        self.assertEqual(host_states_map[('host2', 'node2')].free_disk_mb,
                         1048576)
        self.assertEqual(host_states_map[('host3', 'node3')].free_ram_mb, 3072)
        # 3071GB
        self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb,
                         3145728)
        self.assertThat(
            hardware.VirtNUMAHostTopology.from_json(
                host_states_map[('host3', 'node3')].numa_topology)._to_dict(),
            matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict()))
        self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb, 8192)
        # 8191GB
        self.assertEqual(host_states_map[('host4', 'node4')].free_disk_mb,
                         8388608)
Пример #30
0
    def test_get_image_meta_no_image_system_meta(self):
        for k in self.instance_obj.system_metadata.keys():
            if k.startswith('image_'):
                del self.instance_obj.system_metadata[k]

        with mock.patch('nova.objects.Flavor.get_by_flavor_id') as get:
            get.return_value = objects.Flavor(extra_specs={})
            image_meta = compute_utils.get_image_metadata(
                self.ctx, self.mock_image_api, 'fake-image', self.instance_obj)

        self.image['properties'] = 'DONTCARE'
        self.assertThat(self.image, matchers.DictMatches(image_meta))