def store_structure(device, feature): # get feature and attributes [(ft, attr)] = feature.items() log.info( banner("Learning '{n}' feature with " "attribues {a} on device {d}".format(n=ft, a=attr, d=device))) # perform lookup per device lib = Lookup.from_device(device) # attach ops and conf lib.conf = getattr(lib, 'conf', conf) lib.ops = getattr(lib, 'ops', ops) # create the ops/conf instance try: obj = attrgetter(ft)(lib) except Exception: raise AttributeError('Cannot load %s for ' 'device %s.' % (ft, device.name)) # conf learn_config if issubclass(obj, ConfBase): ret = obj.learn_config(device=device, attributes=attr) ret = _to_dict(ret[0]) # delete the non-used objects for pcall to retrun ret.pop('__testbed__') ret.pop('devices') ret.pop('interfaces') remove_parent_from_conf_dict(ret['device_attr'][device.name]) elif issubclass(obj, OpsBase): ret = obj(device, attributes=attr) ret.learn() temp = AttrDict() temp.info = getattr(ret, 'info', {}) ret = temp ret_dict = {} ret_dict.setdefault('lts', {}).\ setdefault(ft, {}).setdefault(device.name, ret) # return the dictionary return ret_dict
def start_reporter(section, func, name=None): if not issubclass(type(section), Testcase): # If section, dont start return name = name if name else func.__name__ if name in name_mapping: name = name_mapping[name] func.uid = TestableId(name, parent=section) func.logfile = managed_handlers.tasklog.logfile func.source = AttrDict() func.source.name = __file__ func.source.location = func.__code__.co_firstlineno func.description = func.__doc__ func.result = Passed reporter.start_section(func)
class test_filetransferutils(unittest.TestCase): # Instantiate tesbed and device objects tb = Testbed(name='myTestbed') device = Device(testbed=tb, name='aDevice', os='junos') # Instantiate a filetransferutils instance for Junos device fu_device = FileUtils.from_device(device) # Add testbed servers for authentication device.testbed.servers = AttrDict(server_name=dict(username="******", password="******", address='1.1.1.1'), ) # Mock device output raw1 = ''' file copy golden_config ftp://[email protected]:/test/ Password for [email protected]: ftp://[email protected]:/test/golden_config 100% of 3040 B 11 MBps ''' outputs = {} outputs['file copy golden_config ftp://[email protected]:/test/']\ = raw1 def mapper(self, key, timeout=None, reply=None, prompt_recovery=False): return self.outputs[key] def test_copyfile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile(source='golden_config', destination='ftp://1.1.1.1:/test/', timeout_seconds='300', device=self.device)
class test_filetransferutils(unittest.TestCase): # Instantiate tesbed and device objects tb = Testbed(name='myTestbed') device = Device(testbed=tb, name='aDevice', os='iosxe') # Instantiate a filetransferutils instance for IOSXE device fu_device = FileUtils.from_device(device) # Add testbed servers for authentication device.testbed.servers = AttrDict(server_name=dict(username="******", password="******", address='1.1.1.1'), ) dir_output = [ 'flash:/nvram_config', 'flash:/.rollback_timer', 'flash:/memleak.tcl', 'flash:/bootloader_evt_handle.log', 'flash:/ISSUCleanGolden', 'flash:/gs_script', 'flash:/.prst_sync', 'flash:/nvram_config_bkup', 'flash:/tech_support', 'flash:/dc_profile_dir', 'flash:/RestoreTue_Mar_20_12_19_11_2018-Mar-20-11-20-09.900-0', 'flash:/vlan.dat', 'flash:/core', 'flash:/tools', 'flash:/CRDU', 'flash:/.dbpersist', 'flash:/RestoreTue_Mar_20_12_13_39_2018-Mar-20-11-14-38.106-0', 'flash:/iox', 'flash:/onep', 'flash:/boothelper.log', 'flash:/stby-vlan.dat', 'flash:/.installer' ] # Mock device output raw1 = ''' copy flash:/memleak.tcl ftp://1.1.1.1//auto/tftp-ssr/memleak.tcl Address or name of remote host [1.1.1.1]? Destination filename [/auto/tftp-ssr/memleak.tcl]? !! 104260 bytes copied in 0.396 secs (263283 bytes/sec) ''' raw2 = ''' Directory of flash:/ 69698 drwx 4096 Mar 20 2018 10:25:11 +00:00 .installer 69720 -rw- 2097152 Mar 20 2018 13:09:24 +00:00 nvram_config 69700 -rw- 90761 Mar 20 2018 10:25:27 +00:00 bootloader_evt_handle.log 69701 drwx 4096 Feb 1 2018 13:44:32 +00:00 core 15489 drwx 4096 Mar 20 2018 10:31:08 +00:00 .prst_sync 30977 drwx 4096 May 2 2016 07:58:53 +00:00 .rollback_timer 38722 drwx 4096 Mar 20 2018 10:25:43 +00:00 dc_profile_dir 69699 -rw- 76 Mar 20 2018 10:25:46 +00:00 boothelper.log 69705 -rw- 104260 Mar 20 2018 10:26:01 +00:00 memleak.tcl 69706 drwx 4096 May 2 2016 08:11:23 +00:00 onep 69714 drwx 4096 Aug 13 2016 08:55:12 +00:00 iox 69734 -rw- 3496 Mar 11 2018 17:40:26 +00:00 vlan.dat 69708 -rw- 617329255 Sep 27 2017 09:11:39 +00:00 ISSUCleanGolden 69709 drwx 4096 Aug 3 2016 08:07:47 +00:00 gs_script 69712 drwx 4096 Mar 19 2017 09:26:23 +00:00 tools 69719 drwx 4096 Feb 12 2018 11:20:01 +00:00 .dbpersist 69703 -rw- 2097152 Mar 20 2018 13:09:25 +00:00 nvram_config_bkup 69729 -rw- 3496 Feb 12 2018 12:51:01 +00:00 stby-vlan.dat 69735 -rw- 27145 Mar 20 2018 11:14:45 +00:00 RestoreTue_Mar_20_12_13_39_2018-Mar-20-11-14-38.106-0 69721 drwx 4096 Sep 25 2017 07:59:54 +00:00 CRDU 69727 drwx 4096 Oct 23 2017 13:40:11 +00:00 tech_support 69736 -rw- 27145 Mar 20 2018 11:20:16 +00:00 RestoreTue_Mar_20_12_19_11_2018-Mar-20-11-20-09.900-0 1621966848 bytes total (906104832 bytes free) ''' raw3 = ''' delete flash:memleak.tcl Delete filename [memleak.tcl]? Delete flash:/memleak.tcl? [confirm] ''' raw4 = ''' rename flash:memleak.tcl new_file.tcl Destination filename [new_file.tcl]? ''' raw5 = ''' show clock | redirect ftp://1.1.1.1//auto/tftp-ssr/show_clock Writing /auto/tftp-ssr/show_clock ''' raw6 = { 'futlinux.check_file.return_value': '', 'futlinux.deletefile.return_value': '' } raw7 = ''' copy running-config tftp://10.1.7.250//auto/tftp-ssr/test_config.py Address or name of remote host [10.1.7.250]? Destination filename [/auto/tftp-ssr/test_config.py]? !! 27092 bytes copied in 6.764 secs (4005 bytes/sec) ''' outputs = {} outputs['copy flash:/memleak.tcl ftp://1.1.1.1//auto/tftp-ssr/memleak.tcl']\ = raw1 outputs['dir'] = raw2 outputs['delete flash:memleak.tcl'] = raw3 outputs['rename flash:memleak.tcl new_file.tcl'] = raw4 outputs['show clock | redirect ftp://1.1.1.1//auto/tftp-ssr/show_clock'] = \ raw5 outputs['copy running-config tftp://10.1.7.250//auto/tftp-ssr/test_config.py'] = \ raw7 def mapper(self, key, timeout=None, reply=None, prompt_recovery=False): return self.outputs[key] def test_copyfile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile( source='flash:/memleak.tcl', destination='ftp://1.1.1.1//auto/tftp-ssr/memleak.tcl', timeout_seconds='300', device=self.device) def test_dir(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper directory_output = self.fu_device.dir(target='flash:', timeout_seconds=300, device=self.device) self.assertEqual(sorted(directory_output), sorted(self.dir_output)) def test_stat(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper file_details = self.fu_device.stat(target='flash:memleak.tcl', timeout_seconds=300, device=self.device) self.assertEqual(file_details['last_modified_date'], 'Mar 20 2018 10:26:01 +00:00') self.assertEqual(file_details['permissions'], '-rw-') self.assertEqual(file_details['index'], '69705') self.assertEqual(file_details['size'], '104260') def test_deletefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.deletefile(target='flash:memleak.tcl', timeout_seconds=300, device=self.device) def test_renamefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.renamefile(source='flash:memleak.tcl', destination='new_file.tcl', timeout_seconds=300, device=self.device) @patch( 'genie.libs.filetransferutils.plugins.fileutils.FileUtils.validateserver', return_value=raw6) def test_validateserver(self, raw6): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.validateserver( target='ftp://1.1.1.1//auto/tftp-ssr/show_clock', timeout_seconds=300, device=self.device) def test_copyconfiguration(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.copyconfiguration( source='running-config', destination='tftp://10.1.7.250//auto/tftp-ssr/test_config.py', timeout_seconds=300, device=self.device)
def add_device_from_nso_to_testbed(self, device, nso, username, password): """ This keyword adds the device ${device} which is present as device in NSO to the unicon testbed so you can interact with it using the unicon methods (like 'execute command "foo" on device "r1"). It can be used for dynamic environments, like when you add netsim devices as part of a test setup or when you work on an NFV project where NSO might instantiate devices as part of the service model and you want to perform some actions on those devices. As those devices' attributes (like ip address or connection protocol) is not known and therefore can't be defined in the testbed.yaml file, we provide this method. This function extracts some part of the NSO device configuration from NSO using cli (address, port, cli protocol) Prerequisites: a testbed must be loaded (use tesbed "testbed.yaml"), and a connection to NSO needs to be established (connect to device "nso") """ n = self.testbed.devices[nso] cli_style = n.state_machine.current_cli_style r = n.execute( 'show configuration devices device {} device-type cli protocol'. format(device), style='j') protocol = r.split()[1].split(';')[0] r = n.execute( 'show configuration devices device {} address'.format(device), style='j') address = r.split()[1].split(';')[0] r = n.execute( 'show configuration devices device {} port'.format(device), style='j') if re.match('^port', r): port = r.split()[1].split(';')[0] else: port = None r = n.execute( 'show configuration devices device {} device-type cli ned-id'. format(device), style='j') ned = r.split()[1].split(';')[0] # restore cli style to what was set before n.cli_style(cli_style) ned2os = { 'cisco-ios': 'ios', 'cisco-ios-xr': 'iosxr', } ned2type = { 'cisco-ios': 'router', 'cisco-ios-xr': 'router', } dev = topology.Device(device) try: dev.os = ned2os[ned] dev.type = ned2type[ned] except KeyError: print( "\nERROR: device ned {} not defined in ned2os/ned2type dictionary" .format(ned)) traceback.print_exc() raise RastaException dev.tacacs.username = username dev.passwords.tacacs = password dev.passwords.enable = password dev.passwords.line = password dev.connections.defaults = AttrDict() dev.connections.defaults['class'] = Unicon dev.connections.cli = AttrDict() #dev.connections.cli.protocol = protocol #dev.connections.cli.ip = "%s" % address #if port is not None: # dev.connections.cli.port = port dev.connections.cli.command = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " + username + "@" + str( address) + " -p " + str(port) self.testbed.add_device(dev)
class test_filetransferutils(unittest.TestCase): # Instantiate tesbed and device objects tb = Testbed(name='myTestbed') device = Device(testbed=tb, name='aDevice', os='iosxr') # Instantiate a filetransferutils instance for IOSXE device fu_device = FileUtils.from_device(device) # Add testbed servers for authentication device.testbed.servers = AttrDict( server_name = dict( username="******", password="******", address='1.1.1.1'), ) dir_output = ['disk0:/status_file', 'disk0:/clihistory', 'disk0:/cvac', 'disk0:/core', 'disk0:/envoke_log', 'disk0:/lost+found', 'disk0:/pnet_cfg.log', 'disk0:/oor_aware_process', 'disk0:/.python-history', 'disk0:/cvac.log', 'disk0:/nvgen_traces', 'disk0:/fake_config_2.tcl', 'disk0:/ztp', 'disk0:/config -> /misc/config', 'disk0:/memleak.tcl'] # Mock device output raw1 = ''' copy disk0:/memleak.tcl ftp://1.1.1.1//auto/tftp-ssr/memleak.tcl Address or name of remote host [1.1.1.1]? Destination filename [/auto/tftp-ssr/memleak.tcl]? !! 104260 bytes copied in 0.396 secs (263283 bytes/sec) ''' raw2 = ''' dir Directory of /misc/scratch 32 -rw-rw-rw- 1 824 Mar 7 06:29 cvac.log 43 -rwxr--r-- 1 0 Mar 22 08:58 fake_config_2.tcl 41 -rw-r--r-- 1 1985 Mar 12 14:35 status_file 13 -rw-r--r-- 1 1438 Mar 7 14:26 envoke_log 16 -rw-r--r-- 1 98 Mar 7 06:34 oor_aware_process 8178 drwxr-xr-x 2 4096 Mar 7 14:27 memleak.tcl 8177 drwx---r-x 2 4096 Mar 7 14:27 clihistory 15 lrwxrwxrwx 1 12 Mar 7 14:26 config -> /misc/config 12 drwxr-xr-x 2 4096 Mar 7 14:26 core 14 -rw-r--r-- 1 10429 Mar 7 14:26 pnet_cfg.log 11 drwx------ 2 16384 Mar 7 14:26 lost+found 8179 drwxr-xr-x 8 4096 Mar 7 07:01 ztp 42 -rw------- 1 0 Mar 20 11:08 .python-history 16354 drwxr-xr-x 2 4096 Mar 7 07:22 nvgen_traces 16353 drwxrwxrwx 3 4096 Mar 7 14:29 cvac 1012660 kbytes total (938376 kbytes free) ''' raw3 = ''' delete disk0:fake_config_2.tcl Delete disk0:fake_config_2.tcl[confirm] ''' raw4 = ''' show clock | redirect ftp://1.1.1.1//auto/tftp-ssr/show_clock Writing /auto/tftp-ssr/show_clock ''' raw5 = {'futlinux.check_file.return_value': '', 'futlinux.deletefile.return_value': ''} raw6 = ''' copy running-config ftp://10.1.6.242//auto/tftp-ssr/fake_config_2.tcl Host name or IP address (control-c to abort): [10.1.6.242;default]? Destination username: []?rcpuser Destination password: Destination file name (control-c to abort): [/auto/tftp-ssr/fake_config_2.tcl]? Building configuration. 349 lines built in 1 second [OK] ''' raw7 = ''' sftp running-config [email protected]:/home/virl vrf management Thu Oct 10 15:45:18.989 UTC Connecting to 172.16.1.250... Password: /misc/disk1/running-config Overwrite /home/virl/running-config on host 172.16.1.250, continu? [ yes/no]: yes Transferred 11332 Bytes 11332 bytes copied in 0 sec (251822)bytes/sec ''' outputs = {} outputs['copy disk0:/fake_config_2.tcl ' 'ftp://1.1.1.1//auto/tftp-ssr/fake_config_2.tcl'] = raw1 outputs['dir'] = raw2 outputs['delete disk0:fake_config.tcl'] = raw3 outputs['show clock | redirect ftp://1.1.1.1//auto/tftp-ssr/show_clock'] = \ raw4 outputs['copy running-config ftp://10.1.6.242//auto/tftp-ssr/fake_config_2.tcl'] = \ raw6 outputs['sftp running-config [email protected]:/home/virl'] = raw7 def mapper(self, key, timeout=None, reply= None, prompt_recovery=False): return self.outputs[key] def test_copyfile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile(source='disk0:/fake_config_2.tcl', destination='ftp://1.1.1.1//auto/tftp-ssr/fake_config_2.tcl', timeout_seconds='300', device=self.device) def test_copyfile_sftp(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile(source='running-config', destination='sftp://1.1.1.1//home/virl', device=self.device) def test_dir(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper directory_output = self.fu_device.dir(target='disk0:', timeout_seconds=300, device=self.device) self.assertEqual(sorted(directory_output), sorted(self.dir_output)) def test_stat(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper file_details = self.fu_device.stat(target='disk0:memleak.tcl', timeout_seconds=300, device=self.device) self.assertEqual(file_details['index'], '8178') self.assertEqual(file_details['date'], 'Mar 7 14:27') self.assertEqual(file_details['permission'], 'drwxr-xr-x') self.assertEqual(file_details['size'], '4096') def test_deletefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.deletefile(target='disk0:fake_config.tcl', timeout_seconds=300, device=self.device) def test_renamefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper with self.assertRaisesRegex( NotImplementedError, "The fileutils module genie.libs." "filetransferutils.plugins.iosxr.fileutils does not implement " "renamefile."): self.fu_device.renamefile(source='disk0:fake_config.tcl', destination='memleak.tcl', timeout_seconds=300, device=self.device) @patch('genie.libs.filetransferutils.plugins.fileutils.FileUtils.validateserver', return_value=raw5) def test_validateserver(self, raw5): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.validateserver( target='ftp://1.1.1.1//auto/tftp-ssr/show_clock', timeout_seconds=300, device=self.device) def test_copyconfiguration(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.copyconfiguration(source='running-config', destination='ftp://10.1.6.242//auto/tftp-ssr/fake_config_2.tcl', timeout_seconds=300, device=self.device)
class test_filetransferutils(unittest.TestCase): # Instantiate tesbed and device objects tb = Testbed(name='myTestbed') device = Device(testbed=tb, name='aDevice', os='nxos') # Instantiate a filetransferutils instance for NXOS device fu_device = FileUtils.from_device(device) # Add testbed servers for authentication device.testbed.servers = AttrDict(server_name=dict(username="******", password="******", address='1.1.1.1'), ) dir_output = [ 'bootflash:/ISSUCleanGolden.system.gbin', 'bootflash:/ISSUCleanGolden.cfg', 'bootflash:/platform-sdk.cmd', 'bootflash:/virt_strg_pool_bf_vdc_1/', 'bootflash:/virtual-instance/', 'bootflash:/virtual-instance.conf', 'bootflash:/.rpmstore/', 'bootflash:/.swtam/', 'bootflash:/scripts/' ] # Mock device output raw1 = ''' copy bootflash:/virtual-instance.conf ftp://10.1.0.213//auto/tftp-ssr/virtual-instance.conf vrf management Enter username: rcpuser Password: ***** Transfer of file Completed Successfully ***** Copy complete. ''' raw2 = ''' dir 4096 Jan 25 21:00:53 2017 .rpmstore/ 4096 Jan 25 21:01:08 2017 .swtam/ 390 Jan 25 21:36:20 2017 ISSUCleanGolden.cfg 752699904 Jan 25 21:36:26 2017 ISSUCleanGolden.system.gbin 0 Jan 25 21:35:55 2017 platform-sdk.cmd 4096 Jan 25 21:01:57 2017 scripts/ 4096 Jan 25 21:02:02 2017 virt_strg_pool_bf_vdc_1/ 4096 Jan 25 21:01:21 2017 virtual-instance/ 59 Jan 25 21:01:11 2017 virtual-instance.conf Usage for bootflash:// 1150812160 bytes used 2386407424 bytes free 3537219584 bytes total ''' raw3 = ''' delete bootflash:new_file.tcl Do you want to delete "/new_file.tcl" ? (yes/no/abort) [y] ''' raw4 = ''' move bootflash:mem_leak.tcl new_file.tcl ''' raw5 = ''' show clock > ftp://10.1.7.250//auto/tftp-ssr/show_clock vrf management Enter username: rcpuser Password: ***** Transfer of file Completed Successfully ***** ''' raw6 = { 'futlinux.check_file.return_value': '', 'futlinux.deletefile.return_value': '' } raw7 = ''' copy running-config tftp://10.1.7.250//auto/tftp-ssr/test_config.py vrf management Trying to connect to tftp server...... Connection to Server Established. [ ] 0.50KB[# ] 4.50KB[## ] 8.50KB[### ] 12.50KB TFTP put operation was successful Copy complete, now saving to disk (please wait)... Copy complete. ''' raw8 = ''' copy running-config sftp://1.1.1.1//home/virl vrf management Enter username: myuser The authenticity of host '1.1.1.1 (1.1.1.1)' can't be established. ECDSA key fingerprint is SHA256:Q37/fav3nPJT5Y+7IsgST4uN0c2tyToJiDF/gp+wItA. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '1.1.1.1' (ECDSA) to the list of known hosts. Outbound-ReKey for 1.1.1.1:22 Inbound-ReKey for 1.1.1.1:22 [email protected]'s password: Connected to 1.1.1.1. sftp> put /var/tmp/vsh/R3_nx-running-config /home/virl Uploading /var/tmp/vsh/R3_nx-running-config to /home/virl/R3_nx-running-config /var/tmp/vsh/R3_nx-running-config /var/tmp/vsh/R3_nx-running-config 100% 14KB 355.1KB/s 00:00 ''' raw9 = ''' copy bootflash:/virtual-instance.conf ftp://10.1.0.213//auto/tftp-ssr/virtual-instance.conf vrf management Enter username: rcpuser ftp: connect: No route to host ***** Transfer of file aborted, server not connected ***** Error during copy ***** Transfer of file aborted ***** ''' outputs = {} outputs['copy bootflash:/virtual-instance.conf ' 'ftp://10.1.0.213//auto/tftp-ssr/virtual-instance.conf vrf management']\ = raw1 outputs['dir'] = raw2 outputs['delete bootflash:new_file.tcl'] = raw3 outputs['move bootflash:mem_leak.tcl new_file.tcl'] = raw4 outputs[ 'show clock > ftp://1.1.1.1//auto/tftp-ssr/show_clock vrf management'] = raw5 outputs[ 'copy running-config tftp://10.1.7.250//auto/tftp-ssr/test_config.py vrf management'] = raw7 outputs[ 'copy running-config sftp://1.1.1.1//home/virl vrf management'] = raw8 outputs['copy bootflash:/virtual-instance.conf ' 'ftp://10.1.0.214//auto/tftp-ssr/virtual-instance.conf vrf management']\ = raw9 def mapper(self, key, timeout=None, reply=None, prompt_recovery=False): return self.outputs[key] def is_valid_ip_mapper(self, ip, device=None, vrf=None, cache_ip=None): return ip != '2.2.2.2' def test_copyfile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile( source='bootflash:/virtual-instance.conf', destination='ftp://10.1.0.213//auto/tftp-ssr/virtual-instance.conf', timeout_seconds='300', device=self.device) def test_copyfile_exception(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles with self.assertRaises(SubCommandFailure): self.fu_device.copyfile( source='bootflash:/virtual-instance.conf', destination= 'ftp://10.1.0.214//auto/tftp-ssr/virtual-instance.conf', timeout_seconds='300', device=self.device) def test_copyfile_sftp(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper # Call copyfiles self.fu_device.copyfile(source='running-config', destination='sftp://1.1.1.1//home/virl', vrf='management', device=self.device) def test_validate_and_update_url(self): self.fu_device.is_valid_ip = Mock() self.fu_device.is_valid_ip.side_effect = self.is_valid_ip_mapper # set multiple ip for the server self.device.testbed.servers.server_name['address'] = [ '2.2.2.2', '1.1.1.1' ] not_reachable_url = self.fu_device.validate_and_update_url( 'sftp://2.2.2.2//home/virl', device=self.device) reachable_url = self.fu_device.validate_and_update_url( 'sftp://1.1.1.1//home/virl', device=self.device) servername_url = self.fu_device.validate_and_update_url( 'sftp://server_name//home/virl', device=self.device) self.assertEqual(not_reachable_url, 'sftp://1.1.1.1//home/virl') self.assertEqual(reachable_url, 'sftp://1.1.1.1//home/virl') self.assertEqual(servername_url, 'sftp://1.1.1.1//home/virl') self.device.testbed.servers.server_name['address'] = '1.1.1.1' def test_dir(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper directory_output = self.fu_device.dir(target='bootflash:', timeout_seconds=300, device=self.device) self.assertEqual(sorted(directory_output), sorted(self.dir_output)) def test_stat(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper file_details = self.fu_device.stat( target='bootflash:virtual-instance.conf', timeout_seconds=300, device=self.device) self.assertEqual(file_details['time'], '21:01:11') self.assertEqual(file_details['date'], 'Jan 25 2017') self.assertEqual(file_details['size'], '59') def test_deletefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.deletefile(target='bootflash:new_file.tcl', timeout_seconds=300, device=self.device) def test_renamefile(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.renamefile(source='bootflash:mem_leak.tcl', destination='new_file.tcl', timeout_seconds=300, device=self.device) @patch( 'genie.libs.filetransferutils.plugins.fileutils.FileUtils.validateserver', return_value=raw6) def test_validateserver(self, raw6): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.validateserver( target='ftp://1.1.1.1//auto/tftp-ssr/show_clock', timeout_seconds=300, device=self.device) def test_copyconfiguration(self): self.device.execute = Mock() self.device.execute.side_effect = self.mapper self.fu_device.copyconfiguration( source='running-config', destination='tftp://10.1.7.250//auto/tftp-ssr/test_config.py', timeout_seconds=300, device=self.device)