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
28 changes: 25 additions & 3 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ def __init__(self, ansible_adhoc, hostname, user, passwd, gather_facts=False):
'ansible_network_os':'eos', \
'ansible_user': user, \
'ansible_password': passwd, \
'ansible_ssh_user': user, \
'ansible_ssh_pass': passwd, \
'ansible_become_method': 'enable' }
self.host.options['variable_manager'].extra_vars.update(evars)

Expand All @@ -390,6 +392,10 @@ def check_intf_link_state(self, interface_name):
commands=['show interface %s' % interface_name])[self.hostname]
return 'Up' in show_int_result['stdout_lines'][0]

def command(self, cmd):
out = self.host.eos_command(commands=[cmd])
return out

class FanoutHost():
"""
@summary: Class for Fanout switch
Expand All @@ -400,6 +406,8 @@ class FanoutHost():
def __init__(self, ansible_adhoc, os, hostname, device_type, user, passwd):
self.hostname = hostname
self.type = device_type
self.host_to_fanout_port_map = {}
self.fanout_to_host_port_map = {}
if os == 'sonic':
self.os = os
self.host = SonicHost(ansible_adhoc, hostname)
Expand All @@ -415,13 +423,27 @@ def get_fanout_type(self):
return self.type

def shutdown(self, interface_name):
self.host.shutdown(interface_name)
return self.host.shutdown(interface_name)[self.hostname]

def no_shutdown(self, interface_name):
self.host.no_shutdown(interface_name)
return self.host.no_shutdown(interface_name)[self.hostname]

def command(self, cmd):
return self.host.command(cmd)[self.hostname]

def __str__(self):
return "{ os: '%s', hostname: '%s', device_type: '%s' }" % (self.os, self.hostname, self.type)

def __repr__(self):
return self.__str__()
return self.__str__()

def add_port_map(self, host_port, fanout_port):
"""
Fanout switch is build from the connection graph of the
DUT. So each fanout switch instance is relevant to the
DUT instance in the test. As result the port mapping is
unique from the DUT perspective. However, this function
need update when supporting multiple DUT
"""
self.host_to_fanout_port_map[host_port] = fanout_port
self.fanout_to_host_port_map[fanout_port] = host_port
48 changes: 21 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,22 @@ def fanouthosts(ansible_adhoc, conn_graph_facts, creds):
Shortcut fixture for getting Fanout hosts
"""

with open('../ansible/testbed-new.yaml') as stream:
testbed_doc = yaml.safe_load(stream)

fanout_types = ['FanoutLeaf', 'FanoutRoot']
devices = {}
for hostname in conn_graph_facts['device_info'].keys():
device_info = conn_graph_facts['device_info'][hostname]
if device_info['Type'] in fanout_types:
# Use EOS if the target OS type is unknown
os = 'eos' if 'os' not in testbed_doc['devices'][hostname] else testbed_doc['devices'][hostname]['os']
device_exists = False
try:
fanout_host = FanoutHost(ansible_adhoc, os, hostname, device_info['Type'], creds['fanout_admin_user'], creds['fanout_admin_password'])
device_exists = True
except:
logging.warning("Couldn't found the given host(%s) in inventory file" % hostname)

if device_exists:
# Index fanout host by both hostname and mgmt ip
devices[hostname] = fanout_host
devices[device_info['mgmtip']] = fanout_host

return devices
dev_conn = conn_graph_facts['device_conn']
fanout_hosts = {}
for dut_port in dev_conn.keys():
fanout_rec = dev_conn[dut_port]
fanout_host = fanout_rec['peerdevice']
fanout_port = fanout_rec['peerport']
if fanout_host in fanout_hosts.keys():
fanout = fanout_hosts[fanout_host]
else:
# FIXME: assuming all fanout hosts are EOS for now. Needs to figure out the os type and
# create fanout switch with the right type.
fanout = FanoutHost(ansible_adhoc, 'eos', fanout_host, 'FanoutLeaf', creds['fanout_admin_user'], creds['fanout_admin_password'])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We still need a way to figure this out...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a good catch. I added a comment for this PR.

fanout_hosts[fanout_host] = fanout
fanout.add_port_map(dut_port, fanout_port)

return fanout_hosts

@pytest.fixture(scope='session')
def eos():
Expand All @@ -238,10 +231,11 @@ def eos():
return eos


@pytest.fixture(scope="session")
def creds():
""" read and yield lab configuration """
files = glob.glob("../ansible/group_vars/lab/*.yml")
@pytest.fixture(scope="module")
def creds(duthost):
""" read credential information according to the dut inventory """
inv = duthost.host.options['inventory'].split('/')[-1]
files = glob.glob("../ansible/group_vars/{}/*.yml".format(inv))
files += glob.glob("../ansible/group_vars/all/*.yml")
creds = {}
for f in files:
Expand Down