def downloadResults(self, targetPath=None): """ Get the test results path and download all the CSV results to the local system. Works in both Windows and Linux IxLoad sgateways Requirements Must be using IxLoad version > 8.5 Parameter targetPath: The path to store the downloaded result file. Defaults to the path where the script was executed. If saving on Windows OS, provide two backslashes for the path. Ex: c:\\Results Syntax: https://ip:8443/api/v1/downloadResource?localPath=/mnt/ixload-share/&zipName=results.zip """ versionMatch = re.match('([0-9]+\.[0-9]+)', self.ixLoadVersion) if float((versionMatch.group(1))) < float(8.5): self.logInfo('Your IxLoad version {} does not have the rest api to download csv stats. However, real time stats are saved in csv files in your local system'.format(self.ixLoadVersion)) return if targetPath is None: # /OpenIxiaGit/IxLoad/RestApi/Python/Modules targetPath = os.path.abspath(os.path.dirname(__file__)) resultsPath = self.getResultPath() if '/' in resultsPath: # Linux path destinationZipFileName = resultsPath.split('/')[-1] # /mnt/ixload-share/9.10.0.311/Results/IxL_Http_Ipv4Ftp_vm_8.20_20201113_190931 # Purpose: Shorten the filename match = re.search('.*_([0-9]+_[0-9]+)', destinationZipFileName) if match: destinationZipFileName = match.group(1) else: # Windows path destinationZipFileName = resultsPath.split('\\')[-1] zipFileName = 'ixLoadResults_{}.zip'.format(destinationZipFileName) if platform.system() == 'Windows': zipFile = '{}\\{}'.format(targetPath, zipFileName) else: zipFile = '{}/{}'.format(targetPath, zipFileName) # The zipName parameter will be ignored if this rest api is executed by a script. # zipName is used if this rest api is entered on a web browser or postman. The zipName will be used # as the download zip file. url = '{}/api/v1/downloadResource?localPath={}&zipName={}'.format(self.httpHeader, resultsPath, 'zipFileName') self.logInfo('downloadResults: Saving results from {} to: {}'.format(resultsPath, zipFile)) response = self.get(url, downloadStream=True) with open(zipFile, 'wb') as fileHandle: for chunk in response.iter_content(chunk_size=1024): fileHandle.write(chunk)