Merge pull request #45124 from gtmanfred/2017.7

enable using kitchen-salt with ec2 on 2017.7
This commit is contained in:
Nicole Thomas 2017-12-21 14:11:27 -05:00 committed by GitHub
commit b49ee97938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View file

@ -24,7 +24,7 @@ transport:
name: sftp
<% end %>
sudo: false
sudo: true
provisioner:
name: salt_solo
salt_install: bootstrap
@ -184,10 +184,9 @@ suites:
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'
command: 'sudo -E $(kitchen) /tmp/kitchen/testing/tests/runtests.py -v --run-destructive --sysinfo --transport=zeromq --output-columns=80 --ssh --coverage-xml=/tmp/coverage.xml --xml=/tmp/xml-unittests-output'
<% else %>
command: '$(kitchen) /tmp/kitchen/testing/tests/runtests.py --run-destructive --output-columns 80 <%= ENV["TESTOPTS"] %>'
command: 'sudo -E $(kitchen) /tmp/kitchen/testing/tests/runtests.py -v --run-destructive --output-columns 80 <%= ENV["TESTOPTS"] %>'
<% end %>

View file

@ -22,3 +22,7 @@ group :windows do
gem 'winrm', '~>2.0'
gem 'winrm-fs', '~>1.0'
end
group :ec2 do
gem 'kitchen-ec2'
end

View file

@ -131,5 +131,5 @@ class RunnerReturnsTest(ShellCase):
'jid': jid,
'return': {'args': ['foo'], 'kwargs': {'bar': 'hello world!'}},
'success': True,
'user': RUNTIME_VARS.RUNNING_TESTS_USER}
'user': RUNTIME_VARS.RUNNING_TESTS_USER if 'SUDO_USER' not in os.environ else 'root'}
)

View file

@ -14,7 +14,8 @@ class DownloadArtifacts(object):
def __init__(self, instance, artifacts):
self.instance = instance
self.artifacts = artifacts
self.client = self.setup_transport()
self.transport = self.setup_transport()
self.sftpclient = paramiko.SFTPClient.from_transport(self.transport)
def setup_transport(self):
# pylint: disable=minimum-python-version
@ -33,19 +34,30 @@ class DownloadArtifacts(object):
username=state.get('username', tport.get('username', 'root')),
pkey=pkey
)
return paramiko.SFTPClient.from_transport(transport)
return transport
def _set_permissions(self):
'''
Make sure all xml files are readable by the world so that anyone can grab them
'''
for remote, _ in self.artifacts:
self.transport.open_session().exec_command('sudo chmod -R +r {}'.format(remote))
def download(self):
self._set_permissions()
for remote, local in self.artifacts:
if remote.endswith('/'):
for fxml in self.client.listdir(remote):
for fxml in self.sftpclient.listdir(remote):
self._do_download(os.path.join(remote, fxml), os.path.join(local, os.path.basename(fxml)))
else:
self._do_download(remote, os.path.join(local, os.path.basename(remote)))
def _do_download(self, remote, local):
print('Copying from {0} to {1}'.format(remote, local))
self.client.get(remote, local)
try:
self.sftpclient.get(remote, local)
except IOError:
print('Failed to copy: {0}'.format(remote))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Jenkins Artifact Download Helper')