summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules/redfish/test_utils.py
blob: ca8aba9da8f7588e6e8177c662bd513cbe590f13 (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
# 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 collections
import copy
import os
import time
from unittest import mock

from oslo_config import cfg
from oslo_utils import importutils
import requests

from ironic.common import exception
from ironic.drivers.modules.redfish import utils as redfish_utils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.objects import utils as obj_utils

sushy = importutils.try_import('sushy')

INFO_DICT = db_utils.get_test_redfish_info()


class RedfishUtilsTestCase(db_base.DbTestCase):

    def setUp(self):
        super(RedfishUtilsTestCase, self).setUp()
        # Default configurations
        self.config(enabled_hardware_types=['redfish'],
                    enabled_power_interfaces=['redfish'],
                    enabled_boot_interfaces=['redfish-virtual-media'],
                    enabled_management_interfaces=['redfish'])
        # Redfish specific configurations
        self.config(connection_attempts=1, group='redfish')
        self.node = obj_utils.create_test_node(
            self.context, driver='redfish', driver_info=INFO_DICT)
        self.parsed_driver_info = {
            'address': 'https://example.com',
            'system_id': '/redfish/v1/Systems/FAKESYSTEM',
            'username': 'username',
            'password': 'password',
            'verify_ca': True,
            'auth_type': 'auto',
            'node_uuid': self.node.uuid
        }

    def test_parse_driver_info(self):
        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)

    def test_parse_driver_info_default_scheme(self):
        self.node.driver_info['redfish_address'] = 'example.com'
        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)

    def test_parse_driver_info_default_scheme_with_port(self):
        self.node.driver_info['redfish_address'] = 'example.com:42'
        self.parsed_driver_info['address'] = 'https://example.com:42'
        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)

    def test_parse_driver_info_missing_info(self):
        for prop in redfish_utils.REQUIRED_PROPERTIES:
            self.node.driver_info = INFO_DICT.copy()
            self.node.driver_info.pop(prop)
            self.assertRaises(exception.MissingParameterValue,
                              redfish_utils.parse_driver_info, self.node)

    def test_parse_driver_info_invalid_address(self):
        for value in ['/banana!', 42]:
            self.node.driver_info['redfish_address'] = value
            self.assertRaisesRegex(exception.InvalidParameterValue,
                                   'Invalid Redfish address',
                                   redfish_utils.parse_driver_info, self.node)

    @mock.patch.object(os.path, 'isdir', autospec=True)
    def test_parse_driver_info_path_verify_ca(self,
                                              mock_isdir):
        mock_isdir.return_value = True
        fake_path = '/path/to/a/valid/CA'
        self.node.driver_info['redfish_verify_ca'] = fake_path
        self.parsed_driver_info['verify_ca'] = fake_path

        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)
        mock_isdir.assert_called_once_with(fake_path)

    @mock.patch.object(os.path, 'isfile', autospec=True)
    def test_parse_driver_info_valid_capath(self, mock_isfile):
        mock_isfile.return_value = True
        fake_path = '/path/to/a/valid/CA.pem'
        self.node.driver_info['redfish_verify_ca'] = fake_path
        self.parsed_driver_info['verify_ca'] = fake_path

        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)
        mock_isfile.assert_called_once_with(fake_path)

    def test_parse_driver_info_invalid_value_verify_ca(self):
        # Integers are not supported
        self.node.driver_info['redfish_verify_ca'] = 123456
        self.assertRaisesRegex(exception.InvalidParameterValue,
                               'Invalid value type',
                               redfish_utils.parse_driver_info, self.node)

    def test_parse_driver_info_invalid_system_id(self):
        # Integers are not supported
        self.node.driver_info['redfish_system_id'] = 123
        self.assertRaisesRegex(exception.InvalidParameterValue,
                               'The value should be a path',
                               redfish_utils.parse_driver_info, self.node)

    def test_parse_driver_info_missing_system_id(self):
        self.node.driver_info.pop('redfish_system_id')
        redfish_utils.parse_driver_info(self.node)

    def test_parse_driver_info_valid_string_value_verify_ca(self):
        for value in ('0', 'f', 'false', 'off', 'n', 'no'):
            self.node.driver_info['redfish_verify_ca'] = value
            response = redfish_utils.parse_driver_info(self.node)
            parsed_driver_info = copy.deepcopy(self.parsed_driver_info)
            parsed_driver_info['verify_ca'] = False
            self.assertEqual(parsed_driver_info, response)

        for value in ('1', 't', 'true', 'on', 'y', 'yes'):
            self.node.driver_info['redfish_verify_ca'] = value
            response = redfish_utils.parse_driver_info(self.node)
            self.assertEqual(self.parsed_driver_info, response)

    def test_parse_driver_info_invalid_string_value_verify_ca(self):
        for value in ('xyz', '*', '!123', '123'):
            self.node.driver_info['redfish_verify_ca'] = value
            self.assertRaisesRegex(exception.InvalidParameterValue,
                                   'The value should be a Boolean',
                                   redfish_utils.parse_driver_info, self.node)

    def test_parse_driver_info_valid_auth_type(self):
        for value in 'basic', 'session', 'auto':
            self.node.driver_info['redfish_auth_type'] = value
            response = redfish_utils.parse_driver_info(self.node)
            self.parsed_driver_info['auth_type'] = value
            self.assertEqual(self.parsed_driver_info, response)

    def test_parse_driver_info_invalid_auth_type(self):
        for value in 'BasiC', 'SESSION', 'Auto':
            self.node.driver_info['redfish_auth_type'] = value
            self.assertRaisesRegex(exception.InvalidParameterValue,
                                   'The value should be one of ',
                                   redfish_utils.parse_driver_info, self.node)

    def test_parse_driver_info_with_root_prefix(self):
        test_redfish_address = 'https://example.com/test/redfish/v0/'
        self.node.driver_info['redfish_address'] = test_redfish_address
        self.parsed_driver_info['root_prefix'] = '/test/redfish/v0/'
        response = redfish_utils.parse_driver_info(self.node)
        self.assertEqual(self.parsed_driver_info, response)

    def test_get_task_monitor(self):
        redfish_utils._get_connection = mock.Mock()
        fake_monitor = mock.Mock()
        redfish_utils._get_connection.return_value = fake_monitor
        uri = '/redfish/v1/TaskMonitor/FAKEMONITOR'

        response = redfish_utils.get_task_monitor(self.node, uri)

        self.assertEqual(fake_monitor, response)

    def test_get_task_monitor_error(self):
        redfish_utils._get_connection = mock.Mock()
        uri = '/redfish/v1/TaskMonitor/FAKEMONITOR'
        redfish_utils._get_connection.side_effect =\
            sushy.exceptions.ResourceNotFoundError('GET', uri, mock.Mock())

        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_task_monitor, self.node, uri)

    def test_get_update_service(self):
        redfish_utils._get_connection = mock.Mock()
        mock_update_service = mock.Mock()
        redfish_utils._get_connection.return_value = mock_update_service

        result = redfish_utils.get_update_service(self.node)

        self.assertEqual(mock_update_service, result)

    def test_get_update_service_error(self):
        redfish_utils._get_connection = mock.Mock()
        redfish_utils._get_connection.side_effect =\
            sushy.exceptions.MissingAttributeError

        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_update_service, self.node)

    def test_get_event_service(self):
        redfish_utils._get_connection = mock.Mock()
        mock_event_service = mock.Mock()
        redfish_utils._get_connection.return_value = mock_event_service

        result = redfish_utils.get_event_service(self.node)

        self.assertEqual(mock_event_service, result)

    def test_get_event_service_error(self):
        redfish_utils._get_connection = mock.Mock()
        redfish_utils._get_connection.side_effect =\
            sushy.exceptions.MissingAttributeError

        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_event_service, self.node)


class RedfishUtilsAuthTestCase(db_base.DbTestCase):

    def setUp(self):
        super(RedfishUtilsAuthTestCase, self).setUp()
        # Default configurations
        self.config(enabled_hardware_types=['redfish'],
                    enabled_power_interfaces=['redfish'],
                    enabled_boot_interfaces=['redfish-virtual-media'],
                    enabled_management_interfaces=['redfish'])
        # Redfish specific configurations
        self.config(connection_attempts=1, group='redfish')
        self.node = obj_utils.create_test_node(
            self.context, driver='redfish', driver_info=INFO_DICT)
        self.parsed_driver_info = {
            'address': 'https://example.com',
            'system_id': '/redfish/v1/Systems/FAKESYSTEM',
            'username': 'username',
            'password': 'password',
            'verify_ca': True,
            'auth_type': 'auto',
            'node_uuid': self.node.uuid
        }

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_ensure_session_reuse(self, mock_sushy):
        redfish_utils.get_system(self.node)
        redfish_utils.get_system(self.node)
        self.assertEqual(1, mock_sushy.call_count)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    def test_ensure_new_session_address(self, mock_sushy):
        self.node.driver_info['redfish_address'] = 'http://bmc.foo'
        redfish_utils.get_system(self.node)
        self.node.driver_info['redfish_address'] = 'http://bmc.bar'
        redfish_utils.get_system(self.node)
        self.assertEqual(2, mock_sushy.call_count)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    def test_ensure_new_session_username(self, mock_sushy):
        self.node.driver_info['redfish_username'] = 'foo'
        redfish_utils.get_system(self.node)
        self.node.driver_info['redfish_username'] = 'bar'
        redfish_utils.get_system(self.node)
        self.assertEqual(2, mock_sushy.call_count)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache.AUTH_CLASSES', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.SessionCache._sessions',
                collections.OrderedDict())
    def test_ensure_basic_session_caching(self, mock_auth, mock_sushy):
        self.node.driver_info['redfish_auth_type'] = 'basic'
        mock_session_or_basic_auth = mock_auth['auto']
        redfish_utils.get_system(self.node)
        mock_sushy.assert_called_with(
            mock.ANY, verify=mock.ANY,
            auth=mock_session_or_basic_auth.return_value,
        )
        self.assertEqual(len(redfish_utils.SessionCache._sessions), 1)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    def test_expire_old_sessions(self, mock_sushy):
        cfg.CONF.set_override('connection_cache_size', 10, 'redfish')
        for num in range(20):
            self.node.driver_info['redfish_username'] = 'foo-%d' % num
            redfish_utils.get_system(self.node)

        self.assertEqual(mock_sushy.call_count, 20)
        self.assertEqual(len(redfish_utils.SessionCache._sessions), 10)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_disabled_sessions_cache(self, mock_sushy):
        cfg.CONF.set_override('connection_cache_size', 0, 'redfish')
        for num in range(2):
            self.node.driver_info['redfish_username'] = 'foo-%d' % num
            redfish_utils.get_system(self.node)

        self.assertEqual(mock_sushy.call_count, 2)
        self.assertEqual(len(redfish_utils.SessionCache._sessions), 0)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache.AUTH_CLASSES', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_auth_auto(self, mock_auth, mock_sushy):
        redfish_utils.get_system(self.node)
        mock_session_or_basic_auth = mock_auth['auto']
        mock_session_or_basic_auth.assert_called_with(
            username=self.parsed_driver_info['username'],
            password=self.parsed_driver_info['password']
        )
        mock_sushy.assert_called_with(
            self.parsed_driver_info['address'],
            auth=mock_session_or_basic_auth.return_value,
            verify=True)

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache.AUTH_CLASSES', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_auth_session(self, mock_auth, mock_sushy):
        self.node.driver_info['redfish_auth_type'] = 'session'
        mock_session_auth = mock_auth['session']
        redfish_utils.get_system(self.node)
        mock_session_auth.assert_called_with(
            username=self.parsed_driver_info['username'],
            password=self.parsed_driver_info['password']
        )
        mock_sushy.assert_called_with(
            mock.ANY, verify=mock.ANY,
            auth=mock_session_auth.return_value
        )

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache.AUTH_CLASSES', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_auth_basic(self, mock_auth, mock_sushy):
        self.node.driver_info['redfish_auth_type'] = 'basic'
        mock_basic_auth = mock_auth['basic']
        redfish_utils.get_system(self.node)
        mock_basic_auth.assert_called_with(
            username=self.parsed_driver_info['username'],
            password=self.parsed_driver_info['password']
        )
        sushy.Sushy.assert_called_with(
            mock.ANY, verify=mock.ANY,
            auth=mock_basic_auth.return_value
        )


class RedfishUtilsSystemTestCase(db_base.DbTestCase):

    def setUp(self):
        super(RedfishUtilsSystemTestCase, self).setUp()
        # Default configurations
        self.config(enabled_hardware_types=['redfish'],
                    enabled_power_interfaces=['redfish'],
                    enabled_boot_interfaces=['redfish-virtual-media'],
                    enabled_management_interfaces=['redfish'])
        # Redfish specific configurations
        self.config(connection_attempts=1, group='redfish')
        self.node = obj_utils.create_test_node(
            self.context, driver='redfish', driver_info=INFO_DICT)
        self.parsed_driver_info = {
            'address': 'https://example.com',
            'system_id': '/redfish/v1/Systems/FAKESYSTEM',
            'username': 'username',
            'password': 'password',
            'verify_ca': True,
            'auth_type': 'auto',
            'node_uuid': self.node.uuid
        }

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system(self, mock_sushy):
        fake_conn = mock_sushy.return_value
        fake_system = fake_conn.get_system.return_value
        response = redfish_utils.get_system(self.node)
        self.assertEqual(fake_system, response)
        fake_conn.get_system.assert_called_once_with(
            '/redfish/v1/Systems/FAKESYSTEM')

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system_resource_not_found(self, mock_sushy):
        fake_conn = mock_sushy.return_value
        fake_conn.get_system.side_effect = (
            sushy.exceptions.ResourceNotFoundError('GET',
                                                   '/',
                                                   requests.Response()))

        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_system, self.node)
        fake_conn.get_system.assert_called_once_with(
            '/redfish/v1/Systems/FAKESYSTEM')

    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system_multiple_systems(self, mock_sushy):
        self.node.driver_info.pop('redfish_system_id')
        fake_conn = mock_sushy.return_value
        redfish_utils.get_system(self.node)
        fake_conn.get_system.assert_called_once_with(None)

    @mock.patch.object(time, 'sleep', lambda seconds: None)
    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system_resource_connection_error_retry(self, mock_sushy):
        # Redfish specific configurations
        self.config(connection_attempts=3, group='redfish')

        fake_conn = mock.Mock()
        fake_conn.get_system.side_effect = sushy.exceptions.ConnectionError()
        mock_sushy.return_value = fake_conn

        self.assertRaises(exception.RedfishConnectionError,
                          redfish_utils.get_system, self.node)

        expected_get_system_calls = [
            mock.call(self.parsed_driver_info['system_id']),
            mock.call(self.parsed_driver_info['system_id']),
            mock.call(self.parsed_driver_info['system_id']),
        ]
        fake_conn.get_system.assert_has_calls(expected_get_system_calls)
        self.assertEqual(fake_conn.get_system.call_count,
                         redfish_utils.CONF.redfish.connection_attempts)

    @mock.patch.object(time, 'sleep', lambda seconds: None)
    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_wait_until_get_system_ready(self, mock_sushy):
        self.config(connection_attempts=2, group='redfish')
        uri = '/redfish/v1/Systems/FAKESYSTEM'
        fake_conn = mock_sushy.return_value
        fake_system = mock.Mock()
        fake_conn.get_system.side_effect = [
            sushy.exceptions.BadRequestError('GET', uri, fake_system),
            fake_system
        ]
        response = redfish_utils.wait_until_get_system_ready(self.node)
        self.assertEqual(fake_system, response)
        self.assertEqual(fake_conn.get_system.call_count, 2)
        fake_conn.get_system.assert_called_with(uri)

    @mock.patch.object(time, 'sleep', lambda seconds: None)
    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_wait_until_get_system_ready_with_connection_error(self,
                                                               mock_sushy):
        self.config(connection_attempts=2, group='redfish')
        uri = '/redfish/v1/Systems/FAKESYSTEM'
        fake_conn = mock_sushy.return_value
        fake_system = mock.Mock()
        fake_conn.get_system.side_effect = [
            sushy.exceptions.BadRequestError('GET', uri, fake_system),
            sushy.exceptions.BadRequestError('GET', uri, fake_system)
        ]
        self.assertRaises(exception.RedfishConnectionError,
                          redfish_utils.wait_until_get_system_ready, self.node)

        self.assertEqual(fake_conn.get_system.call_count, 2)

    @mock.patch.object(time, 'sleep', lambda seconds: None)
    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system_resource_access_error_retry(self, mock_sushy):

        # Sushy access errors HTTP Errors
        class fake_response(object):
            status_code = 401
            body = None

            def json():
                return {}

        fake_conn = mock_sushy.return_value
        fake_system = mock.Mock()
        fake_conn.get_system.side_effect = iter(
            [
                sushy.exceptions.AccessError(
                    method='GET',
                    url='http://path/to/url',
                    response=fake_response),
                fake_system,
            ])

        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_system, self.node)
        # Retry, as in next power sync perhaps
        client = redfish_utils.get_system(self.node)
        client('foo')

        expected_get_system_calls = [
            mock.call(self.parsed_driver_info['system_id']),
            mock.call(self.parsed_driver_info['system_id']),
        ]
        fake_conn.get_system.assert_has_calls(expected_get_system_calls)
        fake_system.assert_called_with('foo')
        self.assertEqual(fake_conn.get_system.call_count, 2)

    @mock.patch.object(time, 'sleep', lambda seconds: None)
    @mock.patch.object(sushy, 'Sushy', autospec=True)
    @mock.patch('ironic.drivers.modules.redfish.utils.'
                'SessionCache._sessions', {})
    def test_get_system_resource_attribute_error(self, mock_sushy):

        fake_conn = mock_sushy.return_value
        fake_system = mock.Mock()
        fake_conn.get_system.side_effect = iter(
            [
                AttributeError,
                fake_system,
            ])
        # We need to check for AttributeError explicitly as
        # otherwise we break existing tests if we try to catch
        # it explicitly.
        self.assertRaises(exception.RedfishError,
                          redfish_utils.get_system, self.node)
        # Retry, as in next power sync perhaps
        client = redfish_utils.get_system(self.node)
        client('bar')
        expected_get_system_calls = [
            mock.call(self.parsed_driver_info['system_id']),
            mock.call(self.parsed_driver_info['system_id']),
        ]

        fake_conn.get_system.assert_has_calls(expected_get_system_calls)
        fake_system.assert_called_once_with('bar')
        self.assertEqual(fake_conn.get_system.call_count, 2)