[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cobbler-devel
Subject:    patch - update parents of profiles / systems after editing
From:       Mark Levedahl <mlevedahl () gmail ! com>
Date:       2010-11-26 20:42:07
Message-ID: 4CF01B9F.1000601 () gmail ! com
[Download RAW message or body]

With this change, the parents of systems and profiles are updated when
the user edits them. This fixes a really nasty bug wherein objects are
deleted when deleting a former (but not current) parent, e.g.

  1. change profile for 20 systems from Fedora-12 to Fedora-14
  2. delete Fedora-12
  3. Before this patch, the profile and 20 system definitions would
     be deleted as the profile's parent is still Fedora-12.  :^(
  4. With this patch, only the now unused distro (Fedora-12) is deleted.

-Mark

["0001-item_-profile-system-update-parents-after-editing.patch" (text/x-patch)]

>From 58930a2b2d5454eff3b12ecaab0f3d72d9696ebe Mon Sep 17 00:00:00 2001
From: Mark Levedahl <mlevedahl@gmail.com>
Date: Fri, 26 Nov 2010 15:30:46 -0500
Subject: [PATCH] item_[profile|system] - update parents after editing

With this change, the parents of systems and profiles are updated when
the user edits them. This fixes a really nasty bug wherein objects are
deleted when deleting a former (but not current) parent, e.g.

 1. change profile for 20 systems from Fedora-12 to Fedora-14
 2. delete Fedora-12
 3. Before this patch, the profile and 20 system definitions would
    be deleted as the profile's parent is still Fedora-12.  :^(
 4. With this patch, only the now unused distro (Fedora-12) is deleted.
---
 cobbler/item_profile.py |   11 +++++++++++
 cobbler/item_system.py  |   16 ++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cobbler/item_profile.py b/cobbler/item_profile.py
index 047ea62..806ae01 100644
--- a/cobbler/item_profile.py
+++ b/cobbler/item_profile.py
@@ -89,6 +89,10 @@ class Profile(item.Item):
         work.  So, API users -- make sure you pass is_subobject=True into the
         constructor when using this.
         """
+
+        old_parent = self.get_parent()
+        if isinstance(old_parent, item.Item):
+            old_parent.children.pop(self.name, 'pass')
         if parent_name is None or parent_name == '':
            self.parent = ''
            return True
@@ -101,6 +105,9 @@ class Profile(item.Item):
            raise CX(_("profile %s not found, inheritance not possible") % parent_name)
         self.parent = parent_name       
         self.depth = found.depth + 1
+        parent = self.get_parent()
+        if isinstance(parent, item.Item):
+            parent.children[self.name] = self
         return True
 
     def set_distro(self,distro_name):
@@ -110,8 +117,12 @@ class Profile(item.Item):
 	"""
         d = self.config.distros().find(name=distro_name)
         if d is not None:
+            old_parent = self.get_parent()
+            if isinstance(old_parent, item.Item):
+                old_parent.children.pop(self.name, 'pass')
             self.distro = distro_name
             self.depth  = d.depth +1 # reset depth if previously a subprofile and now top-level
+            d.children[self.name] = self
             return True
         raise CX(_("distribution not found"))
 
diff --git a/cobbler/item_system.py b/cobbler/item_system.py
index 33d5c18..b802452 100644
--- a/cobbler/item_system.py
+++ b/cobbler/item_system.py
@@ -369,8 +369,11 @@ class System(item.Item):
         Set the system to use a certain named profile.  The profile
         must have already been loaded into the Profiles collection.
         """
+        old_parent = self.get_parent()
         if profile_name in [ "delete", "None", "~", ""] or profile_name is None:
             self.profile = ""
+            if isinstance(old_parent, item.Item):
+                old_parent.children.pop(self.name, 'pass')
             return True
 
         self.image = "" # mutual exclusion rule
@@ -379,6 +382,11 @@ class System(item.Item):
         if p is not None:
             self.profile = profile_name
             self.depth = p.depth + 1 # subprofiles have varying depths.
+            if isinstance(old_parent, item.Item):
+                old_parent.children.pop(self.name, 'pass')
+            new_parent = self.get_parent()
+            if isinstance(new_parent, item.Item):
+                new_parent.children[self.name] = self
             return True
         raise CX(_("invalid profile name: %s") % profile_name)
 
@@ -387,8 +395,11 @@ class System(item.Item):
         Set the system to use a certain named image.  Works like set_profile
         but cannot be used at the same time.  It's one or the other.
         """
+        old_parent = self.get_parent()
         if image_name in [ "delete", "None", "~", ""] or image_name is None:
             self.image = ""
+            if isinstance(old_parent, item.Item):
+                old_parent.children.pop(self.name, 'pass')
             return True
 
         self.profile = "" # mutual exclusion rule
@@ -398,6 +409,11 @@ class System(item.Item):
         if img is not None:
             self.image = image_name
             self.depth = img.depth + 1
+            if isinstance(old_parent, item.Item):
+                old_parent.children.pop(self.name, 'pass')
+            new_parent = self.get_parent()
+            if isinstance(new_parent, item.Item):
+                new_parent.children[self.name] = self
             return True
         raise CX(_("invalid image name (%s)") % image_name)
 
-- 
9.1.7.3.2.364.g3d778



_______________________________________________
cobbler-devel mailing list
cobbler-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/cobbler-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic