From 042b5baddac87ad3f9be0c1ae3d88b6334e286a8 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Jul 18 2018 23:59:52 +0000 Subject: pygit2 is now available on leap15 use it on get_formulas and local test runs --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49b7c17..aee2096 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,9 +5,6 @@ stages: validate: stage: validate - variables: - # TODO: get rid of GIT_SSL_NO_VERIFY as soon as we switch to letsencrypt wildcard certs - GIT_SSL_NO_VERIFY: 'true' before_script: - bin/prepare_test_env.sh -g - bin/get_formulas.py -c -d /srv/formula -s --clone-from 'https://gitlab.infra.opensuse.org/saltstack-formulas' --clone-branch production @@ -29,9 +26,6 @@ validate_show_highstate_against_upstream_formulas: test_nginx: stage: test - variables: - # TODO: get rid of GIT_SSL_NO_VERIFY as soon as we switch to letsencrypt wildcard certs - GIT_SSL_NO_VERIFY: 'true' before_script: - bin/prepare_test_env.sh -g -p nginx - bin/get_formulas.py -c -d /srv/formula -s --clone-from 'https://gitlab.infra.opensuse.org/saltstack-formulas' --clone-branch production -f nginx diff --git a/bin/get_formulas.py b/bin/get_formulas.py index dbcc337..63ddc2f 100755 --- a/bin/get_formulas.py +++ b/bin/get_formulas.py @@ -3,8 +3,10 @@ # For description and usage, see the argparse options at the end of the file from copy import copy +from pygit2.errors import GitError import argparse import os +import pygit2 import sys import yaml @@ -26,7 +28,7 @@ def check_open_pull_requests(): def git(cmd, cwd=None): - # pygit2 is not available for python3 in Leap, use plain git instead + # TODO migrate to pygit2 import subprocess @@ -35,20 +37,13 @@ def git(cmd, cwd=None): sys.exit(status) -def clone(CLONE_FROM, CLONE_BRANCH, DEST, USE_PYGIT2): +def clone(CLONE_FROM, CLONE_BRANCH, DEST): def clone_repo(): FULL_PATH = '%s/%s-formula' % (DEST, formula) if os.path.isdir(FULL_PATH): return - if USE_PYGIT2: - import pygit2 - - pygit2.clone_repository(url, FULL_PATH, bare=False) - else: - if not os.path.exists(DEST): - os.mkdir(DEST) - git(['clone', '-q', url, FULL_PATH] + branch_opts) + pygit2.clone_repository(url, FULL_PATH, bare=False) branch_opts = [] if CLONE_BRANCH: @@ -80,9 +75,6 @@ def remove_symlinks(): def fetch_remote(remote, formula): - from pygit2.errors import GitError - import pygit2 - remotecallbacks = None if not remote.url.startswith(('http://', 'https://', 'git://', 'ssh://', 'git+ssh://')): username = remote.url.split('@')[0] @@ -95,8 +87,6 @@ def fetch_remote(remote, formula): def add_remote(REMOTES, DEST): - import pygit2 - for remote in REMOTES: namespace = None if len(remote) == 4: @@ -131,8 +121,6 @@ def add_remote(REMOTES, DEST): def update(REMOTES, DEST): - import pygit2 - for formula in FORMULAS.keys(): FULL_PATH = '%s/%s-formula' % (DEST, formula) repo = pygit2.Repository(FULL_PATH) @@ -144,8 +132,6 @@ def update(REMOTES, DEST): def push(REMOTES, DEST): - import pygit2 - for formula in FORMULAS.keys(): FULL_PATH = '%s/%s-formula' % (DEST, formula) repo = pygit2.Repository(FULL_PATH) @@ -191,7 +177,6 @@ Examples: parser.add_argument('-u', '--update', nargs='*', help='Switch to origin/master and git pull. Optionally it can accept a list of remotes as arguments, that will be fetched.') parser.add_argument('-p', '--push', nargs='+', help='Pushes (with --force) to the given list of remotes from origin/master to their master and production branch, and then fetches them.') parser.add_argument('--checkout', nargs=1, help='Checkout to the specified remote/branch.') -parser.add_argument('--use-pygit2', action='store_true', help='Use pygit2 instead of invoking git whenever possible.') args = parser.parse_args() will_run = False @@ -247,7 +232,7 @@ if args.clone or args.symlink or args.clone_from or args.clone_branch or args.ad clone_from = args.clone_from[0] if args.clone_branch: clone_branch = args.clone_branch[0] - clone(clone_from, clone_branch, args.destination[0], args.use_pygit2) + clone(clone_from, clone_branch, args.destination[0]) if args.symlink: create_symlinks(args.destination[0]) diff --git a/bin/prepare_test_env.sh b/bin/prepare_test_env.sh index 71472cc..eb2133d 100755 --- a/bin/prepare_test_env.sh +++ b/bin/prepare_test_env.sh @@ -40,7 +40,7 @@ done [[ -n $HIGHSTATE ]] && HIGHSTATE_PKGS=( git python3-PyYAML ) -$SUDO zypper -qn in --no-recommends salt ${HIGHSTATE_PKGS[@]} ${PKG[@]} +$SUDO zypper -qn in --no-recommends salt python3-pygit2 ca-certificates-freeipa-opensuse ${HIGHSTATE_PKGS[@]} ${PKG[@]} $SUDO rm -rf /srv/{salt,pillar} $SUDO ln -s $PWD/salt /srv/salt $SUDO ln -s $PWD/pillar /srv/pillar diff --git a/bin/run_tests_locally.sh b/bin/run_tests_locally.sh index 81a29ae..4d6bad3 100755 --- a/bin/run_tests_locally.sh +++ b/bin/run_tests_locally.sh @@ -33,8 +33,8 @@ SALT_DIRS=( for dir in ${SALT_DIRS[@]}; do sudo chown -R ${USER}: $dir done -bin/prepare_test_env.sh -g -s -p python3-pygit2 -bin/get_formulas.py --destination $DESTINATION --clone --symlink --use-pygit2 --update opensuse \ +bin/prepare_test_env.sh -g -s +bin/get_formulas.py --destination $DESTINATION --clone --symlink --update opensuse \ --add-remote opensuse no_prefix gitlab@gitlab.infra.opensuse.org: saltstack-formulas ln -s ~/.gnupg /etc/salt/gpgkeys