Merge "Remove catching of ComputeHostNotFound exception"
This commit is contained in:
commit
ac367f582c
@ -224,32 +224,8 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
|||||||
|
|
||||||
@base.remotable_classmethod
|
@base.remotable_classmethod
|
||||||
def get_by_host_and_nodename(cls, context, host, nodename):
|
def get_by_host_and_nodename(cls, context, host, nodename):
|
||||||
try:
|
db_compute = db.compute_node_get_by_host_and_nodename(
|
||||||
db_compute = db.compute_node_get_by_host_and_nodename(
|
context, host, nodename)
|
||||||
context, host, nodename)
|
|
||||||
except exception.ComputeHostNotFound:
|
|
||||||
# FIXME(sbauza): Some old computes can still have no host record
|
|
||||||
# We need to provide compatibility by using the old service_id
|
|
||||||
# record.
|
|
||||||
# We assume the compatibility as an extra penalty of one more DB
|
|
||||||
# call but that's necessary until all nodes are upgraded.
|
|
||||||
try:
|
|
||||||
service = objects.Service.get_by_compute_host(context, host)
|
|
||||||
db_computes = db.compute_nodes_get_by_service_id(
|
|
||||||
context, service.id)
|
|
||||||
except exception.ServiceNotFound:
|
|
||||||
# We need to provide the same exception upstream
|
|
||||||
raise exception.ComputeHostNotFound(host=host)
|
|
||||||
db_compute = None
|
|
||||||
for compute in db_computes:
|
|
||||||
if compute['hypervisor_hostname'] == nodename:
|
|
||||||
db_compute = compute
|
|
||||||
# We can avoid an extra call to Service object in
|
|
||||||
# _from_db_object
|
|
||||||
db_compute['host'] = service.host
|
|
||||||
break
|
|
||||||
if not db_compute:
|
|
||||||
raise exception.ComputeHostNotFound(host=host)
|
|
||||||
return cls._from_db_object(context, cls(), db_compute)
|
return cls._from_db_object(context, cls(), db_compute)
|
||||||
|
|
||||||
@base.remotable_classmethod
|
@base.remotable_classmethod
|
||||||
@ -391,25 +367,7 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
|
|||||||
|
|
||||||
@base.remotable_classmethod
|
@base.remotable_classmethod
|
||||||
def get_all_by_host(cls, context, host, use_slave=False):
|
def get_all_by_host(cls, context, host, use_slave=False):
|
||||||
try:
|
db_computes = db.compute_node_get_all_by_host(context, host,
|
||||||
db_computes = db.compute_node_get_all_by_host(context, host,
|
use_slave)
|
||||||
use_slave)
|
|
||||||
except exception.ComputeHostNotFound:
|
|
||||||
# FIXME(sbauza): Some old computes can still have no host record
|
|
||||||
# We need to provide compatibility by using the old service_id
|
|
||||||
# record.
|
|
||||||
# We assume the compatibility as an extra penalty of one more DB
|
|
||||||
# call but that's necessary until all nodes are upgraded.
|
|
||||||
try:
|
|
||||||
service = objects.Service.get_by_compute_host(context, host,
|
|
||||||
use_slave)
|
|
||||||
db_computes = db.compute_nodes_get_by_service_id(
|
|
||||||
context, service.id)
|
|
||||||
except exception.ServiceNotFound:
|
|
||||||
# We need to provide the same exception upstream
|
|
||||||
raise exception.ComputeHostNotFound(host=host)
|
|
||||||
# We can avoid an extra call to Service object in _from_db_object
|
|
||||||
for db_compute in db_computes:
|
|
||||||
db_compute['host'] = service.host
|
|
||||||
return base.obj_make_list(context, cls(context), objects.ComputeNode,
|
return base.obj_make_list(context, cls(context), objects.ComputeNode,
|
||||||
db_computes)
|
db_computes)
|
||||||
|
@ -194,77 +194,6 @@ class _TestComputeNodeObject(object):
|
|||||||
subs=self.subs(),
|
subs=self.subs(),
|
||||||
comparators=self.comparators())
|
comparators=self.comparators())
|
||||||
|
|
||||||
@mock.patch('nova.objects.Service.get_by_id')
|
|
||||||
@mock.patch('nova.db.compute_nodes_get_by_service_id')
|
|
||||||
@mock.patch('nova.objects.Service.get_by_compute_host')
|
|
||||||
@mock.patch.object(db, 'compute_node_get_by_host_and_nodename')
|
|
||||||
def test_get_by_host_and_nodename_with_old_compute(self, cn_get_by_h_and_n,
|
|
||||||
svc_get_by_ch,
|
|
||||||
cn_get_by_svc_id,
|
|
||||||
svc_get_by_id):
|
|
||||||
cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound(
|
|
||||||
host='fake')
|
|
||||||
fake_service = service.Service(id=123)
|
|
||||||
fake_service.host = 'fake'
|
|
||||||
svc_get_by_ch.return_value = fake_service
|
|
||||||
cn_get_by_svc_id.return_value = [fake_old_compute_node]
|
|
||||||
svc_get_by_id.return_value = fake_service
|
|
||||||
|
|
||||||
compute = compute_node.ComputeNode.get_by_host_and_nodename(
|
|
||||||
self.context, 'fake', 'vm.danplanet.com')
|
|
||||||
# NOTE(sbauza): Result is still converted to new style Compute
|
|
||||||
self.compare_obj(compute, fake_compute_node,
|
|
||||||
subs=self.subs(),
|
|
||||||
comparators=self.comparators())
|
|
||||||
|
|
||||||
@mock.patch('nova.objects.Service.get_by_id')
|
|
||||||
@mock.patch('nova.db.compute_nodes_get_by_service_id')
|
|
||||||
@mock.patch('nova.objects.Service.get_by_compute_host')
|
|
||||||
@mock.patch.object(db, 'compute_node_get_by_host_and_nodename')
|
|
||||||
def test_get_by_host_and_nodename_not_found(self, cn_get_by_h_and_n,
|
|
||||||
svc_get_by_ch,
|
|
||||||
cn_get_by_svc_id,
|
|
||||||
svc_get_by_id):
|
|
||||||
cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound(
|
|
||||||
host='fake')
|
|
||||||
fake_service = service.Service(id=123)
|
|
||||||
fake_service.host = 'fake'
|
|
||||||
another_node = fake_old_compute_node.copy()
|
|
||||||
another_node['hypervisor_hostname'] = 'elsewhere'
|
|
||||||
svc_get_by_ch.return_value = fake_service
|
|
||||||
cn_get_by_svc_id.return_value = [another_node]
|
|
||||||
svc_get_by_id.return_value = fake_service
|
|
||||||
|
|
||||||
self.assertRaises(exception.ComputeHostNotFound,
|
|
||||||
compute_node.ComputeNode.get_by_host_and_nodename,
|
|
||||||
self.context, 'fake', 'vm.danplanet.com')
|
|
||||||
|
|
||||||
@mock.patch('nova.objects.Service.get_by_id')
|
|
||||||
@mock.patch('nova.db.compute_nodes_get_by_service_id')
|
|
||||||
@mock.patch('nova.objects.Service.get_by_compute_host')
|
|
||||||
@mock.patch.object(db, 'compute_node_get_by_host_and_nodename')
|
|
||||||
def test_get_by_host_and_nodename_good_and_bad(self, cn_get_by_h_and_n,
|
|
||||||
svc_get_by_ch,
|
|
||||||
cn_get_by_svc_id,
|
|
||||||
svc_get_by_id):
|
|
||||||
cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound(
|
|
||||||
host='fake')
|
|
||||||
fake_service = service.Service(id=123)
|
|
||||||
fake_service.host = 'fake'
|
|
||||||
bad_node = fake_old_compute_node.copy()
|
|
||||||
bad_node['hypervisor_hostname'] = 'elsewhere'
|
|
||||||
good_node = fake_old_compute_node.copy()
|
|
||||||
svc_get_by_ch.return_value = fake_service
|
|
||||||
cn_get_by_svc_id.return_value = [bad_node, good_node]
|
|
||||||
svc_get_by_id.return_value = fake_service
|
|
||||||
|
|
||||||
compute = compute_node.ComputeNode.get_by_host_and_nodename(
|
|
||||||
self.context, 'fake', 'vm.danplanet.com')
|
|
||||||
# NOTE(sbauza): Result is still converted to new style Compute
|
|
||||||
self.compare_obj(compute, good_node,
|
|
||||||
subs=self.subs(),
|
|
||||||
comparators=self.comparators())
|
|
||||||
|
|
||||||
@mock.patch('nova.db.compute_node_get_all_by_host')
|
@mock.patch('nova.db.compute_node_get_all_by_host')
|
||||||
def test_get_first_node_by_host_for_old_compat(
|
def test_get_first_node_by_host_for_old_compat(
|
||||||
self, cn_get_all_by_host):
|
self, cn_get_all_by_host):
|
||||||
@ -404,30 +333,6 @@ class _TestComputeNodeObject(object):
|
|||||||
subs=self.subs(),
|
subs=self.subs(),
|
||||||
comparators=self.comparators())
|
comparators=self.comparators())
|
||||||
|
|
||||||
@mock.patch('nova.objects.Service.get_by_id')
|
|
||||||
@mock.patch('nova.db.compute_nodes_get_by_service_id')
|
|
||||||
@mock.patch('nova.objects.Service.get_by_compute_host')
|
|
||||||
@mock.patch('nova.db.compute_node_get_all_by_host')
|
|
||||||
def test_get_all_by_host_with_old_compute(self, cn_get_all_by_host,
|
|
||||||
svc_get_by_ch,
|
|
||||||
cn_get_by_svc_id,
|
|
||||||
svc_get_by_id):
|
|
||||||
cn_get_all_by_host.side_effect = exception.ComputeHostNotFound(
|
|
||||||
host='fake')
|
|
||||||
fake_service = service.Service(id=123)
|
|
||||||
fake_service.host = 'fake'
|
|
||||||
svc_get_by_ch.return_value = fake_service
|
|
||||||
cn_get_by_svc_id.return_value = [fake_old_compute_node]
|
|
||||||
svc_get_by_id.return_value = fake_service
|
|
||||||
|
|
||||||
computes = compute_node.ComputeNodeList.get_all_by_host(self.context,
|
|
||||||
'fake')
|
|
||||||
self.assertEqual(1, len(computes))
|
|
||||||
# NOTE(sbauza): Result is still converted to new style Compute
|
|
||||||
self.compare_obj(computes[0], fake_compute_node,
|
|
||||||
subs=self.subs(),
|
|
||||||
comparators=self.comparators())
|
|
||||||
|
|
||||||
def test_compat_numa_topology(self):
|
def test_compat_numa_topology(self):
|
||||||
compute = compute_node.ComputeNode()
|
compute = compute_node.ComputeNode()
|
||||||
versions = ovo_base.obj_tree_get_versions('ComputeNode')
|
versions = ovo_base.obj_tree_get_versions('ComputeNode')
|
||||||
|
Loading…
Reference in New Issue
Block a user