From 3ab575bcac310166e7d29c5a5349d90482f4e629 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
Date: Tue, 11 Aug 2020 17:27:56 -0300
Subject: [PATCH] Reorganize service module tests.

Modify old service module tests to use setup and cleanup include
files to make test environment more consistent.
---
 tests/service/test_service.yml                | 175 +-----------------
 .../test_service_without_skip_host_check.yml  | 137 +-------------
 2 files changed, 8 insertions(+), 304 deletions(-)

diff --git a/tests/service/test_service.yml b/tests/service/test_service.yml
index 26f509ef..7035bb9e 100644
--- a/tests/service/test_service.yml
+++ b/tests/service/test_service.yml
@@ -17,109 +17,8 @@
 
   tasks:
   # setup
-  - name: Get Domain from server name
-    set_fact:
-      ipaserver_domain: "{{ ansible_fqdn.split('.')[1:] | join ('.') }}"
-    when: ipaserver_domain is not defined
-
-  - name: Set host1, host2 and svc hosts fqdn
-    set_fact:
-      host1_fqdn: "{{ 'host1.' + ipaserver_domain }}"
-      host2_fqdn: "{{ 'host2.' + ipaserver_domain }}"
-      svc_fqdn: "{{ 'svc.' + ipaserver_domain }}"
-      nohost_fqdn: "{{ 'nohost.' + ipaserver_domain }}"
-
-  - name: Remove IP address for "nohost" host.
-    ipadnsrecord:
-      ipaadmin_password: SomeADMINpassword
-      zone_name: "{{ ipaserver_domain }}"
-      name: nohost
-      del_all: yes
-      state: absent
-
-  - name: Host absent
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "{{ nohost_fqdn }}"
-      - no.idontexist.info
-      - svc.ihavenodns.info
-      - "{{ host1_fqdn }}"
-      - "{{ host2_fqdn }}"
-      - "{{ svc_fqdn }}"
-      update_dns: no
-      state: absent
-
-  - name: Get IPv4 address prefix from server node
-    set_fact:
-      ipv4_prefix: "{{ ansible_default_ipv4.address.split('.')[:-1] |
-                       join('.') }}"
-
-  - name: Add IP address for "nohost" host.
-    ipadnsrecord:
-      ipaadmin_password: SomeADMINpassword
-      zone_name: "{{ ipaserver_domain }}"
-      name: nohost
-      a_ip_address: "{{ ipv4_prefix + '.100' }}"
-
-  - name: Add hosts for tests.
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      hosts:
-          - name: "{{ host1_fqdn }}"
-            ip_address: "{{ ipv4_prefix + '.101' }}"
-          - name: "{{ host2_fqdn }}"
-            ip_address: "{{ ipv4_prefix + '.102' }}"
-            force: yes
-          - name: "{{ svc_fqdn }}"
-            ip_address: "{{ ipv4_prefix + '.201' }}"
-          - name: svc.ihavenodns.info
-            force: yes
-      update_dns: yes
-
-  - name: Ensure testing user user01 is present.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name: user01
-      first: user01
-      last: last
-
-  - name: Ensure testing user user02 is present.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name: user02
-      first: user02
-      last: last
-
-  - name: Ensure testing group group01 is present.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name: group01
-
-  - name: Ensure testing group group02 is present.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name: group02
-
-  - name: Ensure testing hostgroup hostgroup01 is present.
-    ipahostgroup:
-      ipaadmin_password: SomeADMINpassword
-      name: hostgroup01
-
-  - name: Ensure testing hostgroup hostgroup02 is present.
-    ipahostgroup:
-      ipaadmin_password: SomeADMINpassword
-      name: hostgroup02
-
-  - name: Ensure services are absent.
-    ipaservice:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "HTTP/{{ svc_fqdn }}"
-      - "HTTP/{{ nohost_fqdn }}"
-      - HTTP/svc.ihavenodns.info
-      - HTTP/no.idontexist.info
-      state: absent
+  - name: Setup test environment
+    include_tasks: env_setup.yml
 
   # tests
   - name: Ensure service is present
@@ -476,7 +375,6 @@
     register: result
     failed_when: result.changed
 
-  #
   - name: Ensure service is absent
     ipaservice:
       ipaadmin_password: SomeADMINpassword
@@ -594,70 +492,5 @@
     failed_when: result.changed
 
   # cleanup
-
-  - name: Ensure services are absent.
-    ipaservice:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "HTTP/{{ svc_fqdn }}"
-      - "HTTP/{{ nohost_fqdn }}"
-      - HTTP/svc.ihavenodns.info
-      - HTTP/no.idontexist.local
-      - "cifs/{{ host1_fqdn }}"
-      state: absent
-
-  - name: Ensure host "{{ svc_fqdn }}" is absent
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      name: "{{ svc_fqdn }}"
-      update_dns: yes
-      state: absent
-
-  - name: Ensure host is absent
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "{{ host1_fqdn }}"
-      - "{{ host2_fqdn }}"
-      - "{{ nohost_fqdn }}"
-      - svc.ihavenodns.info
-      update_dns: no
-      state: absent
-
-  - name: Ensure testing users are absent.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - user01
-      - user02
-      state: absent
-
-  - name: Ensure testing groups are absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - group01
-      - group02
-      state: absent
-
-  - name: Ensure testing hostgroup hostgroup01 is absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - hostgroup01
-      state: absent
-
-  - name: Ensure testing hostgroup hostgroup02 is absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - hostgroup02
-      state: absent
-
-  - name: Remove IP address for "nohost" host.
-    ipadnsrecord:
-      ipaadmin_password: SomeADMINpassword
-      zone_name: "{{ ipaserver_domain }}"
-      name: nohost
-      del_all: yes
-      state: absent
+  - name: Cleanup test environment
+    include_tasks: env_cleanup.yml
diff --git a/tests/service/test_service_without_skip_host_check.yml b/tests/service/test_service_without_skip_host_check.yml
index ce703e9a..0f89cc72 100644
--- a/tests/service/test_service_without_skip_host_check.yml
+++ b/tests/service/test_service_without_skip_host_check.yml
@@ -5,91 +5,8 @@
 
   tasks:
   # setup
-  - name: Get Domain from server name
-    set_fact:
-      ipaserver_domain: "{{ ansible_fqdn.split('.')[1:] | join ('.') }}"
-    when: ipaserver_domain is not defined
-
-  - name: Set host1, host2 and svc hosts fqdn
-    set_fact:
-      host1_fqdn: "{{ 'host1.' + ipaserver_domain }}"
-      host2_fqdn: "{{ 'host2.' + ipaserver_domain }}"
-      svc_fqdn: "{{ 'svc.' + ipaserver_domain }}"
-
-  - name: Host absent
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - svc.ihavenodns.info
-      - "{{ host1_fqdn }}"
-      - "{{ host2_fqdn }}"
-      - "{{ svc_fqdn }}"
-      update_dns: yes
-      state: absent
-
-  - name: Get IPv4 address prefix from server node
-    set_fact:
-      ipv4_prefix: "{{ ansible_default_ipv4.address.split('.')[:-1] |
-                       join('.') }}"
-
-  - name: Add hosts for tests.
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      hosts:
-      - name: "{{ host1_fqdn }}"
-        ip_address: "{{ ipv4_prefix + '.201' }}"
-        update_dns: yes
-      - name: "{{ host2_fqdn }}"
-        ip_address: "{{ ipv4_prefix + '.202' }}"
-        update_dns: yes
-      - name: "{{ svc_fqdn }}"
-        ip_address: "{{ ipv4_prefix + '.203' }}"
-        update_dns: yes
-      - name: svc.ihavenodns.info
-        update_dns: no
-        force: yes
-
-  - name: Ensure testing user user01 is present.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name: user01
-      first: user01
-      last: last
-
-  - name: Ensure testing user user02 is present.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name: user02
-      first: user02
-      last: last
-
-  - name: Ensure testing group group01 is present.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name: group01
-
-  - name: Ensure testing group group02 is present.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name: group02
-
-  - name: Ensure testing hostgroup hostgroup01 is present.
-    ipahostgroup:
-      ipaadmin_password: SomeADMINpassword
-      name: hostgroup01
-
-  - name: Ensure testing hostgroup hostgroup02 is present.
-    ipahostgroup:
-      ipaadmin_password: SomeADMINpassword
-      name: hostgroup02
-
-  - name: Ensure services are absent.
-    ipaservice:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "HTTP/{{ svc_fqdn }}"
-      - HTTP/svc.ihavenodns.info
-      state: absent
+  - name: Setup test environment
+    include_tasks: env_setup.yml
 
   # tests
   - name: Ensure service is present
@@ -426,51 +343,5 @@
     failed_when: result.changed
 
   # cleanup
-
-  - name: Ensure services are absent.
-    ipaservice:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "HTTP/{{ svc_fqdn }}"
-      - HTTP/svc.ihavenodns.info
-      state: absent
-
-  - name: Ensure host is absent
-    ipahost:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - "{{ svc_fqdn }}"
-      - "{{ host1_fqdn }}"
-      - "{{ host2_fqdn }}"
-      - svc.ihavenodns.info
-      state: absent
-
-  - name: Ensure testing users are absent.
-    ipauser:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - user01
-      - user02
-      state: absent
-
-  - name: Ensure testing groups are absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - group01
-      - group02
-      state: absent
-
-  - name: Ensure testing hostgroup hostgroup01 is absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - hostgroup01
-      state: absent
-
-  - name: Ensure testing hostgroup hostgroup02 is absent.
-    ipagroup:
-      ipaadmin_password: SomeADMINpassword
-      name:
-      - hostgroup02
-      state: absent
+  - name: Cleanup test environment
+    include_tasks: env_cleanup.yml
-- 
GitLab