summaryrefslogtreecommitdiff
path: root/tempest_lib/tests/services/compute/test_hypervisor_client.py
blob: 1cb85a918b5e8330b7e98559ee8c923b7a0107b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Copyright 2015 IBM Corp.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest_lib.services.compute import hypervisor_client
from tempest_lib.tests import fake_auth_provider
from tempest_lib.tests.services.compute import base


class TestHypervisorClient(base.BaseComputeServiceTest):

    hypervisor_id = "1"
    hypervisor_name = "hyper.hostname.com"

    def setUp(self):
        super(TestHypervisorClient, self).setUp()
        fake_auth = fake_auth_provider.FakeAuthProvider()
        self.client = hypervisor_client.HypervisorClient(
            fake_auth, 'compute', 'regionOne')

    def test_list_hypervisor_str_body(self):
        self._test_list_hypervisor(bytes_body=False)

    def test_list_hypervisor_byte_body(self):
        self._test_list_hypervisor(bytes_body=True)

    def _test_list_hypervisor(self, bytes_body=False):
        expected = {"hypervisors": [{
            "id": 1,
            "hypervisor_hostname": "hypervisor1.hostname.com"},
            {
            "id": 2,
            "hypervisor_hostname": "hypervisor2.hostname.com"}]}
        self.check_service_client_function(
            self.client.list_hypervisors,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body)

    def test_show_hypervisor_str_body(self):
        self._test_show_hypervisor(bytes_body=False)

    def test_show_hypervisor_byte_body(self):
        self._test_show_hypervisor(bytes_body=True)

    def _test_show_hypervisor(self, bytes_body=False):
        expected = {"hypervisor": {
            "cpu_info": "?",
            "current_workload": 0,
            "disk_available_least": 1,
            "host_ip": "10.10.10.10",
            "free_disk_gb": 1028,
            "free_ram_mb": 7680,
            "hypervisor_hostname": "fake-mini",
            "hypervisor_type": "fake",
            "hypervisor_version": 1,
            "id": 1,
            "local_gb": 1028,
            "local_gb_used": 0,
            "memory_mb": 8192,
            "memory_mb_used": 512,
            "running_vms": 0,
            "service": {
                "host": "fake_host",
                "id": 2},
            "vcpus": 1,
            "vcpus_used": 0}}
        self.check_service_client_function(
            self.client.show_hypervisor,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body,
            hypervisor_id=self.hypervisor_id)

    def test_list_servers_on_hypervisor_str_body(self):
        self._test_list_servers_on_hypervisor(bytes_body=False)

    def test_list_servers_on_hypervisor_byte_body(self):
        self._test_list_servers_on_hypervisor(bytes_body=True)

    def _test_list_servers_on_hypervisor(self, bytes_body=False):
        expected = {"hypervisors": [{
            "id": 1,
            "hypervisor_hostname": "hyper.hostname.com",
            "servers": [{
                "uuid": "e1ae8fc4-b72d-4c2f-a427-30dd420b6277",
                "name": "instance-00000001"},
                {
                "uuid": "e1ae8fc4-b72d-4c2f-a427-30dd42066666",
                "name": "instance-00000002"}
                ]}
            ]}
        self.check_service_client_function(
            self.client.list_servers_on_hypervisor,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body,
            hypervisor_name=self.hypervisor_name)

    def test_show_hypervisor_statistics_str_body(self):
        self._test_show_hypervisor_statistics(bytes_body=False)

    def test_show_hypervisor_statistics_byte_body(self):
        self._test_show_hypervisor_statistics(bytes_body=True)

    def _test_show_hypervisor_statistics(self, bytes_body=False):
        expected = {
            "hypervisor_statistics": {
                "count": 1,
                "current_workload": 0,
                "disk_available_least": 0,
                "free_disk_gb": 1028,
                "free_ram_mb": 7680,
                "local_gb": 1028,
                "local_gb_used": 0,
                "memory_mb": 8192,
                "memory_mb_used": 512,
                "running_vms": 0,
                "vcpus": 1,
                "vcpus_used": 0}}
        self.check_service_client_function(
            self.client.show_hypervisor_statistics,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body)

    def test_show_hypervisor_uptime_str_body(self):
        self._test_show_hypervisor_uptime(bytes_body=False)

    def test_show_hypervisor_uptime_byte_body(self):
        self._test_show_hypervisor_uptime(bytes_body=True)

    def _test_show_hypervisor_uptime(self, bytes_body=False):
        expected = {
            "hypervisor": {
                "hypervisor_hostname": "fake-mini",
                "id": 1,
                "uptime": (" 08:32:11 up 93 days, 18:25, 12 users, "
                           " load average: 0.20, 0.12, 0.14")
            }}
        self.check_service_client_function(
            self.client.show_hypervisor_uptime,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body,
            hypervisor_id=self.hypervisor_id)

    def test_search_hypervisor_str_body(self):
        self._test_search_hypervisor(bytes_body=False)

    def test_search_hypervisor_byte_body(self):
        self._test_search_hypervisor(bytes_body=True)

    def _test_search_hypervisor(self, bytes_body=False):
        expected = {"hypervisors": [{
            "id": 2,
            "hypervisor_hostname": "hyper.hostname.com"}]}
        self.check_service_client_function(
            self.client.search_hypervisor,
            'tempest_lib.common.rest_client.RestClient.get',
            expected, bytes_body,
            hypervisor_name=self.hypervisor_name)