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

[ansible][docker.py]Replace docker shell with connection plugin #1269

Merged
Merged
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
8 changes: 5 additions & 3 deletions ansible/roles/fanout/tasks/fanout_sonic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
dest=/etc/sonic/vlan.json
become: yes

- include_tasks: add_container_to_inventory.yml
vars:
container_name: swss

- name: disable all copp rules
copy: content='[]'
dest=/etc/swss/config.d/00-copp.config.json
become: yes
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i swss python
delegate_to: "{{ ansible_host }}_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
8 changes: 5 additions & 3 deletions ansible/roles/sonic-common/tasks/lldp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
docker_volumes:
- /etc/sonic/:/etc/sonic/:ro

- include_tasks: add_container_to_inventory.yml
vars:
container_name: lldp

- block:
- name: Setup LLDPD Daemon Config File
become: true
Expand All @@ -43,9 +47,7 @@
# Force handler flush to trigger daemon restarts
- meta: flush_handlers

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i lldp python
delegate_to: "{{ ansible_host }}_lldp"

- name: Copy lldpctl helper script
become: true
Expand Down
11 changes: 4 additions & 7 deletions ansible/roles/sonic-common/tasks/sensors_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
shell: show platform summary | grep Platform | awk '{print $2}'
register: platform

- set_fact:
ansible_python_interpreter: "docker exec -i {{ pmon_ps.stdout }} python"
- include_tasks: add_container_to_inventory.yml
vars:
container_name: "{{ pmon_ps.stdout }}"

- name: Gather sensors
sensors_facts: checks={{ sensors_checks[platform.stdout] }}
vars:
ansible_shell_type: docker

- set_fact:
ansible_python_interpreter: "/usr/bin/python"
delegate_to: "{{ ansible_host }}_{{ pmon_ps.stdout }}"

- name: Output of sensors information
debug: var=vars['sensors']
Expand Down
8 changes: 5 additions & 3 deletions ansible/roles/sonic-common/tasks/snmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
delegate_to: localhost
register: snmp_remap

- include_tasks: add_container_to_inventory.yml
vars:
container_name: snmp

- block:
- name: Check version of snmpd
shell: dpkg-query -W --showformat='${Version}' snmpd
Expand Down Expand Up @@ -108,6 +112,4 @@
# Force handler flush to trigger daemon restarts
- meta: flush_handlers

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i snmp python
delegate_to: "{{ ansible_host }}_snmp"
8 changes: 5 additions & 3 deletions ansible/roles/sonicv2/tasks/quagga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
docker_volumes_from:
- database

- include_tasks: add_container_to_inventory.yml
vars:
container_name: bgp

- block:
- name: Copy Device Specific Quagga Zebra Configuration File.
become: true
Expand Down Expand Up @@ -78,9 +82,7 @@
- isolate
- unisolate

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i bgp python
delegate_to: "{{ ansible_host }}_bgp"

- name: Copy vtysh helper script
become: true
Expand Down
32 changes: 17 additions & 15 deletions ansible/roles/sonicv2/tasks/teamd_interface.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
- include_tasks: add_container_to_inventory.yml
vars:
container_name: teamd

- block:
- name: Ensure /etc/teamd folder exists
become: true
file: path=/etc/teamd
state=directory
- name: Ensure /etc/teamd folder exists
become: true
file: path=/etc/teamd
state=directory

- debug: msg={{ item }}
- debug: msg={{ item }}

- name: Copy teamd configuration file
become: true
template: src=teamd.j2
dest=/etc/teamd/{{ item['name'] }}.conf
owner=root
group=root
mode=644
- name: Copy teamd configuration file
become: true
template: src=teamd.j2
dest=/etc/teamd/{{ item['name'] }}.conf
owner=root
group=root
mode=644

vars:
msosyak marked this conversation as resolved.
Show resolved Hide resolved
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i teamd python
delegate_to: "{{ ansible_host }}_teamd"
9 changes: 6 additions & 3 deletions ansible/roles/test/tasks/acltb_ranges_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
# Outer block to execute laganalizer in always block
- block:
# Perform the test: generate and apply acl jsons

- include_tasks: add_container_to_inventory.yml
vars:
container_name: swss

- block:
- name: Copy JSON configs into docker filesystem
template: src={{ item }}.j2 dest=/tmp/{{ item }}.json
Expand All @@ -77,9 +82,7 @@
with_items:
- "{{ acltb_configs[::-1] }}"

vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i swss python
delegate_to: "{{ ansible_host }}_swss"

always:
- include_tasks: roles/test/files/tools/loganalyzer/loganalyzer_analyze.yml
Expand Down
26 changes: 26 additions & 0 deletions ansible/roles/test/tasks/add_container_to_inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- name: Add/update the public key in the "{{ lookup('env','HOME') + '/.ssh/known_hosts' }}"
delegate_to: localhost
known_hosts:
name: "{{ ansible_host }}"
key: "{{ lookup('pipe', 'ssh-keyscan ' + ansible_host) }}"
state: "present"

- name: Generate an OpenSSH keypair
delegate_to: localhost
openssh_keypair:
path: "{{ lookup('env','HOME') + '/.ssh/id_rsa' }}"
msosyak marked this conversation as resolved.
Show resolved Hide resolved
register: out

- name: Set authorized key
authorized_key:
user: "{{ ansible_ssh_user }}"
state: present
key: "{{ out.public_key }}"

- name: Add {{ container_name }} container to inventory
add_host:
name: "{{ ansible_host }}_{{ container_name }}"
ansible_connection: docker
ansible_host: "{{ container_name }}"
ansible_docker_extra_args: "-H=ssh://{{ ansible_ssh_user }}@{{ ansible_host }}"
ansible_user: root
24 changes: 9 additions & 15 deletions ansible/roles/test/tasks/bgp_entry_flap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
hwsku: "{{ acs_devices[name]['hwsku'] }}"
cred: "{{ switch_login[acs_devices[name]['hwsku']] }}"

- include_tasks: add_container_to_inventory.yml
vars:
container_name: sswsyncd

- name: Get ASIC tables
switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes
become: yes
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i sswsyncd python
delegate_to: "{{ ansible_host }}_sswsyncd"

- block:
- name: Assert the particular entry is in nexthopgroup table
Expand Down Expand Up @@ -44,9 +46,7 @@
- name: Update list of current nexthop group(s)
switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes
become: yes
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i sswsyncd python
delegate_to: "{{ ansible_host }}_sswsyncd"

- name: Poll for updated tables until peer is not in nexthop groups
switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes
Expand All @@ -56,9 +56,7 @@
retries: 6
delay: 10
with_items: "{{ nexthopgroup }}"
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i sswsyncd python
delegate_to: "{{ ansible_host }}_sswsyncd"

- name: Restart BGP session from neighbor
action: cisco template=bgp_neighbor_noshut.j2
Expand All @@ -73,9 +71,7 @@
- name: Update list of current nexthop group(s)
switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes
become: yes
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i sswsyncd python
delegate_to: "{{ ansible_host }}_sswsyncd"

- name: Poll for updated tables until peer is in nexthop groups
switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes
Expand All @@ -85,8 +81,6 @@
retries: 6
delay: 10
with_items: "{{ nexthopgroup }}"
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i sswsyncd python
delegate_to: "{{ ansible_host }}_sswsyncd"

when: "'T2' in name"
8 changes: 5 additions & 3 deletions ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
with_items: "{{ minigraph_bgp }}"
when: "item.name == vm_name and item.addr|ipv6"

- include_tasks: add_container_to_inventory.yml
vars:
container_name: lldp

- name: Gather information from LLDP
lldp:
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i lldp python
delegate_to: "{{ ansible_host }}_lldp"

- name: Get VM IP address.
set_fact:
Expand Down
31 changes: 13 additions & 18 deletions ansible/roles/test/tasks/copp.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
- include_tasks: add_container_to_inventory.yml
vars:
container_name: "{{ item }}"
with_items:
- "lldp"
- "syncd"

Copy link
Contributor

@qiluo-msft qiluo-msft Dec 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this part into add_container_to_inventory, add with_items for all containers? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can, but I do not see the reason for that. There are only two places where we add more than one container.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if we move every include_task: add_container_to_inventory into inside that file with all the known container names, we can keep other files clean, only include_tasks once.


In reply to: 356377776 [](ancestors = 356377776)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use it in all test cases, so I do not see the reason to implicitly add all containers to inventory.

- block:
- fail: msg="Please set ptf_host variable"
when: ptf_host is not defined

- name: Ensure LLDP Daemon stopped
become: yes
supervisorctl: state=stopped name={{ item }}
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i lldp python
delegate_to: "{{ ansible_host }}_lldp"
with_items:
- lldp-syncd
- lldpd
Expand Down Expand Up @@ -38,15 +43,11 @@

- name: Update ptf_nn_agent configuration inside dut
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
delegate_to: "{{ ansible_host }}_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
delegate_to: "{{ ansible_host }}_syncd"

- name: copy the test to ptf container
copy: src=roles/test/files/ptftests dest=/root
Expand Down Expand Up @@ -96,22 +97,16 @@

- name: Update ptf_nn_agent configuration inside dut
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
delegate_to: "{{ ansible_host }}_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
delegate_to: "{{ ansible_host }}_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
delegate_to: "{{ ansible_host }}_lldp"
with_items:
- lldpd
- lldp-syncd
8 changes: 5 additions & 3 deletions ansible/roles/test/tasks/dip_sip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
script: roles/test/files/helpers/change_mac.sh
delegate_to: "{{ ptf_host }}"

- include_tasks: add_container_to_inventory.yml
vars:
container_name: lldp

- name: "Gather information from LLDP"
lldp:
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i lldp python
delegate_to: "{{ ansible_host }}_lldp"

- name: "Copy tests to PTF"
copy: src=roles/test/files/ptftests dest=/root
Expand Down
17 changes: 9 additions & 8 deletions ansible/roles/test/tasks/ecn_wred.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
- set_fact:
red_min_threshold={{ wred_value.stdout }}

- block:
- name: Copy test files to DUT
copy: src={{ item }} dest={{ tmp_dir }}
with_fileglob:
- "{{ test_files_dir }}/*"
- include_tasks: add_container_to_inventory.yml
vars:
ansible_shell_type: docker
ansible_python_interpreter: docker exec -i database python
container_name: database

- name: Copy test files to DUT database
copy: src={{ item }} dest={{ tmp_dir }}
delegate_to: "{{ ansible_host }}_database"
with_fileglob:
- "{{ test_files_dir }}/*"

- block:
# Test case #3(MA): Check configuration applied
Expand All @@ -45,4 +46,4 @@
shell: ecnconfig -p AZURE_LOSSLESS -rmin {{ red_min_threshold }}
become: yes
register: ecn_restore
failed_when: ecn_restore.rc != 0
failed_when: ecn_restore.rc != 0
Loading