Bug 13034 - Error when executing cloud-setup-databases

status 13034: resolved fixed
This commit is contained in:
frank 2012-01-11 20:41:48 -08:00
parent ae1e70438c
commit 676ac955cb

View File

@ -54,6 +54,7 @@ class DBDeployer(object):
encryptionJarPath = '@JAVADIR@/cloud-jasypt-1.8.jar' encryptionJarPath = '@JAVADIR@/cloud-jasypt-1.8.jar'
success = False success = False
magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate' magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate'
tmpMysqlFile = os.path.join(os.path.expanduser('~/'), 'cloudstackmysql.tmp.sql')
def preRun(self): def preRun(self):
def backUpDbDotProperties(): def backUpDbDotProperties():
@ -75,6 +76,8 @@ class DBDeployer(object):
os.remove(copyPath) os.remove(copyPath)
cleanOrRecoverDbDotProperties() cleanOrRecoverDbDotProperties()
if os.path.exists(self.tmpMysqlFile):
os.remove(self.tmpMysqlFile)
def info(self, msg, result=None): def info(self, msg, result=None):
@ -122,45 +125,19 @@ class DBDeployer(object):
try: try:
conn = MySQLdb.connect(**kwargs) conn = MySQLdb.connect(**kwargs)
conn.close()
except: except:
self.errorAndExit("Connect to mysqld failed, please make sure mysqld is running.\nYou may start it by: service mysqld start") self.errorAndExit("Connect to mysqld failed, please make sure mysqld is running.\nYou may start it by: service mysqld start")
currentStmt = ''
try: try:
cur = conn.cursor() mysqlCmds = ['mysql', '--user=%s'%kwargs['user'], '--host=%s'%kwargs['host'], '--port=%s'%kwargs['port']]
import re if kwargs.has_key['paswd']:
exp = re.compile("DELIMITER (.*)$",re.M) mysqlCmds.append('--password=%s'%kwargs['passwd'])
pairs = [";"]+[x.strip() for x in exp.split(text)] file(self.tmpMysqlFile, 'w').write(text)
delims = [] mysqlCmds.append('<')
chunks = [] mysqlCmds.append(self.tmpMysqlFile)
while pairs: runCmd(mysqlCmds)
delims.append( pairs[0] )
chunks.append( pairs[1] )
pairs = pairs[2:]
for delim,chunk in zip(delims,chunks):
for stmt in chunk.split(delim):
stmt = stmt.strip()
if not stmt: continue
if self.isDebug: self.debug(stmt)
currentStmt = stmt
cur.execute(stmt)
cur.close()
conn.commit()
conn.close()
except Exception, e: except Exception, e:
lineNum = 'unknown'
try:
if os.path.isfile(table):
lines = file(table).readlines()
for l in lines:
if currentStmt in l:
lineNum = int(lines.index(l) + 1)
break
except:
lineNum = 'unknown'
err = '''Encountering an error when executing mysql script err = '''Encountering an error when executing mysql script
---------------------------------------------------------------------- ----------------------------------------------------------------------
table: table:
@ -169,13 +146,10 @@ table:
Error: Error:
%s %s
Sql text(Line number: %s):
%s
Sql parameters: Sql parameters:
%s %s
---------------------------------------------------------------------- ----------------------------------------------------------------------
'''%(table, e.__str__(), lineNum, currentStmt, kwargs) '''%(table, e.__str__(), kwargs)
self.errorAndExit(err) self.errorAndExit(err)
def errorAndExit(self, msg): def errorAndExit(self, msg):