mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
'''
|
|
This script is used to test salt from a jenkins server, specifically
|
|
jenkins.satstack.com.
|
|
|
|
This script is intended to be shell centric!!
|
|
'''
|
|
|
|
# Import python libs
|
|
import sys
|
|
import subprocess
|
|
import hashlib
|
|
import random
|
|
import optparse
|
|
|
|
|
|
def run(platform, provider, commit, clean):
|
|
'''
|
|
RUN!
|
|
'''
|
|
htag = hashlib.md5(str(random.randint(1, 100000000))).hexdigest()[:6]
|
|
vm_name = '{0}{1}'.format(platform, htag)
|
|
cmd = 'salt-cloud --script-args "git {0}" -p {1}_{2} {3}'.format(
|
|
commit, provider, platform, vm_name)
|
|
print('Running CMD: {0}'.format(cmd))
|
|
subprocess.call(
|
|
cmd,
|
|
shell=True)
|
|
# Run tests here
|
|
cmd = 'salt {0} state.sls testrun pillar="{{git_commit: {1}}}" --no-color'.format(
|
|
vm_name,
|
|
commit),
|
|
print('Running CMD: {0}'.format(cmd))
|
|
out = subprocess.Popen(
|
|
cmd,
|
|
shell=True,
|
|
stdout=subprocess.STDOUT,
|
|
stderr=subprocess.PIPE).communicate()[0]
|
|
print(out)
|
|
if 'Result: False' in out:
|
|
retcode = 1
|
|
# Clean up the vm
|
|
if clean:
|
|
cmd = 'salt-cloud -d {0} -y'.format(vm_name),
|
|
print('Running CMD: {0}'.format(cmd))
|
|
subprocess.call(
|
|
cmd,
|
|
shell=True)
|
|
return retcode
|
|
|
|
|
|
def parse():
|
|
'''
|
|
Parse the cli options
|
|
'''
|
|
parser = optparse.OptionParser()
|
|
parser.add_option('--platform',
|
|
dest='platform',
|
|
help='The target platform, choose from:\ncent6\ncent5\nubuntu12.04')
|
|
parser.add_option('--provider',
|
|
dest='provider',
|
|
help='The vm provider')
|
|
parser.add_option('--commit',
|
|
dest='commit',
|
|
help='The git commit to track')
|
|
parser.add_option('--no-clean',
|
|
dest='clean',
|
|
default=True,
|
|
action='store_false',
|
|
help='Clean up the built vm')
|
|
options, args = parser.parse_args()
|
|
return options.__dict__
|
|
|
|
if __name__ == '__main__':
|
|
opts = parse()
|
|
exit_code = run(**opts)
|
|
print('Exit Code: {0}'.format(exit_code))
|
|
sys.exit(exit_code)
|