Py3: Fix overview alarms panel

Change-Id: Ic608f20ca52a5061c8e42ba17cad092d886abac7
This commit is contained in:
Adrian Czarnecki 2018-08-16 11:13:17 +02:00
parent 01ef5c2285
commit 8d99e263a4
2 changed files with 7 additions and 3 deletions

View File

@ -163,7 +163,7 @@ class AlarmServiceView(tables.DataTableView):
try: try:
if self.service[:3] == 'b64': if self.service[:3] == 'b64':
name, value = self.service.split(":") name, value = self.service.split(":")
self.service = base64.urlsafe_b64decode(str(value)) self.service = base64.urlsafe_b64decode(str(value)).decode('utf-8')
results = api.monitor.alarm_list_by_dimension(self.request, results = api.monitor.alarm_list_by_dimension(self.request,
self.service, self.service,
page_offset, page_offset,

View File

@ -167,7 +167,9 @@ def show_by_dimension(data, dim_name):
for metric in data['metrics']: for metric in data['metrics']:
if 'dimensions' in metric: if 'dimensions' in metric:
if dim_name in metric['dimensions']: if dim_name in metric['dimensions']:
dimensions.append(str(metric['dimensions'][dim_name].encode('utf-8'))) dimension = metric['dimensions'][dim_name] if six.PY3 \
else metric['dimensions'][dim_name].encode('utf-8')
dimensions.append(dimension)
return dimensions return dimensions
return [] return []
@ -211,7 +213,9 @@ def generate_status(request):
for group, group_alarms in alarms_by_group.items(): for group, group_alarms in alarms_by_group.items():
name = '%s=%s' % (row['groupBy'], group) name = '%s=%s' % (row['groupBy'], group)
# Encode as base64url to be able to include '/' # Encode as base64url to be able to include '/'
name = 'b64:' + base64.urlsafe_b64encode(name) # encoding and decoding is required because of python3 compatibility
# urlsafe_b64encode requires byte-type text
name = 'b64:' + base64.urlsafe_b64encode(name.encode('utf-8')).decode('utf-8')
service = { service = {
'display': group, 'display': group,
'name': name, 'name': name,