Yuvipanda has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/328564 )

Change subject: labsdb: Run maintain-dbusers only on active NFS host
......................................................................

labsdb: Run maintain-dbusers only on active NFS host

Change-Id: I3156a406f37dd5344273faf5c770c32eddee0e25
---
M modules/role/files/labs/db/maintain-dbusers.py
M modules/role/manifests/labs/db/maintain_dbusers.pp
M modules/role/manifests/labs/nfs/secondary.pp
3 files changed, 28 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/64/328564/1

diff --git a/modules/role/files/labs/db/maintain-dbusers.py 
b/modules/role/files/labs/db/maintain-dbusers.py
index bb5cca5..eb0e5c0 100644
--- a/modules/role/files/labs/db/maintain-dbusers.py
+++ b/modules/role/files/labs/db/maintain-dbusers.py
@@ -63,6 +63,7 @@
 import random
 from hashlib import sha1
 import subprocess
+import netifaces
 
 PROJECT = 'tools'
 PASSWORD_LENGTH = 16
@@ -422,6 +423,19 @@
         """, ('tool', account))
         acct_db.commit()
 
+
+def is_active_nfs(config):
+    """
+    Return true if current host is the active NFS host
+
+    It looks for an interface attached to the current host that has an IP
+    that is the NFS cluster service IP.
+    """
+    for iface in netifaces.interfaces():
+        if netifaces.ipaddresses(iface)[netifaces.AF_INET][0]['addr'] == 
config['nfs-cluster-ip']:
+            return True
+    return False
+
 if __name__ == '__main__':
     argparser = argparse.ArgumentParser()
 
@@ -457,7 +471,7 @@
         delete:
 
         Deletes a given user. Provide a username like tools.admin,
-        not a mysql user name.
+        not a mysql user name. 
         """
     )
     argparser.add_argument(
@@ -483,8 +497,14 @@
         harvest_replica_accts(config)
     elif args.action == 'maintain':
         while True:
-            populate_new_tools(config)
-            create_accounts(config)
+            # Check if we're the primary NFS server.
+            # If we aren't, just loop lamely, not exit. This allows this 
script to
+            # run continuously on both labstores, making for easier monitoring 
given
+            # our puppet situation and also easy failover. When NFS primaries 
are
+            # switched, nothing new needs to be done to switch this over.
+            if is_active_nfs(config):
+                populate_new_tools(config)
+                create_accounts(config)
             time.sleep(60)
     elif args.action == 'delete':
         if args.extra_args is None:
diff --git a/modules/role/manifests/labs/db/maintain_dbusers.pp 
b/modules/role/manifests/labs/db/maintain_dbusers.pp
index edf0591..fd7d8c4 100644
--- a/modules/role/manifests/labs/db/maintain_dbusers.pp
+++ b/modules/role/manifests/labs/db/maintain_dbusers.pp
@@ -68,7 +68,10 @@
             'host' => 'm5-master.eqiad.wmnet',
             'username' => $::passwords::labsdbaccounts::db_user,
             'password' => $::passwords::labsdbaccounts::db_password,
-        }
+        },
+        # Pick this up from Hiera once it gets put into hiera
+        # in role::labs::nfs::secondary
+        'nfs-cluster-ip'   => '10.64.37.18',
     }
 
     file { '/etc/dbusers.yaml':
diff --git a/modules/role/manifests/labs/nfs/secondary.pp 
b/modules/role/manifests/labs/nfs/secondary.pp
index 3d44c72..daf0da4 100644
--- a/modules/role/manifests/labs/nfs/secondary.pp
+++ b/modules/role/manifests/labs/nfs/secondary.pp
@@ -41,7 +41,7 @@
     }
 
     # TODO: hiera this
-
+    # TODO: use hiera in maintain_dbusers too when this is hiera'd
 
     # Floating IP assigned to drbd primary(active NFS server). Should come 
from hiera
     $cluster_ip = '10.64.37.18'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3156a406f37dd5344273faf5c770c32eddee0e25
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <yuvipa...@wikimedia.org>

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

Reply via email to