summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules/ilo/test_bios.py
blob: 9dac237081dd47f6d72d06dec9bc06bcf75bfd86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
# Copyright 2018 Hewlett-Packard Development Company, L.P.
# 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.

"""Test class for IloPower module."""

from unittest import mock

from oslo_config import cfg
from oslo_utils import importutils

from ironic.common import exception
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules.ilo import bios as ilo_bios
from ironic.drivers.modules.ilo import boot as ilo_boot
from ironic.drivers.modules.ilo import common as ilo_common
from ironic import objects
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.drivers.modules.ilo import test_common

ilo_error = importutils.try_import('proliantutils.exception')

INFO_DICT = db_utils.get_test_ilo_info()
CONF = cfg.CONF


class IloBiosTestCase(test_common.BaseIloTest):

    def test_get_properties(self):
        expected = ilo_common.REQUIRED_PROPERTIES
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            self.assertEqual(expected, task.driver.bios.get_properties())

    @mock.patch.object(ilo_common, 'parse_driver_info', spec_set=True,
                       autospec=True)
    def test_validate(self, mock_drvinfo):
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            task.driver.bios.validate(task)
            mock_drvinfo.assert_called_once_with(task.node)

    def _test_ilo_error(self, exc_cls,
                        test_methods_not_called,
                        test_methods_called,
                        method_details, exception_mock,
                        operation='cleaning'):
        exception_mock.side_effect = exc_cls('error')
        method = method_details.get("name")
        args = method_details.get("args")
        if self.node.clean_step:
            self.assertRaises(exception.NodeCleaningFailure,
                              method,
                              *args)
        else:
            self.assertRaises(exception.InstanceDeployFailure,
                              method,
                              *args)
        for test_method in test_methods_not_called:
            test_method.assert_not_called()
        for called_method in test_methods_called:
            called_method["name"].assert_called_once_with(
                *called_method["args"])

    @mock.patch.object(ilo_bios.IloBIOS, 'cache_bios_settings',
                       autospec=True)
    @mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
                       autospec=True)
    @mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
                       autospec=True)
    def test_apply_configuration_pre_boot(self, exe_pre_boot_mock,
                                          exe_post_boot_mock,
                                          cache_settings_mock):
        settings = [
            {
                "name": "SET_A", "value": "VAL_A",
            },
            {
                "name": "SET_B", "value": "VAL_B",
            },
            {
                "name": "SET_C", "value": "VAL_C",
            },
            {
                "name": "SET_D", "value": "VAL_D",
            }
        ]
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_internal_info = task.node.driver_internal_info
            driver_internal_info.pop('apply_bios', None)
            task.node.driver_internal_info = driver_internal_info
            task.node.save()
            actual_settings = {'SET_A': 'VAL_A', 'SET_B': 'VAL_B',
                               'SET_C': 'VAL_C', 'SET_D': 'VAL_D'}
            task.driver.bios.apply_configuration(task, settings)

            exe_pre_boot_mock.assert_called_once_with(
                task.driver.bios, task, 'apply_configuration', actual_settings)
            self.assertFalse(exe_post_boot_mock.called)
            cache_settings_mock.assert_called_once_with(task.driver.bios, task)

    @mock.patch.object(ilo_bios.IloBIOS, 'cache_bios_settings',
                       autospec=True)
    @mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
                       autospec=True)
    @mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
                       autospec=True)
    def test_apply_configuration_post_boot(self, exe_pre_boot_mock,
                                           exe_post_boot_mock,
                                           cache_settings_mock):
        settings = [
            {
                "name": "SET_A", "value": "VAL_A",
            },
            {
                "name": "SET_B", "value": "VAL_B",
            },
            {
                "name": "SET_C", "value": "VAL_C",
            },
            {
                "name": "SET_D", "value": "VAL_D",
            }
        ]
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_internal_info = task.node.driver_internal_info
            driver_internal_info['apply_bios'] = True
            task.node.driver_internal_info = driver_internal_info
            task.node.save()
            task.driver.bios.apply_configuration(task, settings)

            exe_post_boot_mock.assert_called_once_with(
                task.driver.bios, task, 'apply_configuration')
            self.assertFalse(exe_pre_boot_mock.called)
            cache_settings_mock.assert_called_once_with(task.driver.bios, task)

    @mock.patch.object(ilo_boot.IloVirtualMediaBoot, 'prepare_ramdisk',
                       spec_set=True, autospec=True)
    @mock.patch.object(manager_utils, 'node_power_action', spec_set=True,
                       autospec=True)
    @mock.patch.object(deploy_utils, 'build_agent_options', spec_set=True,
                       autospec=True)
    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def test__execute_pre_boot_bios_step_apply_configuration(
            self, get_ilo_object_mock, build_agent_mock,
            node_power_mock, prepare_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value
            data = {
                "SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"
            }
            step = 'apply_configuration'
            task.driver.bios._execute_pre_boot_bios_step(task, step, data)
            driver_info = task.node.driver_internal_info
            self.assertTrue(
                all(x in driver_info for x in (
                    'apply_bios', 'deployment_reboot',
                    'skip_current_deploy_step')))
            ilo_object_mock.set_bios_settings.assert_called_once_with(data)
            self.assertFalse(ilo_object_mock.reset_bios_to_default.called)
            build_agent_mock.assert_called_once_with(task.node)
            self.assertTrue(prepare_mock.called)
            self.assertTrue(node_power_mock.called)

    @mock.patch.object(ilo_boot.IloVirtualMediaBoot, 'prepare_ramdisk',
                       spec_set=True, autospec=True)
    @mock.patch.object(manager_utils, 'node_power_action', spec_set=True,
                       autospec=True)
    @mock.patch.object(deploy_utils, 'build_agent_options', spec_set=True,
                       autospec=True)
    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_pre_boot_bios_step(
            self, get_ilo_mock, build_agent_mock,
            node_power_mock, prepare_mock):
        if self.node.clean_step:
            step_data = self.node.clean_step
            check_fields = ['cleaning_reboot', 'skip_current_clean_step']
        else:
            step_data = self.node.deploy_step
            check_fields = ['deployment_reboot', 'skip_current_deploy_step']

        data = step_data['argsinfo'].get('settings', None)
        step = step_data['step']
        if step == 'factory_reset':
            check_fields.append('reset_bios')
        elif step == 'apply_configuration':
            check_fields.append('apply_bios')

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_mock = get_ilo_mock.return_value
            task.driver.bios._execute_pre_boot_bios_step(task, step, data)
            drv_internal_info = task.node.driver_internal_info
            self.assertTrue(
                all(x in drv_internal_info for x in check_fields))

            if step == 'factory_reset':
                ilo_mock.reset_bios_to_default.assert_called_once_with()

            elif step == 'apply_configuration':
                ilo_mock.set_bios_settings.assert_called_once_with(data)

            build_agent_mock.assert_called_once_with(task.node)
            self.assertTrue(prepare_mock.called)
            self.assertTrue(node_power_mock.called)

    def test__execute_pre_boot_bios_step_apply_conf_cleaning(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'apply_configuration',
                                'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step()

    def test__execute_pre_boot_bios_step_apply_conf_deploying(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'apply_configuration',
                                 'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step()

    def test__execute_pre_boot_bios_step_factory_reset_cleaning(self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_pre_boot_bios_step()

    def test__execute_pre_boot_bios_step_factory_reset_deploying(self):
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_pre_boot_bios_step()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_pre_boot_bios_step_invalid(
            self, get_ilo_object_mock):
        if self.node.clean_step:
            step_data = self.node.clean_step
            exept = exception.NodeCleaningFailure
        else:
            step_data = self.node.deploy_step
            exept = exception.InstanceDeployFailure

        data = step_data['argsinfo'].get('settings', None)
        step = step_data['step']
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value
            ilo_object_mock.set_bios_settings.side_effect = ilo_error.IloError(
                'err')
            if task.node.clean_step:
                exept = exception.NodeCleaningFailure
            else:
                exept = exception.InstanceDeployFailure
            self.assertRaises(exept,
                              task.driver.bios._execute_pre_boot_bios_step,
                              task, step, data)

    def test__execute_pre_boot_bios_step_invalid_cleaning(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'invalid_step',
                                'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step_invalid()

    def test__execute_pre_boot_bios_step_invalid_deploying(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'invalid_step',
                                 'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step_invalid()

    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def _test__execute_pre_boot_bios_step_ilo_fail(self, get_ilo_mock):
        if self.node.clean_step:
            step_data = self.node.clean_step
            exept = exception.NodeCleaningFailure
        else:
            step_data = self.node.deploy_step
            exept = exception.InstanceDeployFailure

        data = step_data['argsinfo'].get('settings', None)
        step = step_data['step']
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            get_ilo_mock.side_effect = exception.MissingParameterValue('err')
            self.assertRaises(exept,
                              task.driver.bios._execute_pre_boot_bios_step,
                              task, step, data)

    def test__execute_pre_boot_bios_step_iloobj_failed_cleaning(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'apply_configuration',
                                'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step_ilo_fail()

    def test__execute_pre_boot_bios_step_iloobj_failed_deploying(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'apply_configuration',
                                 'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_pre_boot_bios_step_ilo_fail()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_pre_boot_bios_step_set_bios_failed(
            self, get_ilo_object_mock):
        if self.node.clean_step:
            step_data = self.node.clean_step
            exept = exception.NodeCleaningFailure
        else:
            step_data = self.node.deploy_step
            exept = exception.InstanceDeployFailure

        data = step_data['argsinfo'].get('settings', None)
        step = step_data['step']
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value
            ilo_object_mock.set_bios_settings.side_effect = ilo_error.IloError(
                'err')
            if task.node.clean_step:
                exept = exception.NodeCleaningFailure
            else:
                exept = exception.InstanceDeployFailure
            self.assertRaises(exept,
                              task.driver.bios._execute_pre_boot_bios_step,
                              task, step, data)

    def test__execute_pre_boot_bios_step_set_bios_failed_cleaning(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'apply_configuration',
                                'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    def test__execute_pre_boot_bios_step_set_bios_failed_deploying(self):
        data = {"SET_A": "VAL_A",
                "SET_B": "VAL_B",
                "SET_C": "VAL_C",
                "SET_D": "VAL_D"}
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'apply_configuration',
                                 'argsinfo': {'settings': data}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    def test__execute_pre_boot_bios_step_reset_bios_failed_cleaning(self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    def test__execute_pre_boot_bios_step_reset_bios_failed_deploying(self):
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def test__execute_post_boot_bios_step_apply_configuration(
            self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_info = task.node.driver_internal_info
            driver_info.update({'apply_bios': True})
            task.node.driver_internal_info = driver_info
            task.node.save()
            ilo_object_mock = get_ilo_object_mock.return_value
            step = 'apply_configuration'
            task.driver.bios._execute_post_boot_bios_step(task, step)
            driver_info = task.node.driver_internal_info
            self.assertNotIn('apply_bios', driver_info)
            ilo_object_mock.get_bios_settings_result.assert_called_once_with()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def test__execute_post_boot_bios_step_factory_reset(
            self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_info = task.node.driver_internal_info
            driver_info.update({'reset_bios': True})
            task.node.driver_internal_info = driver_info
            task.node.save()
            ilo_object_mock = get_ilo_object_mock.return_value
            step = 'factory_reset'
            task.driver.bios._execute_post_boot_bios_step(task, step)
            driver_info = task.node.driver_internal_info
            self.assertNotIn('reset_bios', driver_info)
            ilo_object_mock.get_bios_settings_result.assert_called_once_with()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_post_boot_bios_step_invalid(
            self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_info = task.node.driver_internal_info
            driver_info.update({'apply_bios': True})
            task.node.driver_internal_info = driver_info
            task.node.save()
            step = 'invalid_step'
            if self.node.clean_step:
                exept = exception.NodeCleaningFailure
            else:
                exept = exception.InstanceDeployFailure
            self.assertRaises(exept,
                              task.driver.bios._execute_post_boot_bios_step,
                              task, step)
            self.assertNotIn('apply_bios', task.node.driver_internal_info)

    def test__execute_post_boot_bios_step_invalid_cleaning(self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': u'apply_configuration',
                                'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_step_invalid()

    def test__execute_post_boot_bios_step_invalid_deploy(self):
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': u'apply_configuration',
                                 'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_step_invalid()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_post_boot_bios_step_iloobj_failed(
            self, get_ilo_object_mock):

        if self.node.clean_step:
            step = self.node.clean_step['step']
            exept = exception.NodeCleaningFailure
        if self.node.deploy_step:
            step = self.node.deploy_step['step']
            exept = exception.InstanceDeployFailure
        driver_internal_info = self.node.driver_internal_info
        driver_internal_info['apply_bios'] = True
        self.node.driver_internal_info = driver_internal_info
        self.node.save()
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            get_ilo_object_mock.side_effect = exception.MissingParameterValue(
                'err')
            step = 'apply_configuration'
            self.assertRaises(exept,
                              task.driver.bios._execute_post_boot_bios_step,
                              task, step)
            self.assertNotIn('apply_bios', task.node.driver_internal_info)

    def test__execute_post_boot_bios_step_iloobj_failed_cleaning(self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': u'apply_configuration',
                                'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_step_iloobj_failed()

    def test__execute_post_boot_bios_step_iloobj_failed_deploy(self):
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': u'apply_configuration',
                                 'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_step_iloobj_failed()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_post_boot_bios_get_settings_error(
            self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_info = task.node.driver_internal_info
            driver_info.update({'apply_bios': True})
            task.node.driver_internal_info = driver_info
            task.node.save()
            ilo_object_mock = get_ilo_object_mock.return_value

            step = 'apply_configuration'
            mdobj = {
                "name": task.driver.bios._execute_post_boot_bios_step,
                "args": (task, step,)
            }

            self._test_ilo_error(ilo_error.IloCommandNotSupportedError,
                                 [],
                                 [], mdobj,
                                 ilo_object_mock.get_bios_settings_result)
            self.assertNotIn('apply_bios', task.node.driver_internal_info)

    def test__execute_post_boot_bios_get_settings_error_cleaning(
            self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': u'apply_configuration',
                                'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_error()

    def test__execute_post_boot_bios_get_settings_error_deploying(
            self):
        self.node.deploy_step = {'priority': 100, 'interface': 'bios',
                                 'step': 'apply_configuration',
                                 'argsinfo': {'settings': {'a': 1, 'b': 2}}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_error()

    @mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
                       autospec=True)
    def _test__execute_post_boot_bios_get_settings_failed(
            self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            driver_info = task.node.driver_internal_info
            driver_info.update({'reset_bios': True})
            task.node.driver_internal_info = driver_info
            task.node.save()
            ilo_object_mock = get_ilo_object_mock.return_value
            ilo_object_mock.get_bios_settings_result.return_value = (
                {'status': 'failed', 'message': 'Some data'})
            step = 'factory_reset'
            if task.node.clean_step:
                exept = exception.NodeCleaningFailure
            else:
                exept = exception.InstanceDeployFailure
            self.assertRaises(exept,
                              task.driver.bios._execute_post_boot_bios_step,
                              task, step)
            self.assertNotIn('reset_bios', task.node.driver_internal_info)

    def test__execute_post_boot_bios_get_settings_failed_cleaning(
            self):
        self.node.clean_step = {'priority': 100, 'interface': 'bios',
                                'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    def test__execute_post_boot_bios_get_settings_failed_deploying(
            self):
        self.node.depoy_step = {'priority': 100, 'interface': 'bios',
                                'step': 'factory_reset', 'argsinfo': {}}
        self.node.save()
        self._test__execute_post_boot_bios_get_settings_failed()

    @mock.patch.object(objects.BIOSSettingList, 'create', autospec=True)
    @mock.patch.object(objects.BIOSSettingList, 'save', autospec=True)
    @mock.patch.object(objects.BIOSSettingList, 'delete', autospec=True)
    @mock.patch.object(objects.BIOSSettingList, 'sync_node_setting',
                       autospec=True)
    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def test_cache_bios_settings(self, get_ilo_object_mock, sync_node_mock,
                                 delete_mock, save_mock, create_mock):
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value
            settings = {
                "SET_A": True,
                "SET_B": True,
                "SET_C": True,
                "SET_D": True
            }

            ilo_object_mock.get_current_bios_settings.return_value = settings
            expected_bios_settings = [
                {"name": "SET_A", "value": True},
                {"name": "SET_B", "value": True},
                {"name": "SET_C", "value": True},
                {"name": "SET_D", "value": True}
            ]
            sync_node_mock.return_value = ([], [], [], [])
            all_settings = (
                [
                    {"name": "C_1", "value": "C_1_VAL"},
                    {"name": "C_2", "value": "C_2_VAL"}
                ],
                [
                    {"name": "U_1", "value": "U_1_VAL"},
                    {"name": "U_2", "value": "U_2_VAL"}
                ],
                [
                    {"name": "D_1", "value": "D_1_VAL"},
                    {"name": "D_2", "value": "D_2_VAL"}
                ],
                []
            )
            sync_node_mock.return_value = all_settings
            task.driver.bios.cache_bios_settings(task)
            ilo_object_mock.get_current_bios_settings.assert_called_once_with()
            actual_arg = sorted(sync_node_mock.call_args[0][2],
                                key=lambda x: x.get("name"))
            expected_arg = sorted(expected_bios_settings,
                                  key=lambda x: x.get("name"))
            self.assertEqual(actual_arg, expected_arg)
            create_mock.assert_called_once_with(
                self.context, task.node.id, all_settings[0])
            save_mock.assert_called_once_with(
                self.context, task.node.id, all_settings[1])
            del_names = [setting.get("name") for setting in all_settings[2]]
            delete_mock.assert_called_once_with(
                self.context, task.node.id, del_names)

    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def test_cache_bios_settings_missing_parameter(self, get_ilo_object_mock):
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            mdobj = {
                "name": task.driver.bios.cache_bios_settings,
                "args": (task,)
            }
            self._test_ilo_error(exception.MissingParameterValue,
                                 [],
                                 [], mdobj, get_ilo_object_mock)

    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def test_cache_bios_settings_invalid_parameter(self, get_ilo_object_mock):
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            mdobj = {
                "name": task.driver.bios.cache_bios_settings,
                "args": (task,)
            }
            self._test_ilo_error(exception.InvalidParameterValue,
                                 [],
                                 [], mdobj, get_ilo_object_mock)

    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def test_cache_bios_settings_with_ilo_error(self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value
            mdobj = {
                "name": task.driver.bios.cache_bios_settings,
                "args": (task,)
            }
            self._test_ilo_error(ilo_error.IloError,
                                 [],
                                 [],
                                 mdobj,
                                 ilo_object_mock.get_current_bios_settings)

    @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True)
    def test_cache_bios_settings_with_unknown_error(self, get_ilo_object_mock):

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            ilo_object_mock = get_ilo_object_mock.return_value

            mdobj = {
                "name": task.driver.bios.cache_bios_settings,
                "args": (task,)
            }
            self._test_ilo_error(ilo_error.IloCommandNotSupportedError,
                                 [],
                                 [],
                                 mdobj,
                                 ilo_object_mock.get_current_bios_settings)