Merge "Modify fuel_baremetal pod config file"
[yardstick.git] / yardstick / 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                         "nodeSelector": {
67                             "kubernetes.io/hostname": "node-01"
68                         }
69                     }
70                 }
71             }
72         }
73         input_s = {
74             'command': '/bin/bash',
75             'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
76 service ssh restart;while true ; do sleep 10000; done'],
77             'ssh_key': 'k8s-86096c30-key',
78             'nodeSelector': {'kubernetes.io/hostname': 'node-01'}
79         }
80         name = 'host-k8s-86096c30'
81         output_r = KubernetesObject(name, **input_s).get_template()
82         self.assertEqual(output_r, output_t)
83
84
85 class GetRcPodsTestCase(unittest.TestCase):
86
87     @mock.patch('yardstick.orchestrator.kubernetes.k8s_utils.get_pod_list')
88     def test_get_rc_pods(self, mock_get_pod_list):
89         servers = {
90             'host': {
91                 'image': 'openretriever/yardstick',
92                 'command': '/bin/bash',
93                 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
94 service ssh restart;while true ; do sleep 10000; done']
95             },
96             'target': {
97                 'image': 'openretriever/yardstick',
98                 'command': '/bin/bash',
99                 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
100 service ssh restart;while true ; do sleep 10000; done']
101             }
102         }
103         k8s_template = KubernetesTemplate('k8s-86096c30', servers)
104         mock_get_pod_list.return_value.items = []
105         pods = k8s_template.get_rc_pods()
106         self.assertEqual(pods, [])
107
108
109 def main():
110     unittest.main()
111
112
113 if __name__ == '__main__':
114     main()