Get the first physical ethernet port in Server Hardware

Before, the python-oneviewclient was getting the mac for
the first device and physical port in the Server Hardware.
This patch ensures that the mac its from a physical ethernet
port and port function 'a'.

Change-Id: Ia45053cd9d30cd0496c2b497dc71edd067976e72
This commit is contained in:
Hugo Nicodemos 2017-05-18 16:35:39 -03:00
parent 7fcda18be0
commit a2f112909a
3 changed files with 27 additions and 14 deletions

View File

@ -84,9 +84,22 @@ class ServerHardware(OneViewObject):
def get_mac(self, nic_index=0): def get_mac(self, nic_index=0):
if self.port_map: if self.port_map:
device = self.port_map.get('deviceSlots')[0] try:
physical_port = device.get('physicalPorts')[nic_index] for device in self.port_map.get('deviceSlots'):
return physical_port.get('mac', '').lower() for physical_port in device.get('physicalPorts'):
if physical_port.get('type') == 'Ethernet':
sh_physical_port = physical_port
break
for virtual_port in sh_physical_port.get('virtualPorts'):
# NOTE(nicodemos): Ironic oneview drivers needs to use a
# port that type is Ethernet and function 'a' to be able
# to make a deploy.
if virtual_port.get('portFunction') == 'a':
return virtual_port.get('mac').lower()
except Exception:
raise exceptions.OneViewException(
"There is no Ethernet port on the Server Hardware: %s"
% self.attribute_map.get('uri'))
else: else:
raise exceptions.OneViewException( raise exceptions.OneViewException(
"There is no portMap on the Server Hardware requested. Is " "There is no portMap on the Server Hardware requested. Is "

View File

@ -139,13 +139,10 @@ class Test(unittest.TestCase):
self.assertIsNone(sh.server_profile_uri) self.assertIsNone(sh.server_profile_uri)
self.assertFalse(hasattr(sh, 'something_not_defined')) self.assertFalse(hasattr(sh, 'something_not_defined'))
self.assertDictContainsSubset( self.assertDictContainsSubset(
{'mpIpAddresses': [{ {'mpIpAddresses': [
'address': '172.18.6.18', {'address': '172.18.6.18',
'type': 'Undefined' 'type': 'Undefined'}
}] ]}, sh.mp_host_info)
},
sh.mp_host_info
)
def test_serverprofiletemplate_from_json(self): def test_serverprofiletemplate_from_json(self):
json = { json = {
@ -213,7 +210,10 @@ class Test(unittest.TestCase):
def test_get_mac_from_server_hardware(self): def test_get_mac_from_server_hardware(self):
server_hardware = models.ServerHardware() server_hardware = models.ServerHardware()
server_hardware.port_map = fixtures.PORT_MAP server_hardware.port_map = fixtures.PORT_MAP
self.assertEqual("d8:9d:67:73:54:00", server_hardware.get_mac()) sh_device_port = server_hardware.port_map.get('deviceSlots')[0]
sh_physical_port = sh_device_port.get('physicalPorts')[0]
sh_virtual_port = sh_physical_port.get('virtualPorts')[0]
if __name__ == '__main__': self.assertEqual("ea:ef:c7:70:00:00", server_hardware.get_mac())
unittest.main() self.assertEqual("Ethernet", sh_physical_port.get('type'))
self.assertEqual("a", sh_virtual_port.get('portFunction'))

View File

@ -729,7 +729,7 @@ class OneViewClientTestCase(unittest.TestCase):
self.oneview_client._is_node_port_mac_compatible_with_server_hardware( self.oneview_client._is_node_port_mac_compatible_with_server_hardware(
{}, {},
[type('obj', (object,), {'address': 'D8:9D:67:73:54:00'})] [type('obj', (object,), {'address': 'EA:EF:C7:70:00:00'})]
) )
mock_server_hardware.assert_called_once_with(self.oneview_client, {}) mock_server_hardware.assert_called_once_with(self.oneview_client, {})