Merge ~hloeung/influxdb-charm:master into influxdb-charm:master

Proposed by Haw Loeung
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~hloeung/influxdb-charm:master
Merge into: influxdb-charm:master
Diff against target: 134 lines (+31/-8)
5 files modified
actions/create-database (+7/-2)
actions/create-user (+7/-2)
actions/grant-privilege (+7/-2)
layer.yaml (+6/-2)
reactive/influxdb.py (+4/-0)
Reviewer Review Type Date Requested Status
InfluxDB Charmers Pending
Review via email: mp+333187@code.launchpad.net

Description of the change

Don't run configuration parts on update-status hook

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

Is there a decorator we could use for this? It seems a bit unwieldy as is.

~hloeung/influxdb-charm:master updated
5467c96... by Haw Loeung

Restore virtual env usage removed in commit 392fedea

d9d2d96... by Haw Loeung

Juju actions only available in Xenial and beyond

The juju actions required to interact with InfluxDB uses
python3-influxdb which is only available in Xenial and beyond. This
fixes that to not fail on prior series such as Trusty (LP: #1732015).

Unmerged commits

d9d2d96... by Haw Loeung

Juju actions only available in Xenial and beyond

The juju actions required to interact with InfluxDB uses
python3-influxdb which is only available in Xenial and beyond. This
fixes that to not fail on prior series such as Trusty (LP: #1732015).

5467c96... by Haw Loeung

Restore virtual env usage removed in commit 392fedea

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/actions/create-database b/actions/create-database
2index 96c9cb1..d2cd4bd 100755
3--- a/actions/create-database
4+++ b/actions/create-database
5@@ -1,7 +1,6 @@
6 #!/usr/bin/python3
7 # Create a database
8
9-import influxdb
10 import requests
11 import traceback
12
13@@ -12,6 +11,12 @@ from charmhelpers.core.hookenv import (
14 log,
15 )
16
17+try:
18+ import influxdb
19+except ImportError:
20+ print("Missing python3-influxdb package")
21+ exit(1)
22+
23 action = "create-database"
24
25 try:
26@@ -33,7 +38,7 @@ try:
27 print("Create database: " + database)
28 client.create_database(database)
29 action_set({"created": database})
30-except:
31+except Exception:
32 action_fail('Unhandled exception')
33 tb = traceback.format_exc()
34 action_set(dict(traceback=tb))
35diff --git a/actions/create-user b/actions/create-user
36index cae4df9..8ad8db3 100755
37--- a/actions/create-user
38+++ b/actions/create-user
39@@ -1,7 +1,6 @@
40 #!/usr/bin/python3
41 # Create a database
42
43-import influxdb
44 import random
45 import requests
46 import string
47@@ -14,6 +13,12 @@ from charmhelpers.core.hookenv import (
48 log,
49 )
50
51+try:
52+ import influxdb
53+except ImportError:
54+ print("Missing python3-influxdb package")
55+ exit(1)
56+
57 action = "create-user"
58 charset = string.ascii_lowercase + string.ascii_uppercase + string.digits
59 password = ''.join(random.sample(charset, 16))
60@@ -54,5 +59,5 @@ except influxdb.exceptions.InfluxDBClientError as e:
61 action_fail("User {} already exists".format(user))
62 else:
63 unhandled_exception()
64-except:
65+except Exception:
66 unhandled_exception()
67diff --git a/actions/grant-privilege b/actions/grant-privilege
68index 62626f1..87cfb0d 100755
69--- a/actions/grant-privilege
70+++ b/actions/grant-privilege
71@@ -1,7 +1,6 @@
72 #!/usr/bin/python3
73 # Create a database
74
75-import influxdb
76 import requests
77 import traceback
78
79@@ -12,6 +11,12 @@ from charmhelpers.core.hookenv import (
80 log,
81 )
82
83+try:
84+ import influxdb
85+except ImportError:
86+ print("Missing python3-influxdb package")
87+ exit(1)
88+
89 action = "grant-privilege"
90
91
92@@ -45,5 +50,5 @@ try:
93 client.grant_privilege(privilege, database, user)
94 action_set({"granted": user, "privilege": privilege, "database": database})
95 print("Granted {} {} on {}".format(user, privilege, database))
96-except:
97+except Exception:
98 unhandled_exception()
99diff --git a/layer.yaml b/layer.yaml
100index 0dcf45c..c68c892 100644
101--- a/layer.yaml
102+++ b/layer.yaml
103@@ -8,10 +8,14 @@ includes:
104 - interface:influxdb-api
105 options:
106 basic:
107+ # We need to use virtual env:
108+ # https://github.com/juju-solutions/charms.reactive/issues/135
109+ use_venv: true
110+ include_system_packages: true
111 packages:
112- # we need to specify these here due to https://github.com/juju-solutions/charms.reactive/issues/82
113+ # We need to specify essential required packages:
114+ # https://github.com/juju-solutions/charms.reactive/issues/82
115 - build-essential
116 - python3-setuptools
117 - python3-wheel
118 - python3-yaml
119- - python3-influxdb
120diff --git a/reactive/influxdb.py b/reactive/influxdb.py
121index ae04df9..24b51bf 100644
122--- a/reactive/influxdb.py
123+++ b/reactive/influxdb.py
124@@ -42,6 +42,10 @@ def install_influx():
125 subprocess.check_call(['influx', '--version'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
126 except OSError:
127 apt_install('influxdb-client')
128+ series = host.lsb_release()['DISTRIB_CODENAME']
129+ # python3-influxdb only exists in Ubuntu Xenial and beyond - LP: #1732015.
130+ if series not in ('precise', 'trusty'):
131+ apt_install('python3-influxdb')
132
133
134 def apply_configs(fh, config):

Subscribers

People subscribed via source and target branches

to all changes: