mac_addresses now come across in UNIX format,
the format preferred by hypervisors. update: apparently re is no bueno Change-Id: Ie024e645b4c9a7c39e1e6cc0016a5eb11982312d
This commit is contained in:
parent
eb294a5b69
commit
dd21327846
@ -765,6 +765,10 @@ class MacAddress(ModelBase):
|
||||
def eui_format(self):
|
||||
return str(netaddr.EUI(self.address))
|
||||
|
||||
@property
|
||||
def unix_format(self):
|
||||
return self.eui_format.replace('-', ':')
|
||||
|
||||
def _before_save(self):
|
||||
self.address = int(netaddr.EUI(self.address))
|
||||
|
||||
@ -886,6 +890,11 @@ class Interface(ModelBase):
|
||||
if self.mac_address:
|
||||
return self.mac_address.eui_format
|
||||
|
||||
@property
|
||||
def mac_address_unix_format(self):
|
||||
if self.mac_address:
|
||||
return self.mac_address.unix_format
|
||||
|
||||
def _validate(self):
|
||||
self._validate_presence_of("tenant_id")
|
||||
self._validate_uniqueness_of_virtual_interface_id()
|
||||
|
@ -71,7 +71,7 @@ class InterfaceConfigurationView(object):
|
||||
|
||||
def data(self):
|
||||
data = self.interface.data()
|
||||
data['mac_address'] = self.interface.mac_address_eui_format
|
||||
data['mac_address'] = self.interface.mac_address_unix_format
|
||||
ip_addresses = self.interface.ip_addresses
|
||||
data['ip_addresses'] = IpConfigurationView(*ip_addresses).data()
|
||||
return data
|
||||
|
@ -2336,7 +2336,7 @@ class TestInterface(tests.BaseTest):
|
||||
|
||||
self.assertEqual(interface.mac_address, mac)
|
||||
|
||||
def test_returns_eui_formatted_mac_address(self):
|
||||
def test_eui_formatted_mac_address(self):
|
||||
interface = factory_models.InterfaceFactory()
|
||||
models.MacAddress.create(interface_id=interface.id,
|
||||
address="ab:bc:cd:12:23:34")
|
||||
@ -2349,6 +2349,19 @@ class TestInterface(tests.BaseTest):
|
||||
|
||||
self.assertIsNone(interface.mac_address_eui_format)
|
||||
|
||||
def test_unix_formatted_mac_address(self):
|
||||
interface = factory_models.InterfaceFactory()
|
||||
models.MacAddress.create(interface_id=interface.id,
|
||||
address="ab:bc:cd:12:23:34")
|
||||
|
||||
self.assertEqual(interface.mac_address_unix_format,
|
||||
"AB:BC:CD:12:23:34")
|
||||
|
||||
def test_mac_address_unix_format_is_none_when_no_mac_address(self):
|
||||
interface = factory_models.InterfaceFactory()
|
||||
|
||||
self.assertIsNone(interface.mac_address_unix_format)
|
||||
|
||||
def test_ip_addresses(self):
|
||||
interface = factory_models.InterfaceFactory()
|
||||
|
||||
|
@ -2168,7 +2168,7 @@ class TestInterfacesController(ControllerTestBase):
|
||||
interface_id=created_interface.id)
|
||||
self.assertIsNotNone(allocated_mac)
|
||||
self.assertEqual(response.json['interface']['mac_address'],
|
||||
allocated_mac.eui_format)
|
||||
allocated_mac.unix_format)
|
||||
|
||||
def test_create_interface_allocates_ips_from_network(self):
|
||||
block = factory_models.IpBlockFactory(network_id="net1",
|
||||
@ -2271,7 +2271,7 @@ class TestInterfacesController(ControllerTestBase):
|
||||
self.assertEqual(response.status_int, 200)
|
||||
iface_data = response.json["interface"]
|
||||
self.assertEqual(iface_data['id'], iface.virtual_interface_id)
|
||||
self.assertEqual(iface_data['mac_address'], mac.eui_format)
|
||||
self.assertEqual(iface_data['mac_address'], mac.unix_format)
|
||||
self.assertEqual(len(iface_data['ip_addresses']), 2)
|
||||
self.assertEqual(iface_data['ip_addresses'],
|
||||
views.IpConfigurationView(*iface.ip_addresses).data())
|
||||
|
@ -104,7 +104,7 @@ class TestInterfaceConfigurationView(tests.BaseTest):
|
||||
|
||||
data = views.InterfaceConfigurationView(interface).data()
|
||||
|
||||
self.assertEqual(data['mac_address'], mac.eui_format)
|
||||
self.assertEqual(data['mac_address'], mac.unix_format)
|
||||
self.assertEqual(data['id'], interface.virtual_interface_id)
|
||||
|
||||
def test_data_returns_ip_address_configuration_information(self):
|
||||
|
Loading…
Reference in New Issue
Block a user