-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_server_hardware.py
More file actions
339 lines (240 loc) · 12.9 KB
/
test_server_hardware.py
File metadata and controls
339 lines (240 loc) · 12.9 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# -*- coding: utf-8 -*-
###
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
#
# 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 unittest import TestCase
import mock
from hpeOneView.connection import connection
from hpeOneView.resources.servers.server_hardware import ServerHardware
from hpeOneView.resources.resource import (ResourceHelper,
ResourceUtilizationMixin,
ResourcePatchMixin)
class ServerHardwareTest(TestCase):
def setUp(self):
self.host = '127.0.0.1'
self.connection = connection(self.host, 800)
self._server_hardware = ServerHardware(self.connection)
self.uri = "/rest/server-hardware/1224242424"
self._server_hardware.data = {"uri": self.uri}
@mock.patch.object(ResourceUtilizationMixin, 'get_utilization')
def test_get_utilization_with_all_args(self, mock_get_utilization):
self._server_hardware.get_utilization(fields='AmbientTemperature,AveragePower,PeakPower',
filter='startDate=2016-05-30T03:29:42.361Z',
refresh=True, view='day')
mock_get_utilization.assert_called_once_with(fields='AmbientTemperature,AveragePower,PeakPower',
filter='startDate=2016-05-30T03:29:42.361Z',
refresh=True, view='day')
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_utilization_with_defaults(self, mock_get):
self._server_hardware.get_utilization()
mock_get.assert_called_once_with("{}/utilization".format(self.uri))
@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_called_once(self, mock_get_all):
filter = 'name=TestName'
sort = 'name:ascending'
self._server_hardware.get_all(2, 500, filter, sort)
mock_get_all.assert_called_once_with(start=2, count=500, filter=filter, sort=sort)
@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_called_once_with_default_values(self, mock_get_all):
self._server_hardware.get_all()
mock_get_all.assert_called_once_with(start=0, count=-1, filter='', sort='')
@mock.patch.object(ResourceHelper, 'create')
def test_add_called_once(self, mock_create):
information = {
"licensingIntent": "OneView",
"configurationState": "Managed"
}
mock_create.return_value = {}
self._server_hardware.add(information)
mock_create.assert_called_once_with(information.copy(), None, -1, None, False)
@mock.patch.object(ResourceHelper, 'create')
def test_add_multiple_servers_called_once(self, mock_create):
information = {
"licensingIntent": "OneView",
"configurationState": "Managed"
}
mock_create.return_value = {}
self._server_hardware.add_multiple_servers(information)
mock_create.assert_called_once_with(information.copy(),
'/rest/server-hardware/discovery',
-1, None, False)
@mock.patch.object(ResourceHelper, 'delete')
def test_remove_called_once(self, mock_delete):
self._server_hardware.remove(force=False)
mock_delete.assert_called_once_with(self.uri, force=False,
custom_headers=None, timeout=-1)
@mock.patch.object(ResourceHelper, 'delete')
def test_remove_called_once_with_force(self, mock_delete):
self._server_hardware.remove(force=True)
mock_delete.assert_called_once_with(self.uri, force=True,
custom_headers=None,
timeout=-1)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_bios(self, mock_get):
uri_rest_call = '{}/bios'.format(self.uri)
self._server_hardware.get_bios()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_environmental_configuration(self, mock_get):
uri_rest_call = '{}/environmentalConfiguration'.format(self.uri)
self._server_hardware.get_environmental_configuration()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'update')
def test_update_environmental_configuration(self, mock_update):
uri_rest_call = '{}/environmentalConfiguration'.format(self.uri)
configuration = {"calibratedMaxPower": 2500}
configuration_rest_call = configuration.copy()
self._server_hardware.update_environmental_configuration(
configuration, timeout=-1)
mock_update.assert_called_once_with(
configuration_rest_call, uri_rest_call, timeout=-1)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_ilo_sso_url(self, mock_get):
uri_rest_call = '{}/iloSsoUrl'.format(self.uri)
self._server_hardware.get_ilo_sso_url()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_ilo_sso_url_with_ip(self, mock_get):
uri_rest_call = '{}/iloSsoUrl?ip=172.16.8.4'.format(self.uri)
self._server_hardware.get_ilo_sso_url(ip='172.16.8.4')
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_java_remote_console(self, mock_get):
uri_rest_call = '{}/javaRemoteConsoleUrl'.format(self.uri)
self._server_hardware.get_java_remote_console_url()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_java_remote_console_with_ip(self, mock_get):
uri_rest_call = '{}/javaRemoteConsoleUrl?ip=172.16.8.4'.format(self.uri)
self._server_hardware.get_java_remote_console_url(ip='172.16.8.4')
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'update')
def test_refresh_state(self, mock_update):
uri_rest_call = '{}/refreshState'.format(self.uri)
configuration = {"refreshState": "RefreshPending"}
configuration_rest_call = configuration.copy()
self._server_hardware.refresh_state(
configuration, timeout=-1)
mock_update.assert_called_once_with(
configuration_rest_call, uri=uri_rest_call, timeout=-1)
@mock.patch.object(ResourceHelper, 'update')
def test_power_state(self, mock_update):
uri_rest_call = '{}/powerState'.format(self.uri)
configuration = {
"powerState": "Off",
"powerControl": "MomentaryPress"
}
configuration_rest_call = configuration.copy()
self._server_hardware.update_power_state(configuration)
mock_update.assert_called_once_with(
configuration_rest_call, uri_rest_call, timeout=-1)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_remote_console_url(self, mock_get):
uri_rest_call = '{}/remoteConsoleUrl'.format(self.uri)
self._server_hardware.get_remote_console_url()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_remote_console_url_with_ip(self, mock_get):
uri_rest_call = '{}/remoteConsoleUrl?ip=172.16.8.4'.format(self.uri)
self._server_hardware.get_remote_console_url(ip='172.16.8.4')
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_remote_console_url_with_consoleType(self, mock_get):
uri_rest_call = '{}/remoteConsoleUrl?consoleType=.Net IRC'.format(self.uri)
self._server_hardware.get_remote_console_url(consoleType='.Net IRC')
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_put')
def test_update_mp_firware_version_called_once(self, mock_get):
self._server_hardware.update_mp_firware_version()
uri = "{}/mpFirmwareVersion".format(self.uri)
mock_get.assert_called_once_with(uri, None, -1, None)
@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_firmwares_with_defaults(self, mock_get):
self._server_hardware.get_all_firmwares()
mock_get.assert_called_once_with(0, -1, '', '', '', '', '',
'/rest/server-hardware/*/firmware')
@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_firmwares_with_all_arguments(self, mock_get):
self._server_hardware.get_all_firmwares("name='name'", 2, 5, 'query', 'sort')
mock_get.assert_called_once_with(2, 5, "name='name'",
'query', 'sort',
'', '', '/rest/server-hardware/*/firmware')
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_firmware_by_id(self, mock_get):
self._server_hardware.get_firmware()
mock_get.assert_called_once_with('{}/firmware'.format(self.uri))
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_firmware_by_uri(self, mock_get):
self._server_hardware.get_firmware()
mock_get.assert_called_once_with('{}/firmware'.format(self.uri))
@mock.patch.object(ResourcePatchMixin, 'patch_request')
def test_patch_called_once(self, mock_patch):
self._server_hardware.patch('replace', '/uidState', 'On')
mock_patch.assert_called_once_with(self.uri,
body=[{'op': 'replace',
'path': '/uidState',
'value': 'On'}],
custom_headers=None,
timeout=-1)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_physical_server_hardware(self, mock_get):
uri_rest_call = '{}/physicalServerHardware'.format(self.uri)
self._server_hardware.get_physical_server_hardware()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_local_storage(self, mock_get):
uri_rest_call = '{}/localStorageV2'.format(self.uri)
self._server_hardware.get_local_storage()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_local_storage_with_ip(self, mock_get):
uri_rest_call = '{}/localStorageV2?ip=172.16.8.4'.format(self.uri)
self._server_hardware.get_local_storage(ip='172.16.8.4')
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_chassis(self, mock_get):
uri_rest_call = '{}/chassis'.format(self.uri)
self._server_hardware.get_chassis()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_firmwareInventory(self, mock_get):
uri_rest_call = '{}/firmwareInventory'.format(self.uri)
self._server_hardware.get_firmware_inventory()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_networkAdapters(self, mock_get):
uri_rest_call = '{}/networkAdapters'.format(self.uri)
self._server_hardware.get_network_adapters()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_powerSupplies(self, mock_get):
uri_rest_call = '{}/powerSupplies'.format(self.uri)
self._server_hardware.get_power_supplies()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_processors(self, mock_get):
uri_rest_call = '{}/processors'.format(self.uri)
self._server_hardware.get_processors()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_thermal(self, mock_get):
uri_rest_call = '{}/thermal'.format(self.uri)
self._server_hardware.get_thermal()
mock_get.assert_called_once_with(uri_rest_call)
@mock.patch.object(ResourceHelper, 'do_get')
def test_get_softwareInventory(self, mock_get):
uri_rest_call = '{}/softwareInventory'.format(self.uri)
self._server_hardware.get_software_inventory()
mock_get.assert_called_once_with(uri_rest_call)