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

View File

@ -35,8 +35,8 @@ use OC\Hooks\BasicEmitter;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
use OC_App; use OC_App;
use OCP\IConfig; use OCP\IConfig;
use OC\Setup;
use OCP\ILogger; use OCP\ILogger;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
/** /**
@ -59,12 +59,6 @@ class Updater extends BasicEmitter {
/** @var Checker */ /** @var Checker */
private $checker; private $checker;
/** @var bool */
private $simulateStepEnabled;
/** @var bool */
private $updateStepEnabled;
/** @var bool */ /** @var bool */
private $skip3rdPartyAppsDisable; private $skip3rdPartyAppsDisable;
@ -87,29 +81,6 @@ class Updater extends BasicEmitter {
$this->log = $log; $this->log = $log;
$this->config = $config; $this->config = $config;
$this->checker = $checker; $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() { public function upgrade() {
$this->emitRepairEvents(); $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->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); $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
@ -254,68 +225,48 @@ class Updater extends BasicEmitter {
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
$repair->run(); $repair->run();
// simulate DB upgrade $this->doCoreUpgrade();
if ($this->simulateStepEnabled) {
$this->checkCoreUpgrade();
// simulate apps DB upgrade
$this->checkAppUpgrade($currentVersion);
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) { // update all shipped apps
$this->doCoreUpgrade(); $disabledApps = $this->checkAppsRequirements();
$this->doAppUpgrade();
try { // upgrade appstore apps
// TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 $this->upgradeAppStoreApps($disabledApps);
Setup::installBackgroundJobs();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
// update all shipped apps // install new shipped apps on upgrade
$disabledApps = $this->checkAppsRequirements(); OC_App::loadApps('authentication');
$this->doAppUpgrade(); $errors = Installer::installShippedApps(true);
foreach ($errors as $appId => $exception) {
// upgrade appstore apps /** @var \Exception $exception */
$this->upgradeAppStoreApps($disabledApps); $this->log->logException($exception, ['app' => $appId]);
$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
// 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());
} }
}
protected function checkCoreUpgrade() { // post-upgrade repairs
$this->emit('\OC\Updater', 'dbSimulateUpgradeBefore'); $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
$repair->run();
// simulate core DB upgrade //Invalidate update feed
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); $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() { protected function doCoreUpgrade() {
@ -424,7 +375,7 @@ class Updater extends BasicEmitter {
private function checkAppsRequirements() { private function checkAppsRequirements() {
$isCoreUpgrade = $this->isCodeUpgrade(); $isCoreUpgrade = $this->isCodeUpgrade();
$apps = OC_App::getEnabledApps(); $apps = OC_App::getEnabledApps();
$version = \OCP\Util::getVersion(); $version = Util::getVersion();
$disabledApps = []; $disabledApps = [];
foreach ($apps as $app) { foreach ($apps as $app) {
// check if the app is compatible with this version of ownCloud // check if the app is compatible with this version of ownCloud
@ -461,7 +412,7 @@ class Updater extends BasicEmitter {
*/ */
private function isCodeUpgrade() { private function isCodeUpgrade() {
$installedVersion = $this->config->getSystemValue('version', '0.0.0'); $installedVersion = $this->config->getSystemValue('version', '0.0.0');
$currentVersion = implode('.', \OCP\Util::getVersion()); $currentVersion = implode('.', Util::getVersion());
if (version_compare($currentVersion, $installedVersion, '>')) { if (version_compare($currentVersion, $installedVersion, '>')) {
return true; return true;
} }

View File

@ -191,23 +191,6 @@ class OC_DB {
return $result; 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 * remove all tables defined in a database structure xml file
* @param string $file the xml file describing the tables * @param string $file the xml file describing the tables

View File

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