Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix update #1018

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions cid/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def _deploy(self, dashboard_id: str=None, recursive=True, update=False, **kwargs

# In case if we cannot discover datasets, we need to discover dashboards
# TODO: check if datasets returns explicit permission denied and only then discover dashboards as a workaround
self.qs.discover_dashboards()
self.qs.dashboards

dashboard_id = dashboard_id or get_parameters().get('dashboard-id')
category_filter = [cat for cat in get_parameters().get('category', '').upper().split(',') if cat]
Expand Down Expand Up @@ -782,8 +782,7 @@ def delete_dataset(self, name: str, id: str=None):
# Check if dataset is used in some other dashboard
for dashboard in (self.qs.dashboards or {}).values():
if dataset.id in dashboard.datasets.values():
logger.info(f'Dataset {dataset.name} ({dataset.id}) is still used by dashboard "{dashboard.id}". Skipping.')
print (f'Dataset {dataset.name} ({dataset.id}) is still used by dashboard "{dashboard.id}". Skipping.')
cid_print(f'Dataset {dataset.name} ({dataset.id}) is still used by dashboard "{dashboard.id}". Skipping.')
return False
else: #not used

Expand Down Expand Up @@ -1073,13 +1072,13 @@ def check_dashboard_version_compatibility(self, dashboard_id):

if dashboard.latest:
cid_print("You are up to date!")
cid_print(f" Version {str(dashboard.cid_version)}")
cid_print(f" Version {dashboard.cid_version}")
else:
cid_print(f"An update is available:")
cid_print(f" Version {str(dashboard.cid_version): <9} -> {str(dashboard.cid_version_latest): <9}")
cid_print(f" Version {dashboard.cid_version} -> {dashboard.latest_available_cid_version}")

try:
return dashboard.cid_version.compatible_versions(dashboard.cid_version_latest)
return dashboard.cid_version.compatible_versions(dashboard.latest_available_cid_version)
except ValueError as exc:
logger.info(exc)
return None
Expand All @@ -1094,10 +1093,10 @@ def update_dashboard(self, dashboard_id, dashboard_definition):
if isinstance(dashboard.deployedTemplate, CidQsTemplate):
print(f'Deployed template: {dashboard.deployedTemplate.arn}')
if isinstance(dashboard.sourceTemplate, CidQsTemplate):
print(f"Latest template: {dashboard.sourceTemplate.arn}/version/{dashboard.latest_version}")
print(f"Latest template: {dashboard.sourceTemplate.arn}/version/{dashboard.sourceTemplate.version}")

try:
cid_print(f'\nUpdating {dashboard_id} from <BOLD>{dashboard.cid_version}<END> to <BOLD>{dashboard.cid_version_latest}<END>')
cid_print(f'\nUpdating {dashboard_id} from <BOLD>{dashboard.cid_version}<END> to <BOLD>{dashboard.latest_available_cid_version}<END>')
except:
cid_print(f'\nUpdating {dashboard_id}')
logger.debug('Failed to define versions. Still continue.')
Expand Down
46 changes: 17 additions & 29 deletions cid/helpers/quicksight/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,17 @@ def template_arn(self) -> str:
return None

@property
def deployed_version(self) -> int:
def deployed_cid_version(self) -> int:
if isinstance(self.deployedTemplate, CidQsTemplate):
return self.deployedTemplate.version
return self.deployedTemplate.cid_version
elif isinstance(self.deployedDefinition, CidQsDefinition):
return self.deployedDefinition.cid_version
else:
return -1
return None

@property
def latest(self) -> bool:
return self.latest_version == self.deployed_version

@property
def latest_version(self) -> int:
if isinstance(self.sourceTemplate, CidQsTemplate):
return self.sourceTemplate.version
elif isinstance(self.sourceDefinition, CidQsDefinition):
return self.sourceDefinition.cid_version
else:
return -1
return self.latest_available_cid_version == self.deployed_cid_version

@property
def health(self) -> bool:
Expand All @@ -98,6 +89,7 @@ def origin_type(self) -> str:
else:
return "UNKNOWN"


@property
def cid_version(self) -> int:
if self.origin_type == "TEMPLATE":
Expand All @@ -108,7 +100,7 @@ def cid_version(self) -> int:
return None

@property
def cid_version_latest(self) -> int:
def latest_available_cid_version(self) -> int:
if self.origin_type == "TEMPLATE":
return self.sourceTemplate.cid_version
elif self.origin_type == "DEFINITION":
Expand Down Expand Up @@ -136,11 +128,11 @@ def status(self) -> str:
# Source Template has changed
elif self.deployedTemplate and self.sourceTemplate and self.deployedTemplate.arn and self.sourceTemplate.arn and not self.deployedTemplate.arn.startswith(self.sourceTemplate.arn):
self._status = 'legacy'
elif self.latest_version is None or self.deployed_version is None:
elif not self.latest_available_cid_version or not self.deployed_cid_version:
self._status = 'undetermined'
else:
if self.latest_version > self.deployed_version:
self._status = f'update available {self.deployed_version}->{self.latest_version}'
if self.latest_available_cid_version > self.deployed_cid_version:
self._status = f'update available {self.deployed_cid_version}->{self.latest_available_cid_version}'
elif self.latest:
self._status = 'up to date'
return self._status
Expand All @@ -157,22 +149,18 @@ def display_status(self) -> None:
if self.status_detail:
cid_print(f" <BOLD>Status detail:<END> {self.status_detail}")

cid_version = "N/A"
cid_version_latest = "N/A"

cid_version = self.cid_version
if cid_version is None:
if not self.cid_version:
logger.debug("The cid version of the deployed dashboard could not be retrieved")

cid_version_latest = self.cid_version_latest
if cid_version_latest is None:
if not self.latest_available_cid_version:
logger.debug("The latest version of the dashboard could not be retrieved")

if self.latest:
cid_print(f" <BOLD>Version:<END> <GREEN>{cid_version}<END> (latest)")
cid_print(f" <BOLD>Version:<END> <YELLOW>{self.cid_version or 'N/A'}<END> (unable to find latest)")
else:
logger.debug("An update is available")
cid_print(f" <BOLD>Version:<END> <YELLOW>{str(cid_version): <8} --> {str(cid_version_latest): <8}<END>")
if self.latest:
cid_print(f" <BOLD>Version:<END> <GREEN>{self.cid_version or 'N/A'}<END> (latest)")
else:
logger.debug("An update is available")
cid_print(f" <BOLD>Version:<END> <YELLOW>{self.cid_version or 'N/A'} --> {self.latest_available_cid_version or 'N/A'}<END>")

cid_print(' <BOLD>Owners:<END>')
try:
Expand Down
1 change: 1 addition & 0 deletions cid/test/bats/10-deploy-update-delete/cudos.bats
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cur_table="${cur_table:-cur1}" # If variable not set or null, use default. FIXME
--dashboard-id cudos-v5 \
--cur-table-name $cur_table \
--athena-workgroup primary\
--timezone 'Europe/Paris' \
--quicksight-user $quicksight_user \

[ "$status" -eq 0 ]
Expand Down
Loading