From e4b16e253d8860f1c5aed453a4bf6bc8e36f6628 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Tue, 12 Jun 2018 21:13:51 +0300 Subject: [PATCH 1/5] Use MAC from EEPROM for PortChannels Signed-off-by: Andriy Moroz --- dockers/docker-teamd/start.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dockers/docker-teamd/start.sh b/dockers/docker-teamd/start.sh index 6e80f6eb9a83..88d060f9f54f 100755 --- a/dockers/docker-teamd/start.sh +++ b/dockers/docker-teamd/start.sh @@ -6,7 +6,12 @@ rm -rf $TEAMD_CONF_PATH mkdir -p $TEAMD_CONF_PATH SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) -MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') + +if [ "$SONIC_ASIC_TYPE" == "mellanox" ]; then + MAC_ADDRESS=$(od -vt x1 -An /sys/bus/i2c/devices/8-0051/eeprom | xargs printf "0x%s " | xargs printf "%02x:" | awk 'BEGIN { FS=":"; i=8+1+2+1} {while(i Date: Thu, 14 Jun 2018 13:18:47 +0300 Subject: [PATCH 2/5] Use MAC from EEPROM in DEVICE_METADATA Will affect MAC for VLAN interfaces Signed-off-by: Andriy Moroz --- files/build_templates/sonic_debian_extension.j2 | 2 +- files/build_templates/swss.service.j2 | 1 + .../updategraph.service.j2} | 3 +++ slave.mk | 2 ++ src/sonic-config-engine/sonic_platform.py | 11 +++++++++-- 5 files changed, 16 insertions(+), 3 deletions(-) rename files/{image_config/updategraph/updategraph.service => build_templates/updategraph.service.j2} (58%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index d0afa4659667..67c50e32af43 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -155,7 +155,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostname-config.service sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/ # Copy updategraph script and service file -sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/ +j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/ {% if enable_dhcp_graph_service == "y" %} diff --git a/files/build_templates/swss.service.j2 b/files/build_templates/swss.service.j2 index e16ca6636121..2d46818b59c3 100644 --- a/files/build_templates/swss.service.j2 +++ b/files/build_templates/swss.service.j2 @@ -32,6 +32,7 @@ ExecStartPre=/usr/bin/mlnx-fw-upgrade.sh ExecStartPre=/etc/init.d/sxdkernel start ExecStartPre=/sbin/modprobe i2c-dev ExecStartPre=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)/hw-management start" +ExecStartPre=/usr/local/bin/sonic-cfggen -H --write-to-db {% elif sonic_asic_platform == 'cavium' %} ExecStartPre=/etc/init.d/xpnet.sh start {% endif %} diff --git a/files/image_config/updategraph/updategraph.service b/files/build_templates/updategraph.service.j2 similarity index 58% rename from files/image_config/updategraph/updategraph.service rename to files/build_templates/updategraph.service.j2 index ec478d93a132..10ff1f57bf3a 100644 --- a/files/image_config/updategraph/updategraph.service +++ b/files/build_templates/updategraph.service.j2 @@ -6,6 +6,9 @@ Requires=database.service [Service] Type=oneshot +{% if sonic_asic_platform == 'mellanox' -%} +ExecStartPre=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)/hw-management start" +{% endif -%} ExecStart=/usr/bin/updategraph RemainAfterExit=yes diff --git a/slave.mk b/slave.mk index a81acb1798f4..a58f6335f6b7 100644 --- a/slave.mk +++ b/slave.mk @@ -481,6 +481,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ j2 -f env files/initramfs-tools/union-mount.j2 onie-image.conf > files/initramfs-tools/union-mount j2 -f env files/initramfs-tools/arista-convertfs.j2 onie-image.conf > files/initramfs-tools/arista-convertfs + j2 files/build_templates/updategraph.service.j2 > updategraph.service + $(if $($*_DOCKERS), j2 files/build_templates/sonic_debian_extension.j2 > sonic_debian_extension.sh chmod +x sonic_debian_extension.sh, diff --git a/src/sonic-config-engine/sonic_platform.py b/src/sonic-config-engine/sonic_platform.py index f573d6a6575d..4e47e1b6ba4d 100644 --- a/src/sonic-config-engine/sonic_platform.py +++ b/src/sonic-config-engine/sonic_platform.py @@ -41,12 +41,19 @@ def get_sonic_version_info(): return data def get_system_mac(): - proc = subprocess.Popen("ip link show eth0 | grep ether | awk '{print $2}'", shell=True, stdout=subprocess.PIPE) + get_mac_cmd = "ip link show eth0 | grep ether | awk '{print $2}'" + version_info = get_sonic_version_info() + + if (version_info['asic_type'] == 'mellanox'): + eeprom_file = "/sys/bus/i2c/devices/8-0051/eeprom" + if (os.access(eeprom_file, os.R_OK)): + get_mac_cmd = "od -vt x1 -An " + eeprom_file + "| xargs printf \"0x%s \" | xargs printf \"%02x:\" | awk 'BEGIN { FS=\":\"; i=8+1+2+1} {while(i Date: Tue, 26 Jun 2018 16:01:18 +0300 Subject: [PATCH 3/5] Get MAC via decode-syseeprom Signed-off-by: Andriy Moroz --- dockers/docker-teamd/start.sh | 2 +- files/build_templates/swss.service.j2 | 1 - files/build_templates/updategraph.service.j2 | 3 ++- src/sonic-config-engine/sonic_platform.py | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dockers/docker-teamd/start.sh b/dockers/docker-teamd/start.sh index 88d060f9f54f..fb3b7c3dadf8 100755 --- a/dockers/docker-teamd/start.sh +++ b/dockers/docker-teamd/start.sh @@ -8,7 +8,7 @@ mkdir -p $TEAMD_CONF_PATH SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) if [ "$SONIC_ASIC_TYPE" == "mellanox" ]; then - MAC_ADDRESS=$(od -vt x1 -An /sys/bus/i2c/devices/8-0051/eeprom | xargs printf "0x%s " | xargs printf "%02x:" | awk 'BEGIN { FS=":"; i=8+1+2+1} {while(i Date: Wed, 11 Jul 2018 18:41:59 +0300 Subject: [PATCH 4/5] hw-management is now a service Signed-off-by: Andriy Moroz --- files/build_templates/updategraph.service.j2 | 8 +-- platform/mellanox/.gitignore | 1 + .../Add-systemd-service-config.patch | 58 +++++++++++++++++++ platform/mellanox/hw-management/Makefile | 1 + 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 platform/mellanox/hw-management/Add-systemd-service-config.patch diff --git a/files/build_templates/updategraph.service.j2 b/files/build_templates/updategraph.service.j2 index 7eec7a534164..8039f42531cd 100644 --- a/files/build_templates/updategraph.service.j2 +++ b/files/build_templates/updategraph.service.j2 @@ -3,13 +3,13 @@ Description=Update minigraph and set configuration based on minigraph After=rc-local.service After=database.service Requires=database.service +{% if sonic_asic_platform == 'mellanox' -%} +Requires=hw-management.service +{% endif -%} + [Service] Type=oneshot -{% if sonic_asic_platform == 'mellanox' -%} -EnvironmentFile=/host/machine.conf -ExecStartPre=/bin/bash -c "/usr/share/sonic/device/$onie_platform/hw-management start" -{% endif -%} ExecStart=/usr/bin/updategraph RemainAfterExit=yes diff --git a/platform/mellanox/.gitignore b/platform/mellanox/.gitignore index 3c0769067437..ac1ce990d56d 100644 --- a/platform/mellanox/.gitignore +++ b/platform/mellanox/.gitignore @@ -3,6 +3,7 @@ mlnx-sai/* !mlnx-sai/Makefile hw-management/* !hw-management/Makefile +!hw-management/*.patch mft/* !mft/Makefile diff --git a/platform/mellanox/hw-management/Add-systemd-service-config.patch b/platform/mellanox/hw-management/Add-systemd-service-config.patch new file mode 100644 index 000000000000..4903f508bce6 --- /dev/null +++ b/platform/mellanox/hw-management/Add-systemd-service-config.patch @@ -0,0 +1,58 @@ +From 22fef644b1150677353ab0559828ea45a982d901 Mon Sep 17 00:00:00 2001 +From: Andriy Moroz +Date: Wed, 11 Jul 2018 16:51:07 +0300 +Subject: [PATCH] Add systemd service config + +Signed-off-by: Andriy Moroz +--- + debian/control | 2 +- + debian/hw-management.service | 10 ++++++++++ + debian/rules | 2 +- + 3 files changed, 12 insertions(+), 2 deletions(-) + create mode 100644 debian/hw-management.service + +diff --git a/debian/control b/debian/control +index 048cd61..7e3a545 100644 +--- a/debian/control ++++ b/debian/control +@@ -1,7 +1,7 @@ + Source: hw-management + Priority: extra + Maintainer: Adir Atias +-Build-Depends: ++Build-Depends: dh-systemd + Standards-Version: + Section: libs + Homepage: http://www.mellanox.com +diff --git a/debian/hw-management.service b/debian/hw-management.service +new file mode 100644 +index 0000000..d18916d +--- /dev/null ++++ b/debian/hw-management.service +@@ -0,0 +1,10 @@ ++[Unit] ++Description=Mellanox Hardware Management ++ ++[Service] ++Type=oneshot ++EnvironmentFile=/host/machine.conf ++ExecStart=/bin/bash -c "/usr/share/sonic/device/$onie_platform/hw-management start" ++ ++[Install] ++WantedBy=multi-user.target +diff --git a/debian/rules b/debian/rules +index fc38817..fba4150 100755 +--- a/debian/rules ++++ b/debian/rules +@@ -8,7 +8,7 @@ K_SRC ?= "/lib/modules/$(KVERSION)/build" + pwd=$(shell pwd) + + %: +- dh $@ ++ dh $@ --with systemd + + override_dh_auto_configure: + +-- +1.9.1 + diff --git a/platform/mellanox/hw-management/Makefile b/platform/mellanox/hw-management/Makefile index ee2899d07c39..4fa5d2cf328c 100644 --- a/platform/mellanox/hw-management/Makefile +++ b/platform/mellanox/hw-management/Makefile @@ -10,6 +10,7 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : # build pushd hw-management + git am ../*.patch sed "s~@SED_VERSION@~$(MLNX_HW_MANAGEMENT_VERSION)~" -i debian/changelog chmod +x ./debian/rules sudo ./debian/rules binary KVERSION=$(KVERSION) From 048db4d847e7b9d3789d0d2ef64c499877396d5a Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Fri, 13 Jul 2018 19:15:55 +0300 Subject: [PATCH 5/5] Add error handling for MAC fetch process Signed-off-by: Andriy Moroz --- src/sonic-config-engine/sonic_platform.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sonic-config-engine/sonic_platform.py b/src/sonic-config-engine/sonic_platform.py index 3afc8ba426d1..55ad2325f5db 100644 --- a/src/sonic-config-engine/sonic_platform.py +++ b/src/sonic-config-engine/sonic_platform.py @@ -48,8 +48,11 @@ def get_system_mac(): else: get_mac_cmd = "ip link show eth0 | grep ether | awk '{print $2}'" - proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (mac, err) = proc.communicate() + if err: + return None + mac = mac.strip() # Align last byte of MAC if necessary