def test_compute_node_update(self): node = {"id": "fake-id"} self.mox.StubOutWithMock(db, "compute_node_update") db.compute_node_update(self.context, node["id"], "fake-values", False).AndReturn("fake-result") self.mox.ReplayAll() result = self.conductor.compute_node_update(self.context, node, "fake-values", False) self.assertEqual(result, "fake-result")
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-coompute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ dic = self._max_phy_resouces(ctxt) #dic = self._sum_phy_hosts(ctxt) dic['hypervisor_type'] = 'physical' dic['hypervisor_version'] = 1 dic['cpu_info'] = 'physical cpu' try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) dic['service_id'] = service_ref['id'] compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-coompute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ dic = self._max_baremetal_resources(ctxt) #dic = self._sum_baremetal_resources(ctxt) dic['hypervisor_type'] = self.get_hypervisor_type() dic['hypervisor_version'] = self.get_hypervisor_version() dic['cpu_info'] = 'baremetal cpu' try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) dic['service_id'] = service_ref['id'] compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. Since we don't have a real hypervisor, pretend we have lots of disk and ram. """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = { "vcpus": 1, "memory_mb": 4096, "local_gb": 1028, "vcpus_used": 0, "memory_mb_used": 0, "local_gb_used": 0, "hypervisor_type": "fake", "hypervisor_version": "1.0", "service_id": service_ref["id"], "cpu_info": "?", } compute_node_ref = service_ref["compute_node"] if not compute_node_ref: LOG.info(_("Compute_service record created for %s ") % host) db.compute_node_create(ctxt, dic) else: LOG.info(_("Compute_service record updated for %s ") % host) db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. Since we don't have a real hypervisor, pretend we have lots of disk and ram. """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = {'vcpus': 1, 'memory_mb': 4096, 'local_gb': 1028, 'vcpus_used': 0, 'memory_mb_used': 0, 'local_gb_used': 0, 'hypervisor_type': 'fake', 'hypervisor_version': '1.0', 'service_id': service_ref['id'], 'cpu_info': '?'} compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. Since we don't have a real hypervisor, pretend we have lots of disk and ram. """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = { 'vcpus': 1, 'memory_mb': 4096, 'local_gb': 1028, 'vcpus_used': 0, 'memory_mb_used': 0, 'local_gb_used': 0, 'hypervisor_type': 'fake', 'hypervisor_version': '1.0', 'service_id': service_ref['id'], 'cpu_info': '?' } compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def test_compute_node_update(self): node = {'id': 'fake-id'} self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update(self.context, node['id'], 'fake-values', False).AndReturn('fake-result') self.mox.ReplayAll() result = self.conductor.compute_node_update(self.context, node, 'fake-values', False) self.assertEqual(result, 'fake-result')
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update(self.context, 123, {'vcpus_used': 3}, prune_stats=False ).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode() compute.id = 123 compute.vcpus_used = 3 compute.save(self.context) self.compare_obj(compute, fake_compute_node)
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update(self.context, 123, {'vcpus_used': 3}, prune_stats=False ).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode() compute.id = 123 compute.vcpus_used = 3 compute.save(self.context) self._compare(compute, fake_compute_node)
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update(self.context, 123, {'vcpus_used': 3}).\ AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode() compute.id = 123 compute.vcpus_used = 3 compute.save(self.context) self.compare_obj(compute, fake_compute_node, comparators={'stats': self.json_comparator})
def test_compute_node_stat_prune(self): item = self._create_helper("host1") for stat in item["stats"]: if stat["key"] == "num_instances": num_instance_stat = stat break values = {"stats": dict(num_instances=1)} db.compute_node_update(self.ctxt, item["id"], values, prune_stats=True) item = db.compute_node_get_all(self.ctxt)[0] self.assertEqual(1, len(item["stats"])) stat = item["stats"][0] self.assertEqual(num_instance_stat["id"], stat["id"]) self.assertEqual(num_instance_stat["key"], stat["key"]) self.assertEqual(1, int(stat["value"]))
def save(self, context, prune_stats=False): updates = {} for key in self.obj_what_changed(): updates[key] = self[key] updates.pop("id", None) db_compute = db.compute_node_update(context, self.id, updates, prune_stats=prune_stats) self._from_db_object(context, self, db_compute)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-coompute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = { "vcpus": self.get_vcpu_total(), "memory_mb": self.get_memory_mb_total(), "local_gb": self.get_local_gb_total(), "vcpus_used": self.get_vcpu_used(), "memory_mb_used": self.get_memory_mb_used(), "local_gb_used": self.get_local_gb_used(), "hypervisor_type": self.get_hypervisor_type(), "hypervisor_version": self.get_hypervisor_version(), "cpu_info": self.get_cpu_info(), "cpu_arch": FLAGS.cpu_arch, "xpu_arch": FLAGS.xpu_arch, "xpus": FLAGS.xpus, "xpu_info": FLAGS.xpu_info, "net_arch": FLAGS.net_arch, "net_info": FLAGS.net_info, "net_mbps": FLAGS.net_mbps, "service_id": service_ref["id"], } compute_node_ref = service_ref["compute_node"] LOG.info(_("#### RLK: cpu_arch = %s ") % FLAGS.cpu_arch) if not compute_node_ref: LOG.info(_("Compute_service record created for %s ") % host) dic["service_id"] = service_ref["id"] db.compute_node_create(ctxt, dic) else: LOG.info(_("Compute_service record updated for %s ") % host) db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
def _capture_dom0_hostname(self): """Find dom0's hostname and log it to the DB.""" ctxt = context.get_admin_context() service = db.service_get_by_host_and_topic(ctxt, FLAGS.host, "compute") try: compute_node = db.compute_node_get_for_service(ctxt, service["id"]) except TypeError: return host_stats = self.get_host_stats() db.compute_node_update( ctxt, compute_node["id"], {"hypervisor_hostname": host_stats["host_hostname"]}, auto_adjust=False)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-coompute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = { 'vcpus': self.get_vcpu_total(), 'memory_mb': self.get_memory_mb_total(), 'local_gb': self.get_local_gb_total(), 'vcpus_used': self.get_vcpu_used(), 'memory_mb_used': self.get_memory_mb_used(), 'local_gb_used': self.get_local_gb_used(), 'hypervisor_type': self.get_hypervisor_type(), 'hypervisor_version': self.get_hypervisor_version(), 'cpu_info': self.get_cpu_info(), 'cpu_arch': FLAGS.cpu_arch, 'xpu_arch': FLAGS.xpu_arch, 'xpus': FLAGS.xpus, 'xpu_info': FLAGS.xpu_info, 'net_arch': FLAGS.net_arch, 'net_info': FLAGS.net_info, 'net_mbps': FLAGS.net_mbps, 'service_id': service_ref['id'] } compute_node_ref = service_ref['compute_node'] LOG.info(_('#### RLK: cpu_arch = %s ') % FLAGS.cpu_arch) if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) dic['service_id'] = service_ref['id'] db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def save(self, context, prune_stats=False): updates = {} for key in self.obj_what_changed(): updates[key] = self[key] updates.pop('id', None) db_compute = db.compute_node_update(context, self.id, updates, prune_stats=prune_stats) self._from_db_object(context, self, db_compute)
def save(self, context, prune_stats=False): updates = self.obj_get_changes() updates.pop('id', None) db_compute = db.compute_node_update(context, self.id, updates, prune_stats=prune_stats) self._from_db_object(context, self, db_compute)
def test_compute_node_stat_prune(self): item = self._create_helper('host1') for stat in item['stats']: if stat['key'] == 'num_instances': num_instance_stat = stat break values = { 'stats': dict(num_instances=1) } db.compute_node_update(self.ctxt, item['id'], values, prune_stats=True) item = db.compute_node_get_all(self.ctxt)[0] self.assertEqual(1, len(item['stats'])) stat = item['stats'][0] self.assertEqual(num_instance_stat['id'], stat['id']) self.assertEqual(num_instance_stat['key'], stat['key']) self.assertEqual(1, int(stat['value']))
def save(self, context, 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) db_compute = db.compute_node_update(context, self.id, updates) self._from_db_object(context, self, db_compute)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-compute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) host_stats = self.get_host_stats(refresh=True) # Updating host information total_ram_mb = host_stats['host_memory_total'] / (1024 * 1024) free_ram_mb = host_stats['host_memory_free'] / (1024 * 1024) total_disk_gb = host_stats['disk_total'] / (1024 * 1024 * 1024) used_disk_gb = host_stats['disk_used'] / (1024 * 1024 * 1024) dic = { 'vcpus': 0, 'memory_mb': total_ram_mb, 'local_gb': total_disk_gb, 'vcpus_used': 0, 'memory_mb_used': total_ram_mb - free_ram_mb, 'local_gb_used': used_disk_gb, 'hypervisor_type': 'xen', 'hypervisor_version': 0, 'cpu_info': host_stats['host_cpu_info']['cpu_count'] } compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) dic['service_id'] = service_ref['id'] db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-compute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) host_stats = self.get_host_stats(refresh=True) # Updating host information total_ram_mb = host_stats["host_memory_total"] / (1024 * 1024) free_ram_mb = host_stats["host_memory_free"] / (1024 * 1024) total_disk_gb = host_stats["disk_total"] / (1024 * 1024 * 1024) used_disk_gb = host_stats["disk_used"] / (1024 * 1024 * 1024) dic = { "vcpus": 0, "memory_mb": total_ram_mb, "local_gb": total_disk_gb, "vcpus_used": 0, "memory_mb_used": total_ram_mb - free_ram_mb, "local_gb_used": used_disk_gb, "hypervisor_type": "xen", "hypervisor_version": 0, "hypervisor_hostname": host_stats["host_hostname"], "service_id": service_ref["id"], "cpu_info": host_stats["host_cpu_info"]["cpu_count"], } compute_node_ref = service_ref["compute_node"] if not compute_node_ref: LOG.info(_("Compute_service record created for %s ") % host) db.compute_node_create(ctxt, dic) else: LOG.info(_("Compute_service record updated for %s ") % host) db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-coompute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information dic = {'vcpus': self.get_vcpu_total(), 'memory_mb': self.get_memory_mb_total(), 'local_gb': self.get_local_gb_total(), 'vcpus_used': self.get_vcpu_used(), 'memory_mb_used': self.get_memory_mb_used(), 'local_gb_used': self.get_local_gb_used(), 'hypervisor_type': self.get_hypervisor_type(), 'hypervisor_version': self.get_hypervisor_version(), 'cpu_info': self.get_cpu_info(), 'cpu_arch': FLAGS.cpu_arch, 'xpu_arch': FLAGS.xpu_arch, 'xpus': FLAGS.xpus, 'xpu_info': FLAGS.xpu_info, 'net_arch': FLAGS.net_arch, 'net_info': FLAGS.net_info, 'net_mbps': FLAGS.net_mbps, 'service_id': service_ref['id']} compute_node_ref = service_ref['compute_node'] LOG.info(_('#### RLK: cpu_arch = %s ') % FLAGS.cpu_arch) if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) dic['service_id'] = service_ref['id'] db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def update_available_resource(self, ctxt, host): """Updates compute manager resource info on ComputeNode table. This method is called when nova-compute launches, and whenever admin executes "nova-manage service update_resource". :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(ctxt, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) host_stats = self.get_host_stats(refresh=True) # Updating host information total_ram_mb = host_stats['host_memory_total'] / (1024 * 1024) free_ram_mb = host_stats['host_memory_free'] / (1024 * 1024) total_disk_gb = host_stats['disk_total'] / (1024 * 1024 * 1024) used_disk_gb = host_stats['disk_used'] / (1024 * 1024 * 1024) dic = {'vcpus': 0, 'memory_mb': total_ram_mb, 'local_gb': total_disk_gb, 'vcpus_used': 0, 'memory_mb_used': total_ram_mb - free_ram_mb, 'local_gb_used': used_disk_gb, 'hypervisor_type': 'xen', 'hypervisor_version': 0, 'hypervisor_hostname': host_stats['host_hostname'], 'service_id': service_ref['id'], 'cpu_info': host_stats['host_cpu_info']['cpu_count']} compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(ctxt, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
def save(self, context, prune_stats=False): # NOTE(belliott) ignore prune_stats param, no longer relevant updates = self.obj_get_changes() updates.pop('id', None) stats = updates.pop('stats', None) if stats is not None: updates['stats'] = jsonutils.dumps(stats) db_compute = db.compute_node_update(context, self.id, updates) self._from_db_object(context, self, db_compute)
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update( self.context, 123, { 'vcpus_used': 3, 'stats': fake_stats_db_format, 'host_ip': fake_host_ip, }).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode() compute.id = 123 compute.vcpus_used = 3 compute.stats = fake_stats # NOTE (pmurray): host_ip is coerced to an IPAddress compute.host_ip = fake_host_ip compute.save(self.context) self.compare_obj(compute, fake_compute_node, comparators={'stats': self.json_comparator, 'host_ip': self.str_comparator})
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) self._from_db_object(self._context, self, db_compute)
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update( self.context, 123, { 'vcpus_used': 3, 'stats': fake_stats_db_format, 'host_ip': fake_host_ip, 'supported_instances': fake_supported_hv_specs_db_format, }).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode(context=self.context) compute.id = 123 compute.vcpus_used = 3 compute.stats = fake_stats # NOTE (pmurray): host_ip is coerced to an IPAddress compute.host_ip = fake_host_ip compute.supported_hv_specs = fake_supported_hv_specs compute.save() self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
def update_available_resource(self, context, host): """Updates compute manager resource info on ComputeNode table. This method is called as an periodic tasks and is used only in live migration currently. :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(context, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information # TODO(alexpilotti) implemented cpu_info dic = { 'vcpus': self._get_vcpu_total(), 'memory_mb': self._get_memory_mb_total(), 'local_gb': self._get_local_gb_total(), 'vcpus_used': self._get_vcpu_used(), 'memory_mb_used': self._get_memory_mb_used(), 'local_gb_used': self._get_local_gb_used(), 'hypervisor_type': "hyperv", 'hypervisor_version': self._get_hypervisor_version(), 'cpu_info': "unknown", 'service_id': service_ref['id'], 'disk_available_least': 1 } compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(context, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(context, compute_node_ref[0]['id'], dic)
def test_save(self): self.mox.StubOutWithMock(db, "compute_node_update") db.compute_node_update( self.context, 123, { "vcpus_used": 3, "stats": fake_stats_db_format, "host_ip": fake_host_ip, "supported_instances": fake_supported_hv_specs_db_format, }, ).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode(context=self.context) compute.id = 123 compute.vcpus_used = 3 compute.stats = fake_stats # NOTE (pmurray): host_ip is coerced to an IPAddress compute.host_ip = fake_host_ip compute.supported_hv_specs = fake_supported_hv_specs compute.save() self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
def update_available_resource(self, context, host): """Updates compute manager resource info on ComputeNode table. This method is called as an periodic tasks and is used only in live migration currently. :param ctxt: security context :param host: hostname that compute manager is currently running """ try: service_ref = db.service_get_all_compute_by_host(context, host)[0] except exception.NotFound: raise exception.ComputeServiceUnavailable(host=host) # Updating host information # TODO(alexpilotti) implemented cpu_info dic = {'vcpus': self._get_vcpu_total(), 'memory_mb': self._get_memory_mb_total(), 'local_gb': self._get_local_gb_total(), 'vcpus_used': self._get_vcpu_used(), 'memory_mb_used': self._get_memory_mb_used(), 'local_gb_used': self._get_local_gb_used(), 'hypervisor_type': "hyperv", 'hypervisor_version': self._get_hypervisor_version(), 'cpu_info': "unknown", 'service_id': service_ref['id'], 'disk_available_least': 1} compute_node_ref = service_ref['compute_node'] if not compute_node_ref: LOG.info(_('Compute_service record created for %s ') % host) db.compute_node_create(context, dic) else: LOG.info(_('Compute_service record updated for %s ') % host) db.compute_node_update(context, compute_node_ref[0]['id'], dic)
def test_save(self): self.mox.StubOutWithMock(db, 'compute_node_update') db.compute_node_update( self.context, 123, { 'vcpus_used': 3, 'stats': fake_stats_db_format, 'host_ip': fake_host_ip, 'supported_instances': fake_supported_hv_specs_db_format, 'uuid': uuidsentinel.fake_compute_node, }).AndReturn(fake_compute_node) self.mox.ReplayAll() compute = compute_node.ComputeNode(context=self.context) compute.id = 123 compute.vcpus_used = 3 compute.stats = fake_stats compute.uuid = uuidsentinel.fake_compute_node # NOTE (pmurray): host_ip is coerced to an IPAddress compute.host_ip = fake_host_ip compute.supported_hv_specs = fake_supported_hv_specs compute.save() self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
def test_compute_node_update(self): item = self._create_helper("host1") compute_node_id = item["id"] stats = self._stats_as_dict(item["stats"]) # change some values: stats["num_instances"] = 8 stats["num_tribbles"] = 1 values = {"vcpus": 4, "stats": stats} item = db.compute_node_update(self.ctxt, compute_node_id, values) stats = self._stats_as_dict(item["stats"]) self.assertEqual(4, item["vcpus"]) self.assertEqual(8, int(stats["num_instances"])) self.assertEqual(2, int(stats["num_proj_12345"])) self.assertEqual(1, int(stats["num_tribbles"]))
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 test_compute_node_update(self): item = self._create_helper('host1') compute_node_id = item['id'] stats = self._stats_as_dict(item['stats']) # change some values: stats['num_instances'] = 8 stats['num_tribbles'] = 1 values = { 'vcpus': 4, 'stats': stats, } item = db.compute_node_update(self.ctxt, compute_node_id, values) stats = self._stats_as_dict(item['stats']) self.assertEqual(4, item['vcpus']) self.assertEqual(8, int(stats['num_instances'])) self.assertEqual(2, int(stats['num_proj_12345'])) self.assertEqual(1, int(stats['num_tribbles']))
def _update(self, context, values, prune_stats=False): """Persist the compute node updates to the DB""" return db.compute_node_update(context, self.compute_node["id"], values, prune_stats)
def _update(self, context, values, prune_stats=False): """Persist the compute node updates to the DB""" compute_node = db.compute_node_update(context, self.compute_node['id'], values, prune_stats) self.compute_node = dict(compute_node)
def save(self, context, prune_stats=False): updates = self.obj_get_changes() updates.pop("id", None) db_compute = db.compute_node_update(context, self.id, updates, prune_stats=prune_stats) self._from_db_object(context, self, db_compute)