Remove objectify decorator from dbapi's {get, register}_conductor()

This patch removes the objectify decorator from the get_conductor and
register_conductor dbapi's methods.

For get_condutor() method there's an objects interface to it so this patch
make the code/tests use the object interface vs direct calls to dbapi.

The problem with the objectify decorator is that dbapi methods
doesn't get the context, so when forming the RPC object using the
decorator we can't store the context within the object (which is what
we want to do to have consistent object interfaces).

Partial-Bug: 1314732
Change-Id: I1a955a59435b35277f3bbff2c02c07dd1a4c1d66
This commit is contained in:
Lucas Alvares Gomes 2014-08-14 13:53:22 +01:00
parent 868aacdc21
commit 9a9752e50a
3 changed files with 16 additions and 12 deletions

View File

@ -508,7 +508,6 @@ class Connection(api.Connection):
if count != 1:
raise exception.ChassisNotFound(chassis=chassis_id)
@objects.objectify(objects.Conductor)
def register_conductor(self, values):
try:
conductor = models.Conductor()
@ -522,7 +521,6 @@ class Connection(api.Connection):
raise exception.ConductorAlreadyRegistered(
conductor=values['hostname'])
@objects.objectify(objects.Conductor)
def get_conductor(self, hostname):
try:
return model_query(models.Conductor).\

View File

@ -46,7 +46,11 @@ class Conductor(base.IronicObject):
:returns: a :class:`Conductor` object.
"""
db_obj = cls.dbapi.get_conductor(hostname)
return Conductor._from_db_object(cls(), db_obj)
conductor = Conductor._from_db_object(cls(), db_obj)
# FIXME(comstud): Setting of the context should be moved to
# _from_db_object().
conductor._context = context
return conductor
def save(self, context):
"""Save is not supported by Conductor objects."""

View File

@ -150,7 +150,7 @@ class _ServiceSetUpMixin(object):
def _stop_service(self):
try:
self.dbapi.get_conductor(self.hostname)
objects.Conductor.get_by_hostname(self.context, self.hostname)
except exception.ConductorNotFound:
return
self.service.del_host()
@ -171,20 +171,20 @@ def _mock_record_keepalive(func_or_class):
class StartStopTestCase(_ServiceSetUpMixin, tests_db_base.DbTestCase):
def test_start_registers_conductor(self):
self.assertRaises(exception.ConductorNotFound,
self.dbapi.get_conductor,
self.hostname)
objects.Conductor.get_by_hostname,
self.context, self.hostname)
self._start_service()
res = self.dbapi.get_conductor(self.hostname)
res = objects.Conductor.get_by_hostname(self.context, self.hostname)
self.assertEqual(self.hostname, res['hostname'])
def test_stop_unregisters_conductor(self):
self._start_service()
res = self.dbapi.get_conductor(self.hostname)
res = objects.Conductor.get_by_hostname(self.context, self.hostname)
self.assertEqual(self.hostname, res['hostname'])
self.service.del_host()
self.assertRaises(exception.ConductorNotFound,
self.dbapi.get_conductor,
self.hostname)
objects.Conductor.get_by_hostname,
self.context, self.hostname)
def test_start_registers_driver_names(self):
init_names = ['fake1', 'fake2']
@ -196,14 +196,16 @@ class StartStopTestCase(_ServiceSetUpMixin, tests_db_base.DbTestCase):
self.config(enabled_drivers=init_names)
mock_names.return_value = init_names
self._start_service()
res = self.dbapi.get_conductor(self.hostname)
res = objects.Conductor.get_by_hostname(self.context,
self.hostname)
self.assertEqual(init_names, res['drivers'])
# verify that restart registers new driver names
self.config(enabled_drivers=restart_names)
mock_names.return_value = restart_names
self._start_service()
res = self.dbapi.get_conductor(self.hostname)
res = objects.Conductor.get_by_hostname(self.context,
self.hostname)
self.assertEqual(restart_names, res['drivers'])
@mock.patch.object(driver_factory.DriverFactory, '__init__')