Fix operator cloud get_nic_by_mac
Apparently, this method either never worked or was silently broken at some point in the past, since we didn't have tests. Added two tests and got the method back into working shape. Change-Id: I26591549c082a2cd206f20fbcb7f1e3a1dde91c7
This commit is contained in:
parent
f9465f5abe
commit
bd38f39243
@ -56,8 +56,9 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
|||||||
def get_nic_by_mac(self, mac):
|
def get_nic_by_mac(self, mac):
|
||||||
# TODO(TheJulia): Query /ports?address=mac when converting
|
# TODO(TheJulia): Query /ports?address=mac when converting
|
||||||
try:
|
try:
|
||||||
return self.manager.submit_task(
|
return self._normalize_machine(
|
||||||
_tasks.MachineNodePortGet(port_id=mac))
|
self.manager.submit_task(
|
||||||
|
_tasks.MachinePortGetByAddress(address=mac)))
|
||||||
except ironic_exceptions.ClientException:
|
except ironic_exceptions.ClientException:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -92,3 +92,30 @@ class TestBaremetalPort(base.IronicTestCase):
|
|||||||
self.op_cloud.list_nics_for_machine,
|
self.op_cloud.list_nics_for_machine,
|
||||||
self.fake_baremetal_node['uuid'])
|
self.fake_baremetal_node['uuid'])
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
|
def test_get_nic_by_mac(self):
|
||||||
|
mac = self.fake_baremetal_port['address']
|
||||||
|
query = 'detail?address=%s' % mac
|
||||||
|
self.register_uris([
|
||||||
|
dict(method='GET',
|
||||||
|
uri=self.get_mock_url(resource='ports', append=[query]),
|
||||||
|
json={'ports': [self.fake_baremetal_port]}),
|
||||||
|
])
|
||||||
|
|
||||||
|
return_value = self.op_cloud.get_nic_by_mac(mac)
|
||||||
|
|
||||||
|
self.assertEqual(self.fake_baremetal_port, return_value)
|
||||||
|
self.assert_calls()
|
||||||
|
|
||||||
|
def test_get_nic_by_mac_failure(self):
|
||||||
|
mac = self.fake_baremetal_port['address']
|
||||||
|
query = 'detail?address=%s' % mac
|
||||||
|
self.register_uris([
|
||||||
|
dict(method='GET',
|
||||||
|
uri=self.get_mock_url(resource='ports', append=[query]),
|
||||||
|
json={'ports': []}),
|
||||||
|
])
|
||||||
|
|
||||||
|
self.assertIsNone(self.op_cloud.get_nic_by_mac(mac))
|
||||||
|
|
||||||
|
self.assert_calls()
|
||||||
|
Loading…
Reference in New Issue
Block a user