URL: https://github.com/freeipa/freeipa/pull/3465
Author: tiran
 Title: #3465: [Backport][ipa-4-8] test_xmlrpc: fix 
TestAutomemberFindOrphans.test_find_orphan_automembe…
Action: opened

PR body:
"""
This PR was opened automatically because PR #3413 was pushed to master and 
backport to ipa-4-8 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/3465/head:pr3465
git checkout pr3465
From 49d30bad4c8fb54dc3c4dae32ea838fc1c75e261 Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <f...@redhat.com>
Date: Thu, 18 Jul 2019 15:01:15 +0200
Subject: [PATCH] test_xmlrpc: fix
 TestAutomemberFindOrphans.test_find_orphan_automember_rules

Test scenario:
- create a hostgroup
- create a host
- create an automember rule for the hostgroup with a condition fulfilled
by the host
- delete the hostgroup
- call automember-rebuild (1)
- call automember-find-orphans to remove the orphan automember group
- call automember-rebuild(2)

The test was expecting the first rebuild command to fail but this
assumption is not true if the DS version is >= 1.4.0.22 because of the
fix for https://pagure.io/389-ds-base/issue/50077

Modify the test so that it expects failure only when DS is older.

Fixes: https://pagure.io/freeipa/issue/7902
---
 .../test_xmlrpc/test_automember_plugin.py     | 24 ++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_automember_plugin.py b/ipatests/test_xmlrpc/test_automember_plugin.py
index f1a5f1b81a..21ee880b83 100644
--- a/ipatests/test_xmlrpc/test_automember_plugin.py
+++ b/ipatests/test_xmlrpc/test_automember_plugin.py
@@ -35,7 +35,9 @@
 
 import time
 import pytest
+import re
 import unittest
+from pkg_resources import parse_version
 
 try:
     from ipaserver.plugins.ldap2 import ldap2
@@ -885,7 +887,6 @@ def test_create_deps_for_find_orphans(self, hostgroup1, host1,
 
         hostgroup1.retrieve()
 
-    @pytest.mark.skip(reason="Fails with 389-DS 1.4.0.22, see issue 7902")
     def test_find_orphan_automember_rules(self, hostgroup1):
         """ Remove hostgroup1, find and remove obsolete automember rules. """
         # Remove hostgroup1
@@ -893,12 +894,29 @@ def test_find_orphan_automember_rules(self, hostgroup1):
         hostgroup1.ensure_missing()
 
         # Test rebuild (is failing)
+        # rebuild fails if 389-ds is older than 1.4.0.22 where unmembering
+        # feature was implemented: https://pagure.io/389-ds-base/issue/50077
+        if not have_ldap2:
+            raise unittest.SkipTest('server plugin not available')
+        ldap = ldap2(api)
+        ldap.connect()
+        rootdse = ldap.get_entry(DN(''), ['vendorVersion'])
+        version = rootdse.single_value.get('vendorVersion')
+        # The format of vendorVersion is the following:
+        # 389-Directory/1.3.8.4 B2019.037.1535
+        # Extract everything between 389-Directory/ and ' B'
+        mo = re.search(r'389-Directory/(.*) B', version)
+        vendor_version = parse_version(mo.groups()[0])
+        expected_failure = vendor_version < parse_version('1.4.0.22')
+
         try:
             api.Command['automember_rebuild'](type=u'hostgroup')
         except errors.DatabaseError:
-            pass
+            rebuild_failure = True
         else:
-            pytest.fail("automember_rebuild was not failing with "
+            rebuild_failure = False
+        if expected_failure != rebuild_failure:
+            pytest.fail("unexpected result for automember_rebuild with "
                         "an orphan automember rule")
 
         # Find obsolete automember rules
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to