summaryrefslogtreecommitdiff
diff options
authorCelia Wang <celia.wang@canonical.com>2020-05-21 17:23:27 +1000
committerCelia Wang <celia.wang@canonical.com>2020-05-21 17:23:27 +1000
commit32288e9099d1f814cd8f868a04cf63d527defe5f (patch)
treee2eb4b1b83511a2d6fb8bf7e46a1af80e9988180
parentd0f92fe9721d2d7bcc372298d0d594e3bb2e353a (diff)
Add focal support
- add focal - fix some python2 only syntax - fix lint for actions and hooks directory
-rw-r--r--Makefile10
-rw-r--r--actions/backup.py6
-rwxr-xr-xactions/dump2
-rwxr-xr-xactions/perf31
-rwxr-xr-xactions/restore2
-rwxr-xr-xhooks/hooks.py42
-rwxr-xr-xhooks/install2
-rw-r--r--metadata.yaml3
8 files changed, 55 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index 4d444f8..d2aa8ac 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-PYTHON := /usr/bin/env python
-ACTIONS := $(shell grep -slE '\#!(.*)python' actions/*)
+PYTHON := /usr/bin/env python3
+ACTIONS := $(shell grep -slE '\#!(.*)python3' actions/*)
clean:
rm -f .coverage
@@ -24,9 +24,9 @@ clean:
(which dh_clean && dh_clean) || true
.venv:
- sudo apt-get install -y gcc python-dev python-virtualenv python-apt
- virtualenv .venv --system-site-packages
- .venv/bin/pip install -I -r test_requirements.txt
+ sudo apt-get install -y gcc python3-dev python-virtualenv python3-apt
+ virtualenv .venv --python=python3 --system-site-packages
+ .venv/bin/pip3 install -I -r test_requirements.txt
lint: .venv
.venv/bin/flake8 --exclude hooks/charmhelpers actions $(ACTIONS) hooks tests unit_tests
diff --git a/actions/backup.py b/actions/backup.py
index cac42cd..0930eab 100644
--- a/actions/backup.py
+++ b/actions/backup.py
@@ -4,8 +4,8 @@ import os
try:
from charmhelpers.core.hookenv import action_get, action_set, action_fail
except ImportError:
- subprocess.check_call(['apt-get', 'install', '-y', 'python-pip'])
- subprocess.check_call(['pip', 'install', 'charmhelpers'])
+ subprocess.check_call(['apt-get', 'install', '-y', 'python3-pip'])
+ subprocess.check_call(['pip3', 'install', 'charmhelpers'])
from charmhelpers.core.hookenv import action_get, action_set, action_fail
@@ -35,7 +35,7 @@ def restore():
def backup_command(cmd, args, dir):
try:
mkdir(dir)
- except OSError as e:
+ except OSError:
pass # Ignoring, the directory already exists
except Exception as e:
action_set({"directory creation exception": e})
diff --git a/actions/dump b/actions/dump
index a2a1ea1..bfb9c59 100755
--- a/actions/dump
+++ b/actions/dump
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import backup
backup.dump()
diff --git a/actions/perf b/actions/perf
index d3ff8a6..444987a 100755
--- a/actions/perf
+++ b/actions/perf
@@ -1,17 +1,22 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import signal
import subprocess
import os
import json
import re
from tempfile import NamedTemporaryFile
-from distutils.spawn import find_executable
+
+try:
+ from distutils.spawn import find_executable
+except ImportError:
+ subprocess.check_call(['apt-get', 'install', '-y', 'python3-distutils'])
+ from distutils.spawn import find_executable
try:
from charms.benchmark import Benchmark
except ImportError:
- subprocess.check_call(['apt-get', 'install', '-y', 'python-pip'])
- subprocess.check_call(['pip', 'install', '-U', 'charms.benchmark'])
+ subprocess.check_call(['apt-get', 'install', '-y', 'python3-pip'])
+ subprocess.check_call(['pip3', 'install', '-U', 'charms.benchmark'])
from charms.benchmark import Benchmark
@@ -22,7 +27,7 @@ def handler(signum, frame):
def action_set(key, val):
action_cmd = ['action-set']
if isinstance(val, dict):
- for k, v in val.iteritems():
+ for k, v in val.items():
action_set('%s.%s' % (key, k), v)
return
@@ -52,14 +57,14 @@ def main():
js['nThreads'] = int(action_get('nthreads'))
js['fileSizeMB'] = int(action_get('fileSizeMB'))
js['sleepMicros'] = int(action_get('sleepMicros'))
- js['mmf'] = action_get('mmf')
- js['r'] = action_get('r')
- js['w'] = action_get('w')
+ js['mmf'] = action_get('mmf').decode()
+ js['r'] = action_get('r').decode()
+ js['w'] = action_get('w').decode()
js['recSizeKB'] = int(action_get('recSizeKB'))
js['syncDelay'] = int(action_get('syncDelay'))
config = NamedTemporaryFile(delete=False)
- config.write(json.dumps(js))
+ config.write(json.dumps(js).encode())
config.close()
config = open(config.name, 'r')
@@ -75,8 +80,8 @@ def main():
os.waitpid(p.pid, 0)
except subprocess.CalledProcessError as e:
rc = e.returncode
- print "Exit with error code %d" % rc
- except IOError as e:
+ print("Exit with error code %d" % rc)
+ except IOError:
signal.alarm(0)
os.kill(p.pid, signal.SIGKILL)
finally:
@@ -103,7 +108,7 @@ def main():
action_set(
"results.average",
- {'value': sum(scores) / float(len(scores)), 'units': 'ops/sec'}
+ {'value': sum(scores) / len(scores), 'units': 'ops/sec'}
)
action_set(
"results.max",
@@ -115,7 +120,7 @@ def main():
)
Benchmark.set_composite_score(
- sum(scores) / float(len(scores)),
+ sum(scores) / len(scores),
'ops/sec',
'desc'
)
diff --git a/actions/restore b/actions/restore
index 171813a..ecac7b7 100755
--- a/actions/restore
+++ b/actions/restore
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import backup
backup.restore()
diff --git a/hooks/hooks.py b/hooks/hooks.py
index a4a3ee5..c5729ad 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
'''
Created on Aug 1, 2012
@@ -6,11 +6,10 @@ Created on Aug 1, 2012
'''
import collections
-import commands
import distutils
import json
import os
-import platform
+import distro
import pprint
import re
import signal
@@ -80,7 +79,10 @@ try:
from pymongo import MongoClient
from pymongo.errors import OperationFailure
except ImportError:
- apt_install("python-pymongo", fatal=True)
+ if sys.version_info.major == 2:
+ apt_install("python-pymongo", fatal=True)
+ else:
+ apt_install("python3-pymongo", fatal=True)
from pymongo import MongoClient
from pymongo.errors import OperationFailure
@@ -98,7 +100,7 @@ default_mongos_list = "/etc/mongos.list"
default_wait_for = 3
default_max_tries = 7
-INSTALL_PACKAGES = ['mongodb-server', 'python-yaml']
+INSTALL_PACKAGES = ['mongodb-server', 'python3-yaml']
# number of seconds init_replset will pause while looping to check if
# replicaset is initialized
@@ -129,8 +131,9 @@ was_i_primary = False
def is_bionic_or_greater():
- current_version = platform.linux_distribution()[1]
- if distutils.version.LooseVersion(current_version) >= distutils.version.LooseVersion('18.04'):
+ current_version = distro.linux_distribution()[1]
+ if distutils.version.LooseVersion(current_version) >= \
+ distutils.version.LooseVersion('18.04'):
return True
@@ -229,7 +232,8 @@ def process_check_pidfile(pidfile=None):
def is_valid_ip(bind_ip):
- if bind_ip == unit_get("private-address") or bind_ip == unit_get("public-address"):
+ if bind_ip == unit_get("private-address") or \
+ bind_ip == unit_get("public-address"):
return True
return False
@@ -1092,7 +1096,8 @@ def config_changed():
juju_log("config_changed: Exception: %s" % str(e))
if configsvr_pid is not None:
- configsvr_port = re.search(r'--port (\w+)', configsvr_cmd_line).group(2)
+ configsvr_port = re.search(r'--port (\w+)',
+ configsvr_cmd_line).group(2)
disable_configsvr(configsvr_port)
enable_configsvr(config_data['config_server_port'])
else:
@@ -1152,9 +1157,9 @@ def benchmark_relation_joined():
try:
from charms.benchmark import Benchmark
except ImportError:
- apt_install('python-pip', fatal=True)
+ apt_install('python3-pip', fatal=True)
import subprocess
- subprocess.check_call(['pip', 'install', '-U', 'charms.benchmark'])
+ subprocess.check_call(['pip3', 'install', '-U', 'charms.benchmark'])
from charms.benchmark import Benchmark
# Send a list of benchmark-enabled actions for display in the benchmark-gui
@@ -1232,7 +1237,8 @@ def rs_add(host):
subprocess.check_output(cmd_line)
r = run_admin_command(c, 'replSetGetStatus')
members = r["members"]
- ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY]
+ ok = [m for m in members
+ if m['name'] == host and m['state'] == MONGO_SECONDARY]
if ok:
return ok
@@ -1314,9 +1320,10 @@ def get_mongod_version():
return c.server_info()['version']
-# Retry until the replica set is in active state, retry 45 times before failing,
-# wait 1, 2, 3, 4, ... seconds between each retry, this will add 33 minutes of
-# accumulated sleep()
+# Retry until the replica set is in active state,
+# retry 45 times before failing,
+# wait 1, 2, 3, 4, ... seconds between each retry,
+# this will add 33 minutes of accumulated sleep()
@retry_on_exception(num_retries=45, base_delay=1)
def wait_until_replset_is_active():
status = update_status()
@@ -1546,7 +1553,7 @@ def update_nrpe_config():
host_context = rel['nagios_host_context']
break
nrpe = NRPE(hostname=hostname)
- apt_install('python-dbus')
+ apt_install('python3-dbus')
if host_context:
current_unit = "%s:%s" % (host_context, local_unit())
@@ -1755,7 +1762,7 @@ def volume_init_and_mount(volid):
def volume_get_all_mounted():
command = ("mount |egrep /srv/juju")
- status, output = commands.getstatusoutput(command)
+ status, output = subprocess.getstatusoutput(command)
if status != 0:
return None
return output
@@ -1911,4 +1918,3 @@ if __name__ == "__main__":
hooks.execute(sys.argv)
except UnregisteredHookError as e:
juju_log('Unknown hook {} - skipping'.format(e))
-
diff --git a/hooks/install b/hooks/install
index 8712bfa..baffb57 100755
--- a/hooks/install
+++ b/hooks/install
@@ -16,7 +16,7 @@ check_and_install() {
fi
}
-PYTHON="python"
+PYTHON="python3"
for dep in ${DEPS[@]}; do
check_and_install ${PYTHON} ${dep}
diff --git a/metadata.yaml b/metadata.yaml
index 399301a..fae2335 100644
--- a/metadata.yaml
+++ b/metadata.yaml
@@ -18,9 +18,10 @@ description: |
tags:
- databases
series:
+ - focal
+ - bionic
- xenial
- artful
- - bionic
- trusty
provides:
nrpe-external-master: