From 9c68323035269e79ebc2e418d126a834f5c5ae5c Mon Sep 17 00:00:00 2001 From: "Jay Lau (Guangya Liu)" Date: Tue, 13 Jan 2015 18:53:44 -0500 Subject: [PATCH] Add rc_data support for magnum replication controller Change-Id: I041ee8a4e111d6c900ff6d654eeb23d61fff28ff --- .../controllers/v1/replicationcontroller.py | 8 +++++++- magnum/conductor/handlers/kube.py | 3 ++- magnum/objects/replicationcontroller.py | 4 ++++ magnum/tests/conductor/handlers/test_kube.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/magnum/api/controllers/v1/replicationcontroller.py b/magnum/api/controllers/v1/replicationcontroller.py index 027579befb..a7ea980915 100644 --- a/magnum/api/controllers/v1/replicationcontroller.py +++ b/magnum/api/controllers/v1/replicationcontroller.py @@ -83,11 +83,14 @@ class ReplicationController(base.APIBase): """Selector of this ReplicationController""" replicas = wtypes.IntegerType() - """Replicas of this ReplicationController """ + """Replicas of this ReplicationController""" rc_definition_url = wtypes.text """URL for ReplicationController file to create the RC""" + rc_data = wtypes.text + """Data for service to create the ReplicationController""" + links = wsme.wsattr([link.Link], readonly=True) """A list containing a self link and associated rc links""" @@ -312,6 +315,9 @@ class ReplicationControllersController(rest.RestController): # ignore rc_definition_url as it was used for create rc if field == 'rc_definition_url': continue + # ignore rc_data as it was used for create rc + if field == 'rc_data': + continue try: patch_val = getattr(rc, field) except AttributeError: diff --git a/magnum/conductor/handlers/kube.py b/magnum/conductor/handlers/kube.py index 9b41a914e9..9ae6b97742 100644 --- a/magnum/conductor/handlers/kube.py +++ b/magnum/conductor/handlers/kube.py @@ -174,8 +174,9 @@ class Handler(object): # Replication Controller Operations def rc_create(self, ctxt, rc): LOG.debug("rc_create") + k8s_master_url = _retrive_k8s_master_url(ctxt, rc) # trigger a kubectl command - status = self.kube_cli.rc_create(rc) + status = self.kube_cli.rc_create(k8s_master_url, rc) if not status: return None # call the rc object to persist in db diff --git a/magnum/objects/replicationcontroller.py b/magnum/objects/replicationcontroller.py index 71991dd4da..01f4096211 100644 --- a/magnum/objects/replicationcontroller.py +++ b/magnum/objects/replicationcontroller.py @@ -34,6 +34,7 @@ class ReplicationController(base.MagnumObject): 'selector': obj_utils.dict_or_none, 'replicas': int, 'rc_definition_url': obj_utils.str_or_none, + 'rc_data': obj_utils.str_or_none, } @staticmethod @@ -43,6 +44,9 @@ class ReplicationController(base.MagnumObject): # ignore rc_definition_url as it was used for create rc if field == 'rc_definition_url': continue + # ignore rc_data as it was used for create rc + if field == 'rc_data': + continue rc[field] = db_rc[field] rc.obj_reset_changes() diff --git a/magnum/tests/conductor/handlers/test_kube.py b/magnum/tests/conductor/handlers/test_kube.py index 3190266b3d..a797d5073b 100644 --- a/magnum/tests/conductor/handlers/test_kube.py +++ b/magnum/tests/conductor/handlers/test_kube.py @@ -31,6 +31,9 @@ class TestKube(base.BaseTestCase): def mock_service(self): return objects.Service({}) + def mock_rc(self): + return objects.ReplicationController({}) + def mock_bay(self): return objects.Bay({}) @@ -120,3 +123,18 @@ class TestKube(base.BaseTestCase): self.kube_handler.service_create({}, expected_service) mock_kube_cli.service_create.assert_called_once_with( expected_master_url, expected_service) + + @patch('magnum.conductor.handlers.kube._retrive_k8s_master_url') + def test_rc_create_with_success(self, + mock_retrive_k8s_master_url): + expected_master_url = 'master_address' + expected_rc = self.mock_rc() + expected_rc.create = mock.MagicMock() + + mock_retrive_k8s_master_url.return_value = expected_master_url + with patch.object(self.kube_handler, 'kube_cli') as mock_kube_cli: + mock_kube_cli.rc_create.return_value = True + + self.kube_handler.rc_create({}, expected_rc) + mock_kube_cli.rc_create.assert_called_once_with( + expected_master_url, expected_rc)