Kill update simulation

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Vincent Petry 2016-09-21 15:12:00 +02:00 committed by Lukas Reschke
parent 6ca8ce6228
commit da0cea404d
No known key found for this signature in database
GPG key ID: B9F6980CF6E759B1
5 changed files with 47 additions and 163 deletions

View file

@ -71,12 +71,6 @@ class Upgrade extends Command {
$this
->setName('upgrade')
->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.')
->addOption(
'--skip-migration-test',
null,
InputOption::VALUE_NONE,
'skips the database schema migration simulation and update directly'
)
->addOption(
'--dry-run',
null,
@ -99,28 +93,12 @@ class Upgrade extends Command {
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$simulateStepEnabled = true;
$updateStepEnabled = true;
$skip3rdPartyAppsDisable = false;
if ($input->getOption('skip-migration-test')) {
$simulateStepEnabled = false;
}
if ($input->getOption('dry-run')) {
$updateStepEnabled = false;
}
if ($input->getOption('no-app-disable')) {
$skip3rdPartyAppsDisable = true;
}
if (!$simulateStepEnabled && !$updateStepEnabled) {
$output->writeln(
'<error>Only one of "--skip-migration-test" or "--dry-run" ' .
'can be specified at a time.</error>'
);
return self::ERROR_INVALID_ARGUMENTS;
}
if(\OC::checkUpgrade(false)) {
if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
// Prepend each line with a little timestamp
@ -135,8 +113,6 @@ class Upgrade extends Command {
$this->logger
);
$updater->setSimulateStepEnabled($simulateStepEnabled);
$updater->setUpdateStepEnabled($updateStepEnabled);
$updater->setSkip3rdPartyAppsDisable($skip3rdPartyAppsDisable);
$dispatcher = \OC::$server->getEventDispatcher();
$progress = new ProgressBar($output);
@ -229,11 +205,10 @@ class Upgrade extends Command {
});
$updater->listen('\OC\Updater', 'updateEnd',
function ($success) use($output, $updateStepEnabled, $self) {
$mode = $updateStepEnabled ? 'Update' : 'Update simulation';
if ($success) {
$message = "<info>$mode successful</info>";
$message = "<info>Update successful</info>";
} else {
$message = "<error>$mode failed</error>";
$message = "<error>Update failed</error>";
}
$output->writeln($message);
});

View file

@ -121,17 +121,6 @@ class MDB2SchemaManager {
}
}
/**
* update the database scheme
* @param string $file file to read structure from
* @return boolean
*/
public function simulateUpdateDbFromStructure($file) {
$toSchema = $this->readSchemaFromFile($file);
$this->getMigrator()->checkMigrate($toSchema);
return true;
}
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
* @return string

View file

@ -35,8 +35,8 @@ use OC\Hooks\BasicEmitter;
use OC\IntegrityCheck\Checker;
use OC_App;
use OCP\IConfig;
use OC\Setup;
use OCP\ILogger;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@ -59,12 +59,6 @@ class Updater extends BasicEmitter {
/** @var Checker */
private $checker;
/** @var bool */
private $simulateStepEnabled;
/** @var bool */
private $updateStepEnabled;
/** @var bool */
private $skip3rdPartyAppsDisable;
@ -87,29 +81,6 @@ class Updater extends BasicEmitter {
$this->log = $log;
$this->config = $config;
$this->checker = $checker;
$this->simulateStepEnabled = true;
$this->updateStepEnabled = true;
}
/**
* Sets whether the database migration simulation must
* be enabled.
* This can be set to false to skip this test.
*
* @param bool $flag true to enable simulation, false otherwise
*/
public function setSimulateStepEnabled($flag) {
$this->simulateStepEnabled = $flag;
}
/**
* Sets whether the update must be performed.
* This can be set to false to skip the actual update.
*
* @param bool $flag true to enable update, false otherwise
*/
public function setUpdateStepEnabled($flag) {
$this->updateStepEnabled = $flag;
}
/**
@ -131,9 +102,9 @@ class Updater extends BasicEmitter {
public function upgrade() {
$this->emitRepairEvents();
$logLevel = $this->config->getSystemValue('loglevel', \OCP\Util::WARN);
$logLevel = $this->config->getSystemValue('loglevel', Util::WARN);
$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
$this->config->setSystemValue('loglevel', \OCP\Util::DEBUG);
$this->config->setSystemValue('loglevel', Util::DEBUG);
$wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
@ -254,68 +225,48 @@ class Updater extends BasicEmitter {
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
$repair->run();
// simulate DB upgrade
if ($this->simulateStepEnabled) {
$this->checkCoreUpgrade();
// simulate apps DB upgrade
$this->checkAppUpgrade($currentVersion);
$this->doCoreUpgrade();
try {
// TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
Setup::installBackgroundJobs();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
if ($this->updateStepEnabled) {
$this->doCoreUpgrade();
// update all shipped apps
$disabledApps = $this->checkAppsRequirements();
$this->doAppUpgrade();
try {
// TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
Setup::installBackgroundJobs();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
// upgrade appstore apps
$this->upgradeAppStoreApps($disabledApps);
// update all shipped apps
$disabledApps = $this->checkAppsRequirements();
$this->doAppUpgrade();
// upgrade appstore apps
$this->upgradeAppStoreApps($disabledApps);
// install new shipped apps on upgrade
OC_App::loadApps('authentication');
$errors = Installer::installShippedApps(true);
foreach ($errors as $appId => $exception) {
/** @var \Exception $exception */
$this->log->logException($exception, ['app' => $appId]);
$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
}
// post-upgrade repairs
$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
$repair->run();
//Invalidate update feed
$this->config->setAppValue('core', 'lastupdatedat', 0);
// Check for code integrity if not disabled
if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
$this->emit('\OC\Updater', 'startCheckCodeIntegrity');
$this->checker->runInstanceVerification();
$this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
}
// only set the final version if everything went well
$this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion()));
$this->config->setAppValue('core', 'vendor', $this->getVendor());
// install new shipped apps on upgrade
OC_App::loadApps('authentication');
$errors = Installer::installShippedApps(true);
foreach ($errors as $appId => $exception) {
/** @var \Exception $exception */
$this->log->logException($exception, ['app' => $appId]);
$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
}
}
protected function checkCoreUpgrade() {
$this->emit('\OC\Updater', 'dbSimulateUpgradeBefore');
// post-upgrade repairs
$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
$repair->run();
// simulate core DB upgrade
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
//Invalidate update feed
$this->config->setAppValue('core', 'lastupdatedat', 0);
$this->emit('\OC\Updater', 'dbSimulateUpgrade');
// Check for code integrity if not disabled
if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
$this->emit('\OC\Updater', 'startCheckCodeIntegrity');
$this->checker->runInstanceVerification();
$this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
}
// only set the final version if everything went well
$this->config->setSystemValue('version', implode('.', Util::getVersion()));
$this->config->setAppValue('core', 'vendor', $this->getVendor());
}
protected function doCoreUpgrade() {
@ -424,7 +375,7 @@ class Updater extends BasicEmitter {
private function checkAppsRequirements() {
$isCoreUpgrade = $this->isCodeUpgrade();
$apps = OC_App::getEnabledApps();
$version = \OCP\Util::getVersion();
$version = Util::getVersion();
$disabledApps = [];
foreach ($apps as $app) {
// check if the app is compatible with this version of ownCloud
@ -461,7 +412,7 @@ class Updater extends BasicEmitter {
*/
private function isCodeUpgrade() {
$installedVersion = $this->config->getSystemValue('version', '0.0.0');
$currentVersion = implode('.', \OCP\Util::getVersion());
$currentVersion = implode('.', Util::getVersion());
if (version_compare($currentVersion, $installedVersion, '>')) {
return true;
}

View file

@ -191,23 +191,6 @@ class OC_DB {
return $result;
}
/**
* simulate the database schema update
* @param string $file file to read structure from
* @throws Exception
* @return string|boolean
*/
public static function simulateUpdateDbFromStructure($file) {
$schemaManager = self::getMDB2SchemaManager();
try {
$result = $schemaManager->simulateUpdateDbFromStructure($file);
} catch (Exception $e) {
\OCP\Util::writeLog('core', 'Simulated database structure update failed ('.$e.')', \OCP\Util::FATAL);
throw $e;
}
return $result;
}
/**
* remove all tables defined in a database structure xml file
* @param string $file the xml file describing the tables

View file

@ -27,25 +27,25 @@ use OCP\IConfig;
use OCP\ILogger;
use OC\IntegrityCheck\Checker;
class UpdaterTest extends \Test\TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
class UpdaterTest extends TestCase {
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var ILogger */
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var Updater */
private $updater;
/** @var Checker */
/** @var Checker | \PHPUnit_Framework_MockObject_MockObject */
private $checker;
public function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\\OCP\\IConfig')
$this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$this->logger = $this->getMockBuilder('\\OCP\\ILogger')
$this->logger = $this->getMockBuilder(ILogger::class)
->disableOriginalConstructor()
->getMock();
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
$this->checker = $this->getMockBuilder(Checker::class)
->disableOriginalConstructor()
->getMock();
@ -169,20 +169,6 @@ class UpdaterTest extends \Test\TestCase {
$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion));
}
public function testSetSimulateStepEnabled() {
$this->updater->setSimulateStepEnabled(true);
$this->assertSame(true, $this->invokePrivate($this->updater, 'simulateStepEnabled'));
$this->updater->setSimulateStepEnabled(false);
$this->assertSame(false, $this->invokePrivate($this->updater, 'simulateStepEnabled'));
}
public function testSetUpdateStepEnabled() {
$this->updater->setUpdateStepEnabled(true);
$this->assertSame(true, $this->invokePrivate($this->updater, 'updateStepEnabled'));
$this->updater->setUpdateStepEnabled(false);
$this->assertSame(false, $this->invokePrivate($this->updater, 'updateStepEnabled'));
}
public function testSetSkip3rdPartyAppsDisable() {
$this->updater->setSkip3rdPartyAppsDisable(true);
$this->assertSame(true, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable'));