From 375f7c272c5939008f04f17cd11f3c315a90ce1a Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Mon, 23 Mar 2015 15:06:21 -0700 Subject: [PATCH] Update pod_delete call for new log message The latest kubernetes has changed the log message when a pod is not found, from "pod 'x' not found" to "pods 'x' not found". To handle this, and maintain compatibility, this removes the check for 'pod ' and just checks the log message for "'x' not found". Change-Id: Id3a847a576beed383bb0e382afa545828047648b Closes-Bug: #1435575 --- magnum/conductor/handlers/common/kube_utils.py | 2 +- .../handlers/common/test_kube_utils.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/magnum/conductor/handlers/common/kube_utils.py b/magnum/conductor/handlers/common/kube_utils.py index 47cf882deb..eaf9626b3f 100644 --- a/magnum/conductor/handlers/common/kube_utils.py +++ b/magnum/conductor/handlers/common/kube_utils.py @@ -204,7 +204,7 @@ class KubeClient(object): return False if err: - if ('pod "%s" not found' % name) in err: + if ('"%s" not found' % name) in err: raise exception.PodNotFound(pod=name) else: return False diff --git a/magnum/tests/conductor/handlers/common/test_kube_utils.py b/magnum/tests/conductor/handlers/common/test_kube_utils.py index 9df09d6cf6..e3622a29df 100644 --- a/magnum/tests/conductor/handlers/common/test_kube_utils.py +++ b/magnum/tests/conductor/handlers/common/test_kube_utils.py @@ -196,7 +196,7 @@ class KubeClientTestCase(base.TestCase): mock_trycmd.assert_called_once_with(*expected_command) @patch('magnum.openstack.common.utils.trycmd') - def test_pod_delete_not_found(self, mock_trycmd): + def test_pod_delete_not_found_old(self, mock_trycmd): expected_master_address = 'master-address' expected_pod_name = 'test-pod' expected_command = [ @@ -209,3 +209,18 @@ class KubeClientTestCase(base.TestCase): expected_master_address, expected_pod_name) mock_trycmd.assert_called_once_with(*expected_command) + + @patch('magnum.openstack.common.utils.trycmd') + def test_pod_delete_not_found_new(self, mock_trycmd): + expected_master_address = 'master-address' + expected_pod_name = 'test-pod' + expected_command = [ + 'kubectl', 'delete', 'pod', expected_pod_name, + '-s', expected_master_address + ] + mock_trycmd.return_value = ("", 'pods "test-pod" not found') + + self.assertRaises(exception.PodNotFound, self.kube_client.pod_delete, + expected_master_address, expected_pod_name) + + mock_trycmd.assert_called_once_with(*expected_command)