Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing that service not enabled during check run #16739

Merged
merged 4 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/integration/roles/test_service/files/ansible.systemd
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Description=Ansible Test Service
ExecStart=/usr/sbin/ansible_test_service "Test\nthat newlines in scripts\nwork"
ExecReload=/bin/true
Type=forking

[Install]
WantedBy=multi-user.target
49 changes: 38 additions & 11 deletions test/integration/roles/test_service/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,47 @@
- "install_result.state == 'file'"
- "install_result.mode == '0755'"

- include: 'sysv_setup.yml'
# determine init system is in use
- name: detect sysv init system
set_fact: service_type=sysv
when: ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and (ansible_distribution_version|version_compare('6', '>=') and ansible_distribution_version|version_compare('7', '<'))
- include: 'systemd_setup.yml'
- name: detect systemd init system
set_fact: service_type=systemd
when: (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and (ansible_distribution_version|version_compare('7', '>=') and ansible_distribution_version|version_compare('8', '<'))) or ansible_distribution == 'Fedora' or (ansible_distribution == 'Ubuntu' and ansible_distribution_version|version_compare('15.04', '>=')) or (ansible_distribution == 'Debian' and ansible_distribution_version|version_compare('8', '>=')) or ansible_os_family == 'Suse'
- include: 'upstart_setup.yml'
- name: detect upstart init system
set_fact: service_type=upstart
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version|version_compare('15.04', '<')

# setup test service script
- include: 'sysv_setup.yml'
when: service_type == "sysv"
- include: 'systemd_setup.yml'
when: service_type == "systemd"
- include: 'upstart_setup.yml'
when: service_type == "upstart"

- name: disable the ansible test service
service: name=ansible_test enabled=no

- name: (check mode run) enable the ansible test service
service: name=ansible_test enabled=yes
register: enable_in_check_mode_result
check_mode: yes

- name: assert that changes reported for check mode run
assert:
that:
- "enable_in_check_mode_result.changed == true"

- name: enable the ansible test service
service: name=ansible_test enabled=yes
register: enable_result

- name: assert that the service was enabled
- name: assert that the service was enabled and changes reported
assert:
that:
- "enable_result.enabled == true"
- "enable_result.changed == true"

- name: start the ansible test service
service: name=ansible_test state=started
Expand All @@ -38,6 +64,7 @@
- name: find the service with a pattern
service: name=ansible_test pattern="ansible_test_ser*" state=started
register: start2_result
# don't enable this check yet on systems with systemd because of https://github.com/ansible/ansible/issues/16694
when: service_type != "systemd"

- name: assert that the service was started via the pattern
Expand All @@ -50,17 +77,16 @@
- name: restart the ansible test service
service: name=ansible_test state=restarted
register: restart_result
when: service_type != "systemd"

- name: assert that the service was restarted
assert:
that:
- "restart_result.state == 'started'"
when: service_type != "systemd"

- name: restart the ansible test service with a sleep
service: name=ansible_test state=restarted sleep=2
register: restart_sleep_result
# don't enable this check yet on systems with systemd because of https://github.com/ansible/ansible/issues/16694
when: service_type != "systemd"

- name: assert that the service was restarted with a sleep
Expand All @@ -72,6 +98,8 @@
- name: reload the ansible test service
service: name=ansible_test state=reloaded
register: reload_result
# don't do this on systems with systemd because it triggers error:
# Unable to reload service ansible_test: ansible_test.service is not active, cannot reload.
when: service_type != "systemd"

- name: assert that the service was reloaded
Expand All @@ -92,13 +120,11 @@
- name: disable the ansible test service
service: name=ansible_test enabled=no
register: disable_result
when: service_type != "systemd"

- name: assert that the service was disabled
assert:
that:
- "disable_result.enabled == false"
when: service_type != "systemd"

- name: try to enable a broken service
service: name=ansible_broken_test enabled=yes
Expand All @@ -120,9 +146,10 @@
- "remove_result.path == '/usr/sbin/ansible_test_service'"
- "remove_result.state == 'absent'"

# cleaning up changes made by this playbook
- include: 'sysv_cleanup.yml'
when: ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
when: service_type == "sysv"
- include: 'systemd_cleanup.yml'
when: ansible_distribution == 'Fedora'
when: service_type == "systemd"
- include: 'upstart_cleanup.yml'
when: ansible_distribution == 'Ubuntu'
when: service_type == "upstart"
6 changes: 1 addition & 5 deletions test/integration/roles/test_service/tasks/systemd_setup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- name: set service_type fact
set_fact: service_type=systemd

- name: install the systemd unit file
copy: src=ansible.systemd dest=/etc/systemd/system/ansible_test.service
register: install_systemd_result
Expand All @@ -15,7 +12,6 @@
- "install_systemd_result.dest == '/etc/systemd/system/ansible_test.service'"
- "install_systemd_result.state == 'file'"
- "install_systemd_result.mode == '0644'"
- "install_systemd_result.checksum == 'ca4b413fdf3cb2002f51893b9e42d2e449ec5afb'"
- "install_systemd_result.checksum == '6b5f2b9318524a387c77c550cef4dd411a471acf'"
- "install_broken_systemd_result.dest == '/etc/systemd/system/ansible_test_broken.service'"
- "install_broken_systemd_result.state == 'link'"

3 changes: 0 additions & 3 deletions test/integration/roles/test_service/tasks/sysv_setup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- name: set service_type fact
set_fact: service_type=sysv

- name: install the sysV init file
copy: src=ansible.sysv dest=/etc/init.d/ansible_test mode=0755
register: install_sysv_result
Expand Down
3 changes: 0 additions & 3 deletions test/integration/roles/test_service/tasks/upstart_setup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- name: set service_type fact
set_fact: service_type=upstart

- name: install the upstart init file
copy: src=ansible.upstart dest=/etc/init/ansible_test.conf mode=0644
register: install_upstart_result
Expand Down