File: test_system.py

package info (click to toggle)
python-sushy 5.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,036 kB
  • sloc: python: 16,382; makefile: 24; sh: 2
file content (1102 lines) | stat: -rw-r--r-- 48,068 bytes parent folder | download
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# Copyright 2017 Red Hat, Inc.
# All Rights Reserved.
#
#    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 json
from unittest import mock

from dateutil import parser

import sushy
from sushy import exceptions
from sushy.resources.chassis import chassis
from sushy.resources import constants as res_cons
from sushy.resources.manager import manager
from sushy.resources.manager import virtual_media
from sushy.resources.oem import fake
from sushy.resources.system import bios
from sushy.resources.system import processor
from sushy.resources.system import secure_boot
from sushy.resources.system import simple_storage
from sushy.resources.system import system
from sushy.tests.unit import base


class SystemTestCase(base.TestCase):

    def setUp(self):
        super().setUp()
        self.conn = mock.Mock()
        self.conn.get.return_value.headers = {'Allow': 'GET,HEAD'}
        with open('sushy/tests/unit/json_samples/system.json') as f:
            self.json_doc = json.load(f)

        self.conn.get.return_value.json.return_value = self.json_doc

        self.sys_inst = system.System(
            self.conn, '/redfish/v1/Systems/437XR1138R2',
            redfish_version='1.0.2')
        self.sys_inst._get_etag = mock.Mock()
        self.sys_inst._get_etag.return_value = '81802dbf61beb0bd'

    def test__parse_attributes(self):
        self.sys_inst._parse_attributes(self.json_doc)
        self.assertEqual('1.0.2', self.sys_inst.redfish_version)
        self.assertEqual('Chicago-45Z-2381', self.sys_inst.asset_tag)
        self.assertEqual('P79 v1.45 (12/06/2017)', self.sys_inst.bios_version)
        self.assertEqual('Web Front End node', self.sys_inst.description)
        self.assertEqual('web483', self.sys_inst.hostname)
        self.assertEqual('437XR1138R2', self.sys_inst.identity)
        self.assertEqual(sushy.IndicatorLED.OFF,
                         self.sys_inst.indicator_led)
        self.assertEqual('Contoso', self.sys_inst.manufacturer)
        self.assertEqual('WebFrontEnd483', self.sys_inst.name)
        self.assertEqual('224071-J23', self.sys_inst.part_number)
        self.assertEqual('437XR1138R2', self.sys_inst.serial_number)
        self.assertEqual('8675309', self.sys_inst.sku)
        self.assertEqual(sushy.SystemType.PHYSICAL, self.sys_inst.system_type)
        self.assertEqual('38947555-7742-3448-3784-823347823834',
                         self.sys_inst.uuid)
        self.assertEqual(res_cons.State.ENABLED, self.sys_inst.status.state)
        self.assertEqual(res_cons.Health.OK, self.sys_inst.status.health)
        self.assertEqual(res_cons.Health.OK,
                         self.sys_inst.status.health_rollup)
        self.assertEqual(sushy.PowerState.ON, self.sys_inst.power_state)
        self.assertEqual(96, self.sys_inst.memory_summary.size_gib)
        self.assertEqual("OK", self.sys_inst.memory_summary.health)
        self.assertIsNotNone(self.sys_inst.maintenance_window)
        self.assertEqual(1, self.sys_inst.maintenance_window
                         .maintenance_window_duration_in_seconds)
        self.assertEqual(parser.parse('2016-03-07T14:44:30-05:05'),
                         self.sys_inst.maintenance_window
                         .maintenance_window_start_time)
        for oem_vendor in self.sys_inst.oem_vendors:
            self.assertIn(oem_vendor, ('Contoso', 'Chipwise'))
        self.assertEqual(sushy.BootProgressStates.OS_RUNNING,
                         self.sys_inst.boot_progress.last_state)
        self.assertEqual(66,
                         self.sys_inst.boot_progress.last_boot_seconds_count)
        self.assertEqual(parser.parse('2017-05-03T23:12:37-05:00'),
                         self.sys_inst.boot_progress.last_state_updated_at)
        self.assertEqual("OS foo running.",
                         self.sys_inst.boot_progress.oem_last_state)

    def test__parse_attributes_return(self):
        attributes = self.sys_inst._parse_attributes(self.json_doc)

        # Test that various types are returned correctly
        self.assertEqual('Chicago-45Z-2381', attributes.get('asset_tag'))
        self.assertEqual(sushy.IndicatorLED.OFF,
                         attributes.get('indicator_led'))
        self.assertEqual({'health': res_cons.Health.OK,
                          'health_rollup': res_cons.Health.OK,
                          'state': res_cons.State.ENABLED},
                         attributes.get('status'))
        self.assertEqual({'maintenance_window_duration_in_seconds': 1,
                          'maintenance_window_start_time':
                          parser.parse('2016-03-07T14:44:30-05:05')},
                         attributes.get('maintenance_window'))
        self.assertEqual(
            {'reset': {'allowed_values':
                       ['On', 'ForceOff', 'GracefulShutdown',
                        'GracefulRestart', 'ForceRestart', 'Nmi',
                        'ForceOn', 'PushPowerButton'],
                       'operation_apply_time_support':
                       {'_maintenance_window_resource':
                        {'resource_uri':
                         '/redfish/v1/Systems/437XR1138R2'},
                        'maintenance_window_duration_in_seconds': 600,
                        'maintenance_window_start_time':
                        parser.parse('2017-05-03T23:12:37-05:00'),
                        'supported_values':
                        ['Immediate', 'AtMaintenanceWindowStart'],
                        'mapped_supported_values':
                        [res_cons.ApplyTime.IMMEDIATE,
                         res_cons.ApplyTime.AT_MAINTENANCE_WINDOW_START]},
                       'target_uri':
                       '/redfish/v1/Systems/437XR1138R2/Actions/'
                       'ComputerSystem.Reset'}},
            attributes.get('_actions'))

    def test__parse_attributes_missing_actions(self):
        self.sys_inst.json.pop('Actions')
        self.assertRaisesRegex(
            exceptions.MissingAttributeError, 'attribute Actions',
            self.sys_inst._parse_attributes, self.json_doc)

    def test__parse_attributes_missing_boot(self):
        self.sys_inst.json.pop('Boot')
        self.assertRaisesRegex(
            exceptions.MissingAttributeError, 'attribute Boot',
            self.sys_inst._parse_attributes, self.json_doc)

    def test__parse_attributes_missing_reset_target(self):
        self.sys_inst.json['Actions']['#ComputerSystem.Reset'].pop(
            'target')
        self.assertRaisesRegex(
            exceptions.MissingAttributeError,
            'attribute Actions/#ComputerSystem.Reset/target',
            self.sys_inst._parse_attributes, self.json_doc)

    def test__parse_attributes_null_memory_capacity(self):
        self.sys_inst.json['MemorySummary']['TotalSystemMemoryGiB'] = None
        self.sys_inst._parse_attributes(self.json_doc)
        self.assertIsNone(self.sys_inst.memory_summary.size_gib)

    def test__parse_attributes_bad_maintenance_window_time(self):
        self.sys_inst.json['@Redfish.MaintenanceWindow'][
            'MaintenanceWindowStartTime'] = 'bad date'
        self.assertRaisesRegex(
            exceptions.MalformedAttributeError,
            '@Redfish.MaintenanceWindow/MaintenanceWindowStartTime',
            self.sys_inst._parse_attributes, self.json_doc)

    def test_get__reset_action_element(self):
        value = self.sys_inst._get_reset_action_element()
        self.assertEqual("/redfish/v1/Systems/437XR1138R2/Actions/"
                         "ComputerSystem.Reset",
                         value.target_uri)
        self.assertEqual(["On",
                          "ForceOff",
                          "GracefulShutdown",
                          "GracefulRestart",
                          "ForceRestart",
                          "Nmi",
                          "ForceOn",
                          "PushPowerButton"
                          ],
                         value.allowed_values)

    def test_get__reset_action_element_missing_reset_action(self):
        self.sys_inst._actions.reset = None
        self.assertRaisesRegex(
            exceptions.MissingActionError, 'action #ComputerSystem.Reset',
            self.sys_inst._get_reset_action_element)

    def test_get_allowed_reset_system_values(self):
        values = self.sys_inst.get_allowed_reset_system_values()
        expected = set([sushy.ResetType.GRACEFUL_SHUTDOWN,
                        sushy.ResetType.GRACEFUL_RESTART,
                        sushy.ResetType.FORCE_RESTART,
                        sushy.ResetType.FORCE_OFF,
                        sushy.ResetType.FORCE_ON,
                        sushy.ResetType.ON,
                        sushy.ResetType.NMI,
                        sushy.ResetType.PUSH_POWER_BUTTON])
        self.assertEqual(expected, values)
        self.assertIsInstance(values, set)

    @mock.patch.object(system.LOG, 'warning', autospec=True)
    def test_get_allowed_reset_system_values_no_values_specified(
            self, mock_log):
        self.sys_inst._actions.reset.allowed_values = {}
        values = self.sys_inst.get_allowed_reset_system_values()
        # Assert it returns all values if it can't get the specific ones
        expected = set([sushy.ResetType.GRACEFUL_SHUTDOWN,
                        sushy.ResetType.GRACEFUL_RESTART,
                        sushy.ResetType.FORCE_RESTART,
                        sushy.ResetType.FORCE_OFF,
                        sushy.ResetType.FORCE_ON,
                        sushy.ResetType.ON,
                        sushy.ResetType.NMI,
                        sushy.ResetType.PUSH_POWER_BUTTON,
                        sushy.ResetType.POWER_CYCLE,
                        sushy.ResetType.SUSPEND,
                        sushy.ResetType.RESUME,
                        sushy.ResetType.PAUSE])
        self.assertEqual(expected, values)
        self.assertIsInstance(values, set)
        self.assertEqual(1, mock_log.call_count)

    def test_reset_action_operation_apply_time_support(self):
        support = self.sys_inst._actions.reset.operation_apply_time_support
        self.assertIsNotNone(support)
        self.assertEqual(['Immediate', 'AtMaintenanceWindowStart'],
                         support.supported_values)
        self.assertEqual([res_cons.ApplyTime.IMMEDIATE,
                          res_cons.ApplyTime.AT_MAINTENANCE_WINDOW_START],
                         support.mapped_supported_values)
        self.assertEqual(parser.parse('2017-05-03T23:12:37-05:00'),
                         support.maintenance_window_start_time)
        self.assertEqual(600, support.maintenance_window_duration_in_seconds)
        self.assertEqual('/redfish/v1/Systems/437XR1138R2',
                         support._maintenance_window_resource.resource_uri)

    def test_reset_system(self):
        self.sys_inst.reset_system(sushy.ResetType.FORCE_OFF)
        self.sys_inst._conn.post.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2/Actions/ComputerSystem.Reset',
            data={'ResetType': 'ForceOff'})

    def test_reset_system_invalid_value(self):
        self.assertRaises(exceptions.InvalidParameterValueError,
                          self.sys_inst.reset_system, 'invalid-value')

    def test_get_allowed_system_boot_source_values(self):
        values = self.sys_inst.get_allowed_system_boot_source_values()
        expected = set([sushy.BootSource.NONE,
                        sushy.BootSource.PXE,
                        sushy.BootSource.CD,
                        sushy.BootSource.USB,
                        sushy.BootSource.HDD,
                        sushy.BootSource.BIOS_SETUP,
                        sushy.BootSource.UTILITIES,
                        sushy.BootSource.DIAGS,
                        sushy.BootSource.SD_CARD,
                        sushy.BootSource.UEFI_TARGET,
                        sushy.BootSource.UEFI_HTTP])
        self.assertEqual(expected, values)
        self.assertIsInstance(values, set)

    @mock.patch.object(system.LOG, 'warning', autospec=True)
    def test_get_allowed_system_boot_source_values_no_values_specified(
            self, mock_log):
        self.sys_inst.boot.allowed_values = None
        values = self.sys_inst.get_allowed_system_boot_source_values()
        # Assert it returns all values if it can't get the specific ones
        expected = set([sushy.BootSource.NONE,
                        sushy.BootSource.PXE,
                        sushy.BootSource.CD,
                        sushy.BootSource.USB,
                        sushy.BootSource.HDD,
                        sushy.BootSource.BIOS_SETUP,
                        sushy.BootSource.UTILITIES,
                        sushy.BootSource.DIAGS,
                        sushy.BootSource.SD_CARD,
                        sushy.BootSource.FLOPPY,
                        sushy.BootSource.UEFI_TARGET,
                        sushy.BootSource.UEFI_SHELL,
                        sushy.BootSource.UEFI_HTTP,
                        sushy.BootSource.REMOTE_DRIVE,
                        sushy.BootSource.UEFI_BOOT_NEXT,
                        sushy.BootSource.USB_CD])
        self.assertEqual(expected, values)
        self.assertIsInstance(values, set)
        self.assertEqual(1, mock_log.call_count)

    def test_set_system_boot_options(self):
        self.sys_inst.set_system_boot_options(
            sushy.BootSource.PXE,
            enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
            mode=sushy.BootSourceOverrideMode.UEFI)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
                           'BootSourceOverrideTarget': 'Pxe',
                           'BootSourceOverrideMode': 'UEFI'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_no_mode_specified(self):
        self.sys_inst.set_system_boot_options(
            sushy.BootSource.HDD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Hdd'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_no_target_specified(self):
        self.sys_inst.set_system_boot_options(
            enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
            mode=sushy.BootSourceOverrideMode.UEFI)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
                           'BootSourceOverrideMode': 'UEFI'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_no_freq_specified(self):
        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.PXE,
            mode=sushy.BootSourceOverrideMode.UEFI)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideTarget': 'Pxe',
                           'BootSourceOverrideMode': 'UEFI'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_nothing_specified(self):
        self.sys_inst.set_system_boot_options()
        self.sys_inst._conn.patch.assert_not_called()

    def test_set_system_boot_options_invalid_target(self):
        self.assertRaises(exceptions.InvalidParameterValueError,
                          self.sys_inst.set_system_boot_source,
                          'invalid-target')

    def test_set_system_boot_options_invalid_enabled(self):
        with self.assertRaisesRegex(
            exceptions.InvalidParameterValueError,
            f'"enabled" value.*{list(sushy.BootSourceOverrideEnabled)}'):

            self.sys_inst.set_system_boot_options(
                sushy.BootSource.HDD,
                enabled='invalid-enabled')

    def test_set_system_boot_options_supermicro_usb_cd_boot(self):
        (self.json_doc["Boot"]
         ["BootSourceOverrideTarget@Redfish.AllowableValues"]).append("UsbCd")
        self.sys_inst._parse_attributes(self.json_doc)

        self.sys_inst.manufacturer = "supermicro"
        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'UsbCd'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_supermicro_usb_cd_boot_ars111glnhr(self):
        (self.json_doc["Boot"]
         ["BootSourceOverrideTarget@Redfish.AllowableValues"]).append("UsbCd")
        self.sys_inst._parse_attributes(self.json_doc)

        self.sys_inst.manufacturer = "supermicro"
        self.sys_inst.model = "ARS-111GL-NHR"
        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Cd'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_supermicro_no_usb_cd_boot(self):

        self.sys_inst.manufacturer = "supermicro"
        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Cd'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_options_settings_resource_nokia(self):
        with open('sushy/tests/unit/json_samples/settings-nokia.json') as f:
            settings_obj = json.load(f)

        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        with open('sushy/tests/unit/json_samples/'
                  'settings-body-nokia.json') as f:
            settings_body = json.load(f)

        get_settings = mock.MagicMock(headers={'ETag': '"3d7b838291941d"'})
        get_settings.json.return_value = settings_body
        get_system = mock.MagicMock(headers={'ETag': '"222"'})
        self.conn.get.side_effect = [get_settings, get_system]

        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/Self/SD',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Cd'}},
            etag='"3d7b838291941d"')

    def test_set_system_boot_options_settings_resource(self):
        with open('sushy/tests/unit/json_samples/settings.json') as f:
            settings_obj = json.load(f)

        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        with open('sushy/tests/unit/json_samples/'
                  'settings-body-nokia.json') as f:
            settings_body = json.load(f)

        get_settings = mock.MagicMock(headers={'ETag': '"3d7b838291941d"'})
        get_settings.json.return_value = settings_body
        get_system = mock.MagicMock(headers={'ETag': '"222"'})
        self.conn.get.side_effect = [get_settings, get_system]

        self.conn.get.return_value.json.return_value = settings_body

        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Cd'}},
            etag='"3d7b838291941d"')

    def test_set_system_boot_options_settings_resource_lenovo(self):
        self.sys_inst = system.System(
            self.conn, '/redfish/v1/Systems/1',
            redfish_version='1.0.2')

        with open('sushy/tests/unit/json_samples/'
                  'settings-lenovo-se450.json') as f:
            settings_obj = json.load(f)

        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        with open('sushy/tests/unit/json_samples/'
                  'settings-body-lenovo-se450.json') as f:
            settings_body = json.load(f)

        get_settings = mock.MagicMock(headers={'ETag': '"3d7b838291941d"'})
        get_settings.json.return_value = settings_body
        get_system = mock.MagicMock(headers={'ETag': '"222"'})
        self.conn.get.side_effect = [get_settings, get_system]

        self.sys_inst.set_system_boot_options(
            target=sushy.BootSource.CD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)

        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/1',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Cd'}},
            etag='"222"')

    def test_set_system_boot_options_settings_resource_bootmode_only(self):
        self.sys_inst = system.System(
            self.conn, '/redfish/v1/Systems/1',
            redfish_version='1.0.2')

        with open('sushy/tests/unit/json_samples/'
                  'settings-nokia.json') as f:
            settings_obj = json.load(f)

        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        with open('sushy/tests/unit/json_samples/'
                  'settings-body-bootsourceoverridemode-only.json') as f:
            settings_body = json.load(f)

        get_settings = mock.MagicMock(headers={'ETag': '"3d7b838291941d"'})
        get_settings.json.return_value = settings_body
        get_system = mock.MagicMock(headers={'ETag': '"222"'})
        self.conn.get.side_effect = [get_settings, get_system]

        self.sys_inst.set_system_boot_options(
            mode=sushy.BootSourceOverrideMode.UEFI)

        self.sys_inst._conn.patch.assert_called_with(
            '/redfish/v1/Systems/Self/SD',
            data={'Boot': {'BootSourceOverrideMode': 'UEFI'}},
            etag='"3d7b838291941d"')

    def test_set_system_boot_options_httpbooturi(self):
        self.sys_inst.set_system_boot_options(
            sushy.BootSource.UEFI_HTTP,
            enabled=sushy.BootSourceOverrideEnabled.ONCE,
            mode=sushy.BootSourceOverrideMode.UEFI,
            http_boot_uri='http://test.lan/test_image.iso'
            )
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideTarget': 'UefiHttp',
                           'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideMode': 'UEFI',
                           'HttpBootUri': 'http://test.lan/test_image.iso'}},
            etag=mock.ANY)

    def test_set_system_boot_options_httpboot_settings(self):

        with open('sushy/tests/unit/json_samples/settings-nokia.json') as f:
            settings_obj = json.load(f)

        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        with open('sushy/tests/unit/json_samples/'
                  'settings-body-nokia.json') as f:
            settings_body = json.load(f)

        get_settings = mock.MagicMock(headers={'ETag': '"3d7b838291941d"'})
        get_settings.json.return_value = settings_body
        get_system = mock.MagicMock(headers={'ETag': '"222"'})
        self.conn.get.side_effect = [get_settings, get_system]

        self.sys_inst.set_system_boot_options(
            sushy.BootSource.UEFI_HTTP,
            enabled=sushy.BootSourceOverrideEnabled.ONCE,
            http_boot_uri='http://test.lan/test_image.iso'
            )
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/Self/SD',
            data={'Boot': {'BootSourceOverrideTarget': 'UefiHttp',
                           'BootSourceOverrideEnabled': 'Once',
                           'HttpBootUri': 'http://test.lan/test_image.iso'}},
            etag=mock.ANY)

    def test_set_system_boot_options_httpboot(self):
        self.sys_inst.set_system_boot_options(
            sushy.BootSource.UEFI_HTTP,
            enabled=sushy.BootSourceOverrideEnabled.ONCE,
            mode=sushy.BootSourceOverrideMode.UEFI
            )
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideTarget': 'UefiHttp',
                           'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideMode': 'UEFI',
                           'HttpBootUri': None}},
            etag=mock.ANY)

    def test_set_system_boot_options_httpboot_unset(self):
        self.sys_inst._settings = mock.Mock()
        self.sys_inst._settings.resource_uri = 'meow'
        settings_body = json.dumps(
            {'Boot': {'HttpBootUri': 'http://foo.bar'}}
        )

        get_settings = mock.MagicMock()
        get_settings.json.return_value = settings_body
        self.conn.get.side_effect = get_settings

        self.sys_inst.set_system_boot_options(
            sushy.BootSource.HDD,
            mode=sushy.BootSourceOverrideMode.UEFI
            )
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideTarget': 'Hdd',
                           'BootSourceOverrideMode': 'UEFI',
                           'HttpBootUri': None}},
            etag=mock.ANY)

    def test_set_system_boot_source(self):
        self.sys_inst.set_system_boot_source(
            sushy.BootSource.PXE,
            enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
            mode=sushy.BootSourceOverrideMode.UEFI)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
                           'BootSourceOverrideTarget': 'Pxe',
                           'BootSourceOverrideMode': 'UEFI'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_source_with_etag(self):
        self.conn.get.return_value.headers = {'ETag': '"81802dbf61beb0bd"'}
        self.sys_inst.set_system_boot_source(
            sushy.BOOT_SOURCE_TARGET_PXE,
            enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS,
            mode=sushy.BOOT_SOURCE_MODE_UEFI)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
                           'BootSourceOverrideTarget': 'Pxe',
                           'BootSourceOverrideMode': 'UEFI'}},
            etag="81802dbf61beb0bd")

    def test_set_system_boot_source_no_mode_specified(self):
        self.sys_inst.set_system_boot_source(
            sushy.BootSource.HDD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Hdd'}},
            etag='81802dbf61beb0bd')

    def test_set_system_boot_unsets_http_boot_uri(self):
        self.sys_inst.set_system_boot_source(
            sushy.BootSource.HDD,
            enabled=sushy.BootSourceOverrideEnabled.ONCE)
        self.sys_inst._conn.patch.assert_called_once_with(
            '/redfish/v1/Systems/437XR1138R2',
            data={'Boot': {'BootSourceOverrideEnabled': 'Once',
                           'BootSourceOverrideTarget': 'Hdd'}},
            etag=mock.ANY)

    def test_set_system_boot_source_invalid_target(self):
        self.assertRaises(exceptions.InvalidParameterValueError,
                          self.sys_inst.set_system_boot_source,
                          'invalid-target')

    def test_set_system_boot_source_invalid_enabled(self):
        with self.assertRaisesRegex(
            exceptions.InvalidParameterValueError,
            f'"enabled" value.*{list(sushy.BootSourceOverrideEnabled)}'):

            self.sys_inst.set_system_boot_source(
                sushy.BootSource.HDD,
                enabled='invalid-enabled')

    def test_set_indicator_led(self):
        with mock.patch.object(
                self.sys_inst, 'invalidate', autospec=True) as invalidate_mock:
            self.sys_inst.set_indicator_led(sushy.IndicatorLED.BLINKING)
            self.sys_inst._conn.patch.assert_called_once_with(
                '/redfish/v1/Systems/437XR1138R2',
                data={'IndicatorLED': 'Blinking'},
                etag='81802dbf61beb0bd')

            invalidate_mock.assert_called_once_with()

    def test_set_indicator_led_invalid_state(self):
        self.assertRaises(exceptions.InvalidParameterValueError,
                          self.sys_inst.set_indicator_led,
                          'spooky-glowing')

    def test__get_processor_collection_path_missing_processors_attr(self):
        self.sys_inst._json.pop('Processors')
        self.assertRaisesRegex(
            exceptions.MissingAttributeError, 'attribute Processors',
            self.sys_inst._get_processor_collection_path)

    def test_memory_summary_missing_attr(self):
        # | GIVEN |
        self.sys_inst._json['MemorySummary']['Status'].pop('HealthRollup')
        # | WHEN |
        self.sys_inst._parse_attributes(self.json_doc)
        # | THEN |
        self.assertEqual(96, self.sys_inst.memory_summary.size_gib)
        self.assertIsNone(self.sys_inst.memory_summary.health)

        # | GIVEN |
        self.sys_inst._json['MemorySummary'].pop('Status')
        # | WHEN |
        self.sys_inst._parse_attributes(self.json_doc)
        # | THEN |
        self.assertEqual(96, self.sys_inst.memory_summary.size_gib)
        self.assertIsNone(self.sys_inst.memory_summary.health)

        # | GIVEN |
        self.sys_inst._json['MemorySummary'].pop('TotalSystemMemoryGiB')
        # | WHEN |
        self.sys_inst._parse_attributes(self.json_doc)
        # | THEN |
        self.assertIsNone(self.sys_inst.memory_summary.size_gib)
        self.assertIsNone(self.sys_inst.memory_summary.health)

        # | GIVEN |
        self.sys_inst._json.pop('MemorySummary')
        # | WHEN |
        self.sys_inst._parse_attributes(self.json_doc)
        # | THEN |
        self.assertIsNone(self.sys_inst.memory_summary)

    def test_processors(self):
        # | GIVEN |
        self.conn.get.return_value.json.reset_mock()
        with open('sushy/tests/unit/json_samples/'
                  'processor_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN |
        actual_processors = self.sys_inst.processors
        # | THEN |
        self.assertIsInstance(actual_processors,
                              processor.ProcessorCollection)
        self.conn.get.return_value.json.assert_called_once_with()

        # reset mock
        self.conn.get.return_value.json.reset_mock()
        # | WHEN & THEN |
        # tests for same object on invoking subsequently
        self.assertIs(actual_processors,
                      self.sys_inst.processors)
        self.conn.get.return_value.json.assert_not_called()

    def test_processors_on_refresh(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'processor_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.processors,
                              processor.ProcessorCollection)

        # On refreshing the system instance...
        with open('sushy/tests/unit/json_samples/system.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        self.sys_inst.invalidate()
        self.sys_inst.refresh(force=False)

        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'processor_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.processors,
                              processor.ProcessorCollection)

    def _setUp_processor_summary(self):
        self.conn.get.return_value.json.reset_mock()
        with open('sushy/tests/unit/json_samples/'
                  'processor_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # fetch processors for the first time
        self.sys_inst.processors

        successive_return_values = []
        file_names = ['sushy/tests/unit/json_samples/processor.json',
                      'sushy/tests/unit/json_samples/processor2.json']
        for file_name in file_names:
            with open(file_name) as f:
                successive_return_values.append(json.load(f))

        self.conn.get.return_value.json.side_effect = successive_return_values

    def test_processor_summary(self):
        # | GIVEN |
        self._setUp_processor_summary()
        # | WHEN |
        actual_processor_summary = self.sys_inst.processors.summary
        # | THEN |
        self.assertEqual((16, sushy.ProcessorArchitecture.X86),
                         actual_processor_summary)
        self.assertEqual(16, actual_processor_summary.count)
        self.assertEqual(sushy.ProcessorArchitecture.X86,
                         actual_processor_summary.architecture)

        # reset mock
        self.conn.get.return_value.json.reset_mock()

        # | WHEN & THEN |
        # tests for same object on invoking subsequently
        self.assertIs(actual_processor_summary,
                      self.sys_inst.processors.summary)
        self.conn.get.return_value.json.assert_not_called()

    def test_ethernet_interfaces(self):
        self.conn.get.return_value.json.reset_mock()
        eth_coll_return_value = None
        eth_return_value = None
        with open('sushy/tests/unit/json_samples/'
                  'ethernet_interfaces_collection.json') as f:
            eth_coll_return_value = json.load(f)
        with open('sushy/tests/unit/json_samples/'
                  'ethernet_interfaces.json') as f:
            eth_return_value = json.load(f)

        self.conn.get.return_value.json.side_effect = [eth_coll_return_value,
                                                       eth_return_value]

        actual_macs = self.sys_inst.ethernet_interfaces.summary
        expected_macs = (
            {'12:44:6A:3B:04:11': res_cons.State.ENABLED})
        self.assertEqual(expected_macs, actual_macs)

    def test_bios(self):
        self.conn.get.return_value.json.reset_mock()
        bios_return_value = None
        with open('sushy/tests/unit/json_samples/bios.json') as f:
            bios_return_value = json.load(f)
        self.conn.get.return_value.json.side_effect = [bios_return_value]

        self.assertIsInstance(self.sys_inst.bios, bios.Bios)
        self.assertEqual('BIOS Configuration Current Settings',
                         self.sys_inst.bios.name)

    def test_secure_boot(self):
        self.conn.get.return_value.json.reset_mock()
        with open('sushy/tests/unit/json_samples/secure_boot.json') as f:
            self.conn.get.return_value.json.side_effect = [json.load(f)]

        self.assertIsInstance(self.sys_inst.secure_boot,
                              secure_boot.SecureBoot)
        self.assertEqual('UEFI Secure Boot', self.sys_inst.secure_boot.name)

    def test_simple_storage_for_missing_attr(self):
        self.sys_inst.json.pop('SimpleStorage')
        with self.assertRaisesRegex(
                exceptions.MissingAttributeError, 'attribute SimpleStorage'):
            self.sys_inst.simple_storage

    def test_simple_storage(self):
        # | GIVEN |
        self.conn.get.return_value.json.reset_mock()
        with open('sushy/tests/unit/json_samples/'
                  'simple_storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN |
        actual_simple_storage = self.sys_inst.simple_storage
        # | THEN |
        self.assertIsInstance(actual_simple_storage,
                              simple_storage.SimpleStorageCollection)
        self.conn.get.return_value.json.assert_called_once_with()

        # reset mock
        self.conn.get.return_value.json.reset_mock()
        # | WHEN & THEN |
        # tests for same object on invoking subsequently
        self.assertIs(actual_simple_storage,
                      self.sys_inst.simple_storage)
        self.conn.get.return_value.json.assert_not_called()

    def test_simple_storage_on_refresh(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'simple_storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.simple_storage,
                              simple_storage.SimpleStorageCollection)

        # On refreshing the system instance...
        with open('sushy/tests/unit/json_samples/system.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        self.sys_inst.invalidate()
        self.sys_inst.refresh(force=False)

        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'simple_storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.simple_storage,
                              simple_storage.SimpleStorageCollection)

    def test_storage_for_missing_attr(self):
        self.sys_inst.json.pop('SimpleStorage')
        with self.assertRaisesRegex(
                exceptions.MissingAttributeError, 'attribute Storage'):
            self.sys_inst.storage

    def test_storage(self):
        # | GIVEN |
        self.conn.get.return_value.json.reset_mock()
        with open('sushy/tests/unit/json_samples/'
                  'storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN |
        actual_storage = self.sys_inst.simple_storage
        # | THEN |
        self.assertIsInstance(actual_storage,
                              simple_storage.SimpleStorageCollection)
        self.conn.get.return_value.json.assert_called_once_with()

        # reset mock
        self.conn.get.return_value.json.reset_mock()
        # | WHEN & THEN |
        # tests for same object on invoking subsequently
        self.assertIs(actual_storage, self.sys_inst.simple_storage)
        self.conn.get.return_value.json.assert_not_called()

    def test_storage_on_refresh(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.simple_storage,
                              simple_storage.SimpleStorageCollection)

        # On refreshing the system instance...
        with open('sushy/tests/unit/json_samples/system.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        self.sys_inst.invalidate()
        self.sys_inst.refresh(force=False)

        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'storage_collection.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)
        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.simple_storage,
                              simple_storage.SimpleStorageCollection)

    def test_managers(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'manager.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # | WHEN & THEN |
        actual_managers = self.sys_inst.managers
        self.assertIsInstance(actual_managers[0], manager.Manager)
        self.assertEqual(
            '/redfish/v1/Managers/BMC', actual_managers[0].path)

    def test_managers_retry(self):
        with open('sushy/tests/unit/json_samples/'
                  'system_managedby_missing_manager_present.json') as f:
            settings_obj = json.load(f)
        self.json_doc.update(settings_obj)
        self.sys_inst._parse_attributes(self.json_doc)

        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'manager.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # | WHEN & THEN |
        actual_managers = self.sys_inst.managers
        self.assertIsInstance(actual_managers[0], manager.Manager)
        self.assertEqual(
            '/redfish/v1/Managers/BMC', actual_managers[0].path)

    def test_managers_missing_ref(self):
        # | GIVEN |
        del self.json_doc['Links']['ManagedBy']

        # | WHEN & THEN |
        with self.assertRaisesRegex(
            exceptions.MissingAttributeError, 'attribute Links/ManagedBy'):
            self.sys_inst.managers

    def test_chassis(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'chassis.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # | WHEN & THEN |
        actual_chassis = self.sys_inst.chassis
        self.assertIsInstance(actual_chassis[0], chassis.Chassis)
        self.assertEqual(
            '/redfish/v1/Chassis/1U', actual_chassis[0].path)

    def test_get_oem_extension(self):
        # | WHEN |
        contoso_system_extn_inst = self.sys_inst.get_oem_extension('Contoso')
        # | THEN |
        self.assertIsInstance(contoso_system_extn_inst,
                              fake.FakeOEMSystemExtension)
        self.assertIs(self.sys_inst, contoso_system_extn_inst._parent_resource)
        self.assertEqual('Contoso', contoso_system_extn_inst._vendor_id)

    def test_no_virtual_media_attr(self):
        with self.assertRaisesRegex(
            exceptions.MissingAttributeError, 'attribute VirtualMedia'):
            self.sys_inst.virtual_media


class SystemWithVirtualMedia(base.TestCase):

    def setUp(self):
        super().setUp()
        self.conn = mock.Mock()
        with open('sushy/tests/unit/json_samples/'
                  'systemv1_20.json') as f:
            self.json_doc = json.load(f)

        self.conn.get.return_value.json.return_value = self.json_doc

        self.sys_inst = system.System(
            self.conn, '/redfish/v1/Systems/437XR1138R2',
            redfish_version='1.0.2')

    def test_virtual_media(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'virtual_mediav1_6.json') as f:
            virtual_media_json = json.load(f)

        with open('sushy/tests/unit/json_samples/'
                  'virtual_media_collectionv1_6.json') as f:
            virtual_media_collection_json = json.load(f)

        self.conn.get.return_value.json.side_effect = [
            virtual_media_collection_json, virtual_media_json]

        # | WHEN |
        actual_virtual_media = self.sys_inst.virtual_media

        # | THEN |
        self.assertIsInstance(actual_virtual_media,
                              virtual_media.VirtualMediaCollection)
        self.assertEqual(actual_virtual_media.name, 'Virtual Media Services')

        member = actual_virtual_media.get_member(
            '/redfish/v1/Systems/437XR1138R2/VirtualMedia/CD1')

        self.assertEqual(member.image_name, 'mymedia-read-only')
        self.assertTrue(member.inserted)
        self.assertFalse(member.write_protected)
        self.assertTrue(member.verify_certificate)

    def test_virtual_media_on_refresh(self):
        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'virtual_media_collectionv1_6.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # | WHEN & THEN |
        actual_virtual_media = self.sys_inst.virtual_media
        self.assertIsInstance(actual_virtual_media,
                              virtual_media.VirtualMediaCollection)

        with open('sushy/tests/unit/json_samples/systemv1_20.json') as f:
            self.conn.get.return_value.json.return_value = json.loads(f.read())

        self.sys_inst.invalidate()
        self.sys_inst.refresh(force=False)

        self.assertTrue(actual_virtual_media._is_stale)

        # | GIVEN |
        with open('sushy/tests/unit/json_samples/'
                  'virtual_media_collectionv1_6.json') as f:
            self.conn.get.return_value.json.return_value = json.load(f)

        # | WHEN & THEN |
        self.assertIsInstance(self.sys_inst.virtual_media,
                              virtual_media.VirtualMediaCollection)
        self.assertFalse(actual_virtual_media._is_stale)


class SystemCollectionTestCase(base.TestCase):

    def setUp(self):
        super().setUp()
        self.conn = mock.Mock()
        with open('sushy/tests/unit/json_samples/'
                  'system_collection.json') as f:
            self.json_doc = json.load(f)

        self.conn.get.return_value.json.return_value = self.json_doc

        self.sys_col = system.SystemCollection(
            self.conn, '/redfish/v1/Systems', redfish_version='1.0.2')

    def test__parse_attributes(self):
        self.sys_col._parse_attributes(self.json_doc)
        self.assertEqual('1.0.2', self.sys_col.redfish_version)
        self.assertEqual('Computer System Collection', self.sys_col.name)
        self.assertEqual(('/redfish/v1/Systems/437XR1138R2',),
                         self.sys_col.members_identities)

    @mock.patch.object(system, 'System', autospec=True)
    def test_get_member(self, mock_system):
        self.sys_col.get_member('/redfish/v1/Systems/437XR1138R2')
        mock_system.assert_called_once_with(
            self.sys_col._conn, '/redfish/v1/Systems/437XR1138R2',
            redfish_version=self.sys_col.redfish_version, registries=None,
            root=self.sys_col.root)

    @mock.patch.object(system, 'System', autospec=True)
    def test_get_members(self, mock_system):
        members = self.sys_col.get_members()
        mock_system.assert_called_once_with(
            self.sys_col._conn, '/redfish/v1/Systems/437XR1138R2',
            redfish_version=self.sys_col.redfish_version, registries=None,
            root=self.sys_col.root)
        self.assertIsInstance(members, list)
        self.assertEqual(1, len(members))