Skip to content

Commit 5d0748d

Browse files
andriymoroz-mlnxlguohan
authored andcommitted
[Mellanox] Use MAC from EEPROM for PortChannels and VLAN Interfaces (#1793)
* Use MAC from EEPROM for PortChannels Signed-off-by: Andriy Moroz <[email protected]> * Use MAC from EEPROM in DEVICE_METADATA Will affect MAC for VLAN interfaces Signed-off-by: Andriy Moroz <[email protected]> * Get MAC via decode-syseeprom Signed-off-by: Andriy Moroz <[email protected]> * hw-management is now a service Signed-off-by: Andriy Moroz <[email protected]> * Add error handling for MAC fetch process Signed-off-by: Andriy Moroz <[email protected]>
1 parent de7f5ac commit 5d0748d

File tree

7 files changed

+83
-4
lines changed

7 files changed

+83
-4
lines changed

dockers/docker-teamd/start.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ rm -rf $TEAMD_CONF_PATH
66
mkdir -p $TEAMD_CONF_PATH
77

88
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
9-
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
9+
10+
if [ "$SONIC_ASIC_TYPE" == "mellanox" ]; then
11+
MAC_ADDRESS=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.mac)
12+
else
13+
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
14+
fi
1015

1116
# Align last byte
1217
if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then

files/build_templates/sonic_debian_extension.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostname-config.service
160160
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/
161161

162162
# Copy updategraph script and service file
163-
sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/
163+
j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service
164164
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service
165165
sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/
166166
{% if enable_dhcp_graph_service == "y" %}

files/image_config/updategraph/updategraph.service renamed to files/build_templates/updategraph.service.j2

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Description=Update minigraph and set configuration based on minigraph
33
After=rc-local.service
44
After=database.service
55
Requires=database.service
6+
{% if sonic_asic_platform == 'mellanox' -%}
7+
Requires=hw-management.service
8+
{% endif -%}
9+
610

711
[Service]
812
Type=oneshot

platform/mellanox/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mlnx-sai/*
33
!mlnx-sai/Makefile
44
hw-management/*
55
!hw-management/Makefile
6+
!hw-management/*.patch
67
mft/*
78
!mft/Makefile
89

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From 22fef644b1150677353ab0559828ea45a982d901 Mon Sep 17 00:00:00 2001
2+
From: Andriy Moroz <[email protected]>
3+
Date: Wed, 11 Jul 2018 16:51:07 +0300
4+
Subject: [PATCH] Add systemd service config
5+
6+
Signed-off-by: Andriy Moroz <[email protected]>
7+
---
8+
debian/control | 2 +-
9+
debian/hw-management.service | 10 ++++++++++
10+
debian/rules | 2 +-
11+
3 files changed, 12 insertions(+), 2 deletions(-)
12+
create mode 100644 debian/hw-management.service
13+
14+
diff --git a/debian/control b/debian/control
15+
index 048cd61..7e3a545 100644
16+
--- a/debian/control
17+
+++ b/debian/control
18+
@@ -1,7 +1,7 @@
19+
Source: hw-management
20+
Priority: extra
21+
Maintainer: Adir Atias <adira@dev-r-vrt-128-008>
22+
-Build-Depends:
23+
+Build-Depends: dh-systemd
24+
Standards-Version:
25+
Section: libs
26+
Homepage: http://www.mellanox.com
27+
diff --git a/debian/hw-management.service b/debian/hw-management.service
28+
new file mode 100644
29+
index 0000000..d18916d
30+
--- /dev/null
31+
+++ b/debian/hw-management.service
32+
@@ -0,0 +1,10 @@
33+
+[Unit]
34+
+Description=Mellanox Hardware Management
35+
+
36+
+[Service]
37+
+Type=oneshot
38+
+EnvironmentFile=/host/machine.conf
39+
+ExecStart=/bin/bash -c "/usr/share/sonic/device/$onie_platform/hw-management start"
40+
+
41+
+[Install]
42+
+WantedBy=multi-user.target
43+
diff --git a/debian/rules b/debian/rules
44+
index fc38817..fba4150 100755
45+
--- a/debian/rules
46+
+++ b/debian/rules
47+
@@ -8,7 +8,7 @@ K_SRC ?= "/lib/modules/$(KVERSION)/build"
48+
pwd=$(shell pwd)
49+
50+
%:
51+
- dh $@
52+
+ dh $@ --with systemd
53+
54+
override_dh_auto_configure:
55+
56+
--
57+
1.9.1
58+

slave.mk

+2
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
474474
j2 -f env files/initramfs-tools/union-mount.j2 onie-image.conf > files/initramfs-tools/union-mount
475475
j2 -f env files/initramfs-tools/arista-convertfs.j2 onie-image.conf > files/initramfs-tools/arista-convertfs
476476

477+
j2 files/build_templates/updategraph.service.j2 > updategraph.service
478+
477479
$(if $($*_DOCKERS),
478480
j2 files/build_templates/sonic_debian_extension.j2 > sonic_debian_extension.sh
479481
chmod +x sonic_debian_extension.sh,

src/sonic-config-engine/sonic_platform.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ def get_sonic_version_info():
4141
return data
4242

4343
def get_system_mac():
44-
proc = subprocess.Popen("ip link show eth0 | grep ether | awk '{print $2}'", shell=True, stdout=subprocess.PIPE)
44+
version_info = get_sonic_version_info()
45+
46+
if (version_info['asic_type'] == 'mellanox'):
47+
get_mac_cmd = "sudo decode-syseeprom -m"
48+
else:
49+
get_mac_cmd = "ip link show eth0 | grep ether | awk '{print $2}'"
50+
51+
proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4552
(mac, err) = proc.communicate()
53+
if err:
54+
return None
55+
4656
mac = mac.strip()
4757

4858
# Align last byte of MAC if necessary
49-
version_info = get_sonic_version_info()
5059
if version_info and (version_info['asic_type'] == 'mellanox' or version_info['asic_type'] == 'centec'):
5160
last_byte = mac[-2:]
5261
aligned_last_byte = format(int(int(last_byte, 16) & 0b11000000), '02x')

0 commit comments

Comments
 (0)