Merge "Open storperf testcase to huawei-pod2"
[yardstick.git] / tests / unit / orchestrator / test_kubernetes.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Intel Corporation
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Unittest for yardstick.benchmark.orchestrator.heat
13 import unittest
14 import mock
15
16 from yardstick.orchestrator.kubernetes import KubernetesObject
17 from yardstick.orchestrator.kubernetes import KubernetesTemplate
18
19
20 class GetTemplateTestCase(unittest.TestCase):
21
22     def test_get_template(self):
23         output_t = {
24             "apiVersion": "v1",
25             "kind": "ReplicationController",
26             "metadata": {
27                 "name": "host-k8s-86096c30"
28             },
29             "spec": {
30                 "replicas": 1,
31                 "template": {
32                     "metadata": {
33                         "labels": {
34                             "app": "host-k8s-86096c30"
35                         }
36                     },
37                     "spec": {
38                         "containers": [
39                             {
40                                 "args": [
41                                     "-c",
42                                     "chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
43 service ssh restart;while true ; do sleep 10000; done"
44                                 ],
45                                 "command": [
46                                     "/bin/bash"
47                                 ],
48                                 "image": "openretriever/yardstick",
49                                 "name": "host-k8s-86096c30-container",
50                                 "volumeMounts": [
51                                     {
52                                         "mountPath": "/root/.ssh/",
53                                         "name": "k8s-86096c30-key"
54                                     }
55                                 ]
56                             }
57                         ],
58                         "volumes": [
59                             {
60                                 "configMap": {
61                                     "name": "k8s-86096c30-key"
62                                 },
63                                 "name": "k8s-86096c30-key"
64                             }
65                         ]
66                     }
67                 }
68             }
69         }
70         input_s = {
71             'command': '/bin/bash',
72             'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
73 service ssh restart;while true ; do sleep 10000; done'],
74             'ssh_key': 'k8s-86096c30-key'
75         }
76         name = 'host-k8s-86096c30'
77         output_r = KubernetesObject(name, **input_s).get_template()
78         self.assertEqual(output_r, output_t)
79
80
81 class GetRcPodsTestCase(unittest.TestCase):
82
83     @mock.patch('yardstick.orchestrator.kubernetes.k8s_utils.get_pod_list')
84     def test_get_rc_pods(self, mock_get_pod_list):
85         servers = {
86             'host': {
87                 'image': 'openretriever/yardstick',
88                 'command': '/bin/bash',
89                 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
90 service ssh restart;while true ; do sleep 10000; done']
91             },
92             'target': {
93                 'image': 'openretriever/yardstick',
94                 'command': '/bin/bash',
95                 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
96 service ssh restart;while true ; do sleep 10000; done']
97             }
98         }
99         k8s_template = KubernetesTemplate('k8s-86096c30', servers)
100         mock_get_pod_list.return_value.items = []
101         pods = k8s_template.get_rc_pods()
102         self.assertEqual(pods, [])
103
104
105 def main():
106     unittest.main()
107
108
109 if __name__ == '__main__':
110     main()