test cases for get_nic_capacity and ipmi.py

This commit include test cases for proliantutils/ilo/ipmi.py
and get_server_capabilities() in prolaintutils/ilo/client.py

Change-Id: I27cab2b5cca30e48d5ccb12e14c803d859f468a7
This commit is contained in:
Nisha Agarwal
2015-05-04 00:07:53 -07:00
parent 0a4f6d605e
commit 3e9c796b79
4 changed files with 293 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
# Copyright 2014 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 Utils for iLO test modules."""
NIC_FRU_OUT = (
"Board Mfg Date : Mon Apr 28 23:16:00 2014\n"
"Board Mfg : HP\n"
"Board Product : HP Ethernet 1Gb 4-port 331FLR Adapter\n"
"Board Serial : CN84170RX5\n"
"Board Part Number : 634025-001\n"
"Board Extra : d23041\n"
"Board Extra : d5629133b001\n"
"Product Manufacturer : HP\n"
"Product Name : HP Ethernet 1Gb 4-port 331FLR Adapter\n"
"Product Part Number : 629135-B21\n"
"Product Version : 00\n"
"Product Serial : CN84170RX5")
NIC_FRU_OUT_NO_PORT_DETAILS = (
"Board Mfg Date : Mon Apr 28 23:16:00 2014\n"
"Board Mfg : HP\n"
"Board Serial : CN84170RX5\n"
"Board Part Number : 634025-001\n"
"Board Extra : d23041\n"
"Board Extra : d5629133b001\n"
"Product Manufacturer : HP\n"
"Product Part Number : 629135-B21\n"
"Product Version : 00\n"
"Product Serial : CN84170RX5")
NIC_FRU_OUT_NO_PRODUCT_NAME = (
"Board Mfg Date : Mon Apr 28 23:16:00 2014\n"
"Board Mfg : HP\n"
"Board Product : HP Ethernet 1Gb 4-port 331FLR Adapter\n"
"Board Serial : CN84170RX5\n"
"Board Part Number : 634025-001\n"
"Board Extra : d23041\n"
"Board Extra : d5629133b001\n"
"Product Manufacturer : HP\n"
"Product Part Number : 629135-B21\n"
"Product Version : 00\n"
"Product Serial : CN84170RX5")

View File

@@ -6274,6 +6274,46 @@ GET_EMBEDDED_HEALTH_OUTPUT = '''
"STATUS": {
"VALUE": "OK"
}
},
{
"CAUTION": {
"VALUE": "N/A"
},
"CRITICAL": {
"VALUE": "N/A"
},
"CURRENTREADING": {
"VALUE": "N/A"
},
"LABEL": {
"VALUE": "56-GPU 1"
},
"LOCATION": {
"VALUE": "I/O Board"
},
"STATUS": {
"VALUE": "Not Installed"
}
},
{
"CAUTION": {
"VALUE": "N/A"
},
"CRITICAL": {
"VALUE": "N/A"
},
"CURRENTREADING": {
"VALUE": "N/A"
},
"LABEL": {
"VALUE": "57-GPU 2"
},
"LOCATION": {
"VALUE": "I/O Board"
},
"STATUS": {
"VALUE": "Not Installed"
}
}
]
},

View File

@@ -14,12 +14,16 @@
# under the License.
"""Test class for Client Module."""
import json
import mock
import testtools
from proliantutils.ilo import client
from proliantutils.ilo import ipmi
from proliantutils.ilo import ribcl
from proliantutils.ilo import ris
from proliantutils.tests.ilo import ribcl_sample_outputs as constants
class IloClientTestCase(testtools.TestCase):
@@ -229,3 +233,101 @@ class IloClientTestCase(testtools.TestCase):
self.client.get_host_health_at_a_glance('fake-data')
call_mock.assert_called_once_with('get_host_health_at_a_glance',
'fake-data')
@mock.patch.object(ipmi, 'get_nic_capacity')
@mock.patch.object(ribcl.RIBCLOperations, 'get_server_capabilities')
def test_get_server_capabilities(self, cap_mock, nic_mock):
info = {'address': "1.2.3.4", 'username': "admin", 'password': "Admin"}
nic_mock.return_value = '10Gb'
cap_mock.return_value = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen8',
'pci_gpu_devices': '2'}
capabilities = self.client.get_server_capabilities()
cap_mock.assert_called_once_with()
nic_mock.assert_called_once_with(self.client.info)
expected_capabilities = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen8',
'pci_gpu_devices': '2',
'nic_capacity': '10Gb'}
self.assertEqual(expected_capabilities, capabilities)
self.assertEqual(info, self.client.info)
@mock.patch.object(ipmi, 'get_nic_capacity')
@mock.patch.object(ribcl.RIBCLOperations, 'get_server_capabilities')
def test_get_server_capabilities_no_nic(self, cap_mock, nic_mock):
info = {'address': "1.2.3.4", 'username': "admin", 'password': "Admin"}
nic_mock.return_value = None
cap_mock.return_value = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen8',
'pci_gpu_devices': '2'}
capabilities = self.client.get_server_capabilities()
cap_mock.assert_called_once_with()
nic_mock.assert_called_once_with(self.client.info)
expected_capabilities = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen8',
'pci_gpu_devices': '2'}
self.assertEqual(expected_capabilities, capabilities)
self.assertEqual(info, self.client.info)
@mock.patch.object(ribcl.RIBCLOperations, 'get_host_health_data')
@mock.patch.object(ribcl.RIBCLOperations,
'_get_number_of_gpu_devices_connected')
@mock.patch.object(ipmi, 'get_nic_capacity')
@mock.patch.object(ris.RISOperations, 'get_server_capabilities')
def test_get_server_capabilities_no_nic_Gen9(self, cap_mock, nic_mock,
gpu_mock, host_mock):
info = {'address': "1.2.3.4", 'username': "admin", 'password': "Admin"}
data = constants.GET_EMBEDDED_HEALTH_OUTPUT
json_data = json.loads(data)
host_mock.return_value = json_data
self.client.model = 'Gen9'
nic_mock.return_value = None
gpu_mock.return_value = {'pci_gpu_devices': 2}
cap_mock.return_value = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen9',
'secure_boot': 'true'}
capabilities = self.client.get_server_capabilities()
cap_mock.assert_called_once_with()
nic_mock.assert_called_once_with(self.client.info)
expected_capabilities = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen9',
'pci_gpu_devices': 2,
'secure_boot': 'true'}
self.assertEqual(expected_capabilities, capabilities)
self.assertEqual(info, self.client.info)
@mock.patch.object(ribcl.RIBCLOperations, 'get_host_health_data')
@mock.patch.object(ribcl.RIBCLOperations,
'_get_number_of_gpu_devices_connected')
@mock.patch.object(ipmi, 'get_nic_capacity')
@mock.patch.object(ris.RISOperations, 'get_server_capabilities')
def test_get_server_capabilities_Gen9(self, cap_mock, nic_mock,
gpu_mock, host_mock):
info = {'address': "1.2.3.4", 'username': "admin", 'password': "Admin"}
data = constants.GET_EMBEDDED_HEALTH_OUTPUT
json_data = json.loads(data)
host_mock.return_value = json_data
self.client.model = 'Gen9'
gpu_mock.return_value = {'pci_gpu_devices': 2}
nic_mock.return_value = '10Gb'
cap_mock.return_value = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen9',
'secure_boot': 'true'}
capabilities = self.client.get_server_capabilities()
cap_mock.assert_called_once_with()
nic_mock.assert_called_once_with(self.client.info)
expected_capabilities = {'ilo_firmware_version': '2.10',
'rom_firmware_version': 'x',
'server_model': 'Gen9',
'pci_gpu_devices': 2,
'secure_boot': 'true',
'nic_capacity': '10Gb'}
self.assertEqual(expected_capabilities, capabilities)
self.assertEqual(info, self.client.info)

View File

@@ -0,0 +1,96 @@
# Copyright 2014 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 IPMI Module."""
import subprocess
import unittest
import mock
from proliantutils.ilo import ipmi
from proliantutils.tests.ilo import ipmi_sample_outputs as constants
class IloIpmiTestCase(unittest.TestCase):
def setUp(self):
super(IloIpmiTestCase, self).setUp()
self.info = {'address': "x.x.x.x",
'username': "admin",
'password': "Admin"}
@mock.patch.object(ipmi, '_parse_ipmi_nic_capacity')
@mock.patch.object(ipmi, '_exec_ipmitool')
def test_get_nic_capacity(self, ipmi_mock, parse_mock):
ipmi_mock.return_value = constants.NIC_FRU_OUT
parse_mock.return_value = "1Gb"
expected_out = "1Gb"
actual_out = ipmi.get_nic_capacity(self.info)
self.assertEqual(expected_out, actual_out)
@mock.patch.object(ipmi, '_parse_ipmi_nic_capacity')
@mock.patch.object(ipmi, '_exec_ipmitool')
def test_get_nic_capacity_loop_N_times(self, ipmi_mock, parse_mock):
ipmi_mock.side_effect = ["Device not present", "Device not present",
"Device not present", "Device not present",
"Device not present", "Device not present",
"Device not present", "Device not present",
constants.NIC_FRU_OUT]
parse_mock.return_value = "1Gb"
expected_out = "1Gb"
actual_out = ipmi.get_nic_capacity(self.info)
self.assertEqual(ipmi_mock.call_count, 9)
self.assertEqual(expected_out, actual_out)
@mock.patch.object(ipmi, '_parse_ipmi_nic_capacity')
@mock.patch.object(ipmi, '_exec_ipmitool')
def test_get_nic_capacity_none(self, ipmi_mock, parse_mock):
ipmi_mock.return_value = constants.NIC_FRU_OUT
parse_mock.return_value = None
actual_out = ipmi.get_nic_capacity(self.info)
self.assertIsNone(actual_out)
self.assertEqual(ipmi_mock.call_count, 255)
@mock.patch.object(subprocess, 'check_output')
def test__exec_ipmitool(self, check_mock):
check_mock.return_value = constants.NIC_FRU_OUT
expected_output = constants.NIC_FRU_OUT
cmd = "fru print 0x64"
actual_out = ipmi._exec_ipmitool(self.info, cmd)
self.assertEqual(expected_output, actual_out)
@mock.patch.object(subprocess, 'check_output')
def test__exec_ipmitool_none(self, check_mock):
check_mock.side_effect = Exception
cmd = "fru print 0x2"
actual_out = ipmi._exec_ipmitool(self.info, cmd)
self.assertIsNone(actual_out)
def test__parse_ipmi_nic_capacity(self):
exec_output = constants.NIC_FRU_OUT
expected_output = "1Gb"
actual_out = ipmi._parse_ipmi_nic_capacity(exec_output)
self.assertEqual(expected_output, actual_out)
def test__parse_ipmi_nic_capacity_no_port_details(self):
exec_output = constants.NIC_FRU_OUT_NO_PORT_DETAILS
actual_out = ipmi._parse_ipmi_nic_capacity(exec_output)
self.assertIsNone(actual_out)
def test__parse_ipmi_nic_capacity_no_product_name(self):
exec_output = constants.NIC_FRU_OUT_NO_PRODUCT_NAME
actual_out = ipmi._parse_ipmi_nic_capacity(exec_output)
self.assertIsNone(actual_out)