def __init__(self, ansible_adhoc, hostname, user, passwd, gather_facts=False): AnsibleHostBase.__init__(self, ansible_adhoc, hostname, connection="network_cli") evars = { 'ansible_connection': 'network_cli', 'ansible_network_os': 'onyx', '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) self.localhost = ansible_adhoc(inventory='localhost', connection='local', host_pattern="localhost")["localhost"] self.fanout_helper = FanoutOnyxDropCounter(self)
def __init__(self, ansible_adhoc, hostname, eos_user, eos_passwd, shell_user=None, shell_passwd=None, gather_facts=False): '''Initialize an object for interacting with EoS type device using ansible modules Args: ansible_adhoc (): The pytest-ansible fixture hostname (string): hostname of the EOS device eos_user (string): Username for accessing the EOS CLI interface eos_passwd (string): Password for the eos_user shell_user (string, optional): Username for accessing the Linux shell CLI interface. Defaults to None. shell_passwd (string, optional): Password for the shell_user. Defaults to None. gather_facts (bool, optional): Whether to gather some basic facts. Defaults to False. ''' self.eos_user = eos_user self.eos_passwd = eos_passwd self.shell_user = shell_user self.shell_passwd = shell_passwd AnsibleHostBase.__init__(self, ansible_adhoc, hostname) self.localhost = ansible_adhoc(inventory='localhost', connection='local', host_pattern="localhost")["localhost"]
def setup_config_mode(ansible_adhoc, duthosts, enum_rand_one_per_hwsku_frontend_hostname, request): """ Creates a guest user and configures the interface naming mode Args: ansible_adhoc: Fixture provided by the pytest-ansible package duthost: AnsibleHost instance for DUT request: request parameters for setup_config_mode fixture Yields: dutHostGuest: AnsibleHost instance for DUT with user as 'guest' mode: Interface naming mode to be configured ifmode: Current interface naming mode present in the DUT """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] mode = request.param logger.info('Creating a guest user') duthost.user(name='guest', groups='sudo', state='present', shell='/bin/bash') duthost.shell('echo guest:guest | sudo chpasswd') logger.info( 'Configuring the interface naming mode as {} for the guest user'. format(mode)) dutHostGuest = AnsibleHostBase(ansible_adhoc, duthost.hostname, become_user='******') dutHostGuest.shell('sudo config interface_naming_mode {}'.format(mode)) ifmode = dutHostGuest.shell( 'cat /home/guest/.bashrc | grep SONIC_CLI_IFACE_MODE')['stdout'].split( '=')[-1] naming_mode = dutHostGuest.shell( 'SONIC_CLI_IFACE_MODE={} show interfaces naming_mode'.format( ifmode))['stdout'] # If the correct mode is not set in .bashrc, all test cases will fail. # So return Error from this fixture itself. if (ifmode != mode) or (naming_mode != mode): logger.info('Removing the created guest user') duthost.user(name='guest', groups='sudo', state='absent', shell='/bin/bash', remove='yes') pytest.fail( 'Interface naming mode in .bashrc "{}", returned by show interfaces naming_mode "{}" does not the match the configured naming mode "{}"' .format(ifmode, naming_mode, mode)) yield dutHostGuest, mode, ifmode logger.info('Removing the created guest user') duthost.user(name='guest', groups='sudo', state='absent', shell='/bin/bash', remove='yes')
def __init__(self, ansible_adhoc, hostname, duthost, tbinfo): self.duthost = duthost self.tbinfo = tbinfo AnsibleHostBase.__init__(self, ansible_adhoc, hostname)
def __init__(self, ansible_adhoc): AnsibleHostBase.__init__(self, ansible_adhoc, "localhost")
def __init__(self, ansible_adhoc, hostname): AnsibleHostBase.__init__(self, ansible_adhoc, hostname)