Automatically cleanup _temporary_ids at save
authorIustin Pop <iustin@google.com>
Wed, 23 Sep 2009 16:39:05 +0000 (18:39 +0200)
committerIustin Pop <iustin@google.com>
Thu, 24 Sep 2009 11:37:09 +0000 (13:37 +0200)
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/config.py

index 487d480..46f4134 100644 (file)
@@ -207,6 +207,13 @@ class ConfigWriter:
     self._temporary_ids.add(unique_id)
     return unique_id
 
+  def _CleanupTemporaryIDs(self):
+    """Cleanups the _temporary_ids structure.
+
+    """
+    existing = self._AllIDs(include_temporary=False)
+    self._temporary_ids = self._temporary_ids - existing
+
   def _AllMACs(self):
     """Return all MACs present in the config.
 
@@ -1119,6 +1126,10 @@ class ConfigWriter:
     """Write the configuration data to persistent storage.
 
     """
+    # first, cleanup the _temporary_ids set, if an ID is now in the
+    # other objects it should be discarded to prevent unbounded growth
+    # of that structure
+    self._CleanupTemporaryIDs()
     config_errors = self._UnlockedVerifyConfig()
     if config_errors:
       raise errors.ConfigurationError("Configuration data is not"