BryanDavis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/230833

Change subject: Fix wikiversions compilation problem
......................................................................

Fix wikiversions compilation problem

The inplace chmod introduced in If3bd73f fails when executed by a user
in the wikidev group who doesn't actually own the file. Use the same tmp
file + rename method used by the cdb compilation to avoid this.

Also renames scap.tasks.compile_wikiversions_cdb to
scap.tasks.compile_wikiversions and updates the doc string.

Change-Id: Ice6d60de319368230c015eb28630cd8904236771
---
M docs/scripts.rst
M scap/main.py
M scap/tasks.py
3 files changed, 28 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/scap 
refs/changes/33/230833/1

diff --git a/docs/scripts.rst b/docs/scripts.rst
index 43f34a3..6b15576 100644
--- a/docs/scripts.rst
+++ b/docs/scripts.rst
@@ -14,7 +14,7 @@
 .. seealso::
    * :func:`scap.Scap`
    * :func:`scap.tasks.check_php_syntax`
-   * :func:`scap.tasks.compile_wikiversions_cdb`
+   * :func:`scap.tasks.compile_wikiversions`
    * :func:`scap.tasks.sync_common`
    * :func:`scap.tasks.sync_wikiversions`
 
@@ -75,7 +75,7 @@
 .. program-output:: ../bin/sync-wikiversions --help
 .. seealso::
    * :func:`scap.SyncWikiversions`
-   * :func:`scap.tasks.compile_wikiversions_cdb`
+   * :func:`scap.tasks.compile_wikiversions`
    * :func:`scap.tasks.sync_wikiversions`
 
 
@@ -107,7 +107,7 @@
 .. program-output:: ../bin/compile-wikiversions --help
 .. seealso::
    * :func:`scap.CompileWikiversions`
-   * :func:`scap.tasks.compile_wikiversions_cdb`
+   * :func:`scap.tasks.compile_wikiversions`
 
 
 scap-rebuild-cdbs
diff --git a/scap/main.py b/scap/main.py
index 7861ca4..be59301 100644
--- a/scap/main.py
+++ b/scap/main.py
@@ -113,7 +113,7 @@
     def main(self, *extra_args):
         self._run_as('mwdeploy')
         self._assert_current_user('mwdeploy')
-        tasks.compile_wikiversions_cdb('deploy', self.config)
+        tasks.compile_wikiversions('deploy', self.config)
         return 0
 
 
diff --git a/scap/tasks.py b/scap/tasks.py
index cadf242..699a769 100644
--- a/scap/tasks.py
+++ b/scap/tasks.py
@@ -95,8 +95,8 @@
                 utils.check_valid_json_file(abspath)
 
 
-def compile_wikiversions_cdb(source_tree, cfg):
-    """Validate and compile the wikiversions.json file into a CDB database.
+def compile_wikiversions(source_tree, cfg):
+    """Validate and compile the wikiversions.json file.
 
     1. Find the realm specific filename for wikiversions.json in staging area
     2. Validate that all versions mentioned in the json exist as directories
@@ -106,6 +106,9 @@
     4. Create a temporary CDB file from the json contents
     5. Atomically rename the temporary CDB to the realm specific
        wikiversions.cdb filename
+    6. Create a temporary php file from the json contents
+    7. Atomically rename the temporary php to the realm specific
+       wikiversions.php filename
 
     :param source_tree: Source tree to read file from: 'deploy' or 'stage'
     :param cfg: Dict of global configuration values
@@ -114,7 +117,7 @@
 
     working_dir = cfg['%s_dir' % source_tree]
 
-    # Find the realm specific wikiverisons file names
+    # Find the realm specific wikiversions file names
     base_file = os.path.join(working_dir, 'wikiversions.json')
     json_file = utils.get_realm_specific_filename(
         base_file, cfg['wmf_realm'], cfg['datacenter'])
@@ -143,6 +146,7 @@
         raise KeyError('Missing %d expected dbs in %s: %s' % (
             len(missing_dbs), json_file, ', '.join(missing_dbs)))
 
+    # Build the CDB version
     tmp_cdb_file = '%s.tmp' % cdb_file
     try:
         os.unlink(tmp_cdb_file)
@@ -158,12 +162,14 @@
         os.fsync(fp.fileno())
 
     if not os.path.isfile(tmp_cdb_file):
-        raise IOError(errno.ENOENT, 'Failed to create CDB', tmp_cdb_file)
+        raise IOError(
+            errno.ENOENT, 'Failed to create cdb wikiversions', tmp_cdb_file)
 
     os.rename(tmp_cdb_file, cdb_file)
     os.chmod(cdb_file, 0664)
     logger.info('Compiled %s to %s', json_file, cdb_file)
 
+    # Build the php version
     php_code = '<?php\nreturn array(\n%s\n);\n' % json.dumps(
         wikiversions,
         separators=(',', ' => '),
@@ -171,10 +177,22 @@
         indent=4
     ).strip('{}\n')
 
-    with open(php_file, 'wt') as fp:
+    tmp_php_file = '%s.tmp' % php_file
+    try:
+        os.unlink(tmp_php_file)
+    except OSError:
+        pass
+
+    with open(tmp_php_file, 'wt') as fp:
         fp.write(php_code)
         fp.flush()
         os.fsync(fp.fileno())
+
+    if not os.path.isfile(tmp_php_file):
+        raise IOError(
+            errno.ENOENT, 'Failed to create php wikiversions', tmp_php_file)
+
+    os.rename(tmp_php_file, php_file)
     os.chmod(php_file, 0664)
     logger.info('Compiled %s to %s', json_file, php_file)
 
@@ -322,7 +340,7 @@
     """
     stats = log.Stats(cfg['statsd_host'], int(cfg['statsd_port']))
     with log.Timer('sync_wikiversions', stats):
-        compile_wikiversions_cdb('stage', cfg)
+        compile_wikiversions('stage', cfg)
 
         rsync = ssh.Job(hosts, user=cfg['ssh_user']).shuffle()
         rsync.command('sudo -u mwdeploy -n -- /usr/bin/rsync -l '

-- 
To view, visit https://gerrit.wikimedia.org/r/230833
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice6d60de319368230c015eb28630cd8904236771
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/scap
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to