Remove compute_node from service_get_by_cn Cells API method

As now all the calls to this method are no longer using the compute_node field,
we can safely remove it from what is returned as the behavioural change won't
impact the consumers.

Partially-Implements: blueprint detach-service-from-computenode

Change-Id: I5da325ed4c5ff30f4d062aa7caa92bd3c7a2f4f6
This commit is contained in:
Sylvain Bauza 2015-02-24 09:44:05 +01:00
parent fe1a8fe67d
commit 8a90a0186e
2 changed files with 15 additions and 49 deletions

View File

@ -477,33 +477,6 @@ class ComputeCellsAPI(compute_api.API):
class ServiceProxy(object):
def __init__(self, obj, cell_path, compute_node=None):
self._obj = obj
self._cell_path = cell_path
self._compute_node = compute_node
@property
def id(self):
return cells_utils.cell_with_item(self._cell_path, self._obj.id)
def __getitem__(self, key):
if key == 'id':
return self.id
if key == 'compute_node' and self._compute_node:
return self._compute_node
return getattr(self._obj, key)
def __getattr__(self, key):
if key == 'compute_node' and self._compute_node:
return self._compute_node
return getattr(self._obj, key)
class ComputeNodeProxy(object):
def __init__(self, obj, cell_path):
self._obj = obj
self._cell_path = cell_path
@ -519,6 +492,11 @@ class ComputeNodeProxy(object):
return getattr(self._obj, key)
def __getattr__(self, key):
if key == 'compute_node':
# NOTE(sbauza): As the Service object is still having a nested
# ComputeNode object that consumers of this Proxy don't use, we can
# safely remove it from what's returned
raise AttributeError
return getattr(self._obj, key)
@ -619,31 +597,22 @@ class HostAPI(compute_api.HostAPI):
# NOTE(dheeraj): Use ServiceProxy here too. See johannes'
# note on service_get_all
if db_service:
# NOTE(alaski): Creation of the Service object involves creating
# a ComputeNode object in this case. This will fail because with
# cells the 'id' is a string of the format 'region!child@1' but
# the object expects the 'id' to be an int.
# NOTE(sbauza): Creation of the Service object involves creating
# a ComputeNode object in this case. Now that the relationship
# between those is removed, we can safely remove the compute_node
# field from the DB until we're removing the SQLA relationship too.
# We're sure that no consumers of this method are using the
# nested compute_node field.
if 'compute_node' in db_service:
# NOTE(alaski): compute_node is a list that should have one
# item in it, except in the case of Ironic. But the Service
# object only uses the first compute_node for its relationship
# so we only need to pull the first one here.
db_compute = db_service['compute_node'][0]
comp_cell_path, comp_id = cells_utils.split_cell_and_item(
db_compute['id'])
db_compute['id'] = comp_id
del db_service['compute_node']
cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
db_service['id'] = _id
ser_obj = objects.Service._from_db_object(context,
objects.Service(),
db_service)
compute_proxy = None
if 'compute_node' in db_service:
compute_proxy = ComputeNodeProxy(ser_obj.compute_node,
comp_cell_path)
return ServiceProxy(ser_obj, cell_path, compute_node=compute_proxy)
return ServiceProxy(ser_obj, cell_path)
def service_update(self, context, host_name, binary, params_to_update):
"""Used to enable/disable a service. For compute services, setting to

View File

@ -420,7 +420,6 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
# to IDs
fake_compute_node = dict(test_compute_node.fake_compute_node,
id='region!child@1')
exp_compute_node = fake_compute_node.copy()
fake_service = dict(test_service.fake_service, id='cell1@1',
compute_node=[fake_compute_node])
@ -431,10 +430,8 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
result = self.host_api.service_get_by_compute_host(self.ctxt,
'fake-host')
# NOTE: Testing equality of a compute node obj and dict requires
# multiple comparator methods. So here we just test that the proxy
# object correctly replaces the 'id'.
self.assertEqual(exp_compute_node['id'], result.compute_node.id)
self.assertIsNone(fake_service.get('compute_node'))
self.assertRaises(AttributeError, getattr, result, 'compute_node')
def test_service_update(self):
host_name = 'fake-host'