From f231a609425fc053b5bfd450b219aacaac3008e4 Mon Sep 17 00:00:00 2001 From: Vilobh Meshram Date: Fri, 23 Oct 2015 11:34:16 -0700 Subject: [PATCH] Fix the failure to scale-down k8s cluster Fix the failure to scale-down k8s cluster. We were getting this failure because as part of scaling, Bay needs to be retrieved for the respective k8s obj. But if the object passed is a Bay itself we need not retrieve the Bay. At present even for Bay object the code proceeds ahead to retrieve bay and cannot find bay_uuid attribute. This patch fixes this problem. We might need to backport this fix to stable/liberty as well. Change-Id: I7ed03af8bdbb8647851751bb550d9529d96b5cb4 Closes-Bug: #1509439 --- magnum/conductor/k8s_api.py | 7 ++++++- magnum/tests/unit/conductor/test_k8s_api.py | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/magnum/conductor/k8s_api.py b/magnum/conductor/k8s_api.py index a40b5f7c7e..c7721d83b8 100644 --- a/magnum/conductor/k8s_api.py +++ b/magnum/conductor/k8s_api.py @@ -22,6 +22,7 @@ from magnum.common import cert_manager from magnum.common.pythonk8sclient.swagger_client import api_client from magnum.common.pythonk8sclient.swagger_client.apis import apiv_api from magnum.conductor import utils +from magnum.objects.bay import Bay LOG = logging.getLogger(__name__) @@ -49,7 +50,11 @@ class K8sAPI(apiv_api.ApivApi): self.cert_file = None self.key_file = None - bay = utils.retrieve_bay(context, obj) + # If the obj is already a Bay we need not retrieve a Bay. + if isinstance(obj, Bay): + bay = obj + else: + bay = utils.retrieve_bay(context, obj) if bay.magnum_cert_ref: self._create_certificate_files(bay) diff --git a/magnum/tests/unit/conductor/test_k8s_api.py b/magnum/tests/unit/conductor/test_k8s_api.py index cf2a75d03a..76d68fe925 100644 --- a/magnum/tests/unit/conductor/test_k8s_api.py +++ b/magnum/tests/unit/conductor/test_k8s_api.py @@ -82,8 +82,11 @@ class TestK8sAPI(base.TestCase): context = 'context' obj = getattr(objects, cls)({}) - self.assertFalse(hasattr(obj, 'bay_uuid')) - obj.bay_uuid = 'bay-uuid' + if cls is not 'Bay': + self.assertFalse(hasattr(obj, 'bay_uuid')) + obj.bay_uuid = 'bay-uuid' + else: + obj = bay_obj with patch( 'magnum.conductor.k8s_api.K8sAPI._create_temp_file_with_content',