Mercurial > repos > yufei-luo > s_mart
comparison commons/tools/tests/Test_F_CheckMysqlConnect.py @ 31:0ab839023fe4
Uploaded
| author | m-zytnicki |
|---|---|
| date | Tue, 30 Apr 2013 14:33:21 -0400 |
| parents | 94ab73e8a190 |
| children |
comparison
equal
deleted
inserted
replaced
| 30:5677346472b5 | 31:0ab839023fe4 |
|---|---|
| 1 import unittest | |
| 2 import os | |
| 3 import socket | |
| 4 | |
| 5 class Test_F_CheckMysqlConnect(unittest.TestCase): | |
| 6 | |
| 7 HOST_NAME = "compute-2-46.local" | |
| 8 | |
| 9 def setUp(self): | |
| 10 self._host = socket.gethostname() | |
| 11 self._cmd = "" | |
| 12 | |
| 13 def tearDown(self): | |
| 14 os.remove("testOutputCheckMysqlConnect.txt") | |
| 15 | |
| 16 def test_CheckMysqlConnect_as_script_True(self): | |
| 17 if self.HOST_NAME in self._host: | |
| 18 self._cmd = "CheckMysqlConnect.py -p /share/apps/bin/python > testOutputCheckMysqlConnect.txt" | |
| 19 else: | |
| 20 self._cmd = "CheckMysqlConnect.py > testOutputCheckMysqlConnect.txt" | |
| 21 os.system(self._cmd) | |
| 22 | |
| 23 self.assertFalse(self._isFailedInOutputFile()) | |
| 24 | |
| 25 def test_CheckMysqlConnect_as_script_False(self): | |
| 26 configFile = "%s/repet_tools/tests/config.cfg" % os.environ.get("REPET_PATH") | |
| 27 host = "unknownServer" | |
| 28 self._writeConfig(configFile, host) | |
| 29 | |
| 30 if self.HOST_NAME in self._host: | |
| 31 self._cmd = "CheckMysqlConnect.py -p /share/apps/bin/python -C %s > testOutputCheckMysqlConnect.txt" % configFile | |
| 32 else: | |
| 33 self._cmd = "CheckMysqlConnect.py -C %s > testOutputCheckMysqlConnect.txt " % configFile | |
| 34 os.system(self._cmd) | |
| 35 os.remove(configFile) | |
| 36 | |
| 37 self.assertTrue(self._isFailedInOutputFile()) | |
| 38 | |
| 39 def _isFailedInOutputFile(self): | |
| 40 f = open("testOutputCheckMysqlConnect.txt", "r") | |
| 41 line = f.readline() | |
| 42 | |
| 43 while line: | |
| 44 if "FAILED" in line: | |
| 45 f.close() | |
| 46 return True | |
| 47 line = f.readline() | |
| 48 | |
| 49 f.close() | |
| 50 return False | |
| 51 | |
| 52 def _writeConfig(self, configFileName, repetHost = os.environ.get("REPET_HOST")): | |
| 53 f = open( configFileName, "w" ) | |
| 54 f.write("[repet_env]\n") | |
| 55 f.write("repet_host: %s\n" % repetHost) | |
| 56 f.write("repet_user: %s\n" % os.environ.get("REPET_USER")) | |
| 57 f.write("repet_pw: %s\n" % os.environ.get("REPET_PW")) | |
| 58 f.write("repet_db: %s\n" % os.environ.get("REPET_DB")) | |
| 59 f.write("repet_port: %s\n" % os.environ.get("REPET_PORT")) | |
| 60 f.close() | |
| 61 | |
| 62 if __name__ == "__main__": | |
| 63 unittest.main() | |
| 64 |
