From a376daa04db22cb04e455298692ceb5dc6c5b7de Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 7 Feb 2025 12:27:11 +0000 Subject: [PATCH] CI: Consolidate directory path constants --- .ci/ansible_tests.py | 10 +++++----- .ci/ci_lib.py | 4 ++++ .ci/localhost_ansible_tests.py | 11 +++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.ci/ansible_tests.py b/.ci/ansible_tests.py index 0d67c3b2..4bf86bca 100755 --- a/.ci/ansible_tests.py +++ b/.ci/ansible_tests.py @@ -12,8 +12,6 @@ import jinja2 import ci_lib -TEMPLATES_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible/templates') -TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible') TMP = ci_lib.TempDir(prefix='mitogen_ci_ansible') TMP_HOSTS_DIR = os.path.join(TMP.path, 'hosts') @@ -42,10 +40,10 @@ with ci_lib.Fold('docker_setup'): with ci_lib.Fold('job_setup'): os.chmod(ci_lib.TESTS_SSH_PRIVATE_KEY_FILE, int('0600', 8)) - os.chdir(TESTS_DIR) + os.chdir(ci_lib.ANSIBLE_TESTS_DIR) os.mkdir(TMP_HOSTS_DIR) - for path in glob.glob(TESTS_DIR + '/hosts/*'): + for path in glob.glob(os.path.join(ci_lib.ANSIBLE_TESTS_HOSTS_DIR, '*')): if not path.endswith('default.hosts'): os.symlink(path, os.path.join(TMP_HOSTS_DIR, os.path.basename(path))) @@ -56,7 +54,9 @@ with ci_lib.Fold('job_setup'): families[container['family']].append(container['name']) jinja_env = jinja2.Environment( - loader=jinja2.FileSystemLoader(searchpath=TEMPLATES_DIR), + loader=jinja2.FileSystemLoader( + searchpath=ci_lib.ANSIBLE_TESTS_TEMPLATES_DIR, + ), lstrip_blocks=True, # Remove spaces and tabs from before a block trim_blocks=True, # Remove first newline after a block ) diff --git a/.ci/ci_lib.py b/.ci/ci_lib.py index b37472a2..9f333dde 100644 --- a/.ci/ci_lib.py +++ b/.ci/ci_lib.py @@ -29,10 +29,14 @@ os.chdir( GIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +ANSIBLE_TESTS_DIR = os.path.join(GIT_ROOT, 'tests/ansible') +ANSIBLE_TESTS_HOSTS_DIR = os.path.join(GIT_ROOT, 'tests/ansible/hosts') +ANSIBLE_TESTS_TEMPLATES_DIR = os.path.join(GIT_ROOT, 'tests/ansible/templates') DISTRO_SPECS = os.environ.get( 'MITOGEN_TEST_DISTRO_SPECS', 'centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004', ) +IMAGE_PREP_DIR = os.path.join(GIT_ROOT, 'tests/image_prep') IMAGE_TEMPLATE = os.environ.get( 'MITOGEN_TEST_IMAGE_TEMPLATE', 'public.ecr.aws/n5z0e8q9/%(distro)s-test', diff --git a/.ci/localhost_ansible_tests.py b/.ci/localhost_ansible_tests.py index 29022bf7..359dc195 100755 --- a/.ci/localhost_ansible_tests.py +++ b/.ci/localhost_ansible_tests.py @@ -10,11 +10,6 @@ import sys import ci_lib -TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible') -IMAGE_PREP_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/image_prep') -HOSTS_DIR = os.path.join(TESTS_DIR, 'hosts') - - with ci_lib.Fold('unit_tests'): os.environ['SKIP_MITOGEN'] = '1' ci_lib.run('./run_tests -v') @@ -50,11 +45,11 @@ with ci_lib.Fold('machine_prep'): subprocess.check_call('sudo chmod 700 ~root/.ssh', shell=True) subprocess.check_call('sudo chmod 600 ~root/.ssh/authorized_keys', shell=True) - os.chdir(IMAGE_PREP_DIR) + os.chdir(ci_lib.IMAGE_PREP_DIR) ci_lib.run("ansible-playbook -c local -i localhost, macos_localhost.yml") if os.path.expanduser('~mitogen__user1') == '~mitogen__user1': - os.chdir(IMAGE_PREP_DIR) + os.chdir(ci_lib.IMAGE_PREP_DIR) ci_lib.run("ansible-playbook -c local -i localhost, _user_accounts.yml") cmd = ';'.join([ @@ -79,7 +74,7 @@ with ci_lib.Fold('machine_prep'): with ci_lib.Fold('ansible'): - os.chdir(TESTS_DIR) + os.chdir(ci_lib.ANSIBLE_TESTS_DIR) playbook = os.environ.get('PLAYBOOK', 'all.yml') ci_lib.run('./run_ansible_playbook.py %s %s', playbook, ' '.join(sys.argv[1:]))