salt/tests/jenkins.py

73 lines
1.9 KiB
Python
Raw Normal View History

#!/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!!
'''
2013-08-10 07:23:32 +00:00
# Import python libs
import sys
import subprocess
import hashlib
import random
import optparse
2013-08-10 08:04:45 +00:00
def run(platform, provider, commit, clean):
'''
RUN!
'''
htag = hashlib.md5(str(random.randint(1, 100000000))).hexdigest()[:6]
vm_name = '{0}{1}'.format(platform, htag)
2013-08-10 07:53:28 +00:00
cmd = 'salt-cloud -p {0}_{1} {2}'.format(provider, platform, vm_name)
print('Running CMD: {0}'.format(cmd))
subprocess.call(
2013-08-10 07:53:28 +00:00
cmd,
shell=True)
# Run tests here
2013-08-10 07:53:28 +00:00
cmd = 'salt {0} state.sls testrun pillar="{{git_commit: {1}}}"'.format(
vm_name,
commit),
2013-08-10 07:53:28 +00:00
print('Running CMD: {0}'.format(cmd))
subprocess.call(
cmd,
shell=True)
# Clean up the vm
2013-08-10 08:04:45 +00:00
if clean:
cmd = 'salt-cloud -d {0} -y'.format(vm_name),
print('Running CMD: {0}'.format(cmd))
subprocess.call(
cmd,
shell=True)
2013-08-10 07:23:32 +00:00
return 0
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')
2013-08-10 08:06:03 +00:00
parser.add_option('--no-clean',
2013-08-10 08:04:45 +00:00
dest='clean',
default=True,
action='store_false',
help='Clean up the built vm')
2013-08-10 07:23:32 +00:00
options, args = parser.parse_args()
2013-08-10 07:43:40 +00:00
return options.__dict__
2013-08-10 07:23:32 +00:00
if __name__ == '__main__':
opts = parse()
2013-08-10 08:04:45 +00:00
exit_code = run(**opts)
print('Exit Code: {0}'.format(exit_code))
2013-08-10 07:23:32 +00:00
sys.exit(exit_code)