Skip to content

Commit

Permalink
updates and fixes to produce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausHolbechArista committed May 14, 2024
1 parent 86b205d commit ed07d60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ansible_collections/arista/avd/plugins/action/cv_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def deploy(self, validated_args: dict, result: dict):
)
# Errors and warnings are converted to JSON compatible strings.
result_object.errors = [str(error) for error in result_object.errors]
result_object.warnings = result.get("warnings", []) + [str(warning) for warning in result_object.warnings]
result_object.warnings = [str(warning) for warning in result_object.warnings]

# Add warnings caught by the logger
result_object.warnings.extend(result.get("warnings", []))
Expand All @@ -155,7 +155,7 @@ async def deploy(self, validated_args: dict, result: dict):
else:
result.update(
{
"warnings": result_object.errors,
"warnings": result_object.warnings,
"errors": result_object.errors,
"failed": result_object.failed,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StudioVersion(Enum):
"pathfinder_location": StudioVersion.v3_4,
"internet_exit_zscaler": StudioVersion.v3_4,
}
FEATURE = Literal["pathfinder_location"]
FEATURE = Literal["pathfinder_location", "internet_exit_zscaler"]


async def get_metadata_studio_version(result: DeployToCvResult, cv_client: CVClient) -> StudioVersion | None:
Expand All @@ -54,7 +54,7 @@ async def get_metadata_studio_version(result: DeployToCvResult, cv_client: CVCli
except ValueError:
accepted_versions = [str(v.value) for v in StudioVersion]
warning = (
f"deploy_cv_pathfinder_metadata_to_cv: Got invalid metadata studio version '{version}'."
f"deploy_cv_pathfinder_metadata_to_cv: Got invalid metadata studio version '{version}'. "
f"This plugin only accepts versions '{accepted_versions}'. Skipping upload of metadata."
)
LOGGER.info(warning)
Expand All @@ -63,7 +63,7 @@ async def get_metadata_studio_version(result: DeployToCvResult, cv_client: CVCli


def is_feature_supported(feature: FEATURE, studio_version: StudioVersion) -> bool:
return studio_version.value >= FEATURE_MIN_VERSION.get(feature, 0).value
return studio_version.value >= FEATURE_MIN_VERSION[feature].value


def update_general_metadata(metadata: dict, studio_inputs: dict) -> None:
Expand Down Expand Up @@ -134,8 +134,8 @@ def upsert_pathfinder(metadata: dict, device: CVDevice, studio_inputs: dict, stu
pathfinder_metadata.update(pathfinder_location)
else:
warning = (
"deploy_cv_pathfinder_metadata_to_cv: Ignoring Pathfinder location information since it is not"
f"supported by metadata studio version {studio_version}."
"deploy_cv_pathfinder_metadata_to_cv: Ignoring Pathfinder location information since it is not "
f"supported by metadata studio version {studio_version.value}."
)
LOGGER.info(warning)
warnings.append(warning)
Expand Down Expand Up @@ -364,7 +364,7 @@ def generate_internet_exit_metadata(metadata: dict, device: CVDevice, studio_ver
Returns metadata dict and list of any warnings raised.
"""
if (internet_exit_policies := get(metadata, "internet_exit_policies")) is None:
LOGGER.info("deploy_cv_pathfinder_metadata_to_cv: Did not find 'internet_exit_policies' for device: %s", device.hostname)
LOGGER.debug("deploy_cv_pathfinder_metadata_to_cv: Did not find 'internet_exit_policies' for device: %s", device.hostname)
return {}, []

LOGGER.info("deploy_cv_pathfinder_metadata_to_cv: Found %s 'internet_exit_policies' for device: %s", len(internet_exit_policies), device.hostname)
Expand All @@ -380,14 +380,15 @@ def generate_internet_exit_metadata(metadata: dict, device: CVDevice, studio_ver
f"with type '{internet_exit_policy.get('type')}' for device: {device.hostname}."
)
LOGGER.info(warning)
warnings.append(warning)
continue

if not is_feature_supported("internet_exit_zscaler", studio_version):
LOGGER.info(
"deploy_cv_pathfinder_metadata_to_cv: Ignoring Pathfinder location information since it is not supported by metadata studio version %s.",
studio_version,
warning = (
"deploy_cv_pathfinder_metadata_to_cv: Ignoring Zscaler internet-exit information since "
f"it is not supported by metadata studio version {studio_version.value}."
)
LOGGER.info(warning)
warnings.append(warning)
continue

policy_name = internet_exit_policy["name"]
Expand Down

0 comments on commit ed07d60

Please sign in to comment.