Merge lp:~raharper/charms/trusty/cinder-vnx/validate_source_and_fail_fast into lp:~alai/charms/trusty/cinder-vnx/trunk

Proposed by Ryan Harper
Status: Merged
Merged at revision: 6
Proposed branch: lp:~raharper/charms/trusty/cinder-vnx/validate_source_and_fail_fast
Merge into: lp:~alai/charms/trusty/cinder-vnx/trunk
Diff against target: 94 lines (+53/-6)
1 file modified
hooks/cinder_hooks.py (+53/-6)
To merge this branch: bzr merge lp:~raharper/charms/trusty/cinder-vnx/validate_source_and_fail_fast

Description of the change

Validate vnx_source, vnx_source_key, navicli_source, navicli_source_key charm values; Fail relation if invalid since these are required for cinder-vnx to work.

Explicitly list out the packages to be installed

Run apt_install with fatal=True; we want to fail if we cannot install required packages.

Removed dist-upgrade; I don't think it's expected behavior to perform a dist-upgrade when the charm adds or removes the storage relation.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/cinder_hooks.py'
2--- hooks/cinder_hooks.py 2014-08-07 00:42:21 +0000
3+++ hooks/cinder_hooks.py 2014-08-27 15:14:30 +0000
4@@ -7,7 +7,6 @@
5 add_source,
6 apt_install,
7 apt_update,
8- apt_upgrade
9 )
10
11 from charmhelpers.core.hookenv import (
12@@ -22,6 +21,16 @@
13 from cinder_contexts import VNXSubordinateContext
14 from charmhelpers.payload.execd import execd_preinstall
15
16+PACKAGES = [
17+ 'cinder-api',
18+ 'cinder-backup',
19+ 'cinder-common',
20+ 'cinder-scheduler',
21+ 'cinder-volume',
22+ 'navicli',
23+ 'python-cinder',
24+]
25+
26 hooks = Hooks()
27
28 def juju_log(msg):
29@@ -51,22 +60,60 @@
30 except KeyError:
31 return None
32
33+def valid_source(source):
34+ try:
35+ return \
36+ (source.startswith('https') or \
37+ source.startswith('http') or \
38+ source.startswith('ppa'))
39+ except Exception:
40+ juju_log('invalid source: %s' % source)
41+ return False
42+
43+def valid_key(key):
44+ try:
45+ return (len(key) >= 8)
46+ except Exception:
47+ juju_log('invalid key (len < 8): %s' % key)
48+ return False
49+
50+
51 @hooks.hook('storage-backend-relation-joined',
52 'storage-backend-relation-changed')
53 def storage_backend(rel_id=None):
54- add_source(config_get('vnx_source'), config_get('vnx_source_key'))
55- add_source(config_get('navicli_source'), config_get('navicli_source_key'))
56+ # REQUIRED: add vnx source and key
57+ vnx_source = config_get('vnx_source')
58+ vnx_key = config_get('vnx_source_key')
59+ juju_log('storage_backend: vnx_source=%s vnx_key=%s' % (vnx_source, vnx_key))
60+ if not valid_source(vnx_source) or not valid_key(vnx_key):
61+ raise
62+ add_source(vnx_source, vnx_key)
63+
64+ # REQUIRED: add navicli source and key
65+ navicli_source = config_get('navicli_source')
66+ navicli_key = config_get('navicli_source_key')
67+ juju_log('storage_backend: navicli_source=%s navicli_key=%s' % (navicli_source,
68+ navicli_key))
69+ if not valid_source(navicli_source) or not valid_key(navicli_key):
70+ raise
71+ add_source(navicli_source, navicli_key)
72+
73+ # update and install packages
74 apt_update()
75- apt_install("navicli")
76+ dpkg_opts = [
77+ '--option', 'Dpkg::Options::=--force-confnew',
78+ '--option', 'Dpkg::Options::=--force-confdef',
79+ ]
80+ apt_install(packages=PACKAGES, options=dpkg_opts, fatal=True)
81 relation_set(
82 relation_id=rel_id,
83 backend_name=service_name(),
84 subordinate_configuration=json.dumps(VNXSubordinateContext()())
85 )
86- apt_upgrade(options=None, fatal=True, dist=True)
87+
88
89 if __name__ == '__main__':
90 try:
91 hooks.execute(sys.argv)
92 except UnregisteredHookError as e:
93- log('Unknown hook {} - skipping.'.format(e))
94+ juju_log('Unknown hook {} - skipping.'.format(e))

Subscribers

People subscribed via source and target branches

to all changes: