From 2008b84aa1c12df31ba5cc213ffb13b60d75a44a Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Fri, 7 Oct 2016 18:32:34 +0000 Subject: [PATCH] Add some scripts for exporting and restoring staging modules/ for pkgdb. --- .../scripts/export-pkgdb-stg-modules.py | 21 +++++++ .../scripts/restore-pkgdb-stg-modules.py | 60 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 playbooks/manual/staging-sync/scripts/export-pkgdb-stg-modules.py create mode 100644 playbooks/manual/staging-sync/scripts/restore-pkgdb-stg-modules.py diff --git a/playbooks/manual/staging-sync/scripts/export-pkgdb-stg-modules.py b/playbooks/manual/staging-sync/scripts/export-pkgdb-stg-modules.py new file mode 100644 index 0000000000..a82fe677ef --- /dev/null +++ b/playbooks/manual/staging-sync/scripts/export-pkgdb-stg-modules.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +""" Save the staging modules/ pkgdb entries to a local json file. + +Use this script to save pkgdb modules/ entries in staging before wiping the db. +""" + +import json + +import requests + +filename = 'old-modules.json' + +response = requests.get( + 'https://admin.stg.fedoraproject.org/pkgdb/api/packages/', + params=dict(namespace='modules'), +) +data = response.json() +with open(filename, 'wb') as f: + f.write(json.dumps(data).encode('utf-8')) + +print "Wrote %s" % filename diff --git a/playbooks/manual/staging-sync/scripts/restore-pkgdb-stg-modules.py b/playbooks/manual/staging-sync/scripts/restore-pkgdb-stg-modules.py new file mode 100644 index 0000000000..3217d6948f --- /dev/null +++ b/playbooks/manual/staging-sync/scripts/restore-pkgdb-stg-modules.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +""" Restore modules/ pkgdb entries in staging. + +Use this script to restore pkgdb entries in staging after having wiped that db. + +The workflow usually goes: + +- Run the `export-pkgdb-stg-modules.py` script. This will save the modules and + their acls out to a local `old-modules.json` file. +- Run the `playbooks/manual/staging-sync/db-sync.yml` playbook. This will nuke + the staging pkgdb db and replace it with a copy of the current production + pkgdb db. +- Run this `restore-pkgdb-stg-modules.py` script. It will read in that + `old-modules.json` script and then recreate those entries in the new fresh + staging db. + +""" + +import json + +import pkgdb2client + +client = pkgdb2client.PkgDB( + 'https://admin.stg.fedoraproject.org/pkgdb', + login_callback=pkgdb2client.ask_password, +) + +with open('old-modules.json', 'rb') as f: + data = json.loads(f.read().decode('utf-8')) + +for package in data['packages']: + print "Handling %s/%s" % (package['namespace'], package['name']) + client.create_package( + pkgname=package['name'], + summary=package['summary'], + description=package['description'], + review_url=package['review_url'], + status=package['status'], + shouldopen='whatever', # unused.. + branches='master', + poc=package['acls'][0]['point_of_contact'], + upstream_url=package['upstream_url'], + namespace=package['namespace'], + critpath=False, + #monitoring_status=False, + #koschei=False + ) + users = set([i['fas_name'] for i in package['acls'][0]['acls']]) + for user in users: + print " Granting all to %r" % user + client.update_acl( + pkgname=package['name'], + namespace=package['namespace'], + branches='master', + acls=['watchcommits', 'watchbugzilla', 'approveacls', 'commit'], + status='Approved', + user=user, + ) + +