Yaniv Bronhaim has uploaded a new change for review.

Change subject: Starting svdsm on startup
......................................................................

Starting svdsm on startup

When prepareForShutdown is invoked vdsm restarts itself, when this
haapens super vdsm supposed also to restart itself after the old instance dies.
Apparently, this happens too fast, and until the old instance dies, vdsm
tries to communicate with it and fails, and only then svdsm initiates the new
instance.
This patch initiates svdsm during vdsm startup instead of during the first
proxy call.

Change-Id: Iebee1b4fbb62f3760609d12d694f466dc9379fca
Signed-off-by: Yaniv Bronhaim <[email protected]>
---
M tests/superVdsmTests.py
M vdsm/supervdsm.py
2 files changed, 27 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/9691/1

diff --git a/tests/superVdsmTests.py b/tests/superVdsmTests.py
index 87de66d..a11572b 100644
--- a/tests/superVdsmTests.py
+++ b/tests/superVdsmTests.py
@@ -9,6 +9,7 @@
 from storage import misc
 from monkeypatch import MonkeyPatch
 from time import sleep
+import threading
 
 
 @utils.memoized
@@ -34,40 +35,45 @@
     sleep(2)
 
 
+# This monkey patch allows to get proxy to supervdsm without initiate first
+# process instance. To start svdsm process we should call self._proxy.launch()
+def monkeyInit(self):
+    self.proxyLock = threading.Lock()
+    self._firstRun = True
+
+
 class TestSuperVdsm(TestCaseBase):
+
+    @MonkeyPatch(supervdsm.SuperVdsmProxy, '__init__', monkeyInit)
+    @MonkeyPatch(supervdsm.SuperVdsmProxy, '_start', monkeyStart)
     def setUp(self):
         testValidation.checkSudo(['python', supervdsm.SUPERVDSM])
-        self._proxy = supervdsm.getProxy()
 
         # temporary values to run temporary svdsm
         self.pidfd, pidfile = tempfile.mkstemp()
         self.timefd, timestamp = tempfile.mkstemp()
         self.addfd, address = tempfile.mkstemp()
-
+        self._proxy = supervdsm.getProxy()
         self._proxy.setIPCPaths(pidfile, timestamp, address)
+        self._proxy.launch()
 
     def tearDown(self):
         supervdsm.extraPythonPathList = []
         for fd in (self.pidfd, self.timefd, self.addfd):
             os.close(fd)
-        self._proxy.kill()  # cleanning old temp files
+        self._proxy.kill()  # clean old temp files and kill svdsm process
 
-    @MonkeyPatch(supervdsm.SuperVdsmProxy, '_start', monkeyStart)
     def testIsSuperUp(self):
-        self._proxy.ping()  # this call initiate svdsm
         self.assertTrue(self._proxy.isRunning())
 
     @MonkeyPatch(supervdsm.SuperVdsmProxy, '_start', monkeyStart)
     def testKillSuper(self):
-        self._proxy.ping()
         self._proxy.kill()
         self.assertFalse(self._proxy.isRunning())
         self._proxy.ping()  # Launching vdsm after kill
         self.assertTrue(self._proxy.isRunning())
 
-    @MonkeyPatch(supervdsm.SuperVdsmProxy, '_start', monkeyStart)
     def testNoPidFile(self):
-        self._proxy.ping()  # svdsm is up
         self.assertTrue(self._proxy.isRunning())
         utils.rmFile(self._proxy.timestamp)
         self.assertRaises(IOError, self._proxy.isRunning)
diff --git a/vdsm/supervdsm.py b/vdsm/supervdsm.py
index 532d5ac..4a47292 100644
--- a/vdsm/supervdsm.py
+++ b/vdsm/supervdsm.py
@@ -91,13 +91,21 @@
     _log = logging.getLogger("SuperVdsmProxy")
 
     def __init__(self):
-        self.proxyLock = threading.Lock()
-        self._firstLaunch = True
+        # This varibale indicates if svdsm intiates first time from current
+        # vdsm process. If firstRun is false, internal files must exist.
+        # Otherwise, if somehow svdsm's internal files has been
+        # changed or deleted we need to raise an exception.
+        # This case is handled in isRunning scope.
+        self._firstRun = True
 
+        self.proxyLock = threading.Lock()
         # Declaration of public variables that keep files' names that svdsm
         # uses. We need to be able to change these variables so that running
         # tests doesn't disturb and already running VDSM on the host.
         self.setIPCPaths(PIDFILE, TIMESTAMP, ADDRESS)
+
+        self.kill()
+        self.launch()
 
     def setIPCPaths(self, pidfile, timestamp, address):
         self.pidfile = pidfile
@@ -141,7 +149,7 @@
         self._authkey = None
         self._manager = None
         self._svdsm = None
-        self._firstLaunch = True
+        self._firstRun = True
 
     def isRunning(self):
         try:
@@ -152,7 +160,7 @@
         except IOError as e:
             # pid file and timestamp file must be exist after first launch,
             # otherwise excpetion will be raised to svdsm caller
-            if e.errno == ENOENT and self._firstLaunch:
+            if e.errno == ENOENT and self._firstRun:
                 return False
             else:
                 raise
@@ -185,7 +193,7 @@
         self._svdsm = self._manager.instance()
 
     def launch(self):
-        self._firstLaunch = False
+        self._firstRun = False
         self._start()
         utils.retry(self._connect, Exception, timeout=60)
 


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

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

Reply via email to