Skip to content

Commit

Permalink
Ensure python scripts are py3 compatible
Browse files Browse the repository at this point in the history
This patch set is one of many to migrate existing code/script to be
python-3 compatible as python-2 is sunsetting in January 2020.

Change-Id: I4a8fa4c07fd36583716b5ccfdcb0bcdc008db3e7
Signed-off-by: Tin Lam <[email protected]>
  • Loading branch information
stannum-l authored and Tin Lam committed Oct 14, 2019
1 parent 2b6581d commit 1b01907
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions mariadb/templates/bin/_start.py.tpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2018 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{/*
Copyright 2018 The Openstack-Helm Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}

import errno
import logging
Expand Down Expand Up @@ -461,7 +462,7 @@ def get_grastate_val(key):
"""
logger.debug("Reading grastate.dat key={0}".format(key))
with open("/var/lib/mysql/grastate.dat", "r") as myfile:
grastate_raw = map(lambda s: s.strip(), myfile.readlines())
grastate_raw = [s.strip() for s in myfile.readlines()]
return [i for i in grastate_raw
if i.startswith("{0}:".format(key))][0].split(':')[1].strip()

Expand Down Expand Up @@ -496,7 +497,7 @@ def update_grastate_configmap():
grastate['seqno'] = get_grastate_val(key='seqno')
grastate['safe_to_bootstrap'] = get_grastate_val(key='safe_to_bootstrap')
grastate['sample_time'] = "{0}Z".format(datetime.utcnow().isoformat("T"))
for grastate_key, grastate_value in grastate.iteritems():
for grastate_key, grastate_value in list(grastate.items()):
configmap_key = "{0}.{1}".format(grastate_key, local_hostname)
if get_configmap_value(
type='data', key=configmap_key) != grastate_value:
Expand Down Expand Up @@ -582,14 +583,14 @@ def check_if_cluster_data_is_fresh():
name=state_configmap_name, namespace=pod_namespace)
state_configmap_dict = state_configmap.to_dict()
sample_times = dict()
for key, value in state_configmap_dict['data'].iteritems():
for key, value in list(state_configmap_dict['data'].items()):
keyitems = key.split('.')
key = keyitems[0]
node = keyitems[1]
if key == 'sample_time':
sample_times[node] = value
sample_time_ok = True
for key, value in sample_times.iteritems():
for key, value in list(sample_times.items()):
sample_time = iso8601.parse_date(value).replace(tzinfo=None)
sample_cutoff_time = datetime.utcnow().replace(
tzinfo=None) - timedelta(seconds=20)
Expand All @@ -613,14 +614,14 @@ def get_nodes_with_highest_seqno():
name=state_configmap_name, namespace=pod_namespace)
state_configmap_dict = state_configmap.to_dict()
seqnos = dict()
for key, value in state_configmap_dict['data'].iteritems():
for key, value in list(state_configmap_dict['data'].items()):
keyitems = key.split('.')
key = keyitems[0]
node = keyitems[1]
if key == 'seqno':
seqnos[node] = value
max_seqno = max(seqnos.values())
max_seqno_nodes = sorted([k for k, v in seqnos.items() if v == max_seqno])
max_seqno_nodes = sorted([k for k, v in list(seqnos.items()) if v == max_seqno])
return max_seqno_nodes


Expand Down
2 changes: 1 addition & 1 deletion tools/gate/selenium/kibanaSelenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_variable(env_var):
)
logger.info('{} index loaded successfully'.format(name))
retry = 0
except TimeoutException, e:
except TimeoutException:
logger.error('Error occured loading {} index'.format(name))
prefix = 'Error_'
browser.save_screenshot(
Expand Down

0 comments on commit 1b01907

Please sign in to comment.