Fix multiple role paths

Due to a bug in the equality check of the ZuulRoles class, we
were unable to add more than one roles path.  This corrects that and
adds a test of role inheritance which exercises this.

Change-Id: Icf6daa312405ed56d2fecb89fc6aee69b4b80e41
changes/47/484047/1
James E. Blair 5 years ago
parent 41efa8827a
commit 1b27f6afe0
  1. 2
      tests/fixtures/config/roles/git/org_project/playbooks/parent-post.yaml
  2. 2
      tests/fixtures/config/roles/git/org_project/playbooks/parent-pre.yaml
  3. 0
      tests/fixtures/config/roles/git/org_project/roles/README
  4. 64
      tests/unit/test_v3.py
  5. 3
      zuul/executor/server.py
  6. 2
      zuul/model.py

@ -673,6 +673,25 @@ class TestProjectKeys(ZuulTestCase):
class TestRoles(ZuulTestCase):
tenant_config_file = 'config/roles/main.yaml'
def _assertRolePath(self, build, playbook, content):
path = os.path.join(self.test_root, build.uuid,
'ansible', playbook, 'ansible.cfg')
roles_paths = []
with open(path) as f:
for line in f:
if line.startswith('roles_path'):
roles_paths.append(line)
print(roles_paths)
if content:
self.assertEqual(len(roles_paths), 1,
"Should have one roles_path line in %s" %
(playbook,))
self.assertIn(content, roles_paths[0])
else:
self.assertEqual(len(roles_paths), 0,
"Should have no roles_path line in %s" %
(playbook,))
def test_role(self):
# This exercises a proposed change to a role being checked out
# and used.
@ -687,6 +706,51 @@ class TestRoles(ZuulTestCase):
dict(name='project-test', result='SUCCESS', changes='1,1 2,1'),
])
def test_role_inheritance(self):
self.executor_server.hold_jobs_in_build = True
conf = textwrap.dedent(
"""
- job:
name: parent
roles:
- zuul: bare-role
pre-run: playbooks/parent-pre
post-run: playbooks/parent-post
- job:
name: project-test
parent: parent
roles:
- zuul: org/project
- project:
name: org/project
check:
jobs:
- project-test
""")
file_dict = {'.zuul.yaml': conf}
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertEqual(len(self.builds), 1)
build = self.getBuildByName('project-test')
self._assertRolePath(build, 'pre_playbook_0', 'role_0')
self._assertRolePath(build, 'playbook_0', 'role_0')
self._assertRolePath(build, 'playbook_0', 'role_1')
self._assertRolePath(build, 'post_playbook_0', 'role_0')
self.executor_server.hold_jobs_in_build = False
self.executor_server.release()
self.waitUntilSettled()
self.assertHistory([
dict(name='project-test', result='SUCCESS', changes='1,1'),
])
class TestShadow(ZuulTestCase):
tenant_config_file = 'config/shadow/main.yaml'

@ -1120,7 +1120,8 @@ class AnsibleJob(object):
# This repo has a collection of roles
if not trusted:
for entry in os.listdir(d):
self._blockPluginDirs(os.path.join(d, entry))
if os.path.isdir(os.path.join(d, entry)):
self._blockPluginDirs(os.path.join(d, entry))
return d
# It is neither a bare role, nor a collection of roles
raise Exception("Unable to find role in %s" % (path,))

@ -712,7 +712,7 @@ class ZuulRole(Role):
if not isinstance(other, ZuulRole):
return False
return (super(ZuulRole, self).__eq__(other) and
self.connection_name == other.connection_name,
self.connection_name == other.connection_name and
self.project_name == other.project_name)
def toDict(self):

Loading…
Cancel
Save