Merge "Add kube pod tests in kubeutils"

This commit is contained in:
Jenkins 2015-03-27 06:40:18 +00:00 committed by Gerrit Code Review
commit 5abc83ead1

View File

@ -150,6 +150,94 @@ class KubeClientTestCase(base.TestCase):
super(KubeClientTestCase, self).setUp()
self.kube_client = kube_utils.KubeClient()
@patch('magnum.conductor.handlers.common.kube_utils._k8s_create')
def test_pod_create(self, mock_k8s_create):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_create.return_value = ("", "")
result = self.kube_client.pod_create(expected_api_address,
expected_pod_content)
self.assertTrue(result)
mock_k8s_create.assert_called_once_with(*expected_command)
@patch('magnum.conductor.handlers.common.kube_utils._k8s_create')
def test_pod_create_with_err(self, mock_k8s_create):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_create.return_value = ("", "create failed")
result = self.kube_client.pod_create(expected_api_address,
expected_pod_content)
self.assertFalse(result)
mock_k8s_create.assert_called_once_with(*expected_command)
@patch('magnum.conductor.handlers.common.kube_utils._k8s_create')
def test_pod_create_failure_exception(self, mock_k8s_create):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_create.side_effect = Exception()
result = self.kube_client.pod_create(expected_api_address,
expected_pod_content)
self.assertFalse(result)
mock_k8s_create.assert_called_once_with(*expected_command)
@patch('magnum.conductor.handlers.common.kube_utils._k8s_update')
def test_pod_update(self, mock_k8s_update):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_update.return_value = ("", "")
result = self.kube_client.pod_update(expected_api_address,
expected_pod_content)
self.assertTrue(result)
mock_k8s_update.assert_called_once_with(*expected_command)
@patch('magnum.conductor.handlers.common.kube_utils._k8s_update')
def test_pod_update_with_err(self, mock_k8s_update):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_update.return_value = ("", "create failed")
result = self.kube_client.pod_update(expected_api_address,
expected_pod_content)
self.assertFalse(result)
mock_k8s_update.assert_called_once_with(*expected_command)
@patch('magnum.conductor.handlers.common.kube_utils._k8s_update')
def test_pod_update_failure_exception(self, mock_k8s_update):
expected_api_address = 'master-address'
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
]
mock_k8s_update.side_effect = Exception()
result = self.kube_client.pod_update(expected_api_address,
expected_pod_content)
self.assertFalse(result)
mock_k8s_update.assert_called_once_with(*expected_command)
@patch('magnum.openstack.common.utils.trycmd')
def test_pod_delete(self, mock_trycmd):
expected_api_address = 'master-address'