From e2d2aeb6a024a16d57884580497ac7097f440d36 Mon Sep 17 00:00:00 2001 From: Michael Burke Date: Wed, 24 Jun 2020 10:58:23 -0400 Subject: [PATCH] Update download/import feature in RHEL Agent: - Remove download_only feature from RHEL agent - Move dci-import out of job loop so it executes once per run of agent - Create new download_and_import_topics function to encapsulate functionality Change-Id: Ic676e6b9e9e4cc09684e9565d99757347a146dc9 --- README.md | 3 --- dci-rhel-agent/dci-import.yml | 3 ++- dci-rhel-agent/entrypoint.py | 43 ++++++++++++++--------------------- settings.yml | 1 - 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 5556baf3..8d80aa83 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,6 @@ The possible values are: | local_repo | True | String | Path to store DCI artefacts (Local RHEL mirror that will be exposed to SUT by `httpd`). Default is `/var/www/html`. | | dci_rhel_agent_cert | True | True/False | Enable or disable the certification tests suite. | | dci_rhel_agent_cki | True | True/False | Enable or disable the cki tests suite. | -| download_only | False | True/False | If enable, dci-rhel-agnt will exit after downloading RHEL builds (no job will be executed). | | systems | False | List of string | List of all systems that will be deployed using RHEL from DCI. | | beaker_xml | False | String | Path to a custom XML file to use with Beaker job. | | variants | False | List of string | List of RHEL 8.x variant to enable (AppStream, BaseOS, CRB, HighAvailability, NFV, RT, ResilientStorage, SAP, SAPHANA and unified). | @@ -142,7 +141,6 @@ topics: - topic: RHEL-8.1 dci_rhel_agent_cert: false dci_rhel_agent_cki: false - download_only: false variants: - AppStream - BaseOS @@ -156,7 +154,6 @@ topics: - topic: RHEL-7.8 dci_rhel_agent_cert: false dci_rhel_agent_cki: false - download_only: false variants: - Server archs: diff --git a/dci-rhel-agent/dci-import.yml b/dci-rhel-agent/dci-import.yml index e181dbda..072746ec 100644 --- a/dci-rhel-agent/dci-import.yml +++ b/dci-rhel-agent/dci-import.yml @@ -45,8 +45,9 @@ when: hostvars.localhost.skip_download == False - name: Import the latest build - shell: beaker-import -v --ignore-missing-tree-compose "http://{{ local_repo_ip }}/{{ topic }}/compose/" + shell: beaker-import -v --ignore-missing-tree-compose "http://{{ local_repo_ip }}/{{ item.topic }}/compose/" become: true + with_items: "{{ topics }}" - name: Delete the temporary file file: diff --git a/dci-rhel-agent/entrypoint.py b/dci-rhel-agent/entrypoint.py index cab512bd..16c6d559 100755 --- a/dci-rhel-agent/entrypoint.py +++ b/dci-rhel-agent/entrypoint.py @@ -14,7 +14,6 @@ - Server dci_rhel_agent_cert: false dci_rhel_agent_cki: false - download_only: false systems: - labvm-1.novalocal - labvm-2.novalocal @@ -27,7 +26,6 @@ - AppStream dci_rhel-agent_cert: false dci_rhel-agent_cki: false - download_only: false systems: - SUT3 - SUT4 @@ -46,10 +44,8 @@ def sigterm_handler(signal, frame): print('Handle podman stop here !') sys.exit(0) - signal.signal(signal.SIGTERM, sigterm_handler) - def load_settings(): with open('/etc/dci-rhel-agent/settings.yml', 'r') as settings: try: @@ -58,6 +54,18 @@ def load_settings(): print(exc) sys.exit(1) +def download_and_import_topics(extravars): + r = ansible_runner.run( + private_data_dir="/usr/share/dci-rhel-agent/", + inventory="/etc/dci-rhel-agent/inventory", + verbosity=1, + playbook="dci-import.yml", + extravars=extravars, + quiet=False + ) + if r.rc != 0: + print ("Distro(s) download/import in Beaker has failed. {}: {}".format(r.status, r.rc)) + sys.exit(1) def provision_and_test(extravars): # # Path is static in the container @@ -70,26 +78,8 @@ def provision_and_test(extravars): print ("Error ! No topic found in settings.") sys.exit(1) - # This function is kept for backward compatibility. - if 'download_only' in extravars.keys(): - if extravars['download_only'] == True: - print ('The dci-rhel-agent is configured in download-only mode.') - sys.exit(0) - - r = ansible_runner.run( - private_data_dir="/usr/share/dci-rhel-agent/", - inventory="/etc/dci-rhel-agent/inventory", - verbosity=1, - playbook="dci-import.yml", - extravars=extravars, - quiet=False - ) - if r.rc != 0: - print ("Distro(s) import in Beaker has failed. {}: {}".format(r.status, r.rc)) - sys.exit(1) - if 'systems' not in extravars.keys(): - print ('No hosts found in settings. You should configure download-only mode or add systems[].') + print ('No hosts found in settings. Please add systems to provision to your settings file.') sys.exit(1) fqdns = extravars['systems'] @@ -128,6 +118,8 @@ def main(): sets = load_settings() # Check if the settings contain multiple topics and process accordingly if 'topics' in sets: + #Download and import all topics in settings file + download_and_import_topics(sets) # Break up settings file into individual jobs by topic jobs = sets['topics'] # Loop over each job and provision system(s) @@ -137,9 +129,8 @@ def main(): current_job['local_repo_ip'] = sets['local_repo_ip'] provision_and_test(current_job) else: - # Legacy settings file format (single topic/job) - # preserved for compatibility - provision_and_test(sets) + print ('Incompatible settings file. Topics not found. Please update settings file format.') + sys.exit(1) sys.exit(number_of_failed_jobs) diff --git a/settings.yml b/settings.yml index 15d238e2..060c95fe 100644 --- a/settings.yml +++ b/settings.yml @@ -4,7 +4,6 @@ topics: - topic: RHEL-8.1 dci_rhel_agent_cki: false dci_rhel_agent_cert: false - download_only: false variants: - AppStream - BaseOS