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

[tests/common/devices] Add FanoutHost #1532

Merged
merged 3 commits into from
Apr 9, 2020
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
50 changes: 50 additions & 0 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,53 @@ def __init__(self, ansible_adhoc, hostname, user, passwd, gather_facts=False):
'ansible_password': passwd, \
'ansible_become_method': 'enable' }
self.host.options['variable_manager'].extra_vars.update(evars)

def shutdown(self, interface_name):
Blueve marked this conversation as resolved.
Show resolved Hide resolved
out = self.host.eos_config(
lines=['shutdown'],
parents='interface %s' % interface_name)
logging.info('Shut interface [%s]' % interface_name)
return out

def no_shutdown(self, interface_name):
out = self.host.eos_config(
lines=['no shutdown'],
parents='interface %s' % interface_name)
logging.info('No shut interface [%s]' % interface_name)
return out

class FanoutHost():
"""
@summary: Class for Fanout switch

For running ansible module on the Fanout switch
"""

def __init__(self, ansible_adhoc, os, hostname, device_type, user, passwd):
self.hostname = hostname
self.type = device_type
if os == 'sonic':
self.os = os
self.host = SonicHost(ansible_adhoc, hostname)
else:
# Use eos host if the os type is unknown
Blueve marked this conversation as resolved.
Show resolved Hide resolved
self.os = 'eos'
self.host = EosHost(ansible_adhoc, hostname, user, passwd)

def get_fanout_os(self):
return self.os

def get_fanout_type(self):
return self.type

def shutdown(self, interface_name):
self.host.shutdown(interface_name)

def no_shutdown(self, interface_name):
self.host.no_shutdown(interface_name)

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

def __repr__(self):
return self.__str__()
35 changes: 33 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from ansible_host import AnsibleHost
from collections import defaultdict
from common.devices import SonicHost, Localhost, PTFHost, EosHost
from common.fixtures.conn_graph_facts import conn_graph_facts
from common.devices import SonicHost, Localhost, PTFHost, EosHost, FanoutHost

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -190,7 +191,7 @@ def ptfhost(testbed_devices):
@pytest.fixture(scope="module")
def nbrhosts(ansible_adhoc, testbed, creds):
"""
Shortcut fixture for getting PTF host
Shortcut fixture for getting VM host
"""

vm_base = int(testbed['vm_base'][2:])
Expand All @@ -199,6 +200,36 @@ def nbrhosts(ansible_adhoc, testbed, creds):
devices[k] = EosHost(ansible_adhoc, "VM%04d" % (vm_base + v['vm_offset']), creds['eos_login'], creds['eos_password'])
return devices

@pytest.fixture(scope="module")
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

@pytest.fixture(scope='session')
def eos():
""" read and yield eos configuration """
Expand Down