diff --git a/oneview_client/models.py b/oneview_client/models.py index 59e0e3a..56795dd 100644 --- a/oneview_client/models.py +++ b/oneview_client/models.py @@ -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 " diff --git a/oneview_client/tests/unit/test_models.py b/oneview_client/tests/unit/test_models.py index 76fd00c..33c2c08 100644 --- a/oneview_client/tests/unit/test_models.py +++ b/oneview_client/tests/unit/test_models.py @@ -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')) diff --git a/oneview_client/tests/unit/test_oneview_client.py b/oneview_client/tests/unit/test_oneview_client.py index 11f5fc4..bac75a7 100644 --- a/oneview_client/tests/unit/test_oneview_client.py +++ b/oneview_client/tests/unit/test_oneview_client.py @@ -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, {})