summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-delegate.yaml12
-rw-r--r--tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-localhost.yaml10
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/common-config/playbooks/command-localhost.yaml7
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/common-config/zuul.yaml4
-rw-r--r--tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml8
-rw-r--r--tests/remote/test_remote_action_modules.py3
-rw-r--r--tests/remote/test_remote_zuul_stream.py90
7 files changed, 94 insertions, 40 deletions
diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-delegate.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-delegate.yaml
new file mode 100644
index 000000000..7cb81e3b7
--- /dev/null
+++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-delegate.yaml
@@ -0,0 +1,12 @@
+- hosts: all
+ tasks:
+ - name: Normal shell
+ delegate_to: localhost
+ shell: echo 123
+
+ - name: Shell with executable
+ delegate_to: localhost
+ shell: |
+ echo 123
+ args:
+ executable: /bin/bash
diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-localhost.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-localhost.yaml
new file mode 100644
index 000000000..35f7253f1
--- /dev/null
+++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/shell-localhost.yaml
@@ -0,0 +1,10 @@
+- hosts: localhost
+ tasks:
+ - name: Normal shell
+ shell: echo 123
+
+ - name: Shell with executable
+ shell: |
+ echo 123
+ args:
+ executable: /bin/bash
diff --git a/tests/fixtures/config/remote-zuul-stream/git/common-config/playbooks/command-localhost.yaml b/tests/fixtures/config/remote-zuul-stream/git/common-config/playbooks/command-localhost.yaml
new file mode 100644
index 000000000..629f3398c
--- /dev/null
+++ b/tests/fixtures/config/remote-zuul-stream/git/common-config/playbooks/command-localhost.yaml
@@ -0,0 +1,7 @@
+- hosts: localhost
+ tasks:
+ - name: Local shell task with python exception
+ command: echo foo
+ args:
+ chdir: /local-shelltask/somewhere/that/does/not/exist
+ failed_when: false
diff --git a/tests/fixtures/config/remote-zuul-stream/git/common-config/zuul.yaml b/tests/fixtures/config/remote-zuul-stream/git/common-config/zuul.yaml
index a07342e2e..f9ad5fcfe 100644
--- a/tests/fixtures/config/remote-zuul-stream/git/common-config/zuul.yaml
+++ b/tests/fixtures/config/remote-zuul-stream/git/common-config/zuul.yaml
@@ -15,3 +15,7 @@
- job:
name: base
parent: null
+
+- job:
+ name: command-localhost
+ run: playbooks/command-localhost.yaml
diff --git a/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml b/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml
index ec84cf784..ea772d607 100644
--- a/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml
+++ b/tests/fixtures/config/remote-zuul-stream/git/org_project/playbooks/command.yaml
@@ -97,11 +97,3 @@
args:
chdir: /remote-shelltask/somewhere/that/does/not/exist
failed_when: false
-
-- hosts: localhost
- tasks:
- - name: Local shell task with python exception
- command: echo foo
- args:
- chdir: /local-shelltask/somewhere/that/does/not/exist
- failed_when: false
diff --git a/tests/remote/test_remote_action_modules.py b/tests/remote/test_remote_action_modules.py
index c5818ae9c..23833f174 100644
--- a/tests/remote/test_remote_action_modules.py
+++ b/tests/remote/test_remote_action_modules.py
@@ -18,6 +18,7 @@ import textwrap
from tests.base import AnsibleZuulTestCase, FIXTURE_DIR
ERROR_ACCESS_OUTSIDE = "Accessing files from outside the working dir"
+ERROR_LOCAL_CODE = "Executing local code is prohibited"
ERROR_SYNC_TO_OUTSIDE = "Syncing files to outside the working dir"
ERROR_SYNC_FROM_OUTSIDE = "Syncing files from outside the working dir"
ERROR_SYNC_RSH = "Using custom synchronize rsh is prohibited"
@@ -175,6 +176,8 @@ class FunctionalActionModulesMixIn:
def test_shell_module(self):
self._run_job('shell-good', 'SUCCESS')
+ self._run_job('shell-localhost', 'FAILURE', ERROR_LOCAL_CODE)
+ self._run_job('shell-delegate', 'FAILURE', ERROR_LOCAL_CODE)
def test_synchronize_module(self):
self._run_job('synchronize-good', 'SUCCESS')
diff --git a/tests/remote/test_remote_zuul_stream.py b/tests/remote/test_remote_zuul_stream.py
index 026fd1e7f..9fef472b5 100644
--- a/tests/remote/test_remote_zuul_stream.py
+++ b/tests/remote/test_remote_zuul_stream.py
@@ -32,7 +32,7 @@ class FunctionalZuulStreamMixIn:
ansible_remote = os.environ.get('ZUUL_REMOTE_IPV4')
self.assertIsNotNone(ansible_remote)
- def _run_job(self, job_name):
+ def _run_job(self, job_name, create=True):
# Keep the jobdir around so we can inspect contents if an
# assert fails. It will be cleaned up anyway as it is contained
# in a tmp dir which gets cleaned up after the test.
@@ -40,32 +40,40 @@ class FunctionalZuulStreamMixIn:
# Output extra ansible info so we might see errors.
self.executor_server.verbose = True
- conf = textwrap.dedent(
- """
- - job:
- name: {job_name}
- run: playbooks/{job_name}.yaml
- ansible-version: {version}
- vars:
- test_console_port: {console_port}
- roles:
- - zuul: org/common-config
- nodeset:
- nodes:
- - name: compute1
- label: whatever
- - name: controller
- label: whatever
-
- - project:
- check:
- jobs:
- - {job_name}
- """.format(
- job_name=job_name,
- version=self.ansible_version,
- console_port=self.log_console_port))
+ if create:
+ conf = textwrap.dedent(
+ """
+ - job:
+ name: {job_name}
+ run: playbooks/{job_name}.yaml
+ ansible-version: {version}
+ vars:
+ test_console_port: {console_port}
+ roles:
+ - zuul: org/common-config
+ nodeset:
+ nodes:
+ - name: compute1
+ label: whatever
+ - name: controller
+ label: whatever
+ - project:
+ check:
+ jobs:
+ - {job_name}
+ """.format(
+ job_name=job_name,
+ version=self.ansible_version,
+ console_port=self.log_console_port))
+ else:
+ conf = textwrap.dedent(
+ """
+ - project:
+ check:
+ jobs:
+ - {job_name}
+ """.format(job_name=job_name))
file_dict = {'zuul.yaml': conf}
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
files=file_dict)
@@ -141,9 +149,6 @@ class FunctionalZuulStreamMixIn:
self.assertLogLine(r'compute1 \| failed_in_loop2', text)
self.assertLogLine(r'compute1 \| ok: Item: failed_in_loop2 '
r'Result: 1', text)
- self.assertLogLine(r'localhost \| .*No such file or directory: .*'
- r'\'/local-shelltask/somewhere/'
- r'that/does/not/exist\'', text)
self.assertLogLine(r'compute1 \| .*No such file or directory: .*'
r'\'/remote-shelltask/somewhere/'
r'that/does/not/exist\'', text)
@@ -160,6 +165,18 @@ class FunctionalZuulStreamMixIn:
r'RUN END RESULT_NORMAL: \[untrusted : review.example.com/'
r'org/project/playbooks/command.yaml@master]', text)
+ # Run a pre-defined job that is defined in a trusted repo to test
+ # localhost tasks.
+ job = self._run_job('command-localhost', create=False)
+ with self.jobLog(job):
+ build = self.history[-1]
+ self.assertEqual(build.result, 'SUCCESS')
+
+ text = self._get_job_output(build)
+ self.assertLogLine(r'localhost \| .*No such file or directory: .*'
+ r'\'/local-shelltask/somewhere/'
+ r'that/does/not/exist\'', text)
+
def test_module_exception(self):
job = self._run_job('module_failure_exception')
with self.jobLog(job):
@@ -260,9 +277,6 @@ class TestZuulStream28(AnsibleZuulTestCase, FunctionalZuulStreamMixIn):
self.assertLogLine(r'compute1 \| failed_in_loop2', text)
self.assertLogLine(r'compute1 \| ok: Item: failed_in_loop2 '
r'Result: 1', text)
- self.assertLogLine(r'localhost \| .*No such file or directory: .*'
- r'\'/local-shelltask/somewhere/'
- r'that/does/not/exist\'', text)
self.assertLogLine(r'compute1 \| .*No such file or directory: .*'
r'\'/remote-shelltask/somewhere/'
r'that/does/not/exist\'', text)
@@ -281,6 +295,18 @@ class TestZuulStream28(AnsibleZuulTestCase, FunctionalZuulStreamMixIn):
r'RUN END RESULT_NORMAL: \[untrusted : review.example.com/'
r'org/project/playbooks/command.yaml@master]', text)
+ # Run a pre-defined job that is defined in a trusted repo to test
+ # localhost tasks.
+ job = self._run_job('command-localhost', create=False)
+ with self.jobLog(job):
+ build = self.history[-1]
+ self.assertEqual(build.result, 'SUCCESS')
+
+ text = self._get_job_output(build)
+ self.assertLogLine(r'localhost \| .*No such file or directory: .*'
+ r'\'/local-shelltask/somewhere/'
+ r'that/does/not/exist\'', text)
+
class TestZuulStream29(TestZuulStream28):
ansible_version = '2.9'