summaryrefslogtreecommitdiff
path: root/hooks
diff options
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/hooks.py42
-rwxr-xr-xhooks/install2
2 files changed, 25 insertions, 19 deletions
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}