Update for sushy 4.0.0

* Mappings used to be an implementation detail, and now they're gone.
  The CPU architecture handling was wrong anyway, copy it from Redfish.
* Update some tests to rely on Sushy constants rather than their copies.
* Mock sleep() in tests that can take a lot of time to finish.

Change-Id: I681c829a806fdf2c69ad0af8bbba1b527bffb926
This commit is contained in:
Dmitry Tantsur 2021-11-30 10:53:08 +01:00
parent 29751a500b
commit 500f518d40
5 changed files with 25 additions and 16 deletions

View File

@ -25,7 +25,6 @@ from OpenSSL.crypto import FILETYPE_ASN1
from OpenSSL.crypto import load_certificate
from six.moves.urllib import parse
import sushy
from sushy.resources.system import mappings as sushy_map
from sushy import utils
from proliantutils import exception
@ -127,6 +126,15 @@ _CERTIFICATE_PATTERN = (
LOG = log.get_logger(__name__)
# Copied from ironic/drivers/modules/redfish/inspect.py
CPU_ARCH_MAP = {
sushy.PROCESSOR_ARCH_x86: 'x86_64',
sushy.PROCESSOR_ARCH_IA_64: 'ia64',
sushy.PROCESSOR_ARCH_ARM: 'arm',
sushy.PROCESSOR_ARCH_MIPS: 'mips',
sushy.PROCESSOR_ARCH_OEM: 'oem'
}
class RedfishOperations(operations.IloOperations):
"""Operations supported on redfish based hardware.
@ -1237,8 +1245,8 @@ class RedfishOperations(operations.IloOperations):
# local_gb = sushy_system.storage_summary
prop = {'memory_mb': (sushy_system.memory_summary.size_gib * 1024),
'cpus': sushy_system.processors.summary.count,
'cpu_arch': sushy_map.PROCESSOR_ARCH_VALUE_MAP_REV.get(
sushy_system.processors.summary.architecture),
'cpu_arch': CPU_ARCH_MAP.get(
sushy_system.processors.summary.architecture),
'local_gb': common_storage.get_local_gb(sushy_system)}
return {'properties': prop,
'macs': sushy_system.ethernet_interfaces.summary}

View File

@ -14,14 +14,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import sushy
from sushy.resources import base
from sushy.resources.system import ethernet_interface
from sushy import utils as sushy_utils
from proliantutils.redfish.resources.system import constants as sys_cons
class EthernetInterface(ethernet_interface.EthernetInterface):
uefi_device_path = base.Field('UefiDevicePath')
@ -50,8 +48,8 @@ class EthernetInterfaceCollection(base.ResourceCollectionBase):
for eth in self.get_members():
if eth.mac_address is not None:
if (eth.status is not None
and eth.status.health == sys_cons.HEALTH_OK
and eth.status.state == sys_cons.HEALTH_STATE_ENABLED):
and eth.status.health == sushy.HEALTH_OK
and eth.status.state == sushy.STATE_ENABLED):
mac_dict.update(
{'Port ' + eth.identity: eth.mac_address})
return mac_dict

View File

@ -110,16 +110,20 @@ class HttpsCertTestCase(testtools.TestCase):
'The Redfish controller failed to import certificate. Error',
self.https_cert_inst.import_certificate, 'certificate')
@mock.patch('time.sleep', autospec=True)
@mock.patch.object(https_cert.HttpsCert, 'get_generate_csr_refresh',
autospec=True)
def test_wait_for_csr_to_create_ok(self, get_generate_csr_refresh_mock):
def test_wait_for_csr_to_create_ok(self, get_generate_csr_refresh_mock,
sleep_mock):
self.cert_sign_request = 'certificate'
self.https_cert_inst.wait_for_csr_to_create()
self.assertTrue(get_generate_csr_refresh_mock.called)
@mock.patch('time.sleep', autospec=True)
@mock.patch.object(https_cert.HttpsCert, 'get_generate_csr_refresh',
autospec=True)
def test_wait_for_csr_to_create_fails(self, get_generate_csr_refresh_mock):
def test_wait_for_csr_to_create_fails(self, get_generate_csr_refresh_mock,
sleep_mock):
exc = exception.IloError('error')
get_generate_csr_refresh_mock.side_effect = exc
self.assertRaises(exception.IloError,

View File

@ -16,9 +16,9 @@
import json
import mock
import sushy
import testtools
from proliantutils.redfish.resources.system import constants as sys_cons
from proliantutils.redfish.resources.system import ethernet_interface
@ -48,9 +48,8 @@ class EthernetInterfaceTestCase(testtools.TestCase):
self.assertEqual(
'12:44:6A:3B:04:11', self.sys_eth.permanent_mac_address)
self.assertEqual('12:44:6A:3B:04:11', self.sys_eth.mac_address)
self.assertEqual(sys_cons.HEALTH_STATE_ENABLED,
self.sys_eth.status.state)
self.assertEqual(sys_cons.HEALTH_OK, self.sys_eth.status.health)
self.assertEqual(sushy.STATE_ENABLED, self.sys_eth.status.state)
self.assertEqual(sushy.HEALTH_OK, self.sys_eth.status.health)
self.assertEqual(1000, self.sys_eth.speed_mbps)

View File

@ -1081,7 +1081,7 @@ class RedfishOperationsTestCase(testtools.TestCase):
count_mock = mock.PropertyMock(return_value=40)
type(get_system_mock.return_value.processors.summary).count = (
count_mock)
arch_mock = mock.PropertyMock(return_value='x86 or x86-64')
arch_mock = mock.PropertyMock(return_value=sushy.PROCESSOR_ARCH_x86)
type(get_system_mock.return_value.processors.summary).architecture = (
arch_mock)
type(get_system_mock.return_value.ethernet_interfaces).summary = (
@ -1090,7 +1090,7 @@ class RedfishOperationsTestCase(testtools.TestCase):
local_gb_mock.return_value = 600
actual = self.rf_client.get_essential_properties()
expected = {'properties': {'cpus': 40,
'cpu_arch': 'x86',
'cpu_arch': 'x86_64',
'memory_mb': 20480,
'local_gb': 600},
'macs': {'1': '12:44:6A:3B:04:11'}}