Add kube pod tests in kubeutils

Add tests for pod update/create
Closes-Bug: #1436633

Change-Id: I50fce54588df476bf961b1f4e2cd9bdb8873ce96
This commit is contained in:
Kennan 2015-03-27 09:49:43 +08:00
parent e8ee29b21e
commit 29d77c4d51
1 changed files with 88 additions and 0 deletions

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'