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

Change subject: Remove service-restart and deploy-info
......................................................................

Remove service-restart and deploy-info

These are specific to Trebuchet and can be removed.

Change-Id: I17200715f50327eff2a132756db0f2a0df3ca3fe
---
D modules/deployment/files/git-deploy/utils/deploy-info
D modules/deployment/files/git-deploy/utils/service-restart
2 files changed, 0 insertions(+), 266 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/91/379191/1

diff --git a/modules/deployment/files/git-deploy/utils/deploy-info 
b/modules/deployment/files/git-deploy/utils/deploy-info
deleted file mode 100644
index 39e2fc0..0000000
--- a/modules/deployment/files/git-deploy/utils/deploy-info
+++ /dev/null
@@ -1,204 +0,0 @@
-#!/usr/bin/python
-
-import redis
-import sys
-import subprocess
-import json
-import datetime
-from optparse import OptionParser
-
-
-def main():
-    # TODO: use argparse and for the love of god clean this utility up
-    parser = OptionParser(conflict_handler="resolve")
-    parser.set_usage("deploy-info [options]\n\nexample: deploy-info 
--repo=slot0 --tag=slot0-20121229-034924")
-
-    parser.add_option("--fetch", action="store_true", dest="fetch", 
default=False, help="Report on the state of fetch, rather than checkout")
-    parser.add_option("--restart", action="store_true", dest="restart", 
default=False, help="Report on the state of restart")
-    parser.add_option("--repo", action="store", dest="repo", help="Report on 
this repo and all its dependencies")
-    parser.add_option("--detailed", action="store_true", dest="detailed", 
default=False, help="When reporting on fetch or checkout, also show the minion 
information, rather than a summary.")
-    parser.add_option("--nodeps", action="store_true", dest="nodeps", 
default=False, help="Don't report the dependencies when using --repo")
-    parser.add_option("--tag", action="store", dest="tag", help="Report on the 
specified tag, rather than the current tag")
-    parser.add_option("--full-report", action="store_true", dest="fullreport", 
default=False, help="Show a full report of the state of the requested repo, or 
all repos")
-    (options, args) = parser.parse_args()
-    serv = redis.Redis(host='localhost', port=6379, db=0)
-    p = subprocess.Popen("sudo salt-call -l quiet --out json pillar.data", 
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    out = p.communicate()[0]
-    try:
-        pillar = json.loads(out)
-        if 'local' in pillar:
-            pillar = pillar['local']
-    except ValueError:
-        print "JSON data wasn't loaded from the pillar call. Trebuchet can't 
configure itself. Exiting."
-        return None
-    repos = serv.smembers('deploy:repos')
-    if options.repo:
-        if options.repo not in repos:
-            print "{0}: repo not found in redis".format(options.repo)
-            sys.exit(1)
-        else:
-            try:
-                repo_config = pillar['repo_config'][options.repo]
-            except KeyError:
-                print "{0}: repo not found in pillar data".format(options.repo)
-                sys.exit(1)
-            if 'dependencies' in repo_config and not options.nodeps:
-                dependencies = repo_config['dependencies']
-            else:
-                dependencies = []
-            if options.restart:
-                for dependency in dependencies:
-                    _repo_restart_report(serv, dependency)
-                _repo_restart_report(serv, options.repo)
-            elif options.fullreport:
-                for dependency in dependencies:
-                    _repo_report(serv, dependency, fetch=options.fetch)
-                _repo_report(serv, options.repo, fetch=options.fetch,
-                             detailed=options.detailed)
-            elif options.tag:
-                for dependency in dependencies:
-                    _repo_report(serv, dependency, check_tag=options.tag,
-                                 fetch=options.fetch,
-                                 detailed=options.detailed)
-                _repo_report(serv, options.repo, check_tag=options.tag,
-                             fetch=options.fetch, detailed=options.detailed)
-            else:
-                for dependency in dependencies:
-                    current_tag = _get_current_tag(dependency, pillar)
-                    _repo_report(serv, dependency, check_tag=current_tag, 
fetch=options.fetch, detailed=options.detailed)
-                current_tag = _get_current_tag(options.repo, pillar)
-                _repo_report(serv, options.repo, check_tag=current_tag, 
fetch=options.fetch, detailed=options.detailed)
-    else:
-        for repo in repos:
-            if repo not in pillar['repo_config']:
-                continue
-            if options.restart:
-                _repo_restart_report(serv, repo)
-            elif options.fullreport:
-                _repo_report(serv, repo, fetch=options.fetch, 
detailed=options.detailed)
-            elif options.tag:
-                _repo_report(serv, repo, check_tag=options.tag, 
fetch=options.fetch, detailed=options.detailed)
-            else:
-                current_tag = _get_current_tag(repo, pillar)
-                _repo_report(serv, repo, check_tag=current_tag, 
fetch=options.fetch, detailed=options.detailed)
-
-
-def _get_current_tag(repo, pillar):
-        try:
-            repodir = pillar['repo_config'][repo]['location']
-        except KeyError:
-            parent_dir = pillar['deployment_config']['parent_dir']
-            repodir = '{0}/{1}'.format(parent_dir, repo)
-        f = open(repodir + '/.deploy', 'r')
-        deployinfo = f.readlines()
-        tag = ''
-        for info in deployinfo:
-            if info.startswith('tag: '):
-                tag = info[5:]
-                tag = tag.strip()
-        return tag
-
-
-def _repo_restart_report(serv, repo):
-    print ""
-    print "Repo: {0}".format(repo)
-    minions = serv.smembers('deploy:{0}:minions'.format(repo))
-    print ""
-    for minion in minions:
-        data = _get_minion_data(serv, repo, minion)
-        msg = "{0}: {1} [started: {2} mins, last-return: {3} mins]"
-        print msg.format(minion, data['restart_status'],
-                         data['restart_checkin_mins'], data['restart_mins'])
-    print ""
-    print "{0} minions reporting".format(len(minions))
-
-
-def _repo_report(serv, repo, check_tag=None, fetch=False, detailed=False):
-    print ""
-    header = "Repo: {0}".format(repo)
-    if check_tag:
-        header = header + "; checking tag: {0}".format(check_tag)
-    print header
-    minions = serv.smembers('deploy:{0}:minions'.format(repo))
-    if check_tag:
-        minion_data = {}
-        for minion in minions:
-            data = _get_minion_data(serv, repo, minion)
-            if fetch:
-                check = data['fetch_tag'] != check_tag
-            else:
-                check = data['tag'] != check_tag
-            if check:
-                minion_data[minion] = data
-        if minion_data:
-            print ""
-        if detailed:
-            for item, data in minion_data.items():
-                msg = ("{0}: {1} (fetch: {2} [started: {3} mins,"
-                       " last-return: {4} mins])")
-                if fetch:
-                    print msg.format(minion, data['tag'], data['fetch_status'],
-                                     data['fetch_checkin_mins'],
-                                     data['fetch_mins'])
-                else:
-                    print msg.format(minion, data['tag'],
-                                     data['checkout_status'],
-                                     data['checkout_checkin_mins'],
-                                     data['checkout_mins'])
-        print ""
-        print "{0} minions pending ({1} reporting)".format(len(minion_data),
-                                                           len(minions))
-    else:
-        print ""
-        for minion in minions:
-            data = _get_minion_data(serv, repo, minion)
-            msg = ("{0}: {1} (fetch: {2} [started: {3} mins,"
-                   " last-return: {4} mins], checkout: {5}"
-                   " [started: {6} mins, last-return: {7}])")
-            print msg.format(minion, data['tag'], data['fetch_status'],
-                             data['fetch_checkin_mins'], data['fetch_mins'],
-                             data['checkout_status'],
-                             data['checkout_checkin_mins'],
-                             data['checkout_mins'])
-        print ""
-        print "{0} minions reporting".format(len(minions))
-
-
-def _get_minion_data(serv, repo, minion):
-    data = {}
-    now = datetime.datetime.now()
-    minion_key = 'deploy:{0}:minions:{1}'.format(repo, minion)
-    data['fetch_status'] = serv.hget(minion_key, 'fetch_status')
-    fetch_checkin_timestamp = serv.hget(minion_key, 'fetch_checkin_timestamp')
-    data['fetch_checkin_mins'] = _mins_ago(now, fetch_checkin_timestamp)
-    fetch_timestamp = serv.hget(minion_key, 'fetch_timestamp')
-    data['fetch_mins'] = _mins_ago(now, fetch_timestamp)
-    data['checkout_status'] = serv.hget(minion_key, 'checkout_status')
-    checkout_checkin_timestamp = serv.hget(minion_key,
-                                           'checkout_checkin_timestamp')
-    data['checkout_checkin_mins'] = _mins_ago(now, checkout_checkin_timestamp)
-    checkout_timestamp = serv.hget(minion_key, 'checkout_timestamp')
-    data['checkout_mins'] = _mins_ago(now, checkout_timestamp)
-    data['tag'] = serv.hget(minion_key, 'tag')
-    data['fetch_tag'] = serv.hget(minion_key, 'fetch_tag')
-    restart_checkin_timestamp = serv.hget(minion_key,
-                                          'restart_checkin_timestamp')
-    data['restart_checkin_mins'] = _mins_ago(now, restart_checkin_timestamp)
-    data['restart_status'] = serv.hget(minion_key, 'restart_status')
-    restart_timestamp = serv.hget(minion_key, 'restart_timestamp')
-    data['restart_mins'] = _mins_ago(now, restart_timestamp)
-    return data
-
-
-def _mins_ago(now, timestamp):
-    if timestamp:
-        time = datetime.datetime.fromtimestamp(float(timestamp))
-        delta = now - time
-        mins = delta.seconds / 60
-    else:
-        mins = None
-    return mins
-
-
-if __name__ == "__main__":
-    main()
diff --git a/modules/deployment/files/git-deploy/utils/service-restart 
b/modules/deployment/files/git-deploy/utils/service-restart
deleted file mode 100644
index 4df497d..0000000
--- a/modules/deployment/files/git-deploy/utils/service-restart
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-  service-restart
-  ~~~~~~~~~~~~~~~
-
-  This tool is designed to restart services for trebuchet repositories. If run
-  from within a repo, it will read the repo name from the repo's git config.
-  If run from outside of a repo, it's necessary to provide the repository
-  name.
-
-  Usage: service-restart [--repo=<repo-name>]
-"""
-import argparse
-import logging
-import subprocess
-
-try:
-    NullHandler = logging.NullHandler
-except AttributeError:
-    class NullHandler(logging.Handler):
-        def emit(self, record):
-            pass
-
-logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
-LOG = logging.getLogger(__name__)
-
-
-def main():
-    argparser = argparse.ArgumentParser()
-    argparser.add_argument('--repo', dest='repo', action='store',
-                           help='The repo name that controls the service to 
restart.')
-    argparser.add_argument('--batch', dest='batch', action='store', 
default='10%',
-                           help='The batch size of the restart. Default: 10%')
-    argparser.add_argument('--timeout', dest='timeout', action='store', 
default='5',
-                           help='Timeout to the publish.runner command. 
Default: 5 seconds')
-    args = argparser.parse_args()
-
-    if args.repo:
-        repo = args.repo
-    else:
-        proc = subprocess.Popen("git config deploy.tag-prefix",
-                                shell=True,
-                                stdout=subprocess.PIPE)
-        repo = proc.communicate()[0]
-        repo = repo.strip()
-        if not repo:
-            LOG.warning('service-restart must be run within a repository or'
-                        ' --repo must be provided')
-            raise SystemExit(1)
-    cmd = ("sudo salt-call -l quiet --out json publish.runner --timeout {0} "
-           "deploy.restart '[{1},{2}]'")
-    proc = subprocess.Popen(cmd.format(args.timeout, repo, args.batch),
-                            shell=True,
-                            stdout=subprocess.PIPE)
-    proc.communicate()
-    LOG.info('Service restart sent to salt. Check the status using:'
-             ' deploy-info --repo=%s --restart' % repo)
-
-
-if __name__ == "__main__":
-    main()

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I17200715f50327eff2a132756db0f2a0df3ca3fe
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Muehlenhoff <[email protected]>

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

Reply via email to