BUG 2276 : Add a script to restart a cluster 64/12364/1
authorMoiz Raja <moraja@cisco.com>
Thu, 30 Oct 2014 00:20:17 +0000 (17:20 -0700)
committerMoiz Raja <moraja@cisco.com>
Thu, 30 Oct 2014 00:20:17 +0000 (17:20 -0700)
Change-Id: I4fd10c2f9509d68df3dee2cdd62b8d83ccb8c432
Signed-off-by: Moiz Raja <moraja@cisco.com>
test/tools/cluster-deployer/deploy.py
test/tools/cluster-deployer/remote_host.py [new file with mode: 0644]
test/tools/cluster-deployer/restart.py [new file with mode: 0644]

index 40ccf06ec3723287d894a6baf23222bc8e22df95..57aa51d33ce6fcca471fb65885b489aa7ca735ca 100755 (executable)
@@ -37,6 +37,7 @@ import os
 import sys
 import random
 import re
+from remote_host import RemoteHost
 
 parser = argparse.ArgumentParser(description='Cluster Deployer')
 parser.add_argument("--distribution", default="", help="the absolute path of the distribution on the local host that needs to be deployed. (Must contain version in the form: \"<#>.<#>.<#>-<name>\", e.g. 0.2.0-SNAPSHOT)", required=True)
@@ -49,41 +50,7 @@ parser.add_argument("--user", default="root", help="the SSH username for the rem
 parser.add_argument("--password", default="Ecp123", help="the SSH password for the remote host(s)")
 args = parser.parse_args()
 
-# 
-# The RemoteHost class provides methods to do operations on a remote host
-#
-class RemoteHost:
-       def __init__(self, host, user, password, rootdir):
-               self.host = host
-               self.user = user
-               self.password = password
-               self.rootdir = rootdir
-
-       def exec_cmd(self, command):
-               print "Executing command " + command + " on host " + self.host
-               lib = SSHLibrary()
-               lib.open_connection(self.host)
-               lib.login(username=self.user,password=self.password)
-               lib.execute_command(command)
-               lib.close_connection()
-
-
-       def mkdir(self, dir_name):
-               self.exec_cmd("mkdir -p " + dir_name)
-
-       def copy_file(self, src, dest):
-           lib = SSHLibrary()
-           lib.open_connection(self.host)
-           lib.login(username=self.user, password=self.password)
-           print "Copying " + src + " to " + dest + " on " + self.host
-           lib.put_file(src, dest)
-           lib.close_connection()
-
-       def kill_controller(self):
-           self.exec_cmd("ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
-
-       def start_controller(self, dir_name):
-               self.exec_cmd(dir_name + "/odl/bin/start")
+
 
 #
 # The TemplateRenderer provides methods to render a template
@@ -196,7 +163,7 @@ class Deployer:
         remote.copy_file(management_cfg, self.dir_name + "/odl/etc/")
 
         # Add symlink
-        remote.exec_cmd("ln -s " + self.dir_name + " " + args.rootdir + "/deploy/current")
+        remote.exec_cmd("ln -sfn " + self.dir_name + " " + args.rootdir + "/deploy/current")
 
         # Run karaf
         remote.start_controller(self.dir_name)      
diff --git a/test/tools/cluster-deployer/remote_host.py b/test/tools/cluster-deployer/remote_host.py
new file mode 100644 (file)
index 0000000..d6780ce
--- /dev/null
@@ -0,0 +1,40 @@
+# remote_host.py
+
+# 
+# The RemoteHost class provides methods to do operations on a remote host
+#
+
+from SSHLibrary import SSHLibrary
+
+class RemoteHost:
+       def __init__(self, host, user, password, rootdir):
+               self.host = host
+               self.user = user
+               self.password = password
+               self.rootdir = rootdir
+
+       def exec_cmd(self, command):
+               print "Executing command " + command + " on host " + self.host
+               lib = SSHLibrary()
+               lib.open_connection(self.host)
+               lib.login(username=self.user,password=self.password)
+               lib.execute_command(command)
+               lib.close_connection()
+
+
+       def mkdir(self, dir_name):
+               self.exec_cmd("mkdir -p " + dir_name)
+
+       def copy_file(self, src, dest):
+           lib = SSHLibrary()
+           lib.open_connection(self.host)
+           lib.login(username=self.user, password=self.password)
+           print "Copying " + src + " to " + dest + " on " + self.host
+           lib.put_file(src, dest)
+           lib.close_connection()
+
+       def kill_controller(self):
+           self.exec_cmd("ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
+
+       def start_controller(self, dir_name):
+               self.exec_cmd(dir_name + "/odl/bin/start")
\ No newline at end of file
diff --git a/test/tools/cluster-deployer/restart.py b/test/tools/cluster-deployer/restart.py
new file mode 100644 (file)
index 0000000..61a4846
--- /dev/null
@@ -0,0 +1,34 @@
+# #!/usr/local/bin/python
+# 
+# This script restarts the cluster nodes. It can optionally cleanup the persistent data.
+# --------------------------------------------------------------------------------------
+# 
+# This script takes a list of hosts as parameter
+#
+# 
+# -------------------------------------------------------------------------------------------------------------
+
+import argparse
+from remote_host import RemoteHost
+
+parser = argparse.ArgumentParser(description='Cluster Restart')
+parser.add_argument("--rootdir", default="/root", help="the root directory on the remote host where the distribution is deployed", required=True)
+parser.add_argument("--hosts", default="", help="a comma separated list of host names or ip addresses", required=True)
+parser.add_argument("--clean", action="store_true", default=False, help="clean the persistent data for the current deployment")
+parser.add_argument("--user", default="root", help="the SSH username for the remote host(s)")
+parser.add_argument("--password", default="Ecp123", help="the SSH password for the remote host(s)")
+args = parser.parse_args()
+
+
+def main():
+    hosts = args.hosts.split(",")
+    for x in range(0, len(hosts)):
+        # Connect to the remote host and start doing operations
+        remote = RemoteHost(hosts[x], args.user, args.password, args.rootdir)
+        remote.kill_controller()
+        if(args.clean):
+            remote.exec_cmd("rm -rf " + args.rootdir + "/deploy/current/odl/journal")
+            remote.exec_cmd("rm -rf " + args.rootdir + "/deploy/current/odl/snapshots")
+        remote.start_controller(args.rootdir + "/deploy/current")
+
+main()
\ No newline at end of file