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:
parent
7fcda18be0
commit
a2f112909a
@ -84,9 +84,22 @@ class ServerHardware(OneViewObject):
|
||||
|
||||
def get_mac(self, nic_index=0):
|
||||
if self.port_map:
|
||||
device = self.port_map.get('deviceSlots')[0]
|
||||
physical_port = device.get('physicalPorts')[nic_index]
|
||||
return physical_port.get('mac', '').lower()
|
||||
try:
|
||||
for device in self.port_map.get('deviceSlots'):
|
||||
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:
|
||||
raise exceptions.OneViewException(
|
||||
"There is no portMap on the Server Hardware requested. Is "
|
||||
|
@ -139,13 +139,10 @@ class Test(unittest.TestCase):
|
||||
self.assertIsNone(sh.server_profile_uri)
|
||||
self.assertFalse(hasattr(sh, 'something_not_defined'))
|
||||
self.assertDictContainsSubset(
|
||||
{'mpIpAddresses': [{
|
||||
'address': '172.18.6.18',
|
||||
'type': 'Undefined'
|
||||
}]
|
||||
},
|
||||
sh.mp_host_info
|
||||
)
|
||||
{'mpIpAddresses': [
|
||||
{'address': '172.18.6.18',
|
||||
'type': 'Undefined'}
|
||||
]}, sh.mp_host_info)
|
||||
|
||||
def test_serverprofiletemplate_from_json(self):
|
||||
json = {
|
||||
@ -213,7 +210,10 @@ class Test(unittest.TestCase):
|
||||
def test_get_mac_from_server_hardware(self):
|
||||
server_hardware = models.ServerHardware()
|
||||
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__':
|
||||
unittest.main()
|
||||
self.assertEqual("ea:ef:c7:70:00:00", server_hardware.get_mac())
|
||||
self.assertEqual("Ethernet", sh_physical_port.get('type'))
|
||||
self.assertEqual("a", sh_virtual_port.get('portFunction'))
|
||||
|
@ -729,7 +729,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
||||
|
||||
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, {})
|
||||
|
Loading…
Reference in New Issue
Block a user