[interfaces]: Set hwaddr of VLAN interfaces to system MAC upon creation (#1042)
This commit is contained in:
parent
463c5e46ba
commit
37dc7bd478
@ -1,6 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
sonic-cfggen -d -t /usr/share/sonic/templates/interfaces.j2 >/etc/network/interfaces
|
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
|
||||||
|
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
|
||||||
|
|
||||||
|
# Align last byte of MAC if necessary
|
||||||
|
if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then
|
||||||
|
last_byte=$(python -c "print '$SYSTEM_MAC_ADDRESS'[-2:]")
|
||||||
|
aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix
|
||||||
|
SYSTEM_MAC_ADDRESS=$(python -c "print '$SYSTEM_MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC
|
||||||
|
fi
|
||||||
|
|
||||||
|
sonic-cfggen -d -a '{"hwaddr":"'$SYSTEM_MAC_ADDRESS'"}' -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces
|
||||||
|
|
||||||
[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid
|
[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid
|
||||||
service networking restart
|
|
||||||
|
systemctl restart networking
|
||||||
|
|
||||||
ifdown lo && ifup lo
|
ifdown lo && ifup lo
|
||||||
|
@ -90,6 +90,7 @@ iface {{ member }} inet manual
|
|||||||
auto {{ name }}
|
auto {{ name }}
|
||||||
iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
|
iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
|
||||||
bridge_ports none
|
bridge_ports none
|
||||||
|
hwaddress ether {{ hwaddr }}
|
||||||
address {{ prefix | ip }}
|
address {{ prefix | ip }}
|
||||||
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
|
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -214,6 +214,7 @@ iface fortyGigE0/124 inet manual
|
|||||||
auto Vlan1000
|
auto Vlan1000
|
||||||
iface Vlan1000 inet static
|
iface Vlan1000 inet static
|
||||||
bridge_ports none
|
bridge_ports none
|
||||||
|
hwaddress ether e4:1d:2d:a5:f3:ad
|
||||||
address 192.168.0.1
|
address 192.168.0.1
|
||||||
netmask 255.255.255.224
|
netmask 255.255.255.224
|
||||||
#
|
#
|
||||||
|
@ -20,7 +20,7 @@ class TestJ2Files(TestCase):
|
|||||||
|
|
||||||
def test_interfaces(self):
|
def test_interfaces(self):
|
||||||
interfaces_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'interfaces', 'interfaces.j2')
|
interfaces_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'interfaces', 'interfaces.j2')
|
||||||
argument = '-m ' + self.t0_minigraph + ' -t ' + interfaces_template + ' > ' + self.output_file
|
argument = '-m ' + self.t0_minigraph + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + ' > ' + self.output_file
|
||||||
self.run_script(argument)
|
self.run_script(argument)
|
||||||
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'interfaces'), self.output_file))
|
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'interfaces'), self.output_file))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user