From 4f265b6fda34fd523719903458f20a7f4f8aa7d4 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Mon, 13 Jul 2020 08:27:41 +0000 Subject: [PATCH] Use the creds fixture to get username and password The original code uses secrets['secret-group-vars'] to get username and password of DUT. This is not the standard way for getting credentials. This PR uses the `creds` fixture to get DUT username and password. Signed-off-by: Xin Wang --- tests/arp/test_wr_arp.py | 10 +++------- tests/common/fixtures/advanced_reboot.py | 20 +++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index b38a0dcac99..fe0f91722f0 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -170,7 +170,7 @@ def removePtfhostIp(self, ptfhost): ptfhost.script('./scripts/remove_ip.sh') @pytest.fixture(scope='class', autouse=True) - def prepareSshKeys(self, duthost, ptfhost): + def prepareSshKeys(self, duthost, ptfhost, creds): ''' Prepares testbed ssh keys by generating ssh key on ptf host and adding this key to known_hosts on duthost This class-scope fixture runs once before test start @@ -182,15 +182,11 @@ def prepareSshKeys(self, duthost, ptfhost): Returns: None ''' - hostVars = duthost.host.options['variable_manager']._hostvars[duthost.hostname] - invetory = hostVars['inventory_file'].split('/')[-1] - secrets = duthost.host.options['variable_manager']._hostvars[duthost.hostname]['secret_group_vars'] - - prepareTestbedSshKeys(duthost, ptfhost, secrets[invetory]['sonicadmin_user']) + prepareTestbedSshKeys(duthost, ptfhost, creds['sonicadmin_user']) def testWrArp(self, request, duthost, ptfhost): ''' - Control Plane Assistent test for Warm-Reboot. + Control Plane Assistant test for Warm-Reboot. The test first start Ferret server, implemented in Python. Then initiate Warm-Reboot procedure. While the host in Warm-Reboot test continuously sending ARP request to the Vlan member ports and expect to receive ARP diff --git a/tests/common/fixtures/advanced_reboot.py b/tests/common/fixtures/advanced_reboot.py index 99e9900d0e4..8d4ce60f000 100644 --- a/tests/common/fixtures/advanced_reboot.py +++ b/tests/common/fixtures/advanced_reboot.py @@ -21,13 +21,13 @@ class AdvancedReboot: ''' AdvancedReboot is used to perform reboot dut while running preboot/inboot operations - Thed class collects information about the current testbed. This information is used by test cases to build + This class collects information about the current testbed. This information is used by test cases to build inboot/preboot list. The class transfers number of configuration files to the dut/ptf in preparation for reboot test. Test cases can trigger test start utilizing runRebootTestcase API. ''' - def __init__(self, request, duthost, ptfhost, localhost, testbed, **kwargs): + def __init__(self, request, duthost, ptfhost, localhost, testbed, creds, **kwargs): ''' - Class contructor. + Class constructor. @param request: pytest request object @param duthost: AnsibleHost instance of DUT @param ptfhost: PTFHost for interacting with PTF through ansible @@ -44,6 +44,7 @@ def __init__(self, request, duthost, ptfhost, localhost, testbed, **kwargs): self.ptfhost = ptfhost self.localhost = localhost self.testbed = testbed + self.creds = creds self.__dict__.update(kwargs) self.__extractTestParam() self.rebootData = {} @@ -121,11 +122,8 @@ def __buildTestbedData(self): self.rebootData['vlan_ip_range'] = self.mgFacts['minigraph_vlan_interfaces'][0]['subnet'] self.rebootData['dut_vlan_ip'] = self.mgFacts['minigraph_vlan_interfaces'][0]['addr'] - hostVars = self.duthost.host.options['variable_manager']._hostvars[self.duthost.hostname] - invetory = hostVars['inventory_file'].split('/')[-1] - secrets = hostVars['secret_group_vars'] - self.rebootData['dut_username'] = secrets[invetory]['sonicadmin_user'] - self.rebootData['dut_password'] = secrets[invetory]['sonicadmin_password'] + self.rebootData['dut_username'] = creds['sonicadmin_user'] + self.rebootData['dut_password'] = creds['sonicadmin_password'] # Change network of the dest IP addresses (used by VM servers) to be different from Vlan network prefixLen = self.mgFacts['minigraph_vlan_interfaces'][0]['prefixlen'] - 3 @@ -449,7 +447,7 @@ def __runPtfRunner(self, rebootOper=None): def __restorePrevImage(self): ''' - Resotre previous image and reboot DUT + Restore previous image and reboot DUT ''' currentImage = self.duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout'] if currentImage != self.currentImage: @@ -481,7 +479,7 @@ def tearDown(self): self.__restorePrevImage() @pytest.fixture -def get_advanced_reboot(request, duthost, ptfhost, localhost, testbed): +def get_advanced_reboot(request, duthost, ptfhost, localhost, testbed, creds): ''' Pytest test fixture that provides access to AdvancedReboot test fixture @param request: pytest request object @@ -497,7 +495,7 @@ def get_advanced_reboot(**kwargs): API that returns instances of AdvancedReboot class ''' assert len(instances) == 0, "Only one instance of reboot data is allowed" - advancedReboot = AdvancedReboot(request, duthost, ptfhost, localhost, testbed, **kwargs) + advancedReboot = AdvancedReboot(request, duthost, ptfhost, localhost, testbed, creds, **kwargs) instances.append(advancedReboot) return advancedReboot