Merge "Don't add implicit role if plugin found"

This commit is contained in:
Zuul
2020-01-24 19:11:28 +00:00
committed by Gerrit Code Review
2 changed files with 38 additions and 10 deletions

View File

@@ -5056,6 +5056,10 @@ class TestPlugins(AnsibleZuulTestCase):
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
return A
def _check_job(self, job_name, project='org/project', roles=''):
A = self._run_job(job_name, project, roles)
message = A.messages[0]
self.assertIn('ERROR Ansible plugin dir', message)
@@ -5063,15 +5067,29 @@ class TestPlugins(AnsibleZuulTestCase):
self.assertIn('in non-trusted repo', message)
def test_filter_plugin(self):
self._run_job('filter-plugin-playbook')
self._run_job('filter-plugin-playbook-symlink')
self._run_job('filter-plugin-bare-role')
self._run_job('filter-plugin-role')
self._run_job('filter-plugin-repo-role', project='org/projectrole')
self._run_job('filter-plugin-shared-role',
roles="roles: [{zuul: 'org/project2'}]")
self._run_job('filter-plugin-shared-bare-role',
roles="roles: [{zuul: 'org/project3', name: 'shared'}]")
self._check_job('filter-plugin-playbook')
self._check_job('filter-plugin-playbook-symlink')
self._check_job('filter-plugin-bare-role')
self._check_job('filter-plugin-role')
self._check_job('filter-plugin-repo-role', project='org/projectrole',
roles="roles: [{zuul: 'org/projectrole'}]")
self._check_job('filter-plugin-shared-role',
roles="roles: [{zuul: 'org/project2'}]")
self._check_job(
'filter-plugin-shared-bare-role',
roles="roles: [{zuul: 'org/project3', name: 'shared'}]")
def test_implicit_role_not_added(self):
# This fails because the job uses the role which isn't added
# to the role path, but it's a normal ansible failure, not a
# Zuul executor error.
A = self._run_job('filter-plugin-repo-role', project='org/projectrole')
self.assertHistory([
dict(name='filter-plugin-repo-role', result='FAILURE',
changes='1,1'),
], ordered=False)
message = A.messages[0]
self.assertNotIn('Ansible plugin', message)
class TestNoLog(AnsibleZuulTestCase):

View File

@@ -79,6 +79,10 @@ class RoleNotFoundError(ExecutorError):
pass
class PluginFoundError(ExecutorError):
pass
class RepoLocks:
def __init__(self):
@@ -1488,7 +1492,7 @@ class AnsibleJob(object):
for entry in os.listdir(path):
entry = os.path.join(path, entry)
if os.path.isdir(entry) and entry.endswith('_plugins'):
raise ExecutorError(
raise PluginFoundError(
"Ansible plugin dir %s found adjacent to playbook %s in "
"non-trusted repo." % (entry, path))
@@ -1748,6 +1752,12 @@ class AnsibleJob(object):
self.log.debug("Implicit role not found in %s", link)
return
raise
except PluginFoundError:
if role['implicit']:
self.log.info("Not adding implicit role %s due to "
"plugin", link)
return
raise
if role_path is None:
# In the case of a bare role, add the containing directory
role_path = root