From 943f8e14f59745e3119d8b309e75194e9ff489f1 Mon Sep 17 00:00:00 2001 From: Thomas Buchner Date: Wed, 17 Jan 2024 13:37:56 +0100 Subject: [PATCH] add code for config validation --- .cicd-cli.py | 2 ++ glci/az.py | 13 ++++++++++++- publish.py | 25 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.cicd-cli.py b/.cicd-cli.py index 36c1af0..114cb4a 100755 --- a/.cicd-cli.py +++ b/.cicd-cli.py @@ -817,6 +817,8 @@ def end_phase(name): ) else: raise ValueError(on_absent) # programming error + else: + publish.validate_publishing_configuration(manifest, cfg) phase_logger.info('publishing-cfg was found to be okay - starting publishing now') diff --git a/glci/az.py b/glci/az.py index d67c3b4..6e6153e 100644 --- a/glci/az.py +++ b/glci/az.py @@ -873,9 +873,10 @@ def delete_from_azure_community_gallery( for public_name in configured_gallery.sharing_profile.community_gallery_info.public_names: if public_name == image_community_gallery_name: image_gallery_is_configured_gallery = True + break if not image_gallery_is_configured_gallery: - raise RuntimeError(f"The community gallery of image {community_gallery_image_id} is not from the configured community gallery.") + raise RuntimeError(f"The community gallery of image {community_gallery_image_id} is not from the configured community gallery {shared_gallery_cfg.gallery_name}.") gallery_image_version = cclient.gallery_image_versions.get( resource_group_name=shared_gallery_cfg.resource_group_name, @@ -938,3 +939,13 @@ def delete_from_azure_community_gallery( result = result.result() else: logger.warning(f"{image_definition=} still contains {image_version_count} image versions - keeping definition") + + +def validate_azure_publishing_config( + release: glci.model.OnlineReleaseManifest, + publishing_cfg: glci.model.PublishingCfg, +): + azure_publishing_cfg: glci.model.PublishingTargetAzure = publishing_cfg.target(platform=release.platform) + + if azure_publishing_cfg.publish_to_marketplace and not azure_publishing_cfg.marketplace_cfg: + raise RuntimeError(f"Expected to publish to Azure Marketplace but no marketplace config in publishing config.") diff --git a/publish.py b/publish.py index a60c315..30fb12b 100644 --- a/publish.py +++ b/publish.py @@ -67,6 +67,31 @@ def publish_image( raise +def validate_publishing_configuration( + release: gm.OnlineReleaseManifest, + cfg: gm.PublishingCfg +): + if release.platform == 'azure': + validation_function = glci.az.validate_azure_publishing_config + elif release.platform == 'ali': + validation_function = None + elif release.platform == 'aws': + validation_function = None + elif release.platform == 'gcp': + validation_function = None + elif release.platform == 'openstack': + validation_function = None + elif release.platform == 'openstackbaremetal': + validation_function = None + elif release.platform == 'oci': + validation_function = None + else: + validation_function = None + + if validation_function: + validation_function(release, cfg) + + def _publish_alicloud_image( release: gm.OnlineReleaseManifest, publishing_cfg: gm.PublishingCfg,