Fix issue with kill_controller not working in certain environments
authorMoiz Raja <moraja@cisco.com>
Fri, 5 Jun 2015 01:02:06 +0000 (18:02 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 6 Jun 2015 03:24:56 +0000 (03:24 +0000)
Move the kill functionality to a separate shell script which is
copied over to the destination system before invoking it

Change-Id: If9c01746263448e4dcb8920ebd962fe745275c8b
Signed-off-by: Moiz Raja <moraja@cisco.com>
test/tools/clustering/cluster-deployer/deploy.py
test/tools/clustering/cluster-deployer/kill_controller.sh [new file with mode: 0755]
test/tools/clustering/cluster-deployer/remote_host.py

index ccc69e4a3693387935ad0c4610513030dde01b5d..f9927cc0a165f1f19558f015324751e1ac927299 100755 (executable)
@@ -67,7 +67,10 @@ class TemplateRenderer:
         self.cwd = os.getcwd()
         self.template_root = self.cwd + "/templates/" + template + "/"
 
-    def render(self, template_path, output_path, variables={}):
+    def render(self, template_path, output_path, variables=None):
+        if variables is None:
+            variables = {}
+
         with open(self.template_root + template_path, "r") as myfile:
             data = myfile.read()
 
@@ -90,8 +93,8 @@ def array_str(arr):
     for x in range(0, len(arr)):
         s = s + '"' + arr[x] + '"'
         if x < (len(arr) - 1):
-            s = s + ","
-    s = s + "]"
+            s += ","
+    s += "]"
     return s
 
 
@@ -115,6 +118,10 @@ class Deployer:
         self.rpc_seed_nodes = rpc_seed_nodes
         self.replicas = replicas
 
+    def kill_controller(self, remote):
+        remote.copy_file("kill_controller.sh",  self.rootdir + "/")
+        remote.exec_cmd(self.rootdir + "/kill_controller.sh")
+
     def deploy(self):
         # Determine distribution version
         distribution_name = os.path.splitext(os.path.basename(self.distribution))[0]
@@ -147,17 +154,19 @@ class Deployer:
 
         # Connect to the remote host and start doing operations
         remote = RemoteHost(self.host, self.user, self.password, self.rootdir)
-        remote.mkdir(self.dir_name)
 
         # Delete all the sub-directories under the deploy directory if the --clean flag is used
-        if(self.clean is True):
+        if self.clean is True:
             remote.exec_cmd("rm -rf " + self.rootdir + "/deploy/*")
 
+        # Create the deployment directory
+        remote.mkdir(self.dir_name)
+
         # Clean the m2 repository
         remote.exec_cmd("rm -rf " + self.rootdir + "/.m2/repository")
 
         # Kill the controller if it's running
-        remote.kill_controller()
+        self.kill_controller(remote)
 
         # Copy the distribution to the host and unzip it
         odl_file_path = self.dir_name + "/odl.zip"
@@ -196,7 +205,6 @@ def main():
     hosts = args.hosts.split(",")
     time_stamp = time.time()
     dir_name = args.rootdir + "/deploy/" + str(time_stamp)
-    distribution_name = os.path.splitext(os.path.basename(args.distribution))[0]  # noqa
 
     ds_seed_nodes = []
     rpc_seed_nodes = []
diff --git a/test/tools/clustering/cluster-deployer/kill_controller.sh b/test/tools/clustering/cluster-deployer/kill_controller.sh
new file mode 100755 (executable)
index 0000000..68de138
--- /dev/null
@@ -0,0 +1 @@
+ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sudo sh
index 5da74b77a8a0e259f09f114c4abfce4e5783ba93..34c9f1f065cb496016f5a40ee027f05e264a5e84 100644 (file)
@@ -36,7 +36,7 @@ class RemoteHost:
         lib.close_connection()
 
     def kill_controller(self):
-        self.exec_cmd("ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
+        self.exec_cmd("sudo ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sudo sh")
 
     def start_controller(self, dir_name):
         self.exec_cmd(dir_name + "/odl/bin/start")