Repository: sonic-net/sonic-mgmt

Issue:
Investigate backend T0 nighty failure during restart ptf
Latest run failed with the following error. 

TASK [vm_set : Setup vlan port for vlan tunnel] ********************************
Wednesday 13 October 2021  12:17:07 +0000 (0:00:00.098)       0:00:22.391 ***** 
fatal: [STR2-ACS-SERV-18]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.64.246.97 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/azure/.ansible/tmp/ansible-tmp-1634127427.08-60041-68522534642110/AnsiballZ_vlan_port.py\", line 114, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/azure/.ansible/tmp/ansible-tmp-1634127427.08-60041-68522534642110/AnsiballZ_vlan_port.py\", line 106, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/azure/.ansible/tmp/ansible-tmp-1634127427.08-60041-68522534642110/AnsiballZ_vlan_port.py\", line 49, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_vlan_port_payload_apPh5r/__main__.py\", line 151, in <module>\r\n  File \"/tmp/ansible_vlan_port_payload_apPh5r/__main__.py\", line 139, in main\r\n  File \"/tmp/ansible_vlan_port_payload_apPh5r/__main__.py\", line 65, in create_vlan_ports\r\n  File \"/tmp/ansible_vlan_port_payload_apPh5r/__main__.py\", line 50, in create_vlan_port\r\n  File \"/tmp/ansible_vlan_port_payload_apPh5r/__main__.py\", line 113, in cmd\r\nException: ret_code=3, error message=ERROR: trying to add VLAN #2020 to IF -:enp59s0f1:-  error: File exists\r\n. cmd=vconfig add enp59s0f1 2020\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}



Discussion:

Resolving patch:
diff --git a/ansible/roles/vm_set/library/vlan_port.py b/ansible/roles/vm_set/library/vlan_port.py
--- a/ansible/roles/vm_set/library/vlan_port.py
+++ b/ansible/roles/vm_set/library/vlan_port.py
@@ -47,6 +47,7 @@ def up_external_port(self):
     def create_vlan_port(self, port, vlan_id):
         vlan_port = "%s.%d" % (port, vlan_id)
         if vlan_port not in self.host_ifaces:
+            VlanPort.cmd('vconfig rem %s' % vlan_port, True)
             VlanPort.cmd('vconfig add %s %d' % (port, vlan_id))
 
         VlanPort.iface_up(vlan_port)
@@ -101,7 +102,7 @@ def iface_updown(iface_name, state, pid):
             return VlanPort.cmd('nsenter -t %s -n ip link set %s %s' % (pid, iface_name, state))
 
     @staticmethod
-    def cmd(cmdline):
+    def cmd(cmdline, ignore_error=False):
         with open(CMD_DEBUG_FNAME, 'a') as fp:
             pprint("CMD: %s" % cmdline, fp)
         cmd = cmdline.split(' ')
@@ -109,11 +110,14 @@ def cmd(cmdline):
         stdout, stderr = process.communicate()
         ret_code = process.returncode
 
-        if ret_code != 0:
+        if ret_code != 0 and not ignore_error:
             raise Exception("ret_code=%d, error message=%s. cmd=%s" % (ret_code, stderr, cmdline))
 
         with open(CMD_DEBUG_FNAME, 'a') as fp:
-            pprint("OUTPUT: %s" % stdout, fp)
+            if ret_code == 0:
+                pprint("OUTPUT: %s" % stdout, fp)
+            else:
+                pprint("ERR: %s" % stderr, fp)
 
         return stdout.decode('utf-8')
 


Test patch: