From 0acc2817a57fda0026720ae8c2ee818f3f18948f Mon Sep 17 00:00:00 2001 From: rwaweber Date: Sat, 29 Apr 2017 18:30:15 -0400 Subject: [PATCH] Repository validator for Homu's cfg.toml This test will read the deployed cfg.toml file for Homu, and report if any repositories configured there are not available on github. This will help to prevent typos in repo names. --- tests/sls/homu/valid_repos.py | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/sls/homu/valid_repos.py diff --git a/tests/sls/homu/valid_repos.py b/tests/sls/homu/valid_repos.py new file mode 100644 index 00000000..01489a7b --- /dev/null +++ b/tests/sls/homu/valid_repos.py @@ -0,0 +1,36 @@ +from urllib.error import URLError +from urllib.request import Request, urlopen + +import toml + +from tests.util import Failure, Success + + +def repo_exists(url): + ''' + Checks if the given repo exists on GitHub + ''' + try: + request = Request("https://github.com/{}".format(url), method='HEAD') + with urlopen(request) as conn: + return conn.status == 200 + except URLError: + return False + + +def run(): + repo_cfg = toml.load('/home/servo/homu/cfg.toml')['repo'] + homu_repos = ( + "{}/{}".format(repo['owner'], repo['name']) + for repo in repo_cfg.values() + ) + missing_repos = [ + repository for repository in homu_repos + if not repo_exists(repository) + ] + if len(missing_repos) > 0: + return Failure( + 'Some repos set up for Homu do not exist on GitHub:', + "\n".join(" - {}".format(repo) for repo in missing_repos) + ) + return Success('All repos in the Homu config exist on Github')