Diederik has uploaded a new change for review.

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


Change subject: Incorporated feedback Andrew Bogott
......................................................................

Incorporated feedback Andrew Bogott

- Added check for Mediawiki
- Added check for MySQL
- Update pip to at least version 1.2
- Puppet outdated if last run was older than 24 hours
- Only check pmtpa instances
- Use warning for use of local storage instead of error

Change-Id: I859fcff0d72c284c107c4183c697a82195fc8680
---
M labs-migration-assistant/fabfile.py
M requirements.txt
2 files changed, 60 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/migration-assistant 
refs/changes/40/108340/1

diff --git a/labs-migration-assistant/fabfile.py 
b/labs-migration-assistant/fabfile.py
index ff29abb..fbd6bf4 100644
--- a/labs-migration-assistant/fabfile.py
+++ b/labs-migration-assistant/fabfile.py
@@ -113,12 +113,13 @@
             names = labinstance.get('printouts', {}).get('Instance Name', None)
             project = labinstance.get('printouts', {}).get('Project', None)
             dc = resource.split('.')[1]
-            for name in names:
-                if not name.startswith('tools'):
-                    # ignore all tool-labs instances as they are managed by
-                    # WMF.
-                    labinstance = LabInstance(name, project, dc)
-                    results[str(labinstance)] = labinstance
+            if dc == 'pmtpa': #only analyse instances in Tampa
+                for name in names:
+                    if not name.startswith('tools'):
+                        # ignore all tool-labs instances as they are managed by
+                        # WMF.
+                        labinstance = LabInstance(name, project, dc)
+                        results[str(labinstance)] = labinstance
     return results
 
 
@@ -148,7 +149,7 @@
 def detect_self_puppetmaster(labinstances):
     try:
         result = run(
-            'grep "^server = virt0.wikimedia.org" /etc/puppet/puppet.conf | wc 
-l')
+            'grep "^server = virt0.wikimedia.org|^server = .*localhost.*" 
/etc/puppet/puppet.conf | wc -l')
         if result == '0':
             logging.info('You are not using a self-hosted puppet master. [OK]')
         else:
@@ -184,7 +185,7 @@
             epoch = datetime.fromtimestamp(epoch)
             now = datetime.now()
             dt = now - epoch
-            if dt.days > 29:
+            if dt.days > 1:
                 logging.error(
                     'The last puppet run was %d days ago, please run puppet. 
[FAIL]' % dt.days)
                 labinstances[env.host_string].detect_last_puppet_run = False
@@ -206,8 +207,7 @@
         return
 
     try:
-        result = run('ls -l | wc -l')
-        result = int(result)
+        result = int(run('ls -l | wc -l'))
         if result == 0:
             logging.info(
                 'You seem not to be using your home folder for storing files. 
[OK]')
@@ -238,10 +238,55 @@
             logging.info(
                 'You seem to be using the shared storage space for your home 
folder. [OK]')
         else:
-            logging.error(
-                'You do not seem to be using the shared storage space for your 
home folder. [FAIL]')
+            logging.warn(
+                'You do not seem to be using the shared storage space for your 
home folder. Please make sure that you have backups. [WARNING]')
             labinstances[
                 env.host_string].detect_shared_storage_for_home = False
+    except SystemExit:
+        logging.error('Could not connect to %s.' % env.host_string)
+
+@task
+def detect_databases():
+    '''
+    TODO: refactor this check into a decorator function, but Fabric is not 
really cooperating
+    '''
+    if not labinstances[env.host_string].connect:
+        if not labinstances[env.host_string].connect:
+            logging.info(
+                'Skipping task because during first task was not able to 
connect to labsinstance.')
+        return
+
+    try:
+        result = int(run('ls /etc/init.d | grep mysql | wc -l'))
+        if result == 0:
+            logging.info('You are not running a MySQL instance and hence you 
do not have to make any backups. [OK]')
+        else:
+            result = int(run('mysql -e "show databases" | wc -l'))
+            if result > 1:
+                # ignore information_schema database
+                logging.warn('You are running a MySQL instance and hence you 
should probably make a backup. [OK]')
+            else:
+                logging.info('You are running a MySQL database instance but it 
does not seem to have any databases.')
+    except SystemExit:
+        logging.error('Could not connect to %s.' % env.host_string)
+
+@task
+def detect_mediawiki():
+    '''
+    TODO: refactor this check into a decorator function, but Fabric is not 
really cooperating
+    '''
+    if not labinstances[env.host_string].connect:
+        if not labinstances[env.host_string].connect:
+            logging.info(
+                'Skipping task because during first task was not able to 
connect to labsinstance.')
+        return
+
+    try:
+        result = int(run('test -d /var/lib/mediawiki && echo "Mediawiki 
install folder exists." | wc -l'))
+        if result == 1:
+            logging.warning('We detected an installation of Mediawiki, please 
make sure you have a backup. [WARNING]')
+        else:
+            logging.info('You do not have an installation of Mediawiki hence 
you do not have to make backups. [OK]')
     except SystemExit:
         logging.error('Could not connect to %s.' % env.host_string)
 
@@ -270,6 +315,8 @@
                 hosts=hosts, labinstances=labinstances)
         execute(detect_shared_storage_for_home,
                 hosts=hosts, labinstances=labinstances)
+        execute(detect_databases, hosts=hosts, labinstances=labinstances)
+        execute(detect_mediawiki, hosts=hosts, labinstances=labinstances)
 
     for labsinstance in labinstances.values():
         if not labsinstance.connect:
diff --git a/requirements.txt b/requirements.txt
index f30b06f..dd08097 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
+pip>=1.2
 fabric>=1.8.1
 requests>=2.2.0
 PyYAML==3.10

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I859fcff0d72c284c107c4183c697a82195fc8680
Gerrit-PatchSet: 1
Gerrit-Project: labs/migration-assistant
Gerrit-Branch: master
Gerrit-Owner: Diederik <dvanli...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to