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
|
# 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
import sushy
from sushy import exceptions
from sushy.resources.system.storage import drive
from sushy.tests.unit import base
class DriveTestCase(base.TestCase):
def setUp(self):
super().setUp()
self.conn = mock.Mock()
with open('sushy/tests/unit/json_samples/drive.json') as f:
self.json_doc = json.load(f)
self.conn.get.return_value.json.return_value = self.json_doc
self.stor_drive = drive.Drive(
self.conn,
'/redfish/v1/Systems/437XR1138/Storage/1/Drives/32ADF365C6C1B7BD',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.stor_drive._parse_attributes(self.json_doc)
self.assertEqual('1.0.2', self.stor_drive.redfish_version)
self.assertEqual('32ADF365C6C1B7BD', self.stor_drive.identity)
self.assertEqual('Drive Sample', self.stor_drive.name)
self.assertEqual(512, self.stor_drive.block_size_bytes)
self.assertEqual(899527000000, self.stor_drive.capacity_bytes)
identifiers = self.stor_drive.identifiers
self.assertIsInstance(identifiers, list)
self.assertEqual(1, len(identifiers))
identifier = identifiers[0]
self.assertEqual(sushy.DurableNameFormat.NAA,
identifier.durable_name_format)
self.assertEqual('32ADF365C6C1B7BD', identifier.durable_name)
self.assertEqual('Contoso', self.stor_drive.manufacturer)
self.assertEqual('HDD', self.stor_drive.media_type)
self.assertEqual('C123', self.stor_drive.model)
self.assertEqual('C123-1111', self.stor_drive.part_number)
self.assertEqual(sushy.Protocol.SAS, self.stor_drive.protocol)
self.assertEqual('1234570', self.stor_drive.serial_number)
self.assertEqual('100A', self.stor_drive.revision)
self.assertEqual(sushy.State.ENABLED, self.stor_drive.status.state)
self.assertEqual(sushy.Health.OK, self.stor_drive.status.health)
def test_volumes(self):
with open('sushy/tests/unit/json_samples/drive3.json') as f:
drive_json = json.load(f)
with open('sushy/tests/unit/json_samples/volume2.json') as f:
volume2_json = json.load(f)
with open('sushy/tests/unit/json_samples/volume3.json') as f:
volume3_json = json.load(f)
self.conn.get.return_value.json.side_effect = [drive_json,
volume2_json,
volume3_json]
stor_drive = drive.Drive(
self.conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Drives/'
'3D58ECBC375FD9F2',
redfish_version='1.0.2')
volumes = stor_drive.volumes
self.assertEqual(2, len(volumes))
self.assertEqual('2', volumes[0].identity)
self.assertEqual('3', volumes[1].identity)
def test_set_indicator_led(self):
self.conn.get.return_value.headers = {'ETag': 'a3b01b63f80a4913'}
with mock.patch.object(
self.stor_drive, 'invalidate',
autospec=True) as invalidate_mock:
self.stor_drive.set_indicator_led(sushy.IndicatorLED.BLINKING)
self.stor_drive._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138/Storage/1/Drives/'
'32ADF365C6C1B7BD', data={'IndicatorLED': 'Blinking'},
etag='a3b01b63f80a4913')
invalidate_mock.assert_called_once_with()
def test_set_indicator_led_invalid_state(self):
self.assertRaises(exceptions.InvalidParameterValueError,
self.stor_drive.set_indicator_led,
'spooky-glowing')
|