import unittest
import mock
+from yardstick.benchmark.contexts.base import Context
from yardstick.benchmark.contexts.kubernetes import KubernetesContext
prefix = 'yardstick.benchmark.contexts.kubernetes'
-class UndeployTestCase(unittest.TestCase):
+class KubernetesTestCase(unittest.TestCase):
+
+ def tearDown(self):
+ # clear kubernetes contexts from global list so we don't break other tests
+ Context.list = []
@mock.patch('{}.KubernetesContext._delete_ssh_key'.format(prefix))
@mock.patch('{}.KubernetesContext._delete_rcs'.format(prefix))
self.assertTrue(mock_delete_rcs.called)
self.assertTrue(mock_delete_pods.called)
-
-class DeployTestCase(unittest.TestCase):
-
@mock.patch('{}.KubernetesContext._wait_until_running'.format(prefix))
@mock.patch('{}.KubernetesTemplate.get_rc_pods'.format(prefix))
@mock.patch('{}.KubernetesContext._create_rcs'.format(prefix))
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
- k8s_context.deploy()
+ with mock.patch("yardstick.benchmark.contexts.kubernetes.time"):
+ k8s_context.deploy()
self.assertTrue(mock_set_ssh_key.called)
self.assertTrue(mock_create_rcs.called)
self.assertTrue(mock_get_rc_pods.called)
self.assertTrue(mock_wait_until_running.called)
-
-class SSHKeyTestCase(unittest.TestCase):
-
+ @mock.patch('{}.paramiko'.format(prefix), **{"resource_filename.return_value": ""})
+ @mock.patch('{}.pkg_resources'.format(prefix), **{"resource_filename.return_value": ""})
+ @mock.patch('{}.utils'.format(prefix))
+ @mock.patch('{}.open'.format(prefix), create=True)
@mock.patch('{}.k8s_utils.delete_config_map'.format(prefix))
@mock.patch('{}.k8s_utils.create_config_map'.format(prefix))
- def test_ssh_key(self, mock_create, mock_delete):
+ def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils, mock_resources,
+ mock_paramiko):
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
self.assertTrue(mock_create.called)
self.assertTrue(mock_delete.called)
-
-class WaitUntilRunningTestCase(unittest.TestCase):
-
@mock.patch('{}.k8s_utils.read_pod_status'.format(prefix))
def test_wait_until_running(self, mock_read_pod_status):
mock_read_pod_status.return_value = 'Running'
k8s_context._wait_until_running()
-
-class GetServerTestCase(unittest.TestCase):
-
@mock.patch('{}.k8s_utils.get_pod_list'.format(prefix))
def test_get_server(self, mock_get_pod_list):
k8s_context = KubernetesContext()
server = k8s_context._get_server('server')
self.assertIsNone(server)
-
-class CreateRcsTestCase(unittest.TestCase):
-
@mock.patch('{}.KubernetesContext._create_rc'.format(prefix))
def test_create_rcs(self, mock_create_rc):
k8s_context = KubernetesContext()
k8s_context._create_rcs()
self.assertTrue(mock_create_rc.called)
-
-class CreateRcTestCase(unittest.TestCase):
-
@mock.patch('{}.k8s_utils.create_replication_controller'.format(prefix))
def test_create_rc(self, mock_create_replication_controller):
k8s_context = KubernetesContext()
k8s_context._create_rc({})
self.assertTrue(mock_create_replication_controller.called)
-
-class DeleteRcsTestCases(unittest.TestCase):
-
@mock.patch('{}.KubernetesContext._delete_rc'.format(prefix))
def test_delete_rcs(self, mock_delete_rc):
k8s_context = KubernetesContext()
k8s_context._delete_rcs()
self.assertTrue(mock_delete_rc.called)
-
-class DeleteRcTestCase(unittest.TestCase):
-
@mock.patch('{}.k8s_utils.delete_replication_controller'.format(prefix))
def test_delete_rc(self, mock_delete_replication_controller):
k8s_context = KubernetesContext()