Skip to content
Snippets Groups Projects
Commit 2f79c29d authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Merge branch 'fixed-eumetsat' into develop

parents ef2db7c6 eaf6f584
No related branches found
No related tags found
No related merge requests found
...@@ -116,5 +116,6 @@ ...@@ -116,5 +116,6 @@
}, },
"timezone": "", "timezone": "",
"title": "EUMETSAT", "title": "EUMETSAT",
"uid": "eumetsat",
"version": 1 "version": 1
} }
...@@ -207,16 +207,7 @@ def create_dashboard(request: TokenRequest, dashboard: dict, folder_id=None): ...@@ -207,16 +207,7 @@ def create_dashboard(request: TokenRequest, dashboard: dict, folder_id=None):
has_uid = dashboard.get('uid') is not None has_uid = dashboard.get('uid') is not None
if has_uid: if has_uid:
existing_dashboard = _get_dashboard(request, uid=dashboard['uid']) existing_dashboard = _get_dashboard(request, uid=dashboard['uid'])
# The title might not match the one that's provisioned with that UID.
# Try to find it by searching for the title instead.
if existing_dashboard is not None:
grafana_title = existing_dashboard['title']
different = grafana_title != title
else: else:
different = False
if existing_dashboard is None or different:
existing_dashboard = _search_dashboard(request, dashboard, folder_id) existing_dashboard = _search_dashboard(request, dashboard, folder_id)
if existing_dashboard: if existing_dashboard:
......
...@@ -25,7 +25,7 @@ def _datasource_exists(datasource_to_check, provisioned_datasources): ...@@ -25,7 +25,7 @@ def _datasource_exists(datasource_to_check, provisioned_datasources):
return True return True
for datasource in provisioned_datasources: for datasource in provisioned_datasources:
exists = all(datasource.get(key) == datasource_to_check.get(key) exists = all(datasource.get(key) == datasource_to_check.get(key)
for key in datasource_to_check) for key in datasource_to_check if key != 'secureJsonData') # we can't compare secureJsonData
if exists: if exists:
return True return True
return False return False
......
...@@ -220,7 +220,7 @@ def set_home_dashboard(request: TokenRequest, is_staff): ...@@ -220,7 +220,7 @@ def set_home_dashboard(request: TokenRequest, is_staff):
""" """
payload = render_homedashboard(staff=is_staff) payload = render_homedashboard(staff=is_staff)
dashboard = create_dashboard(request, payload) dashboard = create_dashboard(request, payload)
r = request.put('api/org/preferences', json={ request.put('api/org/preferences', json={
'homeDashboardId': dashboard.get('id') 'homeDashboardId': dashboard.get('id')
}).json() }).json()
return r and r.get('message') == 'Preferences updated' return dashboard
...@@ -698,20 +698,18 @@ def _provision_static_dashboards(config, org_config, ds_name, token): ...@@ -698,20 +698,18 @@ def _provision_static_dashboards(config, org_config, ds_name, token):
logger.info('Provisioning static dashboards') logger.info('Provisioning static dashboards')
for dashboard in get_dashboard_definitions(): for dashboard in get_dashboard_definitions():
if dashboard['title'] not in excluded_dashboards: if dashboard['title'] not in excluded_dashboards:
logger.info(f'Provisioning static {dashboard["title"]} dashboard')
res = create_dashboard(token, dashboard) res = create_dashboard(token, dashboard)
if res: if res:
# yield a fake dashboard dict yield res
# ... only the 'uid' element is referenced
yield {'uid': res.get('uid')}
else: else:
logger.info(f'Ensuring {dashboard["title"]} static dashboard is deleted')
delete_dashboard(token, dashboard) delete_dashboard(token, dashboard)
# Home dashboard is always called "Home" # Home dashboard is always called "Home"
# Make sure it's set for the organization # Make sure it's set for the organization
logger.info('Configuring Home dashboard') logger.info('Configuring Home dashboard')
set_home_dashboard(token, is_staff=org_config['name'] == 'GÉANT Staff') yield set_home_dashboard(token, is_staff=org_config['name'] == 'GÉANT Staff')
yield {'uid': 'home'}
def _get_ignored_dashboards(config, org_config, token): def _get_ignored_dashboards(config, org_config, token):
...@@ -740,9 +738,7 @@ def _get_ignored_dashboards(config, org_config, token): ...@@ -740,9 +738,7 @@ def _get_ignored_dashboards(config, org_config, token):
continue continue
for dash in to_ignore: for dash in to_ignore:
# return a hard-coded fake dashboard dict yield dash
# ... only the 'uid' element is referenced
yield {'uid': dash['uid']} # could just yield dash
def _provision_datasource(config, token): def _provision_datasource(config, token):
...@@ -881,8 +877,7 @@ def provision(config, raise_exceptions=False): ...@@ -881,8 +877,7 @@ def provision(config, raise_exceptions=False):
logger.debug(accounts) logger.debug(accounts)
all_original_dashboards = list_dashboards(token_request) all_original_dashboards = list_dashboards(token_request)
all_original_dashboard_uids = { all_original_dashboard_uids = {d['uid']: d.get('folderUrl', '') + d['url'] for d in all_original_dashboards}
d['uid'] for d in all_original_dashboards}
datasource = _provision_datasource(config, token_request) datasource = _provision_datasource(config, token_request)
ds_name = datasource.get('name', 'PollerInfluxDB') ds_name = datasource.get('name', 'PollerInfluxDB')
...@@ -906,17 +901,21 @@ def provision(config, raise_exceptions=False): ...@@ -906,17 +901,21 @@ def provision(config, raise_exceptions=False):
config, org_config, token_request) config, org_config, token_request)
) )
managed_dashboard_uids = set() managed_dashboard_uids = {}
for dashboard in managed_dashboards: for dashboard in managed_dashboards:
if isinstance(dashboard, Future): if isinstance(dashboard, Future):
dashboard = dashboard.result() dashboard = dashboard.result()
if dashboard is None: if dashboard is None:
continue continue
managed_dashboard_uids.add(dashboard['uid']) assert dashboard['uid'] not in managed_dashboard_uids, \
f'Dashboard with UID {dashboard["uid"]} already exists: {dashboard}'
managed_dashboard_uids[dashboard['uid']] = dashboard['url']
for uid in all_original_dashboard_uids - managed_dashboard_uids: difference = set(all_original_dashboard_uids.keys()) - set(managed_dashboard_uids.keys())
for uid in difference:
info = all_original_dashboard_uids[uid]
# delete unmanaged dashboards # delete unmanaged dashboards
logger.info(f'Deleting stale dashboard with UID {uid}') logger.info(f'Deleting stale dashboard {info} with UID {uid}')
delete_dashboard(token_request, {'uid': uid}) delete_dashboard(token_request, {'uid': uid})
folders_to_keep = { folders_to_keep = {
......
...@@ -223,11 +223,12 @@ def mock_grafana(data_config): ...@@ -223,11 +223,12 @@ def mock_grafana(data_config):
def _create_object(self, obj, all_objects): def _create_object(self, obj, all_objects):
id = obj.get("id") id = obj.get("id")
uid = obj.get("uid") uid = obj.get("uid") or next(self.uids)
obj = { obj = {
'url': '/fake/grafana/' + str(uid),
**obj, **obj,
"id": id if id is not None else next(self.ids), "id": id if id is not None else next(self.ids),
"uid": str(uid if uid is not None else next(self.uids)), "uid": str(uid),
} }
all_objects[obj["uid"]] = obj all_objects[obj["uid"]] = obj
return obj return obj
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment