Merge "Move _normalize_mac to driver utils"

changes/79/264579/24
Jenkins 7 years ago committed by Gerrit Code Review
commit 4d4056a19b

@ -143,7 +143,7 @@ def _get_command_sets(virt_type):
One name per line, can be quoted.
start_cmd / stop_cmd: Starts or stops the identified VM
get_node_macs: Retrieves all MACs for an identified VM.
One MAC per line, any standard format (see _normalize_mac)
One MAC per line, any standard format (see driver_utils.normalize_mac)
get_boot_device / set_boot_device: Gets or sets the primary boot device
"""
if virt_type == 'vbox':
@ -270,10 +270,6 @@ def _get_command_sets(virt_type):
{'virt_type': virt_type})
def _normalize_mac(mac):
return mac.replace('-', '').replace(':', '').lower()
def _get_boot_device(ssh_obj, driver_info):
"""Get the current boot device.
@ -493,7 +489,8 @@ def _get_hosts_name_for_node(ssh_obj, driver_info):
if not host_mac:
continue
for node_mac in driver_info['macs']:
if _normalize_mac(host_mac) in _normalize_mac(node_mac):
if (driver_utils.normalize_mac(host_mac)
in driver_utils.normalize_mac(node_mac)):
LOG.debug("Found Mac address: %s" % node_mac)
matched_name = node
break

@ -242,3 +242,12 @@ def capabilities_to_dict(capabilities):
)
return capabilities_dict
def normalize_mac(mac):
"""Remove '-' and ':' characters and lowercase the MAC string.
:param mac: MAC address to normalize.
:return: Normalized MAC address string.
"""
return mac.replace('-', '').replace(':', '').lower()

@ -156,16 +156,6 @@ class SSHValidateParametersTestCase(db_base.DbTestCase):
ssh._parse_driver_info,
node)
def test__normalize_mac_string(self):
mac_raw = "0A:1B-2C-3D:4F"
mac_clean = ssh._normalize_mac(mac_raw)
self.assertEqual("0a1b2c3d4f", mac_clean)
def test__normalize_mac_unicode(self):
mac_raw = u"0A:1B-2C-3D:4F"
mac_clean = ssh._normalize_mac(mac_raw)
self.assertEqual("0a1b2c3d4f", mac_clean)
def test__parse_driver_info_with_custom_libvirt_uri(self):
CONF.set_override('libvirt_uri', 'qemu:///foo', 'ssh')
expected_base_cmd = "LC_ALL=C /usr/bin/virsh --connect qemu:///foo"

@ -228,3 +228,13 @@ class UtilsTestCase(db_base.DbTestCase):
)
self.assertEqual("Value of 'capabilities' must be string. Got " +
str(int), str(exc))
def test_normalize_mac_string(self):
mac_raw = "0A:1B-2C-3D:4F"
mac_clean = driver_utils.normalize_mac(mac_raw)
self.assertEqual("0a1b2c3d4f", mac_clean)
def test_normalize_mac_unicode(self):
mac_raw = u"0A:1B-2C-3D:4F"
mac_clean = driver_utils.normalize_mac(mac_raw)
self.assertEqual("0a1b2c3d4f", mac_clean)

Loading…
Cancel
Save