Cleanup MagnumService Object usage
Some of MagnumService's function doesn't require context at all, we should clear document these and correct some of wrong usage. Closes-Bug: #1539438 Change-Id: I2b576e8e7fa0b048f022940dc23422d822b68681
This commit is contained in:
parent
511b9df1c6
commit
28f7f0bbd1
|
@ -90,7 +90,12 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
||||||
def create(self, context=None):
|
def create(self, context=None):
|
||||||
"""Create a MagnumService record in the DB.
|
"""Create a MagnumService record in the DB.
|
||||||
|
|
||||||
:param context: Security context.
|
:param context: Security context. NOTE: This should only
|
||||||
|
be used internally by the indirection_api.
|
||||||
|
Unfortunately, RPC requires context as the first
|
||||||
|
argument, even though we don't use it.
|
||||||
|
A context should be set when instantiating the
|
||||||
|
object, e.g.: MagnumService(context)
|
||||||
"""
|
"""
|
||||||
values = self.obj_get_changes()
|
values = self.obj_get_changes()
|
||||||
db_magnum_service = self.dbapi.create_magnum_service(values)
|
db_magnum_service = self.dbapi.create_magnum_service(values)
|
||||||
|
@ -100,7 +105,12 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
||||||
def destroy(self, context=None):
|
def destroy(self, context=None):
|
||||||
"""Delete the MagnumService from the DB.
|
"""Delete the MagnumService from the DB.
|
||||||
|
|
||||||
:param context: Security context.
|
:param context: Security context. NOTE: This should only
|
||||||
|
be used internally by the indirection_api.
|
||||||
|
Unfortunately, RPC requires context as the first
|
||||||
|
argument, even though we don't use it.
|
||||||
|
A context should be set when instantiating the
|
||||||
|
object, e.g.: MagnumService(context)
|
||||||
"""
|
"""
|
||||||
self.dbapi.destroy_magnum_service(self.id)
|
self.dbapi.destroy_magnum_service(self.id)
|
||||||
self.obj_reset_changes()
|
self.obj_reset_changes()
|
||||||
|
@ -112,7 +122,12 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
||||||
Updates will be made column by column based on the result
|
Updates will be made column by column based on the result
|
||||||
of self.what_changed().
|
of self.what_changed().
|
||||||
|
|
||||||
:param context: Security context.
|
:param context: Security context. NOTE: This should only
|
||||||
|
be used internally by the indirection_api.
|
||||||
|
Unfortunately, RPC requires context as the first
|
||||||
|
argument, even though we don't use it.
|
||||||
|
A context should be set when instantiating the
|
||||||
|
object, e.g.: MagnumService(context)
|
||||||
"""
|
"""
|
||||||
updates = self.obj_get_changes()
|
updates = self.obj_get_changes()
|
||||||
self.dbapi.update_magnum_service(self.id, updates)
|
self.dbapi.update_magnum_service(self.id, updates)
|
||||||
|
@ -122,7 +137,12 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
||||||
def report_state_up(self, context=None):
|
def report_state_up(self, context=None):
|
||||||
"""Touching the magnum_service record to show aliveness.
|
"""Touching the magnum_service record to show aliveness.
|
||||||
|
|
||||||
:param context: Security context.
|
:param context: Security context. NOTE: This should only
|
||||||
|
be used internally by the indirection_api.
|
||||||
|
Unfortunately, RPC requires context as the first
|
||||||
|
argument, even though we don't use it.
|
||||||
|
A context should be set when instantiating the
|
||||||
|
object, e.g.: MagnumService(context)
|
||||||
"""
|
"""
|
||||||
self.report_count += 1
|
self.report_count += 1
|
||||||
self.save(context)
|
self.save()
|
||||||
|
|
|
@ -51,8 +51,8 @@ class MagnumServicePeriodicTasks(periodic_task.PeriodicTasks):
|
||||||
}
|
}
|
||||||
self.magnum_service_ref = objects.MagnumService(
|
self.magnum_service_ref = objects.MagnumService(
|
||||||
ctx, **magnum_service_dict)
|
ctx, **magnum_service_dict)
|
||||||
self.magnum_service_ref.create(ctx)
|
self.magnum_service_ref.create()
|
||||||
self.magnum_service_ref.report_state_up(ctx)
|
self.magnum_service_ref.report_state_up()
|
||||||
|
|
||||||
|
|
||||||
def setup(conf, binary, tg):
|
def setup(conf, binary, tg):
|
||||||
|
|
|
@ -48,8 +48,8 @@ class MagnumServicePeriodicTestCase(base.TestCase):
|
||||||
|
|
||||||
mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
|
mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
|
||||||
p_task.binary)
|
p_task.binary)
|
||||||
mock_ms_create.assert_called_once_with(mock.ANY)
|
mock_ms_create.assert_called_once_with()
|
||||||
mock_ms_refresh.assert_called_once_with(mock.ANY)
|
mock_ms_refresh.assert_called_once_with()
|
||||||
|
|
||||||
@mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
|
@mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
|
||||||
@mock.patch.object(objects.MagnumService, 'create')
|
@mock.patch.object(objects.MagnumService, 'create')
|
||||||
|
@ -64,7 +64,7 @@ class MagnumServicePeriodicTestCase(base.TestCase):
|
||||||
|
|
||||||
mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
|
mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
|
||||||
p_task.binary)
|
p_task.binary)
|
||||||
self.fake_ms_refresh.assert_called_once_with(mock.ANY)
|
self.fake_ms_refresh.assert_called_once_with()
|
||||||
|
|
||||||
def test_update_magnum_service_regular(self):
|
def test_update_magnum_service_regular(self):
|
||||||
p_task = periodic.MagnumServicePeriodicTasks(CONF,
|
p_task = periodic.MagnumServicePeriodicTasks(CONF,
|
||||||
|
@ -73,4 +73,4 @@ class MagnumServicePeriodicTestCase(base.TestCase):
|
||||||
|
|
||||||
p_task.update_magnum_service(None)
|
p_task.update_magnum_service(None)
|
||||||
|
|
||||||
self.fake_ms_refresh.assert_called_once_with(mock.ANY)
|
self.fake_ms_refresh.assert_called_once_with()
|
||||||
|
|
Loading…
Reference in New Issue