From 6e04c00c8e4685d82cda7c07b334b4df0bf67e7b Mon Sep 17 00:00:00 2001 From: Myron Sosyak Date: Thu, 5 Dec 2019 05:42:43 -0800 Subject: [PATCH 1/2] Fix docker plugin 2 --- ansible/roles/test/tasks/ecn_wred.yml | 2 +- ansible/shell_plugins/docker.py | 31 +++++++++++---------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/ansible/roles/test/tasks/ecn_wred.yml b/ansible/roles/test/tasks/ecn_wred.yml index c7e1cdaf68..15e3f98439 100644 --- a/ansible/roles/test/tasks/ecn_wred.yml +++ b/ansible/roles/test/tasks/ecn_wred.yml @@ -27,7 +27,7 @@ - "{{ test_files_dir }}/*" vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i database python + container_name: database - block: # Test case #3(MA): Check configuration applied diff --git a/ansible/shell_plugins/docker.py b/ansible/shell_plugins/docker.py index 022eed32c3..d4a1cf378a 100644 --- a/ansible/shell_plugins/docker.py +++ b/ansible/shell_plugins/docker.py @@ -8,6 +8,13 @@ version_added: historical description: - This module allows you to execute commands directly in docker on the remote host +options: + container_name: + description: + - Container name + required: yes + vars: + - name: container_name extends_documentation_fragment: - shell_common ''' @@ -41,12 +48,7 @@ def join_path(self, *args): return super(ShellModule, self).join_path(*args) def remove(self, path, recurse=False): - argv = self.get_option('ansible_python_interpreter').split() - assert(argv[0] == 'docker') - assert(argv[1] == 'exec') - opts, args = getopt.getopt(argv[2:], 'i') - self.container_name = args[0] - + self.container_name = self.get_option('container_name') remove_files_on_host_cmd = super(ShellModule, self).remove(path, recurse) cmd = remove_files_on_host_cmd + "; docker exec -i " @@ -58,18 +60,7 @@ def remove(self, path, recurse=False): return cmd def build_module_command(self, env_string, shebang, cmd, arg_path=None): - # assert(self.container_name) - argv = shlex.split(shebang.replace("#!", "")) - assert(argv[0] == 'docker') - assert(argv[1] == 'exec') - opts, args = getopt.getopt(argv[2:], 'i') - self.container_name = args[0] - - # Inject environment variable before python in the shebang string - assert(args[1].endswith('python')) - args[1] = 'env {0} {1}'.format(env_string, args[1]) - argv_env = argv[0:2] + [o for opt in opts for o in opt] + args - shebang_env = ' '.join(argv_env) + self.container_name = self.get_option('container_name') ## Note: Docker cp behavior ## DEST_PATH exists and is a directory @@ -79,7 +70,9 @@ def build_module_command(self, env_string, shebang, cmd, arg_path=None): pre = ''.join('docker exec {1} mkdir -p {0}; docker cp {0}/. {1}:{0}; ' .format(dtemp, self.container_name) for dtemp in self.dtemps) - return pre + super(ShellModule, self).build_module_command('', shebang_env, cmd, arg_path) + pre += "docker exec -i {} ".format(self.container_name) + + return pre + super(ShellModule, self).build_module_command('', shebang, cmd, arg_path) def checksum(self, path, python_interp): """ From feae863b65115d4cc107263af2726f5d22680266 Mon Sep 17 00:00:00 2001 From: Myron Sosyak Date: Thu, 5 Dec 2019 07:11:40 -0800 Subject: [PATCH 2/2] Replace ansible_python_interpreter with container_name Replace ansible_python_interpreter: docker exec -i with container_name: --- ansible/roles/fanout/tasks/fanout_sonic.yml | 2 +- ansible/roles/sonic-common/tasks/lldp.yml | 2 +- ansible/roles/sonic-common/tasks/sensors_check.yml | 7 +------ ansible/roles/sonic-common/tasks/snmp.yml | 2 +- ansible/roles/sonicv2/tasks/quagga.yml | 2 +- ansible/roles/sonicv2/tasks/teamd_interface.yml | 2 +- ansible/roles/test/tasks/acltb_ranges_test.yml | 2 +- ansible/roles/test/tasks/bgp_entry_flap.yml | 14 +++++++------- .../roles/test/tasks/bgp_gr_helper/get_vm_info.yml | 2 +- ansible/roles/test/tasks/copp.yml | 12 ++++++------ ansible/roles/test/tasks/dip_sip.yml | 2 +- ansible/roles/test/tasks/interface_up_down.yml | 6 +++--- ansible/roles/test/tasks/lag_2.yml | 2 +- ansible/roles/test/tasks/lagall.yml | 2 +- ansible/roles/test/tasks/qos_sai.yml | 12 ++++++------ 15 files changed, 33 insertions(+), 38 deletions(-) diff --git a/ansible/roles/fanout/tasks/fanout_sonic.yml b/ansible/roles/fanout/tasks/fanout_sonic.yml index 04a92835dc..ea3c65a75e 100644 --- a/ansible/roles/fanout/tasks/fanout_sonic.yml +++ b/ansible/roles/fanout/tasks/fanout_sonic.yml @@ -17,7 +17,7 @@ become: yes vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i swss python + container_name: swss - name: generate config_db.json shell: sonic-cfggen -H -j /etc/sonic/vlan.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json diff --git a/ansible/roles/sonic-common/tasks/lldp.yml b/ansible/roles/sonic-common/tasks/lldp.yml index 6b690cab3e..fc0e56680a 100644 --- a/ansible/roles/sonic-common/tasks/lldp.yml +++ b/ansible/roles/sonic-common/tasks/lldp.yml @@ -45,7 +45,7 @@ vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: Copy lldpctl helper script become: true diff --git a/ansible/roles/sonic-common/tasks/sensors_check.yml b/ansible/roles/sonic-common/tasks/sensors_check.yml index 1a915d9e38..66c7008e5c 100644 --- a/ansible/roles/sonic-common/tasks/sensors_check.yml +++ b/ansible/roles/sonic-common/tasks/sensors_check.yml @@ -6,16 +6,11 @@ shell: show platform summary | grep Platform | awk '{print $2}' register: platform -- set_fact: - ansible_python_interpreter: "docker exec -i {{ pmon_ps.stdout }} python" - - name: Gather sensors sensors_facts: checks={{ sensors_checks[platform.stdout] }} vars: ansible_shell_type: docker - -- set_fact: - ansible_python_interpreter: "/usr/bin/python" + container_name: "{{ pmon_ps.stdout }}" - name: Output of sensors information debug: var=vars['sensors'] diff --git a/ansible/roles/sonic-common/tasks/snmp.yml b/ansible/roles/sonic-common/tasks/snmp.yml index 7384e3e8a5..4e218f9dfe 100644 --- a/ansible/roles/sonic-common/tasks/snmp.yml +++ b/ansible/roles/sonic-common/tasks/snmp.yml @@ -110,4 +110,4 @@ vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i snmp python + container_name: snmp diff --git a/ansible/roles/sonicv2/tasks/quagga.yml b/ansible/roles/sonicv2/tasks/quagga.yml index 290cb8a835..76486f4d58 100644 --- a/ansible/roles/sonicv2/tasks/quagga.yml +++ b/ansible/roles/sonicv2/tasks/quagga.yml @@ -80,7 +80,7 @@ vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i bgp python + container_name: bgp - name: Copy vtysh helper script become: true diff --git a/ansible/roles/sonicv2/tasks/teamd_interface.yml b/ansible/roles/sonicv2/tasks/teamd_interface.yml index feeda01322..607bd97873 100644 --- a/ansible/roles/sonicv2/tasks/teamd_interface.yml +++ b/ansible/roles/sonicv2/tasks/teamd_interface.yml @@ -16,4 +16,4 @@ vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i teamd python + container_name: teamd diff --git a/ansible/roles/test/tasks/acltb_ranges_test.yml b/ansible/roles/test/tasks/acltb_ranges_test.yml index 14773cc679..87cbb21717 100644 --- a/ansible/roles/test/tasks/acltb_ranges_test.yml +++ b/ansible/roles/test/tasks/acltb_ranges_test.yml @@ -79,7 +79,7 @@ vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i swss python + container_name: swss always: - include_tasks: roles/test/files/tools/loganalyzer/loganalyzer_analyze.yml diff --git a/ansible/roles/test/tasks/bgp_entry_flap.yml b/ansible/roles/test/tasks/bgp_entry_flap.yml index 4753cbe4e1..cb04b238d3 100644 --- a/ansible/roles/test/tasks/bgp_entry_flap.yml +++ b/ansible/roles/test/tasks/bgp_entry_flap.yml @@ -15,11 +15,11 @@ become: yes vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i sswsyncd python + container_name: sswsyncd - block: - name: Assert the particular entry is in nexthopgroup table - assert: + assert: that: nexthop[addr] in nexthopgroup[item] with_items: "{{ nexthopgroup }}" @@ -46,8 +46,8 @@ become: yes vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i sswsyncd python - + container_name: sswsyncd + - name: Poll for updated tables until peer is not in nexthop groups switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes become: yes @@ -58,7 +58,7 @@ with_items: "{{ nexthopgroup }}" vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i sswsyncd python + container_name: sswsyncd - name: Restart BGP session from neighbor action: cisco template=bgp_neighbor_noshut.j2 @@ -75,7 +75,7 @@ become: yes vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i sswsyncd python + container_name: sswsyncd - name: Poll for updated tables until peer is in nexthop groups switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes @@ -87,6 +87,6 @@ with_items: "{{ nexthopgroup }}" vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i sswsyncd python + container_name: sswsyncd when: "'T2' in name" diff --git a/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml b/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml index b0ba4af092..92f8c256c7 100644 --- a/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml +++ b/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml @@ -34,7 +34,7 @@ lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: Get VM IP address. set_fact: diff --git a/ansible/roles/test/tasks/copp.yml b/ansible/roles/test/tasks/copp.yml index a4902ffa1a..b03198218d 100644 --- a/ansible/roles/test/tasks/copp.yml +++ b/ansible/roles/test/tasks/copp.yml @@ -7,7 +7,7 @@ supervisorctl: state=stopped name={{ item }} vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp with_items: - lldp-syncd - lldpd @@ -40,13 +40,13 @@ template: src=ptf_nn_agent.conf.dut.j2 dest=/etc/supervisor/conf.d/ptf_nn_agent.conf vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd - name: Restart ptf_nn_agent inside dut supervisorctl: state=restarted name=ptf_nn_agent vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd - name: copy the test to ptf container copy: src=roles/test/files/ptftests dest=/root @@ -98,20 +98,20 @@ template: src=ptf_nn_agent.conf.dut.j2 dest=/etc/supervisor/conf.d/ptf_nn_agent.conf vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd - name: Restart ptf_nn_agent inside dut supervisorctl: state=restarted name=ptf_nn_agent vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd - name: Restore LLDP Daemon become: yes supervisorctl: state=started name={{ item }} vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp with_items: - lldpd - lldp-syncd diff --git a/ansible/roles/test/tasks/dip_sip.yml b/ansible/roles/test/tasks/dip_sip.yml index 90090d985f..c2f259ea30 100644 --- a/ansible/roles/test/tasks/dip_sip.yml +++ b/ansible/roles/test/tasks/dip_sip.yml @@ -24,7 +24,7 @@ lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: "Copy tests to PTF" copy: src=roles/test/files/ptftests dest=/root diff --git a/ansible/roles/test/tasks/interface_up_down.yml b/ansible/roles/test/tasks/interface_up_down.yml index 56dcb7ec69..af519b3f29 100644 --- a/ansible/roles/test/tasks/interface_up_down.yml +++ b/ansible/roles/test/tasks/interface_up_down.yml @@ -10,13 +10,13 @@ enabled=yes vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: Gather information from lldp lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: If underlay exists, use underlay to replace it. set_fact: @@ -49,7 +49,7 @@ lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: rearrange lldp received data structure for interface up down test interface_up_down_data_struct_facts: data="{{ lldp }}" diff --git a/ansible/roles/test/tasks/lag_2.yml b/ansible/roles/test/tasks/lag_2.yml index 7f79b4d60b..cf148bffe8 100644 --- a/ansible/roles/test/tasks/lag_2.yml +++ b/ansible/roles/test/tasks/lag_2.yml @@ -27,7 +27,7 @@ lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - name: gathering minigraph of the device configuration minigraph_facts: host={{ inventory_hostname }} diff --git a/ansible/roles/test/tasks/lagall.yml b/ansible/roles/test/tasks/lagall.yml index f8de92b51c..2e97cb0f1d 100644 --- a/ansible/roles/test/tasks/lagall.yml +++ b/ansible/roles/test/tasks/lagall.yml @@ -46,7 +46,7 @@ lldp: vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp - debug: msg: "{{ dut_lag_members }}" diff --git a/ansible/roles/test/tasks/qos_sai.yml b/ansible/roles/test/tasks/qos_sai.yml index cf10f9c57f..9b8d4f02d8 100644 --- a/ansible/roles/test/tasks/qos_sai.yml +++ b/ansible/roles/test/tasks/qos_sai.yml @@ -23,7 +23,7 @@ supervisorctl: state=stopped name={{item}} vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp with_items: - lldpd - lldp-syncd @@ -37,7 +37,7 @@ - Restart Quagga Daemon vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i bgp python + container_name: bgp - meta: flush_handlers @@ -49,7 +49,7 @@ shell: python /root/packets_aging.py disable vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd when: minigraph_hwsku is defined and minigraph_hwsku in mellanox_hwskus - name: copy ptf tests @@ -566,7 +566,7 @@ supervisorctl: state=started name={{item}} vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i lldp python + container_name: lldp with_items: - lldpd - lldp-syncd @@ -580,7 +580,7 @@ - Restart Quagga Daemon vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i bgp python + container_name: bgp python - name: Restore original watermark polling status shell: counterpoll watermark {{watermark_status.stdout}} @@ -596,7 +596,7 @@ shell: python /root/packets_aging.py enable vars: ansible_shell_type: docker - ansible_python_interpreter: docker exec -i syncd python + container_name: syncd when: minigraph_hwsku is defined and minigraph_hwsku in mellanox_hwskus - meta: flush_handlers