def test_get_by_id(self): self.mox.StubOutWithMock(db, 'compute_node_get') db.compute_node_get(self.context, 123).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode.get_by_id(self.context, 123) self.compare_obj(compute, fake_compute_node, comparators={'stats': self.json_comparator})
def test_get_by_id(self): ctxt = context.get_admin_context() self.mox.StubOutWithMock(db, 'compute_node_get') db.compute_node_get(ctxt, 123).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode.get_by_id(ctxt, 123) self._compare(compute, fake_compute_node)
def test_get_by_id(self): self.mox.StubOutWithMock(db, "compute_node_get") db.compute_node_get(self.context, 123).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode.get_by_id(self.context, 123) self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators()) self.assertNotIn("uuid", compute.obj_what_changed())
def test_get_by_id(self): self.mox.StubOutWithMock(db, 'compute_node_get') db.compute_node_get(self.context, 123).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode.get_by_id(self.context, 123) self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators()) self.assertNotIn('uuid', compute.obj_what_changed())
def test_save_creates_inventories(self, mock_minver): mock_minver.return_value = 7 self.cn.create() inventories = objects.InventoryList.get_all_by_resource_provider_uuid( self.context, self.cn.uuid) self.assertEqual(0, len(inventories)) mock_minver.return_value = 10 self.cn.memory_mb = 2048 self.cn.local_gb = 2000 self.cn.save() self.assertEqual(2048, self.cn.memory_mb) self.assertEqual(2000, self.cn.local_gb) self.assertEqual(8, self.cn.vcpus) db_cn = db.compute_node_get(self.context, self.cn.id) self.assertEqual(0, db_cn['memory_mb']) self.assertEqual(0, db_cn['local_gb']) self.assertEqual(0, db_cn['vcpus']) inventories = objects.InventoryList.get_all_by_resource_provider_uuid( self.context, self.cn.uuid) self.assertEqual(3, len(inventories)) inv = {i.resource_class: i.total for i in inventories} expected = { fields.ResourceClass.DISK_GB: 2000, fields.ResourceClass.MEMORY_MB: 2048, fields.ResourceClass.VCPU: 8, } self.assertEqual(expected, inv)
def create(self): if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') updates = self.obj_get_changes() if 'uuid' not in updates: updates['uuid'] = uuidutils.generate_uuid() self.uuid = updates['uuid'] self._convert_stats_to_db_format(updates) self._convert_host_ip_to_db_format(updates) self._convert_supported_instances_to_db_format(updates) self._convert_pci_stats_to_db_format(updates) if self._should_manage_inventory(): self._create_inventory(updates) db_compute = db.compute_node_create(self._context, updates) # NOTE(danms): compute_node_create() operates on (and returns) the # compute node model only. We need to get the full inventory-based # result in order to satisfy _from_db_object(). So, we do a double # query here. This can be removed in Newton once we're sure that all # compute nodes are inventory-based db_compute = db.compute_node_get(self._context, db_compute['id']) self._from_db_object(self._context, self, db_compute)
def create(self, req, body): ''' :request url: /v2/{tenant_id}/pssr-url/{user_id} :param req: user_id:the user to caculate :param request: input user data :return: ''' import time request = body["pssr_tag"] LOG.info("PssrController pssr_conf,req = %s" % req) LOG.info("PssrController pssr_conf,request = %s" % request) context = req.environ['nova.context'] physerver = request["physerver"] node_id = self.get_node_id_from_name(context, physerver) physerver_name = db.compute_node_get( context, node_id)["host"] #name include domain intf_conf = self.pssr_get_intf_conf(context, node_id, request["name"]) intf_conf = intf_conf["pssr_tag"]["results"] #repeat config or have been config other if intf_conf["network_type"] != "" and request[ "network_type"] != "none": return { "pssr_tag": { "results": "config fail,network have been config" } } if intf_conf["network_type"] == "" and request[ "network_type"] == "none": return {"pssr_tag": {"results": "config fail,repeat config"}} request["last_network_type"] = intf_conf["network_type"] cctxt = rpc.get_client( messaging.Target(topic="compute", server=physerver_name)) cctxt = cctxt.prepare(version='4.11') pid1 = cctxt.call(get_admin_context(), "get_nova_compute_pid", req=request) cctxt.cast(get_admin_context(), "nfvi_pssr_conf", req=request) for i in range(0, 10): time.sleep(1) pid2 = cctxt.call(get_admin_context(), "get_nova_compute_pid", req=request) #LOG.info("PssrController nfvi_pssr_conf,pid1 = %s,pid2 = %s" % (pid1,pid2)) if pid1 == pid2: continue else: results = {"status": "success"} self.pssr_update_intf_conf(context, node_id, intf_conf, request) LOG.info( "PssrController nfvi_pssr_conf,pid2 = %s,results = %s" % (pid2, results)) return {"pssr_tag": {"results": results}} LOG.error("nfvi_pssr_conf get_nova_compute_pid fail,pid2 = %s", pid2) return {"pssr_tag": {"results": "config fail"}}
def show(self, req, resp_obj, id): context = req.environ['nova.context'] resp_obj.attach(xml=PciHypervisorTemplate()) hypervisor = resp_obj.obj['hypervisor'] # TODO(yjiang5): Change to compute node object after that change merged #compute_node = compute_obj.ComputeNode.get_by_id( # context, hypervisor['id']) compute_node = db.compute_node_get(context, hypervisor['id']) self._extend_hypervisor(hypervisor, compute_node)
def show(self, req, id): context = req.environ['nova.context'] authorize(context) try: hyp = db.compute_node_get(context, int(id)) except (ValueError, exception.ComputeHostNotFound): msg = _("Hypervisor with ID '%s' could not be found.") % id raise webob.exc.HTTPNotFound(explanation=msg) return dict(hypervisor=self._view_hypervisor(hyp, True))
def detail(self, req, resp_obj): context = req.environ['nova.context'] hypervisors = list(resp_obj.obj['hypervisors']) for hypervisor in hypervisors: # TODO(yjiang5): Change to compute node object after # that changes merged # compute_node = compute_obj.ComputeNode.get_by_id( # context, hypervisor['id']) compute_node = db.compute_node_get(context, hypervisor['id']) hypervisor['os-pci:pci_stats'] = compute_node['pci_stats']
def test_create_honors_version(self, mock_minver): mock_minver.return_value = 7 self.cn.create() self.assertEqual(512, self.cn.memory_mb) self.assertEqual(1000, self.cn.local_gb) self.assertEqual(8, self.cn.vcpus) db_cn = db.compute_node_get(self.context, self.cn.id) self.assertEqual(512, db_cn['memory_mb']) self.assertEqual(1000, db_cn['local_gb']) self.assertEqual(8, db_cn['vcpus']) inventories = objects.InventoryList.get_all_by_resource_provider_uuid( self.context, self.cn.uuid) self.assertEqual(0, len(inventories))
def uptime(self, req, id): context = req.environ['nova.context'] authorize(context) try: hyp = db.compute_node_get(context, int(id)) except (ValueError, exception.ComputeHostNotFound): msg = _("Hypervisor with ID '%s' could not be found.") % id raise webob.exc.HTTPNotFound(explanation=msg) # Get the uptime try: uptime = self.api.get_host_uptime(context, hyp) except NotImplementedError: msg = _("Virt driver does not implement uptime function.") raise webob.exc.HTTPNotImplemented(explanation=msg) return dict(hypervisor=self._view_hypervisor(hyp, False, uptime=uptime))
def uptime(self, req, id): context = req.environ['nova.context'] authorize(context) try: hyp = db.compute_node_get(context, int(id)) except (ValueError, exception.ComputeHostNotFound): msg = _("Hypervisor with ID '%s' could not be found.") % id raise webob.exc.HTTPNotFound(explanation=msg) # Get the uptime try: uptime = self.api.get_host_uptime(context, hyp) except NotImplementedError: msg = _("Virt driver does not implement uptime function.") raise webob.exc.HTTPNotImplemented(explanation=msg) return dict( hypervisor=self._view_hypervisor(hyp, False, uptime=uptime))
def save(self, prune_stats=False): # NOTE(belliott) ignore prune_stats param, no longer relevant updates = self.obj_get_changes() updates.pop('id', None) self._convert_stats_to_db_format(updates) self._convert_host_ip_to_db_format(updates) self._convert_supported_instances_to_db_format(updates) self._convert_pci_stats_to_db_format(updates) db_compute = db.compute_node_update(self._context, self.id, updates) # NOTE(danms): compute_node_update() operates on (and returns) the # compute node model only. We need to get the full inventory-based # result in order to satisfy _from_db_object(). So, we do a double # query here. This can be removed in Newton once we're sure that all # compute nodes are inventory-based db_compute = db.compute_node_get(self._context, self.id) self._from_db_object(self._context, self, db_compute)
def show(self, req, id): ''' :request url: /v2/{tenant_id}/pssr-url/{user_id} :param req: user_id:the user to caculate :param id: input the tenant_id which the user belong to :return: ''' physerver = req.GET.get("physerver") #name don't include domain dev = req.GET.get("dev") LOG.info("PssrController paras id = %s, physerver=%s, dev=%s" % (id, physerver, dev)) context = req.environ['nova.context'] node_id = self.get_node_id_from_name(context, physerver) if node_id == -1: return { "pssr_tag": { "results": [{ "physerver_type": "not_compute" }] } } physerver_name = db.compute_node_get( context, node_id)["host"] #name include domain cctxt = rpc.get_client( messaging.Target(topic="compute", server=physerver_name)) cctxt = cctxt.prepare(version='4.11') # results = cctxt.cast(get_admin_context(), "ttt", a=1, b=2, c=3, d=4) if id == '1': return self.pssr_get_port_info(context, cctxt, node_id) elif id == '2': return self.pssr_get_intf_info(context, cctxt, node_id) elif id == "11": return self.pssr_get_port_conf(context, node_id, dev) elif id == "21": return self.pssr_get_intf_conf(context, node_id, dev) else: LOG.info("PssrController paras error, id = %s" % id) return {"pssr_tag": {"results": "error"}}
def get_by_id(cls, context, compute_id): db_compute = db.compute_node_get(context, compute_id) return cls._from_db_object(context, cls(), db_compute)