Skip to content
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
12 changes: 12 additions & 0 deletions ansible/library/show_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self):
argument_spec=dict(
command=dict(required=True, type='str'),
interfaces=dict(required=False, type='list', default=None),
up_ports=dict(type='raw', default={}),
),
supports_check_mode=False)
self.m_args = self.module.params
Expand Down Expand Up @@ -150,6 +151,17 @@ def collect_interface_status(self):
if rc != 0:
self.module.fail_json(msg="Command failed rc = %d, out = %s, err = %s" % (rc, self.out, err))

if 'up_ports' in self.m_args:
down_ports = []
up_ports = self.m_args['up_ports']
for name in up_ports:
try:
if self.int_status[name]['oper_state'] != 'up':
down_ports += [name]
except:
down_ports += [name]
self.facts['ansible_interface_link_down_ports'] = down_ports

return

def collect_interface_counter(self):
Expand Down
9 changes: 9 additions & 0 deletions ansible/roles/test/tasks/port_toggle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
shell: PORTS="{{minigraph_ports.keys() | join(' ')}}"; for port in $PORTS; do config interface shutdown $port; done
become: yes

- name: wait 20 seconds for ports to down
pause: seconds=20

- name: Get interface facts
interface_facts: up_ports={{minigraph_ports}}

- name: Verify interfaces are all down
assert: { that: "{{ ansible_interface_link_down_ports | length }} == {{ minigraph_ports | length }}" }

- name: Get interface status from show interface status
show_interface: up_ports={{minigraph_ports}} command=status

- name: Verify interfaces with command output
assert: { that: "{{ ansible_interface_link_down_ports | length }} == {{ minigraph_ports | length }}" }

- block:
- name: build shell command string
debug: msg="PORTS={{minigraph_ports.keys() | join(' ')}}; for port in $PORTS; do config interface startup $port; done"
Expand Down