summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/systemd
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/systemd')
-rw-r--r--test/integration/targets/systemd/aliases1
-rw-r--r--test/integration/targets/systemd/defaults/main.yml1
-rw-r--r--test/integration/targets/systemd/handlers/main.yml12
-rw-r--r--test/integration/targets/systemd/meta/main.yml2
-rw-r--r--test/integration/targets/systemd/tasks/main.yml122
-rw-r--r--test/integration/targets/systemd/tasks/test_indirect_service.yml37
-rw-r--r--test/integration/targets/systemd/tasks/test_unit_template.yml50
-rw-r--r--test/integration/targets/systemd/templates/dummy.service11
-rw-r--r--test/integration/targets/systemd/templates/dummy.socket8
-rw-r--r--test/integration/targets/systemd/templates/sleeper@.service8
-rw-r--r--test/integration/targets/systemd/vars/Debian.yml3
-rw-r--r--test/integration/targets/systemd/vars/default.yml3
12 files changed, 258 insertions, 0 deletions
diff --git a/test/integration/targets/systemd/aliases b/test/integration/targets/systemd/aliases
new file mode 100644
index 0000000..a6dafcf
--- /dev/null
+++ b/test/integration/targets/systemd/aliases
@@ -0,0 +1 @@
+shippable/posix/group1
diff --git a/test/integration/targets/systemd/defaults/main.yml b/test/integration/targets/systemd/defaults/main.yml
new file mode 100644
index 0000000..33063b8
--- /dev/null
+++ b/test/integration/targets/systemd/defaults/main.yml
@@ -0,0 +1 @@
+fake_service: nonexisting
diff --git a/test/integration/targets/systemd/handlers/main.yml b/test/integration/targets/systemd/handlers/main.yml
new file mode 100644
index 0000000..57469a0
--- /dev/null
+++ b/test/integration/targets/systemd/handlers/main.yml
@@ -0,0 +1,12 @@
+- name: remove unit file
+ file:
+ path: /etc/systemd/system/sleeper@.service
+ state: absent
+
+- name: remove dummy indirect service
+ file:
+ path: "/etc/systemd/system/{{item}}"
+ state: absent
+ loop:
+ - dummy.service
+ - dummy.socket
diff --git a/test/integration/targets/systemd/meta/main.yml b/test/integration/targets/systemd/meta/main.yml
new file mode 100644
index 0000000..07faa21
--- /dev/null
+++ b/test/integration/targets/systemd/meta/main.yml
@@ -0,0 +1,2 @@
+dependencies:
+ - prepare_tests
diff --git a/test/integration/targets/systemd/tasks/main.yml b/test/integration/targets/systemd/tasks/main.yml
new file mode 100644
index 0000000..3c585e0
--- /dev/null
+++ b/test/integration/targets/systemd/tasks/main.yml
@@ -0,0 +1,122 @@
+# Test code for the systemd module.
+# (c) 2017, James Tanner <tanner.jc@gmail.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+##
+## systemctl
+##
+
+- name: End if this system does not use systemd
+ meta: end_host
+ when: ansible_facts.service_mgr != 'systemd'
+
+- name: Include distribution specific variables
+ include_vars: "{{ lookup('first_found', params) }}"
+ vars:
+ params:
+ files:
+ - "{{ ansible_facts.distribution }}.yml"
+ - "{{ ansible_facts.os_family }}.yml"
+ - default.yml
+ paths:
+ - vars
+
+- name: get a list of running services
+ shell: systemctl | fgrep 'running' | awk '{print $1}' | sed 's/\.service//g' | fgrep -v '.' | egrep ^[a-z]
+ register: running_names
+- debug: var=running_names
+
+- name: check running state
+ systemd:
+ name: "{{ running_names.stdout_lines|random }}"
+ state: started
+ register: systemd_test0
+- debug: var=systemd_test0
+- name: validate results for test0
+ assert:
+ that:
+ - 'systemd_test0.changed is defined'
+ - 'systemd_test0.name is defined'
+ - 'systemd_test0.state is defined'
+ - 'systemd_test0.status is defined'
+ - 'not systemd_test0.changed'
+ - 'systemd_test0.state == "started"'
+
+- name: the module must fail when a service is not found
+ systemd:
+ name: '{{ fake_service }}'
+ state: stopped
+ register: result
+ ignore_errors: yes
+
+- assert:
+ that:
+ - result is failed
+ - 'result is search("Could not find the requested service {{ fake_service }}")'
+
+- name: the module must fail in check_mode as well when a service is not found
+ systemd:
+ name: '{{ fake_service }}'
+ state: stopped
+ register: result
+ check_mode: yes
+ ignore_errors: yes
+
+- assert:
+ that:
+ - result is failed
+ - 'result is search("Could not find the requested service {{ fake_service }}")'
+
+- name: check that the module works even when systemd is offline (eg in chroot)
+ systemd:
+ name: "{{ running_names.stdout_lines|random }}"
+ state: started
+ environment:
+ SYSTEMD_OFFLINE: 1
+
+- name: Disable ssh 1
+ systemd:
+ name: '{{ ssh_service }}'
+ enabled: false
+ register: systemd_disable_ssh_1
+
+- name: Disable ssh 2
+ systemd:
+ name: '{{ ssh_service }}'
+ enabled: false
+ register: systemd_disable_ssh_2
+
+- name: Enable ssh 1
+ systemd:
+ name: '{{ ssh_service }}'
+ enabled: true
+ register: systemd_enable_ssh_1
+
+- name: Enable ssh 2
+ systemd:
+ name: '{{ ssh_service }}'
+ enabled: true
+ register: systemd_enable_ssh_2
+
+- assert:
+ that:
+ - systemd_disable_ssh_2 is not changed
+ - systemd_enable_ssh_1 is changed
+ - systemd_enable_ssh_2 is not changed
+
+- import_tasks: test_unit_template.yml
+- import_tasks: test_indirect_service.yml
diff --git a/test/integration/targets/systemd/tasks/test_indirect_service.yml b/test/integration/targets/systemd/tasks/test_indirect_service.yml
new file mode 100644
index 0000000..fc11343
--- /dev/null
+++ b/test/integration/targets/systemd/tasks/test_indirect_service.yml
@@ -0,0 +1,37 @@
+- name: Copy service file
+ template:
+ src: "{{item}}"
+ dest: "/etc/systemd/system/{{item}}"
+ owner: root
+ group: root
+ loop:
+ - dummy.service
+ - dummy.socket
+ notify: remove dummy indirect service
+
+- name: Ensure dummy indirect service is disabled
+ systemd:
+ name: "{{indirect_service}}"
+ enabled: false
+ register: dummy_disabled
+
+- assert:
+ that:
+ - dummy_disabled is not changed
+
+- name: Enable indirect service 1
+ systemd:
+ name: '{{ indirect_service }}'
+ enabled: true
+ register: systemd_enable_dummy_indirect_1
+
+- name: Enable indirect service 2
+ systemd:
+ name: '{{ indirect_service }}'
+ enabled: true
+ register: systemd_enable_dummy_indirect_2
+
+- assert:
+ that:
+ - systemd_enable_dummy_indirect_1 is changed
+ - systemd_enable_dummy_indirect_2 is not changed \ No newline at end of file
diff --git a/test/integration/targets/systemd/tasks/test_unit_template.yml b/test/integration/targets/systemd/tasks/test_unit_template.yml
new file mode 100644
index 0000000..47cb1c7
--- /dev/null
+++ b/test/integration/targets/systemd/tasks/test_unit_template.yml
@@ -0,0 +1,50 @@
+- name: Copy service file
+ template:
+ src: sleeper@.service
+ dest: /etc/systemd/system/sleeper@.service
+ owner: root
+ group: root
+ mode: '0644'
+ notify: remove unit file
+
+- name: Reload systemd
+ systemd:
+ daemon_reload: yes
+
+- name: Start and enable service using unit template
+ systemd:
+ name: sleeper@100.service
+ state: started
+ enabled: yes
+ register: template_test_1
+
+- name: Start and enable service using unit template again
+ systemd:
+ name: sleeper@100.service
+ state: started
+ enabled: yes
+ register: template_test_2
+
+- name: Stop and disable service using unit template
+ systemd:
+ name: sleeper@100.service
+ state: stopped
+ enabled: no
+ register: template_test_3
+
+- name: Stop and disable service using unit template again
+ systemd:
+ name: sleeper@100.service
+ state: stopped
+ enabled: no
+ register: template_test_4
+
+- name:
+ assert:
+ that:
+ - template_test_1 is changed
+ - template_test_1 is success
+ - template_test_2 is not changed
+ - template_test_2 is success
+ - template_test_3 is changed
+ - template_test_4 is not changed
diff --git a/test/integration/targets/systemd/templates/dummy.service b/test/integration/targets/systemd/templates/dummy.service
new file mode 100644
index 0000000..f38dce1
--- /dev/null
+++ b/test/integration/targets/systemd/templates/dummy.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Dummy Server
+Requires=dummy.socket
+Documentation=dummy
+
+[Service]
+ExecStart=/bin/yes
+StandardInput=socket
+
+[Install]
+Also=dummy.socket
diff --git a/test/integration/targets/systemd/templates/dummy.socket b/test/integration/targets/systemd/templates/dummy.socket
new file mode 100644
index 0000000..f23bf9b
--- /dev/null
+++ b/test/integration/targets/systemd/templates/dummy.socket
@@ -0,0 +1,8 @@
+[Unit]
+Description=Dummy Server Activation Socket
+
+[Socket]
+ListenDatagram=69
+
+[Install]
+WantedBy=sockets.target \ No newline at end of file
diff --git a/test/integration/targets/systemd/templates/sleeper@.service b/test/integration/targets/systemd/templates/sleeper@.service
new file mode 100644
index 0000000..8b47982
--- /dev/null
+++ b/test/integration/targets/systemd/templates/sleeper@.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Basic service to use as a template
+
+[Service]
+ExecStart={{ sleep_bin_path }} %i
+
+[Install]
+WantedBy=multi-user.target
diff --git a/test/integration/targets/systemd/vars/Debian.yml b/test/integration/targets/systemd/vars/Debian.yml
new file mode 100644
index 0000000..613410f
--- /dev/null
+++ b/test/integration/targets/systemd/vars/Debian.yml
@@ -0,0 +1,3 @@
+ssh_service: ssh
+sleep_bin_path: /bin/sleep
+indirect_service: dummy \ No newline at end of file
diff --git a/test/integration/targets/systemd/vars/default.yml b/test/integration/targets/systemd/vars/default.yml
new file mode 100644
index 0000000..0bf1f89
--- /dev/null
+++ b/test/integration/targets/systemd/vars/default.yml
@@ -0,0 +1,3 @@
+ssh_service: sshd
+indirect_service: dummy
+sleep_bin_path: /usr/bin/sleep