Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docker shell 2 #1262

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/roles/fanout/tasks/fanout_sonic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/sonic-common/tasks/lldp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions ansible/roles/sonic-common/tasks/sensors_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/sonic-common/tasks/snmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i snmp python
container_name: snmp
2 changes: 1 addition & 1 deletion ansible/roles/sonicv2/tasks/quagga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/sonicv2/tasks/teamd_interface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i teamd python
container_name: teamd
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/acltb_ranges_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions ansible/roles/test/tasks/bgp_entry_flap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions ansible/roles/test/tasks/copp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/dip_sip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/ecn_wred.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ansible/roles/test/tasks/interface_up_down.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/lag_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/test/tasks/lagall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
12 changes: 6 additions & 6 deletions ansible/roles/test/tasks/qos_sai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}}
Expand All @@ -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
31 changes: 12 additions & 19 deletions ansible/shell_plugins/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand Down Expand Up @@ -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 "
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down