From 39d5558bd2c06b075b2d6175f5d97bcc94b1b8a5 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
Date: Fri, 21 Aug 2020 16:27:43 -0300
Subject: [PATCH] Add IPA version verification for ipaconfig's maxhostname
 tests.

The config attributte maxhostname is only available after IPA
version 4.8.0. The tests for this attribute are now protected to
not run if a previous IPA version is found.
---
 tests/config/test_config.yml | 57 +++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 20 deletions(-)

diff --git a/tests/config/test_config.yml b/tests/config/test_config.yml
index c288e451..e1d33f79 100644
--- a/tests/config/test_config.yml
+++ b/tests/config/test_config.yml
@@ -5,6 +5,8 @@
   gather_facts: false
 
   tasks:
+  - include_tasks: ../env_freeipa_facts.yml
+
   # Retrieve current configuration.
   - name: return current values of the global configuration options
     ipaconfig:
@@ -45,15 +47,17 @@
       ipaadmin_password: SomeADMINpassword
       pac_type: ""
 
-  - name: set maxusername to 255
-    ipaconfig:
-      ipaadmin_password: SomeADMINpassword
-      maxusername: 255
-
   - name: set maxhostname to 255
+    block:
+      - ipaconfig:
+          ipaadmin_password: SomeADMINpassword
+          maxhostname: 255
+    when: ipa_version is version('4.8.0', '>=')
+
+  - name: set maxusername to 45
     ipaconfig:
       ipaadmin_password: SomeADMINpassword
-      maxhostname: 255
+      maxusername: 45
 
   - name: set pwdexpnotify to 0
     ipaconfig:
@@ -186,18 +190,19 @@
     failed_when: result.changed
 
   - name: set maxhostname to 77
-    ipaconfig:
-      ipaadmin_password: SomeADMINpassword
-      maxhostname: 77
-    register: result
-    failed_when: not result.changed
-
-  - name: set maxhostname to 77, again
-    ipaconfig:
-      ipaadmin_password: SomeADMINpassword
-      maxhostname: 77
-    register: result
-    failed_when: result.changed
+    block:
+      - ipaconfig:
+          ipaadmin_password: SomeADMINpassword
+          maxhostname: 77
+        register: result
+        failed_when: not result.changed
+
+      - ipaconfig:
+          ipaadmin_password: SomeADMINpassword
+          maxhostname: 77
+        register: result
+        failed_when: result.changed
+    when: ipa_version is version('4.8.0', '>=')
 
   - name: set pwdexpnotify to 17
     ipaconfig:
@@ -329,7 +334,6 @@
     ipaconfig:
       ipaadmin_password: 'SomeADMINpassword'
       maxusername: '{{previousconfig.config.maxusername | default(omit)}}'
-      maxhostname: '{{previousconfig.config.maxhostname | default(omit)}}'
       homedirectory: '{{previousconfig.config.homedirectory | default(omit)}}'
       defaultshell: '{{previousconfig.config.defaultshell | default(omit)}}'
       defaultgroup: '{{previousconfig.config.defaultgroup | default(omit)}}'
@@ -352,11 +356,17 @@
     register: result
     failed_when: not result.changed
 
+  - name: reset maxhostname
+    block:
+      - ipaconfig:
+          ipaadmin_password: SomeADMINpassword
+          maxhostname: '{{previousconfig.config.maxhostname | default(omit)}}'
+    when: ipa_version is version('4.8.0', '>=')
+
   - name: reset changed fields, again
     ipaconfig:
       ipaadmin_password: 'SomeADMINpassword'
       maxusername: '{{previousconfig.config.maxusername | default(omit)}}'
-      maxhostname: '{{previousconfig.config.maxhostname | default(omit)}}'
       homedirectory: '{{previousconfig.config.homedirectory | default(omit)}}'
       defaultshell: '{{previousconfig.config.defaultshell | default(omit)}}'
       defaultgroup: '{{previousconfig.config.defaultgroup | default(omit)}}'
@@ -379,6 +389,13 @@
     register: result
     failed_when: result.changed
 
+  - name: reset maxhostname
+    block:
+      - ipaconfig:
+          ipaadmin_password: SomeADMINpassword
+          maxhostname: '{{previousconfig.config.maxhostname | default(omit)}}'
+    when: ipa_version is version('4.8.0', '>=')
+
   # cleanup
 
   - name: cleanup test group
-- 
GitLab