Sync script for obs_rsync
This will be triggered on gocd if there are changes in the finished repositories, checks the important repositories and notifies openQA
This commit is contained in:
parent
18d3f20789
commit
7ba26f666c
@ -116,13 +116,12 @@ pipelines:
|
||||
resources:
|
||||
- monitor
|
||||
tasks:
|
||||
# endless loop
|
||||
- script: |-
|
||||
export PYTHONPATH=$PWD/scripts
|
||||
git config --global user.email "coolo@suse.de"
|
||||
git config --global user.name "GoCD Repo Monitor"
|
||||
cd repos
|
||||
../scripts/gocd/rabbit-repoid.py -A https://api.opensuse.org openSUSE:Factory openSUSE:Leap
|
||||
../scripts/gocd/rabbit-repoid.py -A https://api.opensuse.org openSUSE:Factory openSUSE:Leap Virtualization:WSL
|
||||
openSUSE.ObsRsync:
|
||||
group: Monitors
|
||||
lock_behavior: unlockWhenFinished
|
||||
@ -141,20 +140,20 @@ pipelines:
|
||||
git: git://botmaster.suse.de/opensuse-notifications.git
|
||||
branch: master
|
||||
destination: notifications
|
||||
whitelist:
|
||||
- nothing
|
||||
stages:
|
||||
- Run:
|
||||
jobs:
|
||||
Run:
|
||||
timeout: 30
|
||||
resources:
|
||||
- monitor
|
||||
- staging-bot
|
||||
tasks:
|
||||
# endless loop
|
||||
- script: |-
|
||||
export PYTHONPATH=$PWD/scripts
|
||||
git config --global user.email "coolo@suse.de"
|
||||
git config --global user.name "GoCD Repo Monitor"
|
||||
echo "Here we would sync"
|
||||
scripts/gocd/notify-obs_rsync.py --openqa https://openqa.opensuse.org --repos repos --to notifications
|
||||
SUSE.ObsRsync:
|
||||
group: Monitors
|
||||
lock_behavior: unlockWhenFinished
|
||||
@ -173,20 +172,21 @@ pipelines:
|
||||
git: git://botmaster.suse.de/suse-notifications.git
|
||||
branch: master
|
||||
destination: notifications
|
||||
whitelist:
|
||||
- nothing
|
||||
stages:
|
||||
- Run:
|
||||
jobs:
|
||||
Run:
|
||||
timeout: 30
|
||||
resources:
|
||||
- monitor
|
||||
- staging-bot
|
||||
tasks:
|
||||
# endless loop
|
||||
- script: |-
|
||||
export PYTHONPATH=$PWD/scripts
|
||||
git config --global user.email "coolo@suse.de"
|
||||
git config --global user.name "GoCD Repo Monitor"
|
||||
echo "Here we would sync"
|
||||
scripts/gocd/notify-obs_rsync.py --openqa https://openqa.suse.de --repos repos --to notifications
|
||||
|
||||
openSUSE.OriginManagerUpdate:
|
||||
group: Monitors
|
||||
|
68
gocd/notify-obs_rsync.py
Executable file
68
gocd/notify-obs_rsync.py
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from shutil import copyfile
|
||||
import subprocess
|
||||
from os.path import basename
|
||||
import glob
|
||||
from openqa_client.client import OpenQA_Client
|
||||
from openqa_client.exceptions import ConnectionError, RequestError
|
||||
|
||||
def old_filename(state):
|
||||
return f'{args.repos}/{state}.yaml'
|
||||
|
||||
def new_filename(state):
|
||||
return f'{args.to}/{state}.yaml'
|
||||
|
||||
def file_changed(state):
|
||||
with open(old_filename(state), 'r') as old_file:
|
||||
old_content = old_file.read()
|
||||
try:
|
||||
with open(new_filename(state), 'r') as new_file:
|
||||
new_content = new_file.read()
|
||||
except FileNotFoundError:
|
||||
return True
|
||||
return old_content != new_content
|
||||
|
||||
def notify_project(openqa, state):
|
||||
project, repository = state.split('_-_')
|
||||
if not file_changed(state):
|
||||
return
|
||||
try:
|
||||
openqa.openqa_request('PUT', 'obs_rsync/{}/runs?repository={}'.format(project, repository), retries=0)
|
||||
except RequestError as e:
|
||||
logger.info("Got exception on syncing repository: {}".format(e))
|
||||
return
|
||||
copyfile(old_filename(state), new_filename(state))
|
||||
subprocess.run(f'cd {args.to} && git add . && git commit -m "Update of {project}/{repository}" && git push', shell=True, check=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Bot to sync openQA status to OBS')
|
||||
parser.add_argument('--openqa', type=str, required=True, help='OpenQA URL')
|
||||
parser.add_argument('--repos', type=str, required=True, help='Directory to read from')
|
||||
parser.add_argument('--to', type=str, required=True, help='Directory to commit into')
|
||||
|
||||
interesting_repos = dict()
|
||||
# not the complete list - WIP
|
||||
interesting_repos['SUSE:SLE-15-SP2:GA:Staging:A_-_images'] = 1
|
||||
interesting_repos['SUSE:SLE-15-SP2:GA:TEST_-_images'] = 1
|
||||
interesting_repos['openSUSE:Factory:Staging:A_-_images'] = 1
|
||||
interesting_repos['openSUSE:Factory:ToTest_-_images'] = 1
|
||||
interesting_repos['openSUSE:Factory:WSL:ToTest_-_standard'] = 1
|
||||
interesting_repos['openSUSE:Leap:15.2:Staging:A_-_images'] = 1
|
||||
interesting_repos['openSUSE:Leap:15.2:ToTest_-_images'] = 1
|
||||
|
||||
global args
|
||||
args = parser.parse_args()
|
||||
global logger
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
openqa = OpenQA_Client(server=args.openqa)
|
||||
for state in glob.glob('{}/*.yaml'.format(args.repos)):
|
||||
state = basename(state).replace('.yaml', '')
|
||||
if not state in interesting_repos:
|
||||
continue
|
||||
notify_project(openqa, state)
|
Loading…
x
Reference in New Issue
Block a user