comparison commons/tools/CheckMysqlConnect.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
comparison
equal deleted inserted replaced
17:b0e8584489e6 18:94ab73e8a190
1 #!/usr/bin/env python
2
3 # Copyright INRA (Institut National de la Recherche Agronomique)
4 # http://www.inra.fr
5 # http://urgi.versailles.inra.fr
6 #
7 # This software is governed by the CeCILL license under French law and
8 # abiding by the rules of distribution of free software. You can use,
9 # modify and/ or redistribute the software under the terms of the CeCILL
10 # license as circulated by CEA, CNRS and INRIA at the following URL
11 # "http://www.cecill.info".
12 #
13 # As a counterpart to the access to the source code and rights to copy,
14 # modify and redistribute granted by the license, users are provided only
15 # with a limited warranty and the software's author, the holder of the
16 # economic rights, and the successive licensors have only limited
17 # liability.
18 #
19 # In this respect, the user's attention is drawn to the risks associated
20 # with loading, using, modifying and/or developing or reproducing the
21 # software by the user in light of its specific status of free software,
22 # that may mean that it is complicated to manipulate, and that also
23 # therefore means that it is reserved for developers and experienced
24 # professionals having in-depth computer knowledge. Users are therefore
25 # encouraged to load and test the software's suitability as regards their
26 # requirements in conditions enabling the security of their systems and/or
27 # data to be ensured and, more generally, to use and operate it in the
28 # same conditions as regards security.
29 #
30 # The fact that you are presently reading this means that you have had
31 # knowledge of the CeCILL license and that you accept its terms.
32
33 import sys
34 import os
35 from commons.core.utils.RepetOptionParser import RepetOptionParser
36 from commons.core.checker.RepetException import RepetException
37 from commons.tools.CleanClusterNodesAfterRepet import CleanClusterNodesAfterRepet
38
39 REPET_PATH = os.environ.get("REPET_PATH")
40
41 def main():
42
43 description = "Check MySQL connection on each node"
44 usage = "CheckMysqlConnect.py [options]"
45 examples = "\nExample 1: check MySQL connection from every node of a SGE cluster using environment variables:\n"
46 examples += "\t$ python CheckMysqlConnect.py"
47 examples += "\n\t"
48 examples += "\nExample 2: check MySQL connection from every node of a SGE cluster using configuration file:\n"
49 examples += "\t$ python CheckMysqlConnect.py -C configFileName"
50 examples += "\n\t"
51 examples += "\nExample 3: check MySQL connection from every node of a SGE cluster using environment variables and using a different python executable than the one in the PATH:\n"
52 examples += "\t$ python CheckMysqlConnect.py -p /path/to/python"
53 examples += "\n\n"
54
55 parser = RepetOptionParser(description = description, usage = usage, version = "v1.0", epilog = examples)
56 parser.add_option( "-p", "--path", dest = "pythonPath", type = "string", help = "path to python executable ('python' included, without finishing '/')", default = "python")
57 parser.add_option( "-C", "--config", dest = "config", type = "string", help = "path to config file", default = "")
58
59 options, args = parser.parse_args()
60 pythonPath = options.pythonPath
61 configFile = options.config
62
63 iCleanClusterNodesAfterRepet = CleanClusterNodesAfterRepet()
64 nodesList = iCleanClusterNodesAfterRepet.getAllNodesList()
65
66 nbNodes = len(nodesList)
67 nodeCount = 0
68 configOption = ""
69 for node in nodesList:
70 try:
71 nodeCount += 1
72 print "Connect to node '%s' (%i/%i)..." % (node, nodeCount, nbNodes)
73 sys.stdout.flush()
74 cmd = "ssh"
75 cmd += " -q %s " % ( node )
76 if configFile != "":
77 configOption = " -C %s" % configFile
78 cmd += "'%s %s/bin/MysqlConnect.py -n %s %s'" % (pythonPath, REPET_PATH, node, configOption)
79 os.system(cmd)
80 except RepetException, e:
81 print e.getMessage()
82
83 iCleanClusterNodesAfterRepet.clean()
84
85 if __name__ == '__main__':
86 main()