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
=== modified file 'hooks/cinder_hooks.py'
--- hooks/cinder_hooks.py 2014-08-07 00:42:21 +0000
+++ hooks/cinder_hooks.py 2014-08-27 15:14:30 +0000
@@ -7,7 +7,6 @@
7 add_source,7 add_source,
8 apt_install,8 apt_install,
9 apt_update,9 apt_update,
10 apt_upgrade
11)10)
1211
13from charmhelpers.core.hookenv import (12from charmhelpers.core.hookenv import (
@@ -22,6 +21,16 @@
22from cinder_contexts import VNXSubordinateContext21from cinder_contexts import VNXSubordinateContext
23from charmhelpers.payload.execd import execd_preinstall22from charmhelpers.payload.execd import execd_preinstall
2423
24PACKAGES = [
25 'cinder-api',
26 'cinder-backup',
27 'cinder-common',
28 'cinder-scheduler',
29 'cinder-volume',
30 'navicli',
31 'python-cinder',
32]
33
25hooks = Hooks()34hooks = Hooks()
2635
27def juju_log(msg):36def juju_log(msg):
@@ -51,22 +60,60 @@
51 except KeyError:60 except KeyError:
52 return None61 return None
5362
63def valid_source(source):
64 try:
65 return \
66 (source.startswith('https') or \
67 source.startswith('http') or \
68 source.startswith('ppa'))
69 except Exception:
70 juju_log('invalid source: %s' % source)
71 return False
72
73def valid_key(key):
74 try:
75 return (len(key) >= 8)
76 except Exception:
77 juju_log('invalid key (len < 8): %s' % key)
78 return False
79
80
54@hooks.hook('storage-backend-relation-joined',81@hooks.hook('storage-backend-relation-joined',
55 'storage-backend-relation-changed')82 'storage-backend-relation-changed')
56def storage_backend(rel_id=None):83def storage_backend(rel_id=None):
57 add_source(config_get('vnx_source'), config_get('vnx_source_key'))84 # REQUIRED: add vnx source and key
58 add_source(config_get('navicli_source'), config_get('navicli_source_key'))85 vnx_source = config_get('vnx_source')
86 vnx_key = config_get('vnx_source_key')
87 juju_log('storage_backend: vnx_source=%s vnx_key=%s' % (vnx_source, vnx_key))
88 if not valid_source(vnx_source) or not valid_key(vnx_key):
89 raise
90 add_source(vnx_source, vnx_key)
91
92 # REQUIRED: add navicli source and key
93 navicli_source = config_get('navicli_source')
94 navicli_key = config_get('navicli_source_key')
95 juju_log('storage_backend: navicli_source=%s navicli_key=%s' % (navicli_source,
96 navicli_key))
97 if not valid_source(navicli_source) or not valid_key(navicli_key):
98 raise
99 add_source(navicli_source, navicli_key)
100
101 # update and install packages
59 apt_update()102 apt_update()
60 apt_install("navicli")103 dpkg_opts = [
104 '--option', 'Dpkg::Options::=--force-confnew',
105 '--option', 'Dpkg::Options::=--force-confdef',
106 ]
107 apt_install(packages=PACKAGES, options=dpkg_opts, fatal=True)
61 relation_set(108 relation_set(
62 relation_id=rel_id,109 relation_id=rel_id,
63 backend_name=service_name(),110 backend_name=service_name(),
64 subordinate_configuration=json.dumps(VNXSubordinateContext()())111 subordinate_configuration=json.dumps(VNXSubordinateContext()())
65 )112 )
66 apt_upgrade(options=None, fatal=True, dist=True)113
67114
68if __name__ == '__main__':115if __name__ == '__main__':
69 try:116 try:
70 hooks.execute(sys.argv)117 hooks.execute(sys.argv)
71 except UnregisteredHookError as e:118 except UnregisteredHookError as e:
72 log('Unknown hook {} - skipping.'.format(e))119 juju_log('Unknown hook {} - skipping.'.format(e))

Subscribers

People subscribed via source and target branches

to all changes: