pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0222-Fix-ipa-config-mod-ca-renewal-master.patch

483b06
From 9a8352637aeb32ddffd83f4477695ec290da8429 Mon Sep 17 00:00:00 2001
483b06
From: Florence Blanc-Renaud <flo@redhat.com>
483b06
Date: Wed, 23 Aug 2017 16:31:18 +0200
483b06
Subject: [PATCH] Fix ipa config-mod --ca-renewal-master
483b06
483b06
commit bddb90f38a3505a2768862d2f814c5e749a7dcde added the support for
483b06
multivalued server attributes (for pkinit_server_server), but this
483b06
introduced an API change where the setter and getter of ServerAttribute
483b06
are expecting list of values.
483b06
483b06
When a SingleValuedServerAttribute is used, we need to convert one elem
483b06
into a list containing this elem and vice-versa, so that the ipa config-mod
483b06
and ipa config_show APIs are not modified.
483b06
483b06
https://pagure.io/freeipa/issue/7120
483b06
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
483b06
---
483b06
 ipaserver/plugins/serverroles.py            | 16 +++++++++++++++-
483b06
 ipatests/test_ipaserver/test_serverroles.py |  4 ++--
483b06
 2 files changed, 17 insertions(+), 3 deletions(-)
483b06
483b06
diff --git a/ipaserver/plugins/serverroles.py b/ipaserver/plugins/serverroles.py
483b06
index e81635c3315cc3fca84450f43fb7df883aae57d9..04e21090657197b9267f2ffc05048399a7ce3d38 100644
483b06
--- a/ipaserver/plugins/serverroles.py
483b06
+++ b/ipaserver/plugins/serverroles.py
483b06
@@ -46,6 +46,7 @@ from ipalib import errors, _
483b06
 from ipalib.backend import Backend
483b06
 from ipalib.plugable import Registry
483b06
 from ipaserver.servroles import (attribute_instances, ENABLED, role_instances)
483b06
+from ipaserver.servroles import SingleValuedServerAttribute
483b06
 
483b06
 
483b06
 if six.PY3:
483b06
@@ -136,13 +137,26 @@ class serverroles(Backend):
483b06
 
483b06
         for name, attr in assoc_attributes.items():
483b06
             attr_value = attr.get(self.api)
483b06
-            result.update({name: attr_value})
483b06
+
483b06
+            if attr_value:
483b06
+                # attr can be a SingleValuedServerAttribute
483b06
+                # in this case, the API expects a value, not a list of values
483b06
+                if isinstance(attr, SingleValuedServerAttribute):
483b06
+                    attr_value = attr_value[0]
483b06
+                result.update({name: attr_value})
483b06
 
483b06
         return result
483b06
 
483b06
     def config_update(self, **attrs_values):
483b06
         for attr, value in attrs_values.items():
483b06
             try:
483b06
+                # when the attribute is single valued, it will be stored
483b06
+                # in a SingleValuedServerAttribute. The set method expects
483b06
+                # a list containing a single value.
483b06
+                # We need to convert value to a list containing value
483b06
+                if isinstance(self.attributes[attr],
483b06
+                              SingleValuedServerAttribute):
483b06
+                    value = [value]
483b06
                 self.attributes[attr].set(self.api, value)
483b06
             except KeyError:
483b06
                 raise errors.NotFound(
483b06
diff --git a/ipatests/test_ipaserver/test_serverroles.py b/ipatests/test_ipaserver/test_serverroles.py
483b06
index 985c750b64f109e0a83686f31ddb3b8d4171072d..e8967517d0c65fb6e3daebf220cae7df38bfe044 100644
483b06
--- a/ipatests/test_ipaserver/test_serverroles.py
483b06
+++ b/ipatests/test_ipaserver/test_serverroles.py
483b06
@@ -715,7 +715,7 @@ class TestServerAttributes(object):
483b06
         non_ca_fqdn = mock_masters.get_fqdn('trust-controller-dns')
483b06
 
483b06
         with pytest.raises(errors.ValidationError):
483b06
-            self.config_update(mock_api, **{attr_name: [non_ca_fqdn]})
483b06
+            self.config_update(mock_api, **{attr_name: non_ca_fqdn})
483b06
 
483b06
     def test_set_unknown_attribute_on_master_raises_notfound(
483b06
             self, mock_api, mock_masters):
483b06
@@ -732,7 +732,7 @@ class TestServerAttributes(object):
483b06
         original_renewal_master = self.config_retrieve(
483b06
             role_name, mock_api)[attr_name]
483b06
 
483b06
-        other_ca_server = [mock_masters.get_fqdn('trust-controller-ca')]
483b06
+        other_ca_server = mock_masters.get_fqdn('trust-controller-ca')
483b06
 
483b06
         for host in (other_ca_server, original_renewal_master):
483b06
             self.config_update(mock_api, **{attr_name: host})
483b06
-- 
483b06
2.13.5
483b06