File: test_common.py

package info (click to toggle)
python-proliantutils 2.16.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,684 kB
  • sloc: python: 58,655; makefile: 163; sh: 2
file content (152 lines) | stat: -rw-r--r-- 6,545 bytes parent folder | download | duplicates (4)
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
# Copyright 2017 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
__author__ = 'HPE'

from unittest import mock

import ddt
import sushy
import testtools

from proliantutils import exception
from proliantutils.redfish.resources.system.storage import common


@ddt.ddt
class CommonMethodsTestCase(testtools.TestCase):

    def setUp(self):
        super(CommonMethodsTestCase, self).setUp()
        self.system_obj = mock.MagicMock()

    def _mock_property(self, value):
        if value is sushy.exceptions.SushyError:
            mock_value = mock.PropertyMock(side_effect=value)
        else:
            mock_value = mock.PropertyMock(return_value=value)
        return mock_value

    @ddt.data((953837, 60000, 60000, 60000, 60000, 930),
              (sushy.exceptions.SushyError, 1000169537536, 60000, 60000,
               60000, 930),
              (953837, sushy.exceptions.SushyError, 60000, 60000, 60000,
               930),
              (sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               953837, 60000, 40000, 930),
              (sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               sushy.exceptions.SushyError, 1000169537536, 40000, 930),
              (sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               1000169537536, 930),
              (sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               sushy.exceptions.SushyError, sushy.exceptions.SushyError,
               sushy.exceptions.SushyError, 0),
              )
    @ddt.unpack
    def test_get_local_gb(self, logical_max, volume_max, physical_max,
                          drive_max, simple_max, expected):

        system_obj = self.system_obj
        type(system_obj.smart_storage).logical_drives_maximum_size_mib = (
            self._mock_property(logical_max))
        type(system_obj.storages).volumes_maximum_size_bytes = (
            self._mock_property(volume_max))
        type(system_obj.smart_storage).physical_drives_maximum_size_mib = (
            self._mock_property(physical_max))
        type(system_obj.storages).drives_maximum_size_bytes = (
            self._mock_property(drive_max))
        type(system_obj.simple_storages).maximum_size_bytes = (
            self._mock_property(simple_max))
        actual = common.get_local_gb(system_obj)
        self.assertEqual(expected, actual)

    def test__get_attribute_value_of(self):
        system_obj = self.system_obj
        si_mock = mock.PropertyMock(return_value=1000169537536)
        type(system_obj.simple_storages).maximum_size_bytes = si_mock
        actual = common._get_attribute_value_of(system_obj.simple_storages,
                                                'maximum_size_bytes')
        self.assertEqual(1000169537536, actual)

    def test__get_attribute_value_of_sushy_error(self):
        system_obj = self.system_obj
        si_mock = mock.PropertyMock(side_effect=sushy.exceptions.SushyError)
        type(system_obj.simple_storages).maximum_size_bytes = si_mock
        actual = common._get_attribute_value_of(system_obj.simple_storages,
                                                'maximum_size_bytes',
                                                default=0)
        self.assertEqual(0, actual)

    def test__get_attribute_value_of_fail_missing_attribute(self):
        system_obj = self.system_obj
        si_mock = mock.PropertyMock(
            side_effect=exception.MissingAttributeError)
        type(system_obj.simple_storages).maximum_size_bytes = si_mock
        actual = common._get_attribute_value_of(system_obj.simple_storages,
                                                'maximum_size_bytes')
        self.assertIsNone(actual)

    @ddt.data((True, False, True),
              (True, True, True),
              (False, True, True),
              (False, False, False))
    @ddt.unpack
    def test_has_ssd(self, smart_value, storage_value, expected):
        system_obj = self.system_obj
        type(system_obj.smart_storage).has_ssd = (
            self._mock_property(smart_value))
        type(system_obj.storages).has_ssd = (
            self._mock_property(storage_value))
        actual = common.has_ssd(system_obj)
        self.assertEqual(expected, actual)

    @ddt.data((True, False, True),
              (True, True, True),
              (False, True, True),
              (False, False, False))
    @ddt.unpack
    def test_has_rotational(self, smart_value, storage_value,
                            expected):
        system_obj = self.system_obj
        type(system_obj.smart_storage).has_rotational = (
            self._mock_property(smart_value))
        type(system_obj.storages).has_rotational = (
            self._mock_property(storage_value))
        actual = common.has_rotational(system_obj)
        self.assertEqual(expected, actual)

    @ddt.data((False, False),
              (True, True))
    @ddt.unpack
    def test_has_nvme_ssd(self, storage_value, expected):
        system_obj = self.system_obj
        type(system_obj.storages).has_nvme_ssd = (
            self._mock_property(storage_value))
        actual = common.has_nvme_ssd(system_obj)
        self.assertEqual(expected, actual)

    @ddt.data((set([10000]), set([15000]), set([10000, 15000])),
              (set([10000]), set(), set([10000])),
              (set(), set([15000]), set([15000])),
              (set(), set(), set()))
    @ddt.unpack
    def test_get_drive_rotational_speed_rpm(self, smart_value,
                                            storage_value, expected):
        system_obj = self.system_obj
        type(system_obj.smart_storage).drive_rotational_speed_rpm = (
            self._mock_property(smart_value))
        type(system_obj.storages).drive_rotational_speed_rpm = (
            self._mock_property(storage_value))
        actual = common.get_drive_rotational_speed_rpm(system_obj)
        self.assertEqual(expected, actual)