forked from HewlettPackard/oneview-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_oneview_logical_interconnect.py
742 lines (570 loc) · 27.4 KB
/
test_oneview_logical_interconnect.py
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-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.
###
import mock
import pytest
from hpe_test_utils import OneViewBaseTest
from oneview_module_loader import LogicalInterconnectModule
FAKE_MSG_ERROR = 'Fake message error'
LOGICAL_INTERCONNECT = {'uri': '/rest/logical-interconnects/id',
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 10
},
'fcoeSettings': {
'fcoeMode': 'Unknown'
},
'telemetryConfiguration': {
'category': 'telemetry-configurations',
'enableTelemetry': True,
'modified': None,
'name': 'name-670923271-1482252496500',
'sampleCount': 10,
'sampleInterval': 250,
'uri': '/rest/logical-interconnects/123/telemetry-configurations/abc'
},
'portFlapProtection': {
'enabled': False
},
'scopeUris': 'rest/scopes/test'
}
TELEMETRY_CONFIG = dict(
sampleCount=12,
enableTelemetry=True,
sampleInterval=300
)
TELEMETRY_PARAMS_CONFIGURATION = dict(
config='config.json',
state='telemetry_configuration_updated',
data=dict(name='Test', telemetryConfiguration=TELEMETRY_CONFIG))
PARAMS_COMPLIANCE = dict(
config='config.json',
state='compliant',
data=dict(name='Name of the Logical Interconnect')
)
PARAMS_ETHERNET_SETTINGS = dict(
config='config.json',
state='ethernet_settings_updated',
data=dict(name='Name of the Logical Interconnect', ethernetSettings=dict(macRefreshInterval=7))
)
PARAMS_ETHERNET_SETTINGS_NO_CHANGES = dict(
config='config.json',
state='ethernet_settings_updated',
data=dict(name='Name of the Logical Interconnect', ethernetSettings=dict(macRefreshInterval=10))
)
PARAMS_INTERNAL_NETWORKS = dict(
config='config.json',
state='internal_networks_updated',
data=dict(name='Name of the Logical Interconnect',
internalNetworks=[dict(name='Network Name 1'), dict(name='Network Name 2'), dict(uri='/path/3')])
)
PARAMS_SETTINGS = dict(
config='config.json',
state='settings_updated',
data=dict(name='Name of the Logical Interconnect',
ethernetSettings=dict(macRefreshInterval=12),
fcoeSettings=dict(fcoeMode='NotApplicable'))
)
PARAMS_SETTINGS_ETHERNET = dict(
config='config.json',
state='settings_updated',
data=dict(name='Name of the Logical Interconnect',
ethernetSettings=dict(macRefreshInterval=12))
)
PARAMS_SETTTINGS_FCOE = dict(
config='config.json',
state='settings_updated',
data=dict(name='Name of the Logical Interconnect',
fcoeSettings=dict(fcoeMode='NotApplicable'))
)
PARAMS_GENERATE_FIB = dict(
config='config.json',
state='forwarding_information_base_generated',
data=dict(name='Name of the Logical Interconnect')
)
PARAMS_QOS_AGGREG_CONFIG = dict(
config='config.json',
state='qos_aggregated_configuration_updated',
data=dict(name='Name of the Logical Interconnect',
qosConfiguration=dict(activeQosConfig=dict(category='qos-aggregated-configuration',
configType='Passthrough',
downlinkClassificationType=None,
uplinkClassificationType=None,
qosTrafficClassifiers=[],
type='QosConfiguration')))
)
PARAMS_QOS_AGGREG_NO_CHANGES = dict(
config='config.json',
state='qos_aggregated_configuration_updated',
data=dict(name='Name of the Logical Interconnect',
qosConfiguration=dict(activeQosConfig=dict(category='qos-aggregated-configuration',
configType='CustomNoFCoE',
downlinkClassificationType='DSCP',
uplinkClassificationType=None,
qosTrafficClassifiers=['a', 'list', 'with', 'classifiers'],
type='QosConfiguration')))
)
PARAMS_SNMP_CONFIG = dict(
config='config.json',
state='snmp_configuration_updated',
data=dict(name='Name of the Logical Interconnect',
snmpConfiguration=dict(enabled=True))
)
PARAMS_SNMP_CONFIG_NO_CHANGES = dict(
config='config.json',
state='snmp_configuration_updated',
data=dict(name='Name of the Logical Interconnect',
snmpConfiguration=dict(enabled=False))
)
PARAMS_IGMP_SETTINGS = dict(
config='config.json',
state='igmp_settings_updated',
data=dict(name='Name of the Logical Interconnect',
igmpSettings=dict(enabled=True))
)
PARAMS_IGMP_SETTINGS_NO_CHANGES = dict(
config='config.json',
state='igmp_settings_updated',
data=dict(name='Name of the Logical Interconnect',
igmpSettings=dict(enabled=False))
)
PARAMS_PORT_MONITOR_CONFIGURATION = dict(
config='config.json',
state='port_monitor_updated',
data=dict(name='Name of the Logical Interconnect',
portMonitor=dict(enablePortMonitor=False))
)
PARAMS_PORT_MONITOR_CONFIGURATION_NO_CHANGES = dict(
config='config.json',
state='port_monitor_updated',
data=dict(name='Name of the Logical Interconnect',
portMonitor=dict(enablePortMonitor=True))
)
PARAMS_PORT_FLAP_SETTINGS = dict(
config='config.json',
state='port_flap_settings_updated',
data=dict(name='Name of the Logical Interconnect',
portFlapProtection=dict(enabled=True))
)
PARAMS_PORT_FLAP_SETTINGS_NO_CHANGES = dict(
config='config.json',
state='port_flap_settings_updated',
data=dict(name='Name of the Logical Interconnect',
portFlapProtection=dict(enabled=False))
)
PARAMS_CONFIGURATION = dict(
config='config.json',
state='configuration_updated',
data=dict(name='Name of the Logical Interconnect', enabled=True)
)
PARAMS_FIRMWARE_WITH_SPP_NAME = dict(
config='config.json',
state='firmware_installed',
data=dict(name='Name of the Logical Interconnect',
firmware=dict(command='Update',
spp='filename-of-the-firmware-to-install')))
PARAMS_BULK_INCONSISTENCY = dict(
config='config.json',
state='bulk_inconsistency_validated',
data=dict(name='Name of the Logical Interconnect',
bulk_update=dict(logicalInterconnectUris=['/rest/fake/1'])))
PARAMS_SCOPES = dict(
config='config.json',
state='scopes_updated',
data=dict(name='Name of the Logical Interconnect')
)
PARAMS_FIRMWARE_WITH_SPP_URI = dict(
config='config.json',
state='firmware_installed',
data=dict(name='Name of the Logical Interconnect',
firmware=dict(command='Update',
sppUri='/rest/firmware-drivers/filename-of-the-firmware-to-install')))
@pytest.mark.resource(TestLogicalInterconnectModule='logical_interconnects')
class TestLogicalInterconnectModule(OneViewBaseTest):
"""
Test the module constructor and shared functions
OneViewBaseTestCase has common mocks and tests for main function
"""
status = "Forwarding information base dump for logical interconnect yielded no results and ended with warnings."
response_body = {
'status': status,
'state': 'Warning'
}
qos_config = {
'inactiveFCoEQosConfig': None,
'inactiveNonFCoEQosConfig': None,
'activeQosConfig': {
'category': 'qos-aggregated-configuration',
'configType': 'CustomNoFCoE',
'downlinkClassificationType': 'DSCP',
'uplinkClassificationType': None,
'qosTrafficClassifiers': ['a', 'list', 'with', 'classifiers'],
'type': 'QosConfiguration'
}
}
snmp_config = {'enabled': False}
igmp_settings = {'enabled': False}
monitor_config = {'enablePortMonitor': True}
port_flap_config = {'enabled': False}
expected_data = {
'command': 'Update',
'sppUri': '/rest/firmware-drivers/filename-of-the-firmware-to-install'
}
li_inconsistency_data = {
'logicalInterconnectUris': '/rest/fake/1'
}
response = {
"response": "data"
}
telemetry_config_uri = LOGICAL_INTERCONNECT['telemetryConfiguration']['uri']
@pytest.fixture(autouse=True)
def specific_set_up(self):
self.mock_ov_client.api_version = 500
def test_should_fail_when_option_is_invalid(self):
self.mock_ansible_module.params = dict(
config='config.json',
state='ethernet_settings_updated',
data=dict(name='Name of the Logical Interconnect')
)
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=LogicalInterconnectModule.MSG_NO_OPTIONS_PROVIDED)
def test_should_return_to_a_consistent_state(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_compliance.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_COMPLIANCE
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_CONSISTENT,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = PARAMS_COMPLIANCE
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=LogicalInterconnectModule.MSG_NOT_FOUND)
def test_should_update_ethernet_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_ETH_SETTINGS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_ethernet_with_merged_data(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
expected_data = {'enableIgmpSnooping': True, 'macRefreshInterval': 7}
self.resource.update_ethernet_settings.assert_called_once_with(expected_data)
def test_should_do_nothing_when_no_changes_ethernet_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_ETHERNET_SETTINGS_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_internal_networks(self):
self.resource.data = LOGICAL_INTERCONNECT
self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], [{'uri': '/path/2'}]]
self.resource.update_internal_networks.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_INTERNAL_NETWORKS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_internal_networks_with_given_list(self):
self.resource.data = LOGICAL_INTERCONNECT
self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], [{'uri': '/path/2'}]]
self.resource.update_internal_networks.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
expected_list = ['/path/1', '/path/2', '/path/3']
self.resource.update_internal_networks.assert_called_once_with(
expected_list)
def test_should_fail_when_ethernet_network_not_found(self):
self.resource.data = LOGICAL_INTERCONNECT
self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], []]
self.resource.update_internal_networks.return_value = {}
self.mock_ansible_module.params = PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
exception=mock.ANY, msg=LogicalInterconnectModule.MSG_ETH_NETWORK_NOT_FOUND + "Network Name 2")
def test_should_update_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_SETTINGS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_settings_ethernet(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_SETTINGS_ETHERNET
LogicalInterconnectModule().run()
expected_settings = {
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 12
},
'fcoeSettings': {
'fcoeMode': 'Unknown'
}
}
self.resource.update_settings.assert_called_once_with(expected_settings)
def test_should_update_fcoe_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_SETTTINGS_FCOE
LogicalInterconnectModule().run()
expected_settings = {
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 10
},
'fcoeSettings': {
'fcoeMode': 'NotApplicable'
}
}
self.resource.update_settings.assert_called_once_with(expected_settings)
def test_update_settings_should_do_nothing_when_data_was_not_modified(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
params = PARAMS_SETTINGS.copy()
params['data']['ethernetSettings']['macRefreshInterval'] = 10
params['data']['fcoeSettings']['fcoeMode'] = 'Unknown'
self.mock_ansible_module.params = PARAMS_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_fail_when_settings_are_invalid(self):
self.mock_ansible_module.params = dict(
config='config.json',
state='settings_updated',
data=dict(name='Name of the Logical Interconnect')
)
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=LogicalInterconnectModule.MSG_NO_OPTIONS_PROVIDED)
def test_should_generate_interconnect_fib(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.create_forwarding_information_base.return_value = self.response_body
self.mock_ansible_module.params = PARAMS_GENERATE_FIB
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=self.status,
ansible_facts=dict(interconnect_fib=self.response_body)
)
def test_should_update_qos_aggreg_config(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_qos_aggregated_configuration.return_value = self.qos_config
self.resource.update_qos_aggregated_configuration.return_value = self.qos_config
self.mock_ansible_module.params = PARAMS_QOS_AGGREG_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_QOS_UPDATED,
ansible_facts=dict(qos_configuration=self.qos_config)
)
def test_should_do_nothing_when_no_changes_qos(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_qos_aggregated_configuration.return_value = self.qos_config
self.mock_ansible_module.params = PARAMS_QOS_AGGREG_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_snmp_configuration(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_snmp_configuration.return_value = self.snmp_config
self.resource.update_snmp_configuration.return_value = self.snmp_config
self.mock_ansible_module.params = PARAMS_SNMP_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_SNMP_UPDATED,
ansible_facts=dict(snmp_configuration=self.snmp_config)
)
def test_should_do_nothing_when_no_changes_snmp(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_snmp_configuration.return_value = self.snmp_config
self.resource.update_snmp_configuration.return_value = self.snmp_config
self.mock_ansible_module.params = PARAMS_SNMP_CONFIG_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_igmp_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_igmp_settings.return_value = self.igmp_settings
self.resource.update_igmp_settings.return_value = self.igmp_settings
self.mock_ansible_module.params = PARAMS_IGMP_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_IGMP_UPDATED,
ansible_facts=dict(igmp_settings=self.igmp_settings)
)
def test_should_do_nothing_when_no_changes_igmp(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_igmp_settings.return_value = self.igmp_settings
self.resource.update_igmp_settings.return_value = self.igmp_settings
self.mock_ansible_module.params = PARAMS_IGMP_SETTINGS_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_port_monitor_configuration(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_port_monitor.return_value = self.monitor_config
self.resource.update_port_monitor.return_value = self.monitor_config
self.mock_ansible_module.params = PARAMS_PORT_MONITOR_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_PORT_MONITOR_UPDATED,
ansible_facts=dict(port_monitor=self.monitor_config)
)
def test_should_do_nothing_when_no_changes_port_monitor(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.get_port_monitor.return_value = self.monitor_config
self.resource.update_port_monitor.return_value = self.monitor_config
self.mock_ansible_module.params = PARAMS_PORT_MONITOR_CONFIGURATION_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_port_flap_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_port_flap_settings.return_value = self.port_flap_config
self.mock_ansible_module.params = PARAMS_PORT_FLAP_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_PORT_FLAP_SETTINGS_UPDATED,
ansible_facts=dict(port_flap_settings=self.port_flap_config)
)
def test_should_do_nothing_when_no_changes_port_flap_settings(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_port_flap_settings.return_value = self.port_flap_config
self.mock_ansible_module.params = PARAMS_PORT_FLAP_SETTINGS_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED)
def test_should_update_configuration(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_configuration.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = PARAMS_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_CONFIGURATION_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_install_firmware(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = PARAMS_FIRMWARE_WITH_SPP_NAME
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_FIRMWARE_INSTALLED,
ansible_facts=dict(li_firmware=self.response)
)
def test_should_update_bulk_inconsistency(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.bulk_inconsistency_validate.return_value = self.li_inconsistency_data
self.mock_ansible_module.params = PARAMS_BULK_INCONSISTENCY
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_INCONSISTENCY_VALIDATED,
ansible_facts=dict(li_inconsistency_report=self.li_inconsistency_data)
)
def test_should_install_firmware_when_spp_name_set(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = PARAMS_FIRMWARE_WITH_SPP_NAME
LogicalInterconnectModule().run()
self.resource.install_firmware.assert_called_once_with(self.expected_data)
def test_should_update_firmware_when_spp_uri_set(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = PARAMS_FIRMWARE_WITH_SPP_URI
LogicalInterconnectModule().run()
self.resource.install_firmware.assert_called_once_with(self.expected_data)
def test_update_telemetry_configuration(self):
self.resource.data = LOGICAL_INTERCONNECT
self.resource.update_telemetry_configurations.return_value = LOGICAL_INTERCONNECT
telemetry_config = LOGICAL_INTERCONNECT['telemetryConfiguration']
self.mock_ansible_module.params = TELEMETRY_PARAMS_CONFIGURATION
LogicalInterconnectModule().run()
self.resource.update_telemetry_configurations.assert_called_once_with(
TELEMETRY_CONFIG)
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LogicalInterconnectModule.MSG_TELEMETRY_CONFIGURATION_UPDATED,
ansible_facts=dict(telemetry_configuration=telemetry_config)
)
def test_update_scopes_when_different(self):
self.resource.data = LOGICAL_INTERCONNECT
params_to_scope = PARAMS_SCOPES.copy()
params_to_scope['data']['scopeUris'] = ['test']
self.mock_ansible_module.params = params_to_scope
patch_return = LOGICAL_INTERCONNECT.copy()
patch_return['scopeUris'] = ['test']
obj = mock.Mock()
obj.data = patch_return
self.resource.patch.return_value = obj
LogicalInterconnectModule().run()
self.resource.patch.assert_called_once_with(operation='replace',
path='/scopeUris',
value=['test'])
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
ansible_facts=dict(scope_uris=['test']),
msg=LogicalInterconnectModule.MSG_SCOPES_UPDATED
)
def test_should_do_nothing_when_scopes_are_the_same(self):
params_to_scope = PARAMS_SCOPES.copy()
params_to_scope['data']['scopeUris'] = ['test']
self.mock_ansible_module.params = params_to_scope
resource_data = LOGICAL_INTERCONNECT.copy()
resource_data['scopeUris'] = ['test']
self.resource.data = resource_data
LogicalInterconnectModule().run()
self.resource.patch.not_been_called()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(scope_uris=['test']),
msg=LogicalInterconnectModule.MSG_NO_CHANGES_PROVIDED
)
if __name__ == '__main__':
pytest.main([__file__])