Antoni Segura Puimedon has uploaded a new change for review.

Change subject: netconf_persistence: teach PersistentConfig to atomically store 
itself
......................................................................

netconf_persistence: teach PersistentConfig to atomically store itself

This will be used by the test code and in the future by a python
vdsm-store-net-config.

Change-Id: Ida957b6c68607743b9efa85f4263451c955b398a
Signed-off-by: Antoni S. Puimedon <[email protected]>
---
M lib/vdsm/netconfpersistence.py
1 file changed, 37 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/09/35709/1

diff --git a/lib/vdsm/netconfpersistence.py b/lib/vdsm/netconfpersistence.py
index f0aac38..80b2ab7 100644
--- a/lib/vdsm/netconfpersistence.py
+++ b/lib/vdsm/netconfpersistence.py
@@ -19,9 +19,11 @@
 #
 
 import errno
+import glob
 import json
 import logging
 import os
+import time
 
 from .config import config
 from .tool.restore_nets import restore
@@ -33,7 +35,8 @@
 # The persistent path is inside of an extra "persistence" dir in order to get
 # oVirt Node to persist the symbolic links that are necessary for the
 # atomic storage of running config into persistent config.
-CONF_PERSIST_DIR = constants.P_VDSM_LIB + 'persistence/netconf/'
+CONF_PERSIST_DIR = constants.P_VDSM_LIB + 'persistence/'
+CONF_PERSIST_NETCONF_DIR = CONF_PERSIST_DIR + 'netconf/'
 
 
 class BaseConfig(object):
@@ -194,12 +197,44 @@
 
 class PersistentConfig(Config):
     def __init__(self):
-        super(PersistentConfig, self).__init__(CONF_PERSIST_DIR)
+        super(PersistentConfig, self).__init__(CONF_PERSIST_NETCONF_DIR)
 
     def restore(self):
         restore()
         return RunningConfig()
 
+    def store(self):
+        """Atomically stores PersistentConfig"""
+        symlink_path = os.path.dirname(CONF_PERSIST_NETCONF_DIR)
+        timestamp = _nano_timestamp()
+        new_dir = symlink_path + '.' + timestamp
+        super(PersistentConfig, self).__init__(new_dir)
+        new_symlink = symlink_path + '.link.' + timestamp
+
+        logging.debug('Persistence: persisting "%s"' % new_dir)
+        self.save()
+        os.symlink(new_dir, new_symlink)
+        logging.debug('Persistence: atomically making "%s" point to the new '
+                      'configuration directory "%s' %
+                      (CONF_PERSIST_NETCONF_DIR, new_dir))
+        os.rename(new_symlink, os.path.dirname(CONF_PERSIST_NETCONF_DIR))
+
+
+def _nano_timestamp():
+    return ('%.20f' % time.time()).replace('.', '')[:19]
+
+
+def _cleanupPersistence(keep=()):
+    """Cleans up CONF_PERSIST_DIR from netconfs not in 'keep'"""
+    for path in glob.iglob(os.path.dirname(CONF_PERSIST_NETCONF_DIR) + '.*'):
+        if path in keep:
+            continue
+        logging.debug('Persistence: removing old config "%s"' % path)
+        if os.path.islink(path) or os.path.isfile(path):
+            utils.rmFile(path)
+        else:  # Directory
+            utils.rmTree(path)
+
 
 def configuredPorts(nets, bridge):
     """Return the configured ports for the bridge"""


-- 
To view, visit http://gerrit.ovirt.org/35709
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida957b6c68607743b9efa85f4263451c955b398a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to