Check the cloned repository commit for the appropriate match

This split's the Jenkins script execution into one additional step.
Prepare the source to match the cloned repository commit, then resume
previous steps.
This commit is contained in:
Pedro Algarvio 2014-04-06 19:10:56 +01:00
parent 32597a7083
commit 80e0886bdd

View file

@ -316,10 +316,8 @@ def run(opts):
sys.stdout.flush()
time.sleep(5)
# Let's findout if the installed version meeds the passed in pillar
# information
if opts.commit is not None:
# Let's findout if the installed version meeds the passed in pillar
# Let's find out if the installed version matches the passed in pillar
# information
proc = NonBlockingPopen(
'salt -t 100 {vm_name} --out json test.version'.format(vm_name),
@ -383,6 +381,77 @@ def run(opts):
print(stdout)
sys.stdout.flush()
# Run tests here
cmd = (
'salt -t 1800 {vm_name} state.sls {prep_sls} pillar="{pillar}" '
'--no-color'.format(
prep_sls=opts.prep_sls,
pillar=opts.pillar.format(
commit=opts.commit,
salt_url=opts.salt_url
),
vm_name=vm_name,
commit=opts.commit
)
)
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stream_stds=True
)
proc.poll_and_read_until_finish()
stdout, _ = proc.communicate()
retcode = proc.returncode
if retcode != 0:
print('Failed to execute the preparation SLS file. Exit code: {0}'.format(retcode))
sys.stdout.flush()
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
delete_vm(vm_name)
sys.exit(retcode)
if opts.commit is not None:
# Let's find out if the cloned repository if checked out at the desired
# commit
proc = NonBlockingPopen(
'salt -t 100 {vm_name} --out json git.revision /testing'.format(vm_name),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stream_stds=True
)
proc.poll_and_read_until_finish()
stdout, _ = proc.communicate()
retcode = proc.returncode
if retcode != 0:
print('Failed to get the cloned repository revision. Exit code: {0}'.format(retcode))
sys.stdout.flush()
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
delete_vm(vm_name)
sys.exit(retcode)
if not stdout:
print('Failed to get the cloned repository revision(no output). Exit code: {0}'.format(retcode))
sys.stdout.flush()
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
delete_vm(vm_name)
sys.exit(retcode)
revision_info = json.loads(stdout.strip())
if revision_info[vm_name][7:] != opts.commit[7:]:
print('The cloned repository commit is not the desired one:')
print(' {0!r} != {1!r}'.format(version_info[vm_name][:7], opts.commit[:7]))
sys.stdout.flush()
if opts.clean and 'JENKINS_SALTCLOUD_VM_NAME' not in os.environ:
delete_vm(vm_name)
sys.exit(retcode)
# Run tests here
cmd = (
'salt -t 1800 {vm_name} state.sls {sls} pillar="{pillar}" '
@ -471,10 +540,14 @@ def parse():
parser.add_option(
'--commit',
help='The git commit to track')
parser.add_option(
'--prep-sls',
default='git.salt',
help='The sls file to execute to prepare the system')
parser.add_option(
'--sls',
default='testrun',
help='The sls file to execute')
help='The final sls file to execute')
parser.add_option(
'--pillar',
default='{{git_commit: {commit}, git_url: \'{salt_url}\'}}',