add script for copying back artifacts

This commit is contained in:
Daniel Wallace 2017-10-16 10:09:15 -06:00
parent 255118cfd7
commit 7465f9b27a
No known key found for this signature in database
GPG key ID: 5FA5E5544F010D48
2 changed files with 51 additions and 0 deletions

View file

@ -154,6 +154,7 @@ verifier:
name: shell
remote_exec: true
sudo: false
live_stream: {}
<% if ENV['TESTOPTS'].nil? %>
command: '$(kitchen) /tmp/kitchen/testing/tests/runtests.py --run-destructive --sysinfo --transport=zeromq --output-columns=80 --ssh --coverage-xml=/tmp/coverage.xml --xml=/tmp/xml-unittests-output'
<% else %>

50
tests/copyartifacts.py Normal file
View file

@ -0,0 +1,50 @@
import argparse
import os
import paramiko
import subprocess
import yaml
class DownloadArtifacts(object):
def __init__(self, instance, artifacts):
self.instance = instance
self.artifacts = artifacts
self.client = self.setup_transport()
def setup_transport(self):
config = yaml.load(subprocess.check_output(['bundle', 'exec', 'kitchen', 'diagnose', self.instance]))
instance = config['instances'][self.instance]['state_file']
transport = paramiko.Transport((instance['hostname'], instance['port']))
pkey = paramiko.rsakey.RSAKey(filename=instance['ssh_key'])
transport.connect(username=instance['username'], pkey=pkey)
return paramiko.SFTPClient.from_transport(transport)
def download(self):
for remote, local in self.artifacts:
if remote.endswith('/'):
for fxml in self.client.listdir(remote):
print(os.path.join(remote, fxml))
print(os.path.join(local, os.path.basename(fxml)))
self.client.get(os.path.join(remote, fxml), os.path.join(local, os.path.basename(fxml)))
else:
self.client.get(fxml, os.path.join([local, os.path.basename(fxml)]))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Jenkins Artifact Download Helper')
parser.add_argument(
'--instance',
required=True,
action='store',
help='Instance on Test Kitchen to pull from',
)
parser.add_argument(
'--download-artifacts',
dest='artifacts',
nargs=2,
action='append',
metavar=('REMOTE_PATH', 'LOCAL_PATH'),
help='Download remote artifacts',
)
args = parser.parse_args()
downloader = DownloadArtifacts(args.instance, args.artifacts)
downloader.download()