diff --git a/core/operation/baseoperation.py b/core/operation/baseoperation.py index 7912361..261a7ea 100644 --- a/core/operation/baseoperation.py +++ b/core/operation/baseoperation.py @@ -31,7 +31,7 @@ def __init__(self, qs_client, aws_account_id: str): def execute(self) -> dict: pass - def _create_or_update_template(self, template_data: dict) -> TemplateResponse: + def _recreate_template(self, template_data: dict) -> TemplateResponse: """ Creates new or updates existing template. :param template_data: @@ -76,11 +76,11 @@ def _create_or_update_template(self, template_data: dict) -> TemplateResponse: response["Arn"], response["VersionArn"], response["TemplateId"] ) - def _create_or_update_template_from_template_definition( + def _recreate_template_from_template_definition( self, template_definition: dict ) -> TemplateResponse: template_definition["AwsAccountId"] = self._aws_account_id - return self._create_or_update_template(template_data=template_definition) + return self._recreate_template(template_data=template_definition) def _resolve_data_set_id_from_placeholder( self, namespace: str, placeholder: str diff --git a/core/operation/export_analysis_operation.py b/core/operation/export_analysis_operation.py index f7939a3..9b77641 100644 --- a/core/operation/export_analysis_operation.py +++ b/core/operation/export_analysis_operation.py @@ -114,7 +114,7 @@ def _create_or_update_template_from_analysis( }, }, } - return self._create_or_update_template(template_data=params) + return self._recreate_template(template_data=params) def _save_dataset_to_file(self, di) -> str: """ diff --git a/core/operation/import_from_json_operation.py b/core/operation/import_from_json_operation.py index e296975..b93bbbd 100644 --- a/core/operation/import_from_json_operation.py +++ b/core/operation/import_from_json_operation.py @@ -44,7 +44,7 @@ def execute(self) -> dict: # create or update template template_data["Name"] = self._target_namespace + "-" + self._template_name template_data["TemplateId"] = template_data["Name"] - template_response = self._create_or_update_template_from_template_definition( + template_response = self._recreate_template_from_template_definition( template_definition=template_data ) @@ -73,7 +73,7 @@ def execute(self) -> dict: placeholder=placeholder, namespace=self._target_namespace ) dataset["Name"] = dataset["Name"] - ds_response = self._create_or_update_data_set(dataset_definition=dataset) + ds_response = self._recreate_data_set(dataset_definition=dataset) data_sets_created.append( { @@ -92,7 +92,7 @@ def execute(self) -> dict: }, } - def _create_or_update_data_set(self, dataset_definition: dict): + def _recreate_data_set(self, dataset_definition: dict): """ Create new or updates existing DataSet :param dataset_definition: diff --git a/core/operation/publish_dashboard_from_template.py b/core/operation/publish_dashboard_from_template.py index 93b7518..9305358 100644 --- a/core/operation/publish_dashboard_from_template.py +++ b/core/operation/publish_dashboard_from_template.py @@ -78,7 +78,7 @@ def execute(self) -> dict: ) # publish dashboard - dashboard_arn, dashboard_id = self._create_or_update_dashboard( + dashboard_arn, dashboard_id = self._recreate_dashboard( dashboard_params=parameters ) @@ -142,12 +142,20 @@ def execute(self) -> dict: return result - def _create_or_update_dashboard(self, dashboard_params: dict) -> tuple[str, str]: + def _recreate_dashboard(self, dashboard_params: dict) -> tuple[str, str]: """ - Creates new or updates existing template. + Creates new or recreates existing template. :param dashboard_params: :return: Dashboard ARN, Dashboard ID """ + try: + response = self._qs_client.delete_dashboard( + AwsAccountId=dashboard_params["AwsAccountId"], + DashboardId=dashboard_params["DashboardId"], + ) + except self._qs_client.exceptions.ResourceNotFoundException as e: + pass + try: response = self._qs_client.create_dashboard(**dashboard_params) except self._qs_client.exceptions.ResourceExistsException as e: diff --git a/tests/core/operation/test_publish_operation.py b/tests/core/operation/test_publish_operation.py index 9266e97..ca39267 100644 --- a/tests/core/operation/test_publish_operation.py +++ b/tests/core/operation/test_publish_operation.py @@ -102,6 +102,15 @@ def test(self): }, ) + qs_stub.add_response( + "delete_dashboard", + service_response={}, + expected_params={ + "AwsAccountId": account, + "DashboardId": template_id, + }, + ) + qs_stub.add_response( "create_dashboard", service_response={