From d27134787a465bab5e2839bfd259de9662d04638 Mon Sep 17 00:00:00 2001 From: Yurii Lisovskyi Date: Wed, 13 Sep 2023 16:21:00 +0300 Subject: [PATCH 1/3] Remove unnecessary adding BPs to default VLAN on init Signed-off-by: Yurii Lisovskyi --- common/sai_npu.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/sai_npu.py b/common/sai_npu.py index 5a380aeb..761bb241 100644 --- a/common/sai_npu.py +++ b/common/sai_npu.py @@ -70,13 +70,12 @@ def init(self, attr): assert len(self.dot1q_bp_oids) > 0 assert self.dot1q_bp_oids[0].startswith("oid:") - if self.sku_config is None: - # The ports will not be re-created. - # Make sure the bridge ports are added into the default VLAN. - for bp_oid in self.dot1q_bp_oids: - vlan_mbr_oid = self.get_vlan_member(self.default_vlan_oid, bp_oid) - if vlan_mbr_oid == None: - self.create_vlan_member(self.default_vlan_oid, bp_oid, "SAI_VLAN_TAGGING_MODE_UNTAGGED") + # The ports will not be re-created. + # Make sure the bridge ports are added into the default VLAN. + for bp_oid in self.dot1q_bp_oids: + vlan_mbr_oid = self.get_vlan_member(self.default_vlan_oid, bp_oid) + if vlan_mbr_oid == None and self.sku_config is None: + self.create_vlan_member(self.default_vlan_oid, bp_oid, "SAI_VLAN_TAGGING_MODE_UNTAGGED") # Update SKU if self.sku_config is not None: @@ -207,7 +206,8 @@ def set_sku_mode(self, sku): # Remove existing ports num_ports = len(self.dot1q_bp_oids) for idx in range(num_ports): - self.remove_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]) + if self.get_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]): + self.remove_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]) self.remove(self.dot1q_bp_oids[idx]) oid = self.get(self.port_oids[idx], ["SAI_PORT_ATTR_PORT_SERDES_ID"]).oid() if oid != "oid:0x0": From 598adf14fbbd99081b0adf95013bd75f47a8ed3e Mon Sep 17 00:00:00 2001 From: Yurii Lisovskyi Date: Fri, 15 Sep 2023 16:31:10 +0300 Subject: [PATCH 2/3] fixes according to comments Signed-off-by: Yurii Lisovskyi --- common/sai_npu.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/sai_npu.py b/common/sai_npu.py index 761bb241..a03ced00 100644 --- a/common/sai_npu.py +++ b/common/sai_npu.py @@ -70,12 +70,13 @@ def init(self, attr): assert len(self.dot1q_bp_oids) > 0 assert self.dot1q_bp_oids[0].startswith("oid:") - # The ports will not be re-created. - # Make sure the bridge ports are added into the default VLAN. - for bp_oid in self.dot1q_bp_oids: - vlan_mbr_oid = self.get_vlan_member(self.default_vlan_oid, bp_oid) - if vlan_mbr_oid == None and self.sku_config is None: - self.create_vlan_member(self.default_vlan_oid, bp_oid, "SAI_VLAN_TAGGING_MODE_UNTAGGED") + if self.sku_config is None: + # The ports will not be re-created. + # Make sure the bridge ports are added into the default VLAN. + for bp_oid in self.dot1q_bp_oids: + vlan_mbr_oid = self.get_vlan_member(self.default_vlan_oid, bp_oid) + if vlan_mbr_oid == None: + self.create_vlan_member(self.default_vlan_oid, bp_oid, "SAI_VLAN_TAGGING_MODE_UNTAGGED") # Update SKU if self.sku_config is not None: @@ -206,11 +207,12 @@ def set_sku_mode(self, sku): # Remove existing ports num_ports = len(self.dot1q_bp_oids) for idx in range(num_ports): - if self.get_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]): - self.remove_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]) + oid = self.get_vlan_member(self.default_vlan_oid, self.dot1q_bp_oids[idx]) + if oid: + self.remove(oid) self.remove(self.dot1q_bp_oids[idx]) - oid = self.get(self.port_oids[idx], ["SAI_PORT_ATTR_PORT_SERDES_ID"]).oid() - if oid != "oid:0x0": + status, oid = self.get(self.port_oids[idx], ["SAI_PORT_ATTR_PORT_SERDES_ID"], do_assert=False).oid() + if status == "SAI_STATUS_SUCCESS" and oid != "oid:0x0": self.remove(oid) self.remove(self.port_oids[idx]) self.port_oids.clear() From be814694e736a9a9e99435231a57fb8ade1a8377 Mon Sep 17 00:00:00 2001 From: Yurii Lisovskyi Date: Fri, 15 Sep 2023 16:41:02 +0300 Subject: [PATCH 3/3] fixes according to CI Signed-off-by: Yurii Lisovskyi --- common/sai_npu.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/sai_npu.py b/common/sai_npu.py index a03ced00..9bd3245c 100644 --- a/common/sai_npu.py +++ b/common/sai_npu.py @@ -211,9 +211,10 @@ def set_sku_mode(self, sku): if oid: self.remove(oid) self.remove(self.dot1q_bp_oids[idx]) - status, oid = self.get(self.port_oids[idx], ["SAI_PORT_ATTR_PORT_SERDES_ID"], do_assert=False).oid() - if status == "SAI_STATUS_SUCCESS" and oid != "oid:0x0": - self.remove(oid) + status, data = self.get(self.port_oids[idx], ["SAI_PORT_ATTR_PORT_SERDES_ID"], do_assert=False) + serdes_oid = data.oid() + if status == "SAI_STATUS_SUCCESS" and serdes_oid != "oid:0x0": + self.remove(serdes_oid) self.remove(self.port_oids[idx]) self.port_oids.clear() self.dot1q_bp_oids.clear()