forked from HewlettPackard/oneview-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_oneview_logical_interconnect.py
879 lines (656 loc) · 33.8 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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
###
# Copyright (2016) 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 unittest
import mock
from utils import ValidateEtagTestCase, ModuleContructorTestCase, PreloadedMocksBaseTestCase
from oneview_logical_interconnect import (LogicalInterconnectModule,
LOGICAL_INTERCONNECT_CONSISTENT,
LOGICAL_INTERCONNECT_NOT_FOUND,
LOGICAL_INTERCONNECT_FIRMWARE_INSTALLED,
LOGICAL_INTERCONNECT_ETH_SETTINGS_UPDATED,
LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED,
LOGICAL_INTERCONNECT_INTERNAL_NETWORKS_UPDATED,
LOGICAL_INTERCONNECT_ETH_NETWORK_NOT_FOUND,
LOGICAL_INTERCONNECT_SETTINGS_UPDATED,
LOGICAL_INTERCONNECT_QOS_UPDATED,
LOGICAL_INTERCONNECT_SNMP_UPDATED,
LOGICAL_INTERCONNECT_PORT_MONITOR_UPDATED,
LOGICAL_INTERCONNECT_CONFIGURATION_UPDATED,
LOGICAL_INTERCONNECT_NO_OPTIONS_PROVIDED)
FAKE_MSG_ERROR = 'Fake message error'
LOGICAL_INTERCONNECT = {'uri': '/rest/logical-interconnects/id',
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 10
},
'fcoeSettings': {
'fcoeMode': 'Unknown'
}}
class LogicalInterconnectModuleSpec(unittest.TestCase, ModuleContructorTestCase, ValidateEtagTestCase):
"""
Test the module constructor
ModuleContructorTestCase has common tests for class constructor and main function
"""
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
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(
msg=LOGICAL_INTERCONNECT_NO_OPTIONS_PROVIDED
)
class LogicalInterconnectCompliantStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
ValidateEtagTestCase has common tests for the validate_etag attribute,
also provides the mocks used in this test case.
"""
PARAMS_COMPLIANCE = dict(
config='config.json',
state='compliant',
data=dict(name='Name of the Logical Interconnect')
)
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_return_to_a_consistent_state(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_compliance.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_COMPLIANCE
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_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 = self.PARAMS_COMPLIANCE
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_compliance_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_compliance.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_COMPLIANCE
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectEthernetSettingsUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
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))
)
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_ethernet_settings(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_ETH_SETTINGS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_ethernet_with_merged_data(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
expected_uri = '/rest/logical-interconnects/id'
expected_data = {'enableIgmpSnooping': True, 'macRefreshInterval': 7}
self.resource.update_ethernet_settings.assert_called_once_with(expected_uri, expected_data)
def test_should_do_nothing_when_no_changes(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_ETHERNET_SETTINGS_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_ethernet_raises_exception(self
):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_ethernet_settings.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_ETHERNET_SETTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectInternalNetworksUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
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')])
)
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_internal_networks(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_INTERNAL_NETWORKS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_internal_networks_with_given_list(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
expected_uri = '/rest/logical-interconnects/id'
expected_list = ['/path/1', '/path/2', '/path/3']
self.resource.update_internal_networks.assert_called_once_with(expected_uri,
expected_list)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_ethernet_network_not_found(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_ETH_NETWORK_NOT_FOUND + "Network Name 2"
)
def test_should_fail_when_update_internal_networks_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.mock_ov_client.ethernet_networks.get_by.side_effect = [[{'uri': '/path/1'}], [{'uri': '/path/2'}]]
self.resource.update_internal_networks.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_INTERNAL_NETWORKS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectSettingsUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
PARAMS_SETTTINGS = dict(
config='config.json',
state='settings_updated',
data=dict(name='Name of the Logical Interconnect',
ethernetSettings=dict(macRefreshInterval=12),
fcoeSettings=dict(fcoeMode='NotApplicable'))
)
PARAMS_SETTTINGS_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'))
)
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_settings(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_SETTTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_SETTINGS_UPDATED,
ansible_facts=dict(logical_interconnect=LOGICAL_INTERCONNECT)
)
def test_should_update_ethernet_settings(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_SETTTINGS_ETHERNET
LogicalInterconnectModule().run()
expected_uri = '/rest/logical-interconnects/id'
expected_settings = {
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 12
},
'fcoeSettings': {
'fcoeMode': 'Unknown'
}
}
self.resource.update_settings.assert_called_once_with(expected_uri, expected_settings)
def test_should_update_fcoe_settings(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_SETTTINGS_FCOE
LogicalInterconnectModule().run()
expected_uri = '/rest/logical-interconnects/id'
expected_settings = {
'ethernetSettings': {
'enableIgmpSnooping': True,
'macRefreshInterval': 10
},
'fcoeSettings': {
'fcoeMode': 'NotApplicable'
}
}
self.resource.update_settings.assert_called_once_with(expected_uri, expected_settings)
def test_update_settings_should_do_nothing_when_data_was_not_modified(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_settings.return_value = LOGICAL_INTERCONNECT
params = self.PARAMS_SETTTINGS.copy()
params['data']['ethernetSettings']['macRefreshInterval'] = 10
params['data']['fcoeSettings']['fcoeMode'] = 'Unknown'
self.mock_ansible_module.params = self.PARAMS_SETTTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED,
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 = self.PARAMS_SETTTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_settings_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_settings.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_SETTTINGS
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
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(
msg=LOGICAL_INTERCONNECT_NO_OPTIONS_PROVIDED
)
class LogicalInterconnectForwardingInformationBaseGeneratedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
PARAMS_GENERATE_FIB = dict(
config='config.json',
state='forwarding_information_base_generated',
data=dict(name='Name of the Logical Interconnect')
)
status = "Forwarding information base dump for logical interconnect yielded no results and ended with warnings."
response_body = {
'status': status,
'state': 'Warning'
}
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_generate_interconnect_fib(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.create_forwarding_information_base.return_value = self.response_body
self.mock_ansible_module.params = self.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_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_GENERATE_FIB
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_generate_fib_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.create_forwarding_information_base.side_effect = \
Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_GENERATE_FIB
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectQosAggregatedConfigurationUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
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')))
)
qos_config = {
'inactiveFCoEQosConfig': None,
'inactiveNonFCoEQosConfig': None,
'activeQosConfig': {
'category': 'qos-aggregated-configuration',
'configType': 'CustomNoFCoE',
'downlinkClassificationType': 'DSCP',
'uplinkClassificationType': None,
'qosTrafficClassifiers': ['a', 'list', 'with', 'classifiers'],
'type': 'QosConfiguration'
}
}
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_qos_aggreg_config(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_QOS_AGGREG_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_QOS_UPDATED,
ansible_facts=dict(qos_configuration=self.qos_config)
)
def test_should_do_nothing_when_no_changes(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.get_qos_aggregated_configuration.return_value = self.qos_config
self.mock_ansible_module.params = self.PARAMS_QOS_AGGREG_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_QOS_AGGREG_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_qos_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.get_qos_aggregated_configuration.return_value = self.qos_config
self.resource.update_qos_aggregated_configuration.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_QOS_AGGREG_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectSnmpConfigurationUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
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))
)
snmp_config = {'enabled': False}
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_snmp_configuration(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_SNMP_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_SNMP_UPDATED,
ansible_facts=dict(snmp_configuration=self.snmp_config)
)
def test_should_do_nothing_when_no_changes(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_SNMP_CONFIG_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_SNMP_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_snmp_raises_exception(self
):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.get_snmp_configuration.return_value = self.snmp_config
self.resource.update_snmp_configuration.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_SNMP_CONFIG
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectPortMonitorUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
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))
)
monitor_config = {'enablePortMonitor': True}
def test_should_update_port_monitor_configuration(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_PORT_MONITOR_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_PORT_MONITOR_UPDATED,
ansible_facts=dict(port_monitor=self.monitor_config)
)
def test_should_do_nothing_when_no_changes(self):
self.resource.get_by_name.return_value = 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 = self.PARAMS_PORT_MONITOR_CONFIGURATION_NO_CHANGES
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=LOGICAL_INTERCONNECT_NO_CHANGES_PROVIDED)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_PORT_MONITOR_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_port_monitor_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.get_port_monitor.return_value = self.monitor_config
self.resource.update_port_monitor.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_PORT_MONITOR_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectConfigurationUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
PARAMS_CONFIGURATION = dict(
config='config.json',
state='configuration_updated',
data=dict(name='Name of the Logical Interconnect', enabled=True)
)
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_update_configuration(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_configuration.return_value = LOGICAL_INTERCONNECT
self.mock_ansible_module.params = self.PARAMS_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_CONFIGURATION_UPDATED,
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 = self.PARAMS_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_update_configuration_raises_exception(self
):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.update_configuration.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_CONFIGURATION
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
class LogicalInterconnectFirmwareUpdatedStateSpec(unittest.TestCase, PreloadedMocksBaseTestCase):
"""
PreloadedMocksBaseTestCase provides the mocks used in this test case.
"""
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_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')))
expected_data = {
'command': 'Update',
'sppUri': '/rest/firmware-drivers/filename-of-the-firmware-to-install'
}
response = {
"response": "data"
}
def setUp(self):
self.configure_mocks(self, LogicalInterconnectModule)
self.resource = self.mock_ov_client.logical_interconnects
def test_should_install_firmware(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_NAME
LogicalInterconnectModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=LOGICAL_INTERCONNECT_FIRMWARE_INSTALLED,
ansible_facts=dict(li_firmware=self.response)
)
def test_should_install_firmware_when_spp_name_set(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_NAME
LogicalInterconnectModule().run()
self.resource.install_firmware.assert_called_once_with(self.expected_data, mock.ANY)
def test_should_update_firmware_when_spp_uri_set(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.install_firmware.return_value = self.response
self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_URI
LogicalInterconnectModule().run()
self.resource.install_firmware.assert_called_once_with(self.expected_data, mock.ANY)
def test_should_fail_when_logical_interconnect_not_found(self):
self.resource.get_by_name.return_value = None
self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_URI
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=LOGICAL_INTERCONNECT_NOT_FOUND
)
def test_should_fail_when_install_firmware_raises_exception(self):
self.resource.get_by_name.return_value = LOGICAL_INTERCONNECT
self.resource.install_firmware.side_effect = Exception(FAKE_MSG_ERROR)
self.mock_ansible_module.params = self.PARAMS_FIRMWARE_WITH_SPP_URI
LogicalInterconnectModule().run()
self.mock_ansible_module.fail_json.assert_called_once_with(
msg=FAKE_MSG_ERROR
)
if __name__ == '__main__':
unittest.main()