mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #11817 from s0undt3ch/develop
jenkins.py improvements
This commit is contained in:
commit
007c48cffa
@ -353,34 +353,6 @@ def run(opts):
|
||||
delete_vm(vm_name)
|
||||
sys.exit(retcode)
|
||||
|
||||
# Do we need extra setup?
|
||||
if opts.salt_url != SALT_GIT_URL:
|
||||
cmds = (
|
||||
'salt -t 100 {vm_name} git.remote_set /testing name={0!r} url={1!r}'.format(
|
||||
'upstream',
|
||||
SALT_GIT_URL,
|
||||
vm_name=vm_name
|
||||
),
|
||||
'salt -t 100 {vm_name} git.fetch /testing \'upstream --tags\''.format(
|
||||
vm_name=vm_name
|
||||
)
|
||||
)
|
||||
for cmd in cmds:
|
||||
print('Running CMD: {0}'.format(cmd))
|
||||
sys.stdout.flush()
|
||||
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
stdout, _ = proc.communicate()
|
||||
|
||||
if stdout:
|
||||
print(stdout)
|
||||
sys.stdout.flush()
|
||||
|
||||
# Run tests here
|
||||
cmd = (
|
||||
'salt -t 1800 {vm_name} state.sls {prep_sls} pillar="{pillar}" '
|
||||
@ -406,6 +378,7 @@ def run(opts):
|
||||
)
|
||||
proc.poll_and_read_until_finish()
|
||||
stdout, _ = proc.communicate()
|
||||
sys.stdout.flush()
|
||||
|
||||
retcode = proc.returncode
|
||||
if retcode != 0:
|
||||
@ -415,6 +388,44 @@ def run(opts):
|
||||
delete_vm(vm_name)
|
||||
sys.exit(retcode)
|
||||
|
||||
if opts.salt_url is not None:
|
||||
# Let's find out if the cloned repository if checked out from the
|
||||
# desired repository
|
||||
proc = NonBlockingPopen(
|
||||
'salt -t 100 {vm_name} --out json git.remote_get /testing'.format(vm_name=vm_name),
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
stream_stds=False
|
||||
)
|
||||
proc.poll_and_read_until_finish()
|
||||
stdout, _ = proc.communicate()
|
||||
sys.stdout.flush()
|
||||
|
||||
retcode = proc.returncode
|
||||
if retcode != 0:
|
||||
print('Failed to get the cloned repository remove. 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 remote(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)
|
||||
|
||||
remotes_info = json.loads(stdout.strip())
|
||||
if opts.salt_url not in remotes_info[vm_name]:
|
||||
print('The cloned repository remote is not the desired one:')
|
||||
print(' {0!r} is not in {1}'.format(opts.salt_url, remotes_info))
|
||||
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
|
||||
@ -427,6 +438,7 @@ def run(opts):
|
||||
)
|
||||
proc.poll_and_read_until_finish()
|
||||
stdout, _ = proc.communicate()
|
||||
sys.stdout.flush()
|
||||
|
||||
retcode = proc.returncode
|
||||
if retcode != 0:
|
||||
@ -446,7 +458,7 @@ def run(opts):
|
||||
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]))
|
||||
print(' {0!r} != {1!r}'.format(revision_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)
|
||||
|
Loading…
Reference in New Issue
Block a user