Testing that service not enabled during check run (#16739)
* Enabled more tests in test_service on systems with systemd. * Fix inconsistency in cleaning up test service. The conditions for service setup and service cleanup were different. * Add check mode run for service enable.
This commit is contained in:
parent
380ed053e8
commit
2bc679be07
5 changed files with 42 additions and 22 deletions
|
@ -5,3 +5,6 @@ Description=Ansible Test Service
|
||||||
ExecStart=/usr/sbin/ansible_test_service "Test\nthat newlines in scripts\nwork"
|
ExecStart=/usr/sbin/ansible_test_service "Test\nthat newlines in scripts\nwork"
|
||||||
ExecReload=/bin/true
|
ExecReload=/bin/true
|
||||||
Type=forking
|
Type=forking
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -10,21 +10,47 @@
|
||||||
- "install_result.state == 'file'"
|
- "install_result.state == 'file'"
|
||||||
- "install_result.mode == '0755'"
|
- "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', '<'))
|
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'
|
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', '<')
|
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
|
- name: enable the ansible test service
|
||||||
service: name=ansible_test enabled=yes
|
service: name=ansible_test enabled=yes
|
||||||
register: enable_result
|
register: enable_result
|
||||||
|
|
||||||
- name: assert that the service was enabled
|
- name: assert that the service was enabled and changes reported
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "enable_result.enabled == true"
|
- "enable_result.enabled == true"
|
||||||
|
- "enable_result.changed == true"
|
||||||
|
|
||||||
- name: start the ansible test service
|
- name: start the ansible test service
|
||||||
service: name=ansible_test state=started
|
service: name=ansible_test state=started
|
||||||
|
@ -38,6 +64,7 @@
|
||||||
- name: find the service with a pattern
|
- name: find the service with a pattern
|
||||||
service: name=ansible_test pattern="ansible_test_ser*" state=started
|
service: name=ansible_test pattern="ansible_test_ser*" state=started
|
||||||
register: start2_result
|
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"
|
when: service_type != "systemd"
|
||||||
|
|
||||||
- name: assert that the service was started via the pattern
|
- name: assert that the service was started via the pattern
|
||||||
|
@ -50,17 +77,16 @@
|
||||||
- name: restart the ansible test service
|
- name: restart the ansible test service
|
||||||
service: name=ansible_test state=restarted
|
service: name=ansible_test state=restarted
|
||||||
register: restart_result
|
register: restart_result
|
||||||
when: service_type != "systemd"
|
|
||||||
|
|
||||||
- name: assert that the service was restarted
|
- name: assert that the service was restarted
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "restart_result.state == 'started'"
|
- "restart_result.state == 'started'"
|
||||||
when: service_type != "systemd"
|
|
||||||
|
|
||||||
- name: restart the ansible test service with a sleep
|
- name: restart the ansible test service with a sleep
|
||||||
service: name=ansible_test state=restarted sleep=2
|
service: name=ansible_test state=restarted sleep=2
|
||||||
register: restart_sleep_result
|
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"
|
when: service_type != "systemd"
|
||||||
|
|
||||||
- name: assert that the service was restarted with a sleep
|
- name: assert that the service was restarted with a sleep
|
||||||
|
@ -72,6 +98,8 @@
|
||||||
- name: reload the ansible test service
|
- name: reload the ansible test service
|
||||||
service: name=ansible_test state=reloaded
|
service: name=ansible_test state=reloaded
|
||||||
register: reload_result
|
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"
|
when: service_type != "systemd"
|
||||||
|
|
||||||
- name: assert that the service was reloaded
|
- name: assert that the service was reloaded
|
||||||
|
@ -92,13 +120,11 @@
|
||||||
- name: disable the ansible test service
|
- name: disable the ansible test service
|
||||||
service: name=ansible_test enabled=no
|
service: name=ansible_test enabled=no
|
||||||
register: disable_result
|
register: disable_result
|
||||||
when: service_type != "systemd"
|
|
||||||
|
|
||||||
- name: assert that the service was disabled
|
- name: assert that the service was disabled
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "disable_result.enabled == false"
|
- "disable_result.enabled == false"
|
||||||
when: service_type != "systemd"
|
|
||||||
|
|
||||||
- name: try to enable a broken service
|
- name: try to enable a broken service
|
||||||
service: name=ansible_broken_test enabled=yes
|
service: name=ansible_broken_test enabled=yes
|
||||||
|
@ -120,9 +146,10 @@
|
||||||
- "remove_result.path == '/usr/sbin/ansible_test_service'"
|
- "remove_result.path == '/usr/sbin/ansible_test_service'"
|
||||||
- "remove_result.state == 'absent'"
|
- "remove_result.state == 'absent'"
|
||||||
|
|
||||||
|
# cleaning up changes made by this playbook
|
||||||
- include: 'sysv_cleanup.yml'
|
- include: 'sysv_cleanup.yml'
|
||||||
when: ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
|
when: service_type == "sysv"
|
||||||
- include: 'systemd_cleanup.yml'
|
- include: 'systemd_cleanup.yml'
|
||||||
when: ansible_distribution == 'Fedora'
|
when: service_type == "systemd"
|
||||||
- include: 'upstart_cleanup.yml'
|
- include: 'upstart_cleanup.yml'
|
||||||
when: ansible_distribution == 'Ubuntu'
|
when: service_type == "upstart"
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
- name: set service_type fact
|
|
||||||
set_fact: service_type=systemd
|
|
||||||
|
|
||||||
- name: install the systemd unit file
|
- name: install the systemd unit file
|
||||||
copy: src=ansible.systemd dest=/etc/systemd/system/ansible_test.service
|
copy: src=ansible.systemd dest=/etc/systemd/system/ansible_test.service
|
||||||
register: install_systemd_result
|
register: install_systemd_result
|
||||||
|
@ -15,7 +12,6 @@
|
||||||
- "install_systemd_result.dest == '/etc/systemd/system/ansible_test.service'"
|
- "install_systemd_result.dest == '/etc/systemd/system/ansible_test.service'"
|
||||||
- "install_systemd_result.state == 'file'"
|
- "install_systemd_result.state == 'file'"
|
||||||
- "install_systemd_result.mode == '0644'"
|
- "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.dest == '/etc/systemd/system/ansible_test_broken.service'"
|
||||||
- "install_broken_systemd_result.state == 'link'"
|
- "install_broken_systemd_result.state == 'link'"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
- name: set service_type fact
|
|
||||||
set_fact: service_type=sysv
|
|
||||||
|
|
||||||
- name: install the sysV init file
|
- name: install the sysV init file
|
||||||
copy: src=ansible.sysv dest=/etc/init.d/ansible_test mode=0755
|
copy: src=ansible.sysv dest=/etc/init.d/ansible_test mode=0755
|
||||||
register: install_sysv_result
|
register: install_sysv_result
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
- name: set service_type fact
|
|
||||||
set_fact: service_type=upstart
|
|
||||||
|
|
||||||
- name: install the upstart init file
|
- name: install the upstart init file
|
||||||
copy: src=ansible.upstart dest=/etc/init/ansible_test.conf mode=0644
|
copy: src=ansible.upstart dest=/etc/init/ansible_test.conf mode=0644
|
||||||
register: install_upstart_result
|
register: install_upstart_result
|
||||||
|
|
Loading…
Reference in a new issue