Update register_machine to use the Ironic format for ports
It's confusing to use two different formats across the SDK. Also allow a simple list of MAC addresses, since that's what most people presumably want. Change-Id: I47448850225f04f24fb0dfc6a1700b5e2c26a450
This commit is contained in:
parent
41c39a4848
commit
75237720f6
|
@ -24,6 +24,25 @@ import jsonpatch
|
||||||
from openstack.cloud import exc
|
from openstack.cloud import exc
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_port_list(nics):
|
||||||
|
ports = []
|
||||||
|
for row in nics:
|
||||||
|
if isinstance(row, str):
|
||||||
|
address = row
|
||||||
|
row = {}
|
||||||
|
elif 'mac' in row:
|
||||||
|
address = row.pop('mac')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
address = row.pop('address')
|
||||||
|
except KeyError:
|
||||||
|
raise TypeError(
|
||||||
|
"Either 'address' or 'mac' must be provided "
|
||||||
|
"for port %s" % row)
|
||||||
|
ports.append(dict(row, address=address))
|
||||||
|
return ports
|
||||||
|
|
||||||
|
|
||||||
class BaremetalCloudMixin:
|
class BaremetalCloudMixin:
|
||||||
|
|
||||||
def list_nics(self):
|
def list_nics(self):
|
||||||
|
@ -182,10 +201,12 @@ class BaremetalCloudMixin:
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
[
|
[
|
||||||
{'mac': 'aa:bb:cc:dd:ee:01'},
|
{'address': 'aa:bb:cc:dd:ee:01'},
|
||||||
{'mac': 'aa:bb:cc:dd:ee:02'}
|
{'address': 'aa:bb:cc:dd:ee:02'}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Alternatively, you can provide an array of MAC addresses.
|
||||||
|
|
||||||
:param wait: Boolean value, defaulting to false, to wait for the node
|
:param wait: Boolean value, defaulting to false, to wait for the node
|
||||||
to reach the available state where the node can be provisioned. It
|
to reach the available state where the node can be provisioned. It
|
||||||
must be noted, when set to false, the method will still wait for
|
must be noted, when set to false, the method will still wait for
|
||||||
|
@ -233,11 +254,9 @@ class BaremetalCloudMixin:
|
||||||
# Create NICs before trying to run cleaning
|
# Create NICs before trying to run cleaning
|
||||||
created_nics = []
|
created_nics = []
|
||||||
try:
|
try:
|
||||||
for row in nics:
|
for port in _normalize_port_list(nics):
|
||||||
address = row.pop('mac')
|
|
||||||
nic = self.baremetal.create_port(node_id=machine.id,
|
nic = self.baremetal.create_port(node_id=machine.id,
|
||||||
address=address,
|
**port)
|
||||||
**row)
|
|
||||||
created_nics.append(nic.id)
|
created_nics.append(nic.id)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -295,9 +314,9 @@ class BaremetalCloudMixin:
|
||||||
"Error unregistering node '%s': Exception occured while"
|
"Error unregistering node '%s': Exception occured while"
|
||||||
" waiting to be able to proceed: %s" % (machine['uuid'], e))
|
" waiting to be able to proceed: %s" % (machine['uuid'], e))
|
||||||
|
|
||||||
for nic in nics:
|
for nic in _normalize_port_list(nics):
|
||||||
try:
|
try:
|
||||||
port = next(self.baremetal.ports(address=nic['mac']))
|
port = next(self.baremetal.ports(address=nic['address']))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
continue
|
continue
|
||||||
self.baremetal.delete_port(port.id)
|
self.baremetal.delete_port(port.id)
|
||||||
|
|
|
@ -1063,7 +1063,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine(self):
|
def test_register_machine(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
# TODO(TheJulia): There is a lot of duplication
|
# TODO(TheJulia): There is a lot of duplication
|
||||||
# in testing creation. Surely this hsould be a helper
|
# in testing creation. Surely this hsould be a helper
|
||||||
|
@ -1104,7 +1104,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
# accounted for newer microversions.
|
# accounted for newer microversions.
|
||||||
def test_register_machine_enroll(self):
|
def test_register_machine_enroll(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address, 'pxe_enabled': False}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1143,7 +1143,8 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
uri=self.get_mock_url(
|
uri=self.get_mock_url(
|
||||||
resource='ports'),
|
resource='ports'),
|
||||||
validate=dict(json={'address': mac_address,
|
validate=dict(json={'address': mac_address,
|
||||||
'node_uuid': node_uuid}),
|
'node_uuid': node_uuid,
|
||||||
|
'pxe_enabled': False}),
|
||||||
json=self.fake_baremetal_port),
|
json=self.fake_baremetal_port),
|
||||||
dict(
|
dict(
|
||||||
method='PUT',
|
method='PUT',
|
||||||
|
@ -1166,7 +1167,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine_enroll_wait(self):
|
def test_register_machine_enroll_wait(self):
|
||||||
mac_address = self.fake_baremetal_port
|
mac_address = self.fake_baremetal_port
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1241,7 +1242,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine_enroll_failure(self):
|
def test_register_machine_enroll_failure(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1291,7 +1292,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine_enroll_timeout(self):
|
def test_register_machine_enroll_timeout(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1345,7 +1346,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine_enroll_timeout_wait(self):
|
def test_register_machine_enroll_timeout_wait(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1414,7 +1415,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
def test_register_machine_port_create_failed(self):
|
def test_register_machine_port_create_failed(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'address': mac_address}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
@ -1455,7 +1456,8 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
def test_register_machine_several_ports_create_failed(self):
|
def test_register_machine_several_ports_create_failed(self):
|
||||||
mac_address = '00:01:02:03:04:05'
|
mac_address = '00:01:02:03:04:05'
|
||||||
mac_address2 = mac_address[::-1]
|
mac_address2 = mac_address[::-1]
|
||||||
nics = [{'mac': mac_address}, {'mac': mac_address2}]
|
# Verify a couple of ways to provide MACs
|
||||||
|
nics = [mac_address, {'mac': mac_address2}]
|
||||||
node_uuid = self.fake_baremetal_node['uuid']
|
node_uuid = self.fake_baremetal_node['uuid']
|
||||||
node_to_post = {
|
node_to_post = {
|
||||||
'chassis_uuid': None,
|
'chassis_uuid': None,
|
||||||
|
|
Loading…
Reference in New Issue