Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions ansible/group_vars/all/ceos.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ceos_image_filename: cEOS64-lab-4.23.2F.tar.xz
ceos_image_orig: ceosimage:4.23.2F
ceos_image: ceosimage:4.23.2F-1
ceos_image_filename: cEOS64-lab-4.25.5.1M.tar
ceos_image_orig: ceosimage:4.25.5.1M
ceos_image: ceosimage:4.25.5.1M-1
skip_ceos_image_downloading: false
2 changes: 1 addition & 1 deletion ansible/roles/eos/tasks/ceos_ensure_reachable.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- block:
- name: set time out threshold
set_fact:
timeout_threshold: 120
timeout_threshold: 240

- name: wait until container's mgmt-ip is reachable
wait_for:
Expand Down
45 changes: 43 additions & 2 deletions ansible/roles/test/files/ptftests/arista.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ def get_arista_prompt(self, first_prompt):
# match all modes - A#, A(config)#, A(config-if)#
return prompt.strip().replace('>', '.*#')

def exec_command(self, cmd):
"""
Execute single command without interaction
Args:
cmd (str): command, e.g. show version
Returns:
int: command execution status code
str: command return value
"""
stdin, stdout, stderr = self.conn.exec_command(cmd)
return stdout.channel.recv_exit_status(), stdout.read()

def exec_command_compatible(self, *cmds):
"""
Execute several equivalent commands:
return first success command returned value,
return last command returned value if all failed.
Used for compatible scenario, for example:
in EOS 4.20.15M lacp show command is 'show lacp neighbor', but in EOS 4.25.5.1M it is 'show lacp peer'
Args:
cmds (*str): command, e.g. 'show lacp neighbor', 'show lacp peer'
Returns:
str: command return value
"""
value = None
for cmd in cmds:
(code, value) = self.exec_command(cmd)
if code == 0:
break
return value


def do_cmd(self, cmd, prompt = None):
if prompt == None:
prompt = self.arista_prompt
Expand All @@ -91,8 +123,15 @@ def do_cmd(self, cmd, prompt = None):
self.shell.send(cmd + '\n')

input_buffer = ''
loop_times = 0
while re.search(prompt, input_buffer) is None:
input_buffer += self.shell.recv(16384)
loop_times += 1
# cEOS will not return a arista_prompt if you send lots of 'exit' to close the ssh connect(vEOS do will),
# then an endless loop emerges,
# so if input_buffer is merely an 'exit', we can break the loop immediately
if loop_times > 10 and input_buffer.replace('\n', '').replace('\r', '').strip().lower() == 'exit':
break

return input_buffer

Expand Down Expand Up @@ -135,7 +174,9 @@ def run(self):
cur_time = time.time()
info = {}
debug_info = {}
lacp_output = self.do_cmd('show lacp neighbor')
# 'show lacp neighbor' command is deprecated by 'show lacp peer'
# execute both of them, get the success returned one as lacp_output
lacp_output = self.exec_command_compatible('show lacp neighbor', 'show lacp peer')
info['lacp'] = self.parse_lacp(lacp_output)
bgp_neig_output = self.do_cmd('show ip bgp neighbors')
info['bgp_neig'] = self.parse_bgp_neighbor(bgp_neig_output)
Expand Down Expand Up @@ -170,7 +211,7 @@ def run(self):
samples[cur_time] = sample
if self.DEBUG:
debug_data[cur_time] = {
'show lacp neighbor' : lacp_output,
'show lacp neighbor/peer' : lacp_output,
'show ip bgp neighbors' : bgp_neig_output,
'show ip route bgp' : bgp_route_v4_output,
'show ipv6 route bgp' : bgp_route_v6_output,
Expand Down