jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/367828 )
Change subject: Moving update wikiversions to scap
......................................................................
Moving update wikiversions to scap
Change-Id: I868103305074ed19fa14a444cd42b67755d57250
---
D multiversion/updateWikiversions
A scap/plugins/updatewikiversions.py
2 files changed, 87 insertions(+), 128 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/multiversion/updateWikiversions b/multiversion/updateWikiversions
deleted file mode 100755
index ae32287..0000000
--- a/multiversion/updateWikiversions
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/usr/bin/env php
-<?php
-error_reporting( E_ALL );
-
-require_once __DIR__ . '/defines.php';
-require_once __DIR__ . '/MWWikiversions.php';
-require_once __DIR__ . '/MWRealm.php';
-
-/*
- * This script switches all wikis in a .dblist file running one MediaWiki
- * version to another MediaWiki version. Since this only changes the
wikiversions.json
- * and wikiversions.php files on tin, they will still need to be synced to push
- * the upgrade/downgrade to the apaches.
- *
- * The first argument is the old version, typically of the format
"php-X.XX-wmf.X".
- * If "all" is given, then all wikis will be switched over.
- * The second argument is the new version, typically of the format
"php-X.XX-wmf.X".
- * The third argument is the name of a .dblist file under the common/ dir.
- *
- * @return void
- */
-function updateWikiversions() {
- global $argv;
- $common = MEDIAWIKI_STAGING_DIR;
- $jsonPath = getRealmSpecificFilename( MEDIAWIKI_STAGING_DIR .
'/wikiversions.json' );
-
- if ( count( $argv ) !== 3 ) {
- print "Usage: updateWikiversions <name>.dblist
php-X.XX-wmf.X\n";
- exit( 1 );
- }
-
- $dbListName = basename( $argv[1], '.dblist' );
- $dbList = MWWikiversions::readDbListFile( $dbListName );
-
- $newVersion = $argv[2];
- if ( !preg_match( MEDIAWIKI_DIRECTORY_REGEX, $newVersion ) || !is_dir(
"$common/$newVersion" ) ) {
- print "Invalid version specifier: $newVersion\n";
- exit( 1 );
- }
-
- if ( file_exists( $jsonPath ) ) {
- $versionRows = MWWikiversions::readWikiVersionsFile( $jsonPath
);
- } else {
- if ( $dbListName !== 'all' ) {
- echo "No $jsonPath file and not invoked with 'all'.
Cowardly refusing to act.\n";
- exit( 1 );
- }
- echo "$jsonPath not found -- rebuilding from scratch!\n";
- $versionRows = array();
- }
-
- $inserted = 0;
- $migrated = 0;
-
- foreach ( $dbList as $dbName ) {
- if ( !isset( $versionRows[$dbName] ) ) {
- $inserted++;
- } else {
- $migrated++;
- }
- $versionRows[$dbName] = $newVersion;
- }
-
- $total = count( $versionRows );
- ksort( $versionRows );
-
- MWWikiversions::writeWikiVersionsFile( $jsonPath, $versionRows );
- echo "Updated $jsonPath: $inserted inserted, $migrated migrated.\n";
-}
-
-function updateBranchPointers() {
- $branchDirs = MWWikiversions::getAvailableBranchDirs();
-
- if ( !$branchDirs ) {
- fwrite( STDERR, __FUNCTION__ . ': no deployment branch
directories found in ' . MEDIAWIKI_DEPLOYMENT_DIR . "\n" );
- exit( 1 );
- }
-
- // Default sort is lexographical which incorrectly sorts e.g.
[1.23wmf9, 1.23wmf10]
- usort( $branchDirs, 'version_compare' );
- $current = array_pop( $branchDirs );
-
- // Symlink common/php to the current branch using a relative path so
that
- // the symlink works from both MEDIAWIKI_STAGING_DIR and
- // MEDIAWIKI_DEPLOYMENT_DIR
- $phpLinkTarget = substr( $current, strlen( MEDIAWIKI_DEPLOYMENT_DIR ) +
1 );
- updateSymlink( MEDIAWIKI_STAGING_DIR . '/php', $phpLinkTarget );
-}
-
-/**
- * @param string $link
- * @param string $dest
- */
-function updateSymlink( $link, $dest ) {
- // Change pwd to MEDIAWIKI_STAGING_DIR so that relative paths can be
verified
- chdir( MEDIAWIKI_STAGING_DIR );
-
- if ( !file_exists( $dest ) ) {
- fwrite( STDERR, __FUNCTION__ . ": link target $dest does not
exist.\n" );
- exit( 1 );
- }
-
- if ( file_exists( $link ) ) {
- if ( realpath( $link ) === realpath( $dest ) ) {
- echo "$link is already up-to-date.\n";
- return;
- }
-
- if ( !is_link( $link ) ) {
- fwrite( STDERR, __FUNCTION__ . ": $link exists and is
not a symbolic link.\n" );
- exit( 1 );
- }
-
- if ( !unlink( $link ) ) {
- fwrite( STDERR, __FUNCTION__ . ": failed to unlink
$link\n" );
- exit( 1 );
- }
- }
-
- if ( !symlink( $dest, $link ) ) {
- fwrite( STDERR, __FUNCTION__ . ": failed to create $link\n" );
- exit( 1 );
- }
- echo "$link => $dest\n";
-}
-
-updateWikiversions();
-updateBranchPointers();
diff --git a/scap/plugins/updatewikiversions.py
b/scap/plugins/updatewikiversions.py
new file mode 100644
index 0000000..ad88663
--- /dev/null
+++ b/scap/plugins/updatewikiversions.py
@@ -0,0 +1,87 @@
+"""
+Updates wiki versions json files and symlink pointers
+"""
+
+import json
+import os
+import subprocess
+
+import scap.cli as cli
+import scap.utils as utils
+
+
[email protected]('update-wikiversions')
+class UpdateWikiversions(cli.Application):
+ """ Scap subcommand for updating wikiversions.json to a new version"""
+
+ @cli.argument('dblist',
+ help='The dblist file to use as input for migrating.')
+ @cli.argument('branch', help='The name of the branch to migrate to.')
+ def main(self, *extra_args):
+ self.update_wikiversions_json()
+ self.update_branch_pointer()
+
+ def update_wikiversions_json(self):
+ """
+ Does the first step of migrating: actually change all the requested
+ dblist entries to the new version!
+ """
+ json_path = utils.get_realm_specific_filename(
+ 'wikiversions.json', self.config['wmf_realm'],
+ self.config['datacenter'])
+
+ db_list_name = os.path.basename(
+ os.path.splitext(self.arguments.dblist)[0])
+
+ script = os.path.join(
+ self.config['stage_dir'], 'multiversion', 'bin', 'expanddblist')
+ dblist = subprocess.check_output([script, db_list_name]).splitlines()
+
+ new_dir = 'php-%s' % self.arguments.branch
+
+ if not os.path.isdir(os.path.join(self.config['stage_dir'], new_dir)):
+ raise ValueError('Invalid version specifier: %s' % new_dir)
+
+ if os.path.exists(json_path):
+ with open(json_path) as json_in:
+ version_rows = json.load(json_in)
+ else:
+ if db_list_name is not 'all':
+ raise RuntimeError(
+ 'No %s file and not invoked with "all."' % json_path +
+ 'Cowardly refusing to act.'
+ )
+ self.get_logger().info('%s not found -- rebuilding from scratch!' %
+ json_path)
+ version_rows = {}
+
+ inserted = 0
+ migrated = 0
+
+ for dbname in dblist:
+ if dbname in version_rows:
+ inserted += 1
+ else:
+ migrated += 1
+ version_rows[dbname] = new_dir
+
+ with open(json_path, 'w') as json_out:
+ json.dump(version_rows, json_out, ensure_ascii=False, indent=4,
+ separators=(',', ':'), sort_keys=True)
+
+ self.get_logger().info('Updated %s: %s inserted, %s migrated.' %
+ (json_path, inserted, migrated))
+
+ def update_branch_pointer(self):
+ """
+ This being the second step: if appropriate, swap the php symlink over
+ to the new version as well
+ """
+ cur_version = self.active_wikiversions().popitem()[0]
+
+ utils.move_symlink(
+ os.path.join(self.config['stage_dir'],
+ 'php-%s' % cur_version),
+ os.path.join(self.config['stage_dir'], 'php')
+ )
+ self.get_logger().info('Symlink updated')
--
To view, visit https://gerrit.wikimedia.org/r/367828
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I868103305074ed19fa14a444cd42b67755d57250
Gerrit-PatchSet: 19
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits