Fix lazy loading cluster field from Service OVO
Lazy loading of the cluster field in the Service OVO is broken because we are missing an argument when calling get_by_id method. This patch adds this argument. Change-Id: I53e302e7d31d23a1fb2bbfb3ceeaceb980417798
This commit is contained in:
parent
57e6ac9f20
commit
a1f6436465
@ -113,7 +113,7 @@ class Service(base.CinderPersistentObject, base.CinderObject,
|
||||
# If this service doesn't belong to a cluster (cluster_name is empty),
|
||||
# then cluster field will be None.
|
||||
if self.cluster_name:
|
||||
self.cluster = objects.Cluster.get_by_id(self._context,
|
||||
self.cluster = objects.Cluster.get_by_id(self._context, None,
|
||||
name=self.cluster_name)
|
||||
else:
|
||||
self.cluster = None
|
||||
|
@ -19,6 +19,7 @@ import six
|
||||
|
||||
from cinder import exception
|
||||
from cinder import objects
|
||||
from cinder.tests.unit import fake_cluster
|
||||
from cinder.tests.unit import fake_service
|
||||
from cinder.tests.unit import objects as test_objects
|
||||
|
||||
@ -162,6 +163,20 @@ class TestService(test_objects.BaseObjectsTestCase):
|
||||
service_get_all.assert_called_once_with(self.context, binary=None,
|
||||
disabled=None)
|
||||
|
||||
@mock.patch('cinder.db.sqlalchemy.api.cluster_get')
|
||||
def test_lazy_loading_cluster_field(self, cluster_get):
|
||||
cluster_orm = fake_cluster.fake_cluster_orm(name='mycluster')
|
||||
cluster_get.return_value = cluster_orm
|
||||
cluster = objects.Cluster._from_db_object(self.context,
|
||||
objects.Cluster(),
|
||||
cluster_orm)
|
||||
|
||||
service = fake_service.fake_service_obj(self.context,
|
||||
cluster_name='mycluster')
|
||||
self.assertEqual(cluster, service.cluster)
|
||||
cluster_get.assert_called_once_with(self.context, None,
|
||||
name='mycluster')
|
||||
|
||||
|
||||
class TestServiceList(test_objects.BaseObjectsTestCase):
|
||||
@mock.patch('cinder.db.service_get_all')
|
||||
|
Loading…
Reference in New Issue
Block a user