Merge "Make ansible version configurable"
This commit is contained in:
@@ -1524,7 +1524,8 @@ class RecordingAnsibleJob(zuul.executor.server.AnsibleJob):
|
||||
self.recordResult(result)
|
||||
return result
|
||||
|
||||
def runAnsible(self, cmd, timeout, playbook, wrapped=True):
|
||||
def runAnsible(self, cmd, timeout, playbook, ansible_version,
|
||||
wrapped=True):
|
||||
build = self.executor_server.job_builds[self.job.unique]
|
||||
|
||||
if self.executor_server._run_ansible:
|
||||
@@ -1532,7 +1533,7 @@ class RecordingAnsibleJob(zuul.executor.server.AnsibleJob):
|
||||
# hold real ansible jobs.
|
||||
build.run()
|
||||
result = super(RecordingAnsibleJob, self).runAnsible(
|
||||
cmd, timeout, playbook, wrapped)
|
||||
cmd, timeout, playbook, ansible_version, wrapped)
|
||||
else:
|
||||
if playbook.path:
|
||||
result = build.run()
|
||||
|
||||
15
tests/fixtures/config/ansible-versions/git/common-config/playbooks/ansible-version.yaml
vendored
Normal file
15
tests/fixtures/config/ansible-versions/git/common-config/playbooks/ansible-version.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- name: Print ansible version
|
||||
debug:
|
||||
msg: "{{ ansible_version }}"
|
||||
|
||||
- name: Print expected ansible version
|
||||
debug:
|
||||
msg: "{{ test_ansible_version_major }}.{{ test_ansible_version_minor }}"
|
||||
|
||||
- name: Check ansible version
|
||||
assert:
|
||||
that:
|
||||
- test_ansible_version_major == ansible_version.major
|
||||
- test_ansible_version_minor == ansible_version.minor
|
||||
44
tests/fixtures/config/ansible-versions/git/common-config/zuul.yaml
vendored
Normal file
44
tests/fixtures/config/ansible-versions/git/common-config/zuul.yaml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
- pipeline:
|
||||
name: check
|
||||
manager: independent
|
||||
trigger:
|
||||
gerrit:
|
||||
- event: patchset-created
|
||||
success:
|
||||
gerrit:
|
||||
Verified: 1
|
||||
failure:
|
||||
gerrit:
|
||||
Verified: -1
|
||||
|
||||
- job:
|
||||
name: base
|
||||
parent: null
|
||||
|
||||
- job:
|
||||
name: ansible-version
|
||||
run: playbooks/ansible-version.yaml
|
||||
|
||||
|
||||
- job:
|
||||
name: ansible-default
|
||||
parent: ansible-version
|
||||
vars:
|
||||
test_ansible_version_major: 2
|
||||
test_ansible_version_minor: 5
|
||||
|
||||
- job:
|
||||
name: ansible-25
|
||||
parent: ansible-version
|
||||
ansible-version: 2.5
|
||||
vars:
|
||||
test_ansible_version_major: 2
|
||||
test_ansible_version_minor: 5
|
||||
|
||||
|
||||
- project:
|
||||
name: common-config
|
||||
check:
|
||||
jobs:
|
||||
- ansible-default
|
||||
- ansible-25
|
||||
6
tests/fixtures/config/ansible-versions/main.yaml
vendored
Normal file
6
tests/fixtures/config/ansible-versions/main.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
- tenant:
|
||||
name: tenant-one
|
||||
source:
|
||||
gerrit:
|
||||
config-projects:
|
||||
- common-config
|
||||
@@ -1,3 +1,8 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- debug:
|
||||
msg: Ansible version={{ ansible_version.major }}.{{ ansible_version.minor }}
|
||||
|
||||
- hosts: all
|
||||
tasks:
|
||||
# Create unwritable /tmp/console-None.log
|
||||
|
||||
20
tests/fixtures/config/tenant-parser/ansible-version.yaml
vendored
Normal file
20
tests/fixtures/config/tenant-parser/ansible-version.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
- tenant:
|
||||
name: tenant-no-default
|
||||
source:
|
||||
gerrit:
|
||||
config-projects:
|
||||
- common-config
|
||||
untrusted-projects:
|
||||
- org/project1
|
||||
- org/project2
|
||||
|
||||
- tenant:
|
||||
name: tenant-default-2-5
|
||||
default-ansible-version: "2.5"
|
||||
source:
|
||||
gerrit:
|
||||
config-projects:
|
||||
- common-config
|
||||
untrusted-projects:
|
||||
- org/project1
|
||||
- org/project2
|
||||
4
tests/fixtures/config/tenant-parser/git/common-config/playbooks/common.yaml
vendored
Normal file
4
tests/fixtures/config/tenant-parser/git/common-config/playbooks/common.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: test
|
||||
debug: test
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
- job:
|
||||
name: common-config-job
|
||||
run: playbooks/common.yaml
|
||||
|
||||
# Use the canonical name here. This should be merged with the org/project1 in
|
||||
# the other repo.
|
||||
|
||||
@@ -22,11 +22,12 @@ ERROR_SYNC_TO_OUTSIDE = "Syncing files to outside the working dir"
|
||||
ERROR_SYNC_FROM_OUTSIDE = "Syncing files from outside the working dir"
|
||||
|
||||
|
||||
class TestActionModules(AnsibleZuulTestCase):
|
||||
class TestActionModules25(AnsibleZuulTestCase):
|
||||
tenant_config_file = 'config/remote-action-modules/main.yaml'
|
||||
ansible_version = '2.5'
|
||||
|
||||
def setUp(self):
|
||||
super(TestActionModules, self).setUp()
|
||||
super().setUp()
|
||||
self.fake_nodepool.remote_ansible = True
|
||||
|
||||
ansible_remote = os.environ.get('ZUUL_REMOTE_IPV4')
|
||||
@@ -50,6 +51,7 @@ class TestActionModules(AnsibleZuulTestCase):
|
||||
- job:
|
||||
name: {job_name}
|
||||
run: playbooks/{job_name}.yaml
|
||||
ansible-version: {version}
|
||||
roles:
|
||||
- zuul: org/common-config
|
||||
nodeset:
|
||||
@@ -61,7 +63,7 @@ class TestActionModules(AnsibleZuulTestCase):
|
||||
check:
|
||||
jobs:
|
||||
- {job_name}
|
||||
""".format(job_name=job_name))
|
||||
""".format(job_name=job_name, version=self.ansible_version))
|
||||
|
||||
file_dict = {'zuul.yaml': conf}
|
||||
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
|
||||
|
||||
@@ -20,11 +20,12 @@ import textwrap
|
||||
from tests.base import AnsibleZuulTestCase
|
||||
|
||||
|
||||
class TestZuulJSON(AnsibleZuulTestCase):
|
||||
class TestZuulJSON25(AnsibleZuulTestCase):
|
||||
tenant_config_file = 'config/remote-zuul-json/main.yaml'
|
||||
ansible_version = '2.5'
|
||||
|
||||
def setUp(self):
|
||||
super(TestZuulJSON, self).setUp()
|
||||
super().setUp()
|
||||
self.fake_nodepool.remote_ansible = True
|
||||
|
||||
ansible_remote = os.environ.get('ZUUL_REMOTE_IPV4')
|
||||
@@ -43,6 +44,7 @@ class TestZuulJSON(AnsibleZuulTestCase):
|
||||
- job:
|
||||
name: {job_name}
|
||||
run: playbooks/{job_name}.yaml
|
||||
ansible-version: {version}
|
||||
roles:
|
||||
- zuul: org/common-config
|
||||
nodeset:
|
||||
@@ -54,7 +56,7 @@ class TestZuulJSON(AnsibleZuulTestCase):
|
||||
check:
|
||||
jobs:
|
||||
- {job_name}
|
||||
""".format(job_name=job_name))
|
||||
""".format(job_name=job_name, version=self.ansible_version))
|
||||
|
||||
file_dict = {'zuul.yaml': conf}
|
||||
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
|
||||
|
||||
@@ -19,11 +19,12 @@ import textwrap
|
||||
from tests.base import AnsibleZuulTestCase
|
||||
|
||||
|
||||
class TestZuulStream(AnsibleZuulTestCase):
|
||||
class TestZuulStream25(AnsibleZuulTestCase):
|
||||
tenant_config_file = 'config/remote-zuul-stream/main.yaml'
|
||||
ansible_version = '2.5'
|
||||
|
||||
def setUp(self):
|
||||
super(TestZuulStream, self).setUp()
|
||||
super().setUp()
|
||||
self.fake_nodepool.remote_ansible = True
|
||||
|
||||
ansible_remote = os.environ.get('ZUUL_REMOTE_IPV4')
|
||||
@@ -45,6 +46,7 @@ class TestZuulStream(AnsibleZuulTestCase):
|
||||
- job:
|
||||
name: {job_name}
|
||||
run: playbooks/{job_name}.yaml
|
||||
ansible-version: {version}
|
||||
roles:
|
||||
- zuul: org/common-config
|
||||
nodeset:
|
||||
@@ -58,7 +60,7 @@ class TestZuulStream(AnsibleZuulTestCase):
|
||||
check:
|
||||
jobs:
|
||||
- {job_name}
|
||||
""".format(job_name=job_name))
|
||||
""".format(job_name=job_name, version=self.ansible_version))
|
||||
|
||||
file_dict = {'zuul.yaml': conf}
|
||||
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
|
||||
@@ -94,6 +96,8 @@ class TestZuulStream(AnsibleZuulTestCase):
|
||||
r'RUN START: \[untrusted : review.example.com/org/project/'
|
||||
r'playbooks/command.yaml@master\]', text)
|
||||
self.assertLogLine(r'PLAY \[all\]', text)
|
||||
self.assertLogLine(
|
||||
r'Ansible version={}'.format(self.ansible_version), text)
|
||||
self.assertLogLine(r'TASK \[Show contents of first file\]', text)
|
||||
self.assertLogLine(r'controller \| command test one', text)
|
||||
self.assertLogLine(
|
||||
|
||||
@@ -33,6 +33,7 @@ from tests.base import (
|
||||
|
||||
from zuul.executor.sensors.startingbuilds import StartingBuildsSensor
|
||||
from zuul.executor.sensors.ram import RAMSensor
|
||||
from zuul.lib.ansible import AnsibleManager
|
||||
|
||||
|
||||
class TestExecutorRepos(ZuulTestCase):
|
||||
@@ -428,7 +429,9 @@ class TestAnsibleJob(ZuulTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAnsibleJob, self).setUp()
|
||||
job = gear.TextJob('executor:execute', '{}', unique='test')
|
||||
ansible_version = AnsibleManager().default_version
|
||||
args = '{"ansible_version": "%s"}' % ansible_version
|
||||
job = gear.TextJob('executor:execute', args, unique='test')
|
||||
self.test_job = zuul.executor.server.AnsibleJob(self.executor_server,
|
||||
job)
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ from zuul.lib import yamlutil as yaml
|
||||
import zuul.lib.connections
|
||||
|
||||
from tests.base import BaseTestCase, FIXTURE_DIR
|
||||
from zuul.lib.ansible import AnsibleManager
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
@@ -45,6 +46,7 @@ class TestJob(BaseTestCase):
|
||||
self.source = Dummy(canonical_hostname='git.example.com',
|
||||
connection=self.connection)
|
||||
self.tenant = model.Tenant('tenant')
|
||||
self.tenant.default_ansible_version = AnsibleManager().default_version
|
||||
self.layout = model.Layout(self.tenant)
|
||||
self.project = model.Project('project', self.source)
|
||||
self.context = model.SourceContext(self.project, 'master',
|
||||
@@ -58,7 +60,7 @@ class TestJob(BaseTestCase):
|
||||
self.layout.addPipeline(self.pipeline)
|
||||
self.queue = model.ChangeQueue(self.pipeline)
|
||||
self.pcontext = configloader.ParseContext(
|
||||
self.connections, None, self.tenant)
|
||||
self.connections, None, self.tenant, AnsibleManager())
|
||||
|
||||
private_key_file = os.path.join(FIXTURE_DIR, 'private.pem')
|
||||
with open(private_key_file, "rb") as f:
|
||||
|
||||
@@ -2264,10 +2264,11 @@ class TestInRepoJoin(ZuulTestCase):
|
||||
self.assertHistory([])
|
||||
|
||||
|
||||
class TestAnsible(AnsibleZuulTestCase):
|
||||
class TestAnsible25(AnsibleZuulTestCase):
|
||||
# A temporary class to hold new tests while others are disabled
|
||||
|
||||
tenant_config_file = 'config/ansible/main.yaml'
|
||||
ansible_version = '2.5'
|
||||
|
||||
def test_playbook(self):
|
||||
# This test runs a bit long and needs extra time.
|
||||
@@ -2381,15 +2382,17 @@ class TestAnsible(AnsibleZuulTestCase):
|
||||
conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: %s
|
||||
run: playbooks/%s.yaml
|
||||
name: {job_name}
|
||||
run: playbooks/{job_name}.yaml
|
||||
ansible-version: {ansible_version}
|
||||
|
||||
- project:
|
||||
name: org/plugin-project
|
||||
check:
|
||||
jobs:
|
||||
- %s
|
||||
""" % (job_name, job_name, job_name))
|
||||
- {job_name}
|
||||
""".format(job_name=job_name,
|
||||
ansible_version=self.ansible_version))
|
||||
|
||||
file_dict = {'.zuul.yaml': conf}
|
||||
A = self.fake_gerrit.addFakeChange('org/plugin-project', 'master', 'A',
|
||||
@@ -5296,3 +5299,20 @@ class TestJobPausePriority(AnsibleZuulTestCase):
|
||||
|
||||
self.fake_nodepool.unpause()
|
||||
self.waitUntilSettled()
|
||||
|
||||
|
||||
class TestAnsibleVersion(AnsibleZuulTestCase):
|
||||
tenant_config_file = 'config/ansible-versions/main.yaml'
|
||||
|
||||
def test_ansible_versions(self):
|
||||
"""
|
||||
Tests that jobs run with the requested ansible version.
|
||||
"""
|
||||
A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A')
|
||||
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertHistory([
|
||||
dict(name='ansible-default', result='SUCCESS', changes='1,1'),
|
||||
dict(name='ansible-25', result='SUCCESS', changes='1,1'),
|
||||
], ordered=False)
|
||||
|
||||
@@ -296,6 +296,7 @@ class TestWeb(BaseTestWeb):
|
||||
{
|
||||
'name': 'project-test1',
|
||||
'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 4,
|
||||
'branches': [],
|
||||
'dependencies': [],
|
||||
@@ -334,6 +335,7 @@ class TestWeb(BaseTestWeb):
|
||||
}, {
|
||||
'name': 'project-test1',
|
||||
'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': ['stable'],
|
||||
'dependencies': [],
|
||||
@@ -376,6 +378,7 @@ class TestWeb(BaseTestWeb):
|
||||
self.assertEqual([
|
||||
{
|
||||
'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': [],
|
||||
'dependencies': [],
|
||||
@@ -485,6 +488,7 @@ class TestWeb(BaseTestWeb):
|
||||
'api/tenant/tenant-one/project/org/project1').json()
|
||||
|
||||
jobs = [[{'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': [],
|
||||
'dependencies': [],
|
||||
@@ -515,6 +519,7 @@ class TestWeb(BaseTestWeb):
|
||||
'variant_description': '',
|
||||
'voting': True}],
|
||||
[{'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': [],
|
||||
'dependencies': [{'name': 'project-merge',
|
||||
@@ -546,6 +551,7 @@ class TestWeb(BaseTestWeb):
|
||||
'variant_description': '',
|
||||
'voting': True}],
|
||||
[{'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': [],
|
||||
'dependencies': [{'name': 'project-merge',
|
||||
@@ -577,6 +583,7 @@ class TestWeb(BaseTestWeb):
|
||||
'variant_description': '',
|
||||
'voting': True}],
|
||||
[{'abstract': False,
|
||||
'ansible_version': None,
|
||||
'attempts': 3,
|
||||
'branches': [],
|
||||
'dependencies': [{'name': 'project-merge',
|
||||
|
||||
Reference in New Issue
Block a user