annotate commons/tools/CheckMysqlConnect.py @ 19:9bcfa7936eec

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