Skip to content

Commit 676ac95

Browse files
author
frank
committed
Bug 13034 - Error when executing cloud-setup-databases
status 13034: resolved fixed
1 parent ae1e704 commit 676ac95

1 file changed

Lines changed: 13 additions & 39 deletions

File tree

setup/bindir/cloud-setup-databases.in

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class DBDeployer(object):
5454
encryptionJarPath = '@JAVADIR@/cloud-jasypt-1.8.jar'
5555
success = False
5656
magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate'
57+
tmpMysqlFile = os.path.join(os.path.expanduser('~/'), 'cloudstackmysql.tmp.sql')
5758

5859
def preRun(self):
5960
def backUpDbDotProperties():
@@ -75,6 +76,8 @@ class DBDeployer(object):
7576
os.remove(copyPath)
7677

7778
cleanOrRecoverDbDotProperties()
79+
if os.path.exists(self.tmpMysqlFile):
80+
os.remove(self.tmpMysqlFile)
7881

7982

8083
def info(self, msg, result=None):
@@ -122,45 +125,19 @@ class DBDeployer(object):
122125

123126
try:
124127
conn = MySQLdb.connect(**kwargs)
128+
conn.close()
125129
except:
126130
self.errorAndExit("Connect to mysqld failed, please make sure mysqld is running.\nYou may start it by: service mysqld start")
127-
128-
currentStmt = ''
131+
129132
try:
130-
cur = conn.cursor()
131-
import re
132-
exp = re.compile("DELIMITER (.*)$",re.M)
133-
pairs = [";"]+[x.strip() for x in exp.split(text)]
134-
delims = []
135-
chunks = []
136-
while pairs:
137-
delims.append( pairs[0] )
138-
chunks.append( pairs[1] )
139-
pairs = pairs[2:]
140-
141-
for delim,chunk in zip(delims,chunks):
142-
for stmt in chunk.split(delim):
143-
stmt = stmt.strip()
144-
if not stmt: continue
145-
if self.isDebug: self.debug(stmt)
146-
currentStmt = stmt
147-
cur.execute(stmt)
148-
149-
cur.close()
150-
conn.commit()
151-
conn.close()
133+
mysqlCmds = ['mysql', '--user=%s'%kwargs['user'], '--host=%s'%kwargs['host'], '--port=%s'%kwargs['port']]
134+
if kwargs.has_key['paswd']:
135+
mysqlCmds.append('--password=%s'%kwargs['passwd'])
136+
file(self.tmpMysqlFile, 'w').write(text)
137+
mysqlCmds.append('<')
138+
mysqlCmds.append(self.tmpMysqlFile)
139+
runCmd(mysqlCmds)
152140
except Exception, e:
153-
lineNum = 'unknown'
154-
try:
155-
if os.path.isfile(table):
156-
lines = file(table).readlines()
157-
for l in lines:
158-
if currentStmt in l:
159-
lineNum = int(lines.index(l) + 1)
160-
break
161-
except:
162-
lineNum = 'unknown'
163-
164141
err = '''Encountering an error when executing mysql script
165142
----------------------------------------------------------------------
166143
table:
@@ -169,13 +146,10 @@ table:
169146
Error:
170147
%s
171148
172-
Sql text(Line number: %s):
173-
%s
174-
175149
Sql parameters:
176150
%s
177151
----------------------------------------------------------------------
178-
'''%(table, e.__str__(), lineNum, currentStmt, kwargs)
152+
'''%(table, e.__str__(), kwargs)
179153
self.errorAndExit(err)
180154

181155
def errorAndExit(self, msg):

0 commit comments

Comments
 (0)