def test_instance_get_all_by_host(self): self.mox.StubOutWithMock(db, "instance_get_all_by_host") self.mox.StubOutWithMock(db, "instance_get_all_by_host_and_node") db.instance_get_all_by_host(self.context.elevated(), "host").AndReturn("result") db.instance_get_all_by_host_and_node(self.context.elevated(), "host", "node").AndReturn("result") self.mox.ReplayAll() result = self.conductor.instance_get_all_by_host(self.context, "host") self.assertEqual(result, "result") result = self.conductor.instance_get_all_by_host(self.context, "host", "node") self.assertEqual(result, "result")
def test_get_by_host_and_node(self): fakes = [self.fake_instance(1), self.fake_instance(2)] self.mox.StubOutWithMock(db, "instance_get_all_by_host_and_node") db.instance_get_all_by_host_and_node(self.context, "foo", "bar").AndReturn(fakes) self.mox.ReplayAll() inst_list = instance.InstanceList.get_by_host_and_node(self.context, "foo", "bar") for i in range(0, len(fakes)): self.assertIsInstance(inst_list.objects[i], instance.Instance) self.assertEqual(inst_list.objects[i].uuid, fakes[i]["uuid"]) self.assertRemotes()
def test_get_by_host_and_node(self): fakes = [self.fake_instance(1), self.fake_instance(2)] self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node') db.instance_get_all_by_host_and_node(self.context, 'foo', 'bar').AndReturn(fakes) self.mox.ReplayAll() inst_list = instance.InstanceList.get_by_host_and_node( self.context, 'foo', 'bar') for i in range(0, len(fakes)): self.assertIsInstance(inst_list.objects[i], instance.Instance) self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid']) self.assertRemotes()
def test_instance_get_all_by_host(self): self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node') db.instance_get_all_by_host(self.context.elevated(), 'host').AndReturn('result') db.instance_get_all_by_host_and_node(self.context.elevated(), 'host', 'node').AndReturn('result') self.mox.ReplayAll() result = self.conductor.instance_get_all_by_host(self.context, 'host') self.assertEqual(result, 'result') result = self.conductor.instance_get_all_by_host( self.context, 'host', 'node') self.assertEqual(result, 'result')
def test_instance_get_all_by_host(self): self.mox.StubOutWithMock(db, 'instance_get_all_by_host') self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node') db.instance_get_all_by_host(self.context.elevated(), 'host').AndReturn('result') db.instance_get_all_by_host_and_node(self.context.elevated(), 'host', 'node').AndReturn('result') self.mox.ReplayAll() result = self.conductor.instance_get_all_by_host(self.context, 'host') self.assertEqual(result, 'result') result = self.conductor.instance_get_all_by_host(self.context, 'host', 'node') self.assertEqual(result, 'result')
def test_get_by_host_and_node(self): fakes = [self.fake_instance(1), self.fake_instance(2)] self.mox.StubOutWithMock(db, 'instance_get_all_by_host_and_node') db.instance_get_all_by_host_and_node(self.context, 'foo', 'bar' ).AndReturn(fakes) self.mox.ReplayAll() inst_list = instance.InstanceList.get_by_host_and_node(self.context, 'foo', 'bar') for i in range(0, len(fakes)): self.assertTrue(isinstance(inst_list.objects[i], instance.Instance)) self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid']) self.assertRemotes()
def update_available_resource(self, context): """Override in-memory calculations of compute node resource usage based on data audited from the hypervisor layer. Add in resource claims in progress to account for operations that have declared a need for resources, but not necessarily retrieved them from the hypervisor layer yet. """ resources = self.driver.get_available_resource(self.nodename) if not resources: # The virt driver does not support this function LOG.audit(_("Virt driver does not support " "'get_available_resource' Compute tracking is disabled.")) self.compute_node = None return self._verify_resources(resources) self._report_hypervisor_resource_view(resources) # Grab all instances assigned to this node: instances = db.instance_get_all_by_host_and_node(context, self.host, self.nodename) # Now calculate usage based on instance utilization: self._update_usage_from_instances(resources, instances) self._report_final_resource_view(resources) self._sync_compute_node(context, resources)
def get_by_host_and_node(cls, context, host, node, expected_attrs=None): db_inst_list = db.instance_get_all_by_host_and_node( context, host, node, columns_to_join=_expected_cols(expected_attrs)) return _make_instance_list(context, cls(), db_inst_list, expected_attrs)
def update_available_resource(self, context): """Override in-memory calculations of compute node resource usage based on data audited from the hypervisor layer. Add in resource claims in progress to account for operations that have declared a need for resources, but not necessarily retrieved them from the hypervisor layer yet. """ LOG.audit(_("Auditing locally available compute resources")) resources = self.driver.get_available_resource(self.nodename) if not resources: # The virt driver does not support this function LOG.audit( _("Virt driver does not support " "'get_available_resource' Compute tracking is disabled.")) self.compute_node = None return self._verify_resources(resources) self._report_hypervisor_resource_view(resources) # Grab all instances assigned to this node: instances = db.instance_get_all_by_host_and_node( context, self.host, self.nodename) # Now calculate usage based on instance utilization: self._update_usage_from_instances(resources, instances) # Grab all in-progress migrations: migrations = db.migration_get_in_progress_by_host_and_node( context, self.host, self.nodename) self._update_usage_from_migrations(resources, migrations) # Detect and account for orphaned instances that may exist on the # hypervisor, but are not in the DB: orphans = self._find_orphaned_instances() self._update_usage_from_orphans(resources, orphans) self._report_final_resource_view(resources) self._sync_compute_node(context, resources)
def get_by_host_and_node(cls, context, host, node, expected_attrs=None): db_inst_list = db.instance_get_all_by_host_and_node( context, host, node) return _make_instance_list(context, cls(), db_inst_list, expected_attrs)