run the scripts

This commit is contained in:
Alex Huang 2011-02-28 08:43:08 -08:00
parent a53a07985b
commit ab3c719389
3 changed files with 13 additions and 47 deletions

View File

@ -232,9 +232,6 @@
-->
<!--bootclasspath refid="test.classpath"/-->
<classpath refid="test.classpath"/>
<permissions>
<grant class="java.security.AllPermission"/>
</permissions>
<jvmarg value="${debug.jvmarg}"/>
<batchtest todir="${unittest.dir}">
<formatter type="plain"/>

View File

@ -152,6 +152,10 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
if (upgrades == null) {
throw new ConfigurationException("There is no upgrade path from " + dbVersion + " to " + currentVersion);
}
if (Version.compare(currentVersion, upgrades[upgrades.length - 1].getUpgradedVersion()) == 0) {
throw new ConfigurationException("The end upgrade version is actually at " + upgrades[upgrades.length - 1].getUpgradedVersion() + " but our management server code version is at " + currentVersion);
}
boolean supportsRollingUpgrade = true;
for (DbUpgrade upgrade : upgrades) {
@ -170,7 +174,9 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
Transaction txn = Transaction.currentTxn();
txn.start();
File script = upgrade.getPrepareScript();
runScript(script);
if (script != null) {
runScript(script);
}
upgrade.performDataMigration();
VersionVO version = new VersionVO(upgrade.getUpgradedVersion());
persist(version);
@ -183,7 +189,9 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
Transaction txn = Transaction.currentTxn();
txn.start();
File script = upgrade.getCleanupScript();
runScript(script);
if (script != null) {
runScript(script);
}
version.setStep(Step.Complete);
version.setUpdated(new Date());
update(version.getId(), version);

View File

@ -18,13 +18,6 @@
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.ConfigurationException;
import junit.framework.TestCase;
@ -34,10 +27,8 @@ import org.junit.After;
import org.junit.Before;
import com.cloud.upgrade.dao.VersionVO.Step;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.ScriptRunner;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.DbTestUtils;
public class VersionDaoImplTest extends TestCase {
private static final Logger s_logger = Logger.getLogger(VersionDaoImplTest.class);
@ -47,39 +38,9 @@ public class VersionDaoImplTest extends TestCase {
public void setUp() throws Exception {
VersionVO version = new VersionVO("2.1.7");
version.setStep(Step.Cleanup);
executeScript("VersionDaoImplTest/clean-db.sql");
DbTestUtils.executeScript("VersionDaoImplTest/clean-db.sql", false, true);
}
protected void executeScript(String file) {
File cleanScript = PropertiesUtil.findConfigFile(file);
if (cleanScript == null) {
throw new RuntimeException("Unable to clean the database because I can't find " + file);
}
Connection conn = Transaction.getStandaloneConnection();
ScriptRunner runner = new ScriptRunner(conn, false, true);
FileReader reader;
try {
reader = new FileReader(cleanScript);
} catch (FileNotFoundException e) {
throw new RuntimeException("Unable to read " + file, e);
}
try {
runner.runScript(reader);
} catch (IOException e) {
throw new RuntimeException("Unable to read " + file, e);
} catch (SQLException e) {
throw new RuntimeException("Unable to execute " + file, e);
}
try {
conn.close();
} catch (SQLException e) {
throw new RuntimeException("Unable to close DB connection", e);
}
}
@Override
@After
public void tearDown() throws Exception {
@ -87,7 +48,7 @@ public class VersionDaoImplTest extends TestCase {
public void test217to22Upgrade() {
s_logger.debug("Finding sample data from 2.1.7");
executeScript("VersionDaoImplTest/2.1.7/2.1.7.sample.sql");
DbTestUtils.executeScript("VersionDaoImplTest/2.1.7/2.1.7.sample.sql", false, true);
VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class);