Andrew Bogott has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/392939 )

Change subject: Horizon puppet:  Merge role-associated hiera values with 
freeform hiera
......................................................................


Horizon puppet:  Merge role-associated hiera values with freeform hiera

Bug: T181196
Change-Id: I8d4276b58f86d659475170df754a2857cb870f02
---
M modules/openstack/files/mitaka/horizon/puppettab/puppet_config.py
M modules/openstack/files/mitaka/horizon/puppettab/views.py
2 files changed, 33 insertions(+), 2 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/openstack/files/mitaka/horizon/puppettab/puppet_config.py 
b/modules/openstack/files/mitaka/horizon/puppettab/puppet_config.py
index 7e2c5ca..671d335 100644
--- a/modules/openstack/files/mitaka/horizon/puppettab/puppet_config.py
+++ b/modules/openstack/files/mitaka/horizon/puppettab/puppet_config.py
@@ -82,7 +82,7 @@
                     if key.startswith(role):
                         # (len(role)+2) is the length of the rolename plus the 
::,
                         # getting us the raw param name
-                        argname = key[(len(role)+2):]
+                        argname = key[(len(role) + 2):]
                         if hiera_yaml[key]:
                             self.role_dict[role][argname] = hiera_yaml[key]
                             del hiera_yaml[key]
@@ -169,6 +169,37 @@
     def set_role_list(self, role_list):
         self.set_roles(role_list + self.other_classes)
 
+    # This function is for setting the hiera that's not attached
+    #  to parsed roles.  This needs to be separate from set_hiera below
+    #  so that we don't clear role params when the user edits the
+    #  free-form hiera field.
+    def set_roleless_hiera(self, hiera_yaml):
+        # Add role-associated hiera params to this freeform block before
+        #  sending it on to the backend
+
+        raw_hiera_yaml = yaml.safe_load(self.hiera_raw)
+        if not raw_hiera_yaml:
+            raw_hiera_yaml = {}
+        allrole_dict = {role.name: role for role in self.allroles}
+
+        # This next bit is the reverse of what we do to self.hiera in refresh()
+        for role in list(self.roles):
+            if role in allrole_dict:
+                self.role_dict[role] = {}
+                for key in raw_hiera_yaml.keys():
+                    if key.startswith(role):
+                        # (len(role)+2) is the length of the rolename plus the 
::,
+                        # getting us the raw param name
+                        if raw_hiera_yaml[key]:
+                            hiera_yaml[key] = raw_hiera_yaml[key]
+            elif role:
+                # This is an unknown role, so its hiera was already part of 
the freeform block.
+                pass
+
+        self.set_hiera(hiera_yaml)
+
+    # This function sets all hiera settings, including those that belong
+    #  to a set role in the UI
     def set_hiera(self, hiera_yaml):
         if not hiera_yaml:
             # The user probably cleared the field.  That's fine, we'll just
diff --git a/modules/openstack/files/mitaka/horizon/puppettab/views.py 
b/modules/openstack/files/mitaka/horizon/puppettab/views.py
index 1eaf027..2ad6b5d 100644
--- a/modules/openstack/files/mitaka/horizon/puppettab/views.py
+++ b/modules/openstack/files/mitaka/horizon/puppettab/views.py
@@ -43,7 +43,7 @@
 
     def handle(self, request, data):
         config = puppet_config(data['prefix'], data['tenant_id'])
-        config.set_hiera(yaml.safe_load(data['hieradata']))
+        config.set_roleless_hiera(yaml.safe_load(data['hieradata']))
         return True
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/392939
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8d4276b58f86d659475170df754a2857cb870f02
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to