summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-08-30 02:31:40 +0000
committerRoss Brattain <ross.b.brattain@intel.com>2017-09-25 08:30:21 -0700
commit86c0326342b33f6e0b090b973fb58831ed1d38d2 (patch)
treef7e15ee3417040f214a496d80d6953087d42f567 /tests
parentc793405a28a3b26845c379e3f4b60deab026d76d (diff)
Add service in kubernetes context
JIRA: YARDSTICK-803 Currently kubernetes test case can only run in master node. We need to support it run in jump server. So I add service and use nodePort type. Then we can login the pod using nodePort. Change-Id: Ia7900d263f1c5323f132435addec27ad10547ef9 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/benchmark/contexts/test_kubernetes.py65
1 files changed, 59 insertions, 6 deletions
diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py
index 4976a9fe0..3a926f85c 100644
--- a/tests/unit/benchmark/contexts/test_kubernetes.py
+++ b/tests/unit/benchmark/contexts/test_kubernetes.py
@@ -47,13 +47,15 @@ class KubernetesTestCase(unittest.TestCase):
# clear kubernetes contexts from global list so we don't break other tests
Context.list = []
+ @mock.patch('{}.KubernetesContext._delete_services'.format(prefix))
@mock.patch('{}.KubernetesContext._delete_ssh_key'.format(prefix))
@mock.patch('{}.KubernetesContext._delete_rcs'.format(prefix))
@mock.patch('{}.KubernetesContext._delete_pods'.format(prefix))
def test_undeploy(self,
mock_delete_pods,
mock_delete_rcs,
- mock_delete_ssh):
+ mock_delete_ssh,
+ mock_delete_services):
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
@@ -61,7 +63,9 @@ class KubernetesTestCase(unittest.TestCase):
self.assertTrue(mock_delete_ssh.called)
self.assertTrue(mock_delete_rcs.called)
self.assertTrue(mock_delete_pods.called)
+ self.assertTrue(mock_delete_services.called)
+ @mock.patch('{}.KubernetesContext._create_services'.format(prefix))
@mock.patch('{}.KubernetesContext._wait_until_running'.format(prefix))
@mock.patch('{}.KubernetesTemplate.get_rc_pods'.format(prefix))
@mock.patch('{}.KubernetesContext._create_rcs'.format(prefix))
@@ -70,7 +74,8 @@ class KubernetesTestCase(unittest.TestCase):
mock_set_ssh_key,
mock_create_rcs,
mock_get_rc_pods,
- mock_wait_until_running):
+ mock_wait_until_running,
+ mock_create_services):
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
@@ -78,6 +83,7 @@ class KubernetesTestCase(unittest.TestCase):
k8s_context.deploy()
self.assertTrue(mock_set_ssh_key.called)
self.assertTrue(mock_create_rcs.called)
+ self.assertTrue(mock_create_services.called)
self.assertTrue(mock_get_rc_pods.called)
self.assertTrue(mock_wait_until_running.called)
@@ -106,14 +112,39 @@ class KubernetesTestCase(unittest.TestCase):
mock_read_pod_status.return_value = 'Running'
k8s_context._wait_until_running()
- @mock.patch('{}.k8s_utils.get_pod_list'.format(prefix))
- def test_get_server(self, mock_get_pod_list):
+ @mock.patch('{}.k8s_utils.get_pod_by_name'.format(prefix))
+ @mock.patch('{}.KubernetesContext._get_node_ip'.format(prefix))
+ @mock.patch('{}.k8s_utils.get_service_by_name'.format(prefix))
+ def test_get_server(self,
+ mock_get_service_by_name,
+ mock_get_node_ip,
+ mock_get_pod_by_name):
+ class Service(object):
+ def __init__(self):
+ self.name = 'yardstick'
+ self.node_port = 30000
+
+ class Services(object):
+ def __init__(self):
+ self.ports = [Service()]
+
+ class Status(object):
+ def __init__(self):
+ self.pod_ip = '172.16.10.131'
+
+ class Pod(object):
+ def __init__(self):
+ self.status = Status()
+
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
- mock_get_pod_list.return_value.items = []
+ mock_get_service_by_name.return_value = Services()
+ mock_get_pod_by_name.return_value = Pod()
+ mock_get_node_ip.return_value = '172.16.10.131'
+
server = k8s_context._get_server('server')
- self.assertIsNone(server)
+ self.assertIsNotNone(server)
@mock.patch('{}.KubernetesContext._create_rc'.format(prefix))
def test_create_rcs(self, mock_create_rc):
@@ -143,6 +174,28 @@ class KubernetesTestCase(unittest.TestCase):
k8s_context._delete_rc({})
self.assertTrue(mock_delete_replication_controller.called)
+ @mock.patch('{}.k8s_utils.get_node_list'.format(prefix))
+ def test_get_node_ip(self, mock_get_node_list):
+
+ k8s_context = KubernetesContext()
+ k8s_context.init(context_cfg)
+ k8s_context._get_node_ip()
+ self.assertTrue(mock_get_node_list.called)
+
+ @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create')
+ def test_create_services(self, mock_create):
+ k8s_context = KubernetesContext()
+ k8s_context.init(context_cfg)
+ k8s_context._create_services()
+ self.assertTrue(mock_create.called)
+
+ @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete')
+ def test_delete_services(self, mock_delete):
+ k8s_context = KubernetesContext()
+ k8s_context.init(context_cfg)
+ k8s_context._delete_services()
+ self.assertTrue(mock_delete.called)
+
def main():
unittest.main()