Merge lp:~thedac/charm-helpers/os-snaps into lp:charm-helpers

Proposed by David Ames
Status: Merged
Merged at revision: 769
Proposed branch: lp:~thedac/charm-helpers/os-snaps
Merge into: lp:charm-helpers
Diff against target: 112 lines (+30/-14)
2 files modified
charmhelpers/contrib/openstack/utils.py (+28/-12)
tests/contrib/openstack/test_openstack_utils.py (+2/-2)
To merge this branch: bzr merge lp:~thedac/charm-helpers/os-snaps
Reviewer Review Type Date Requested Status
Pen Gale (community) Approve
Review via email: mp+327980@code.launchpad.net

Description of the change

Use track/channel
Determine installed version of snap
Support snap upgrades

To post a comment you must log in.
Revision history for this message
Pen Gale (pengale) wrote :

"make test" runs for me , and code looks good, other than a null value getting passed in a way that I think will cause trouble.

I'd be +1 on this after that is addressed (either by being changed, or letting me know why I'm wrong to worry :-) )

review: Abstain
lp:~thedac/charm-helpers/os-snaps updated
770. By David Ames

Avoid NoneType error

Revision history for this message
David Ames (thedac) wrote :

Pete,

Thanks for that catch.

First some context, my goal was to re-use as many existing helper functions as possible to implement the snap integration as possible in order to avoid more changes to every charm.

os_release (which calls get_os_codename_package) get's called early often before the package has been installed. Thus the try/except when we expect no output from snap list. So we needed to handle this edge case.

In practice openstack_upgrade_available would not get called *before* the package has actually been installed. However, we should not leave that potential bug so I now have openstack_upgrade_available returning false if get_os_codename_package returns None.

Let me know what you think.

Revision history for this message
Pen Gale (pengale) wrote :

The latest change addresses my concern, and I am +1 to merging.

(I am still a little bit worried that swallowing the exception will mask a system problem with the snap command -- it's always nice to let an operator know when their tools are broken -- but you know this codebase better than I do, so I don't think that my worry should block a merge.)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/utils.py'
2--- charmhelpers/contrib/openstack/utils.py 2017-07-12 15:52:38 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2017-07-24 18:57:46 +0000
4@@ -94,6 +94,7 @@
5
6 from charmhelpers.fetch.snap import (
7 snap_install,
8+ snap_refresh,
9 SNAP_CHANNELS,
10 )
11
12@@ -408,7 +409,16 @@
13 '''Derive OpenStack release codename from an installed package.'''
14
15 if snap_install_requested():
16- return None
17+ cmd = ['snap', 'list', package]
18+ try:
19+ out = subprocess.check_output(cmd)
20+ except subprocess.CalledProcessError as e:
21+ return None
22+ lines = out.split('\n')
23+ for line in lines:
24+ if package in line:
25+ # Second item in list is Version
26+ return line.split()[1]
27
28 import apt_pkg as apt
29
30@@ -623,13 +633,12 @@
31 a newer version of package.
32 """
33
34- # TODO make upgrades snap aware
35- if snap_install_requested():
36- return False
37-
38 import apt_pkg as apt
39 src = config('openstack-origin')
40 cur_vers = get_os_version_package(package)
41+ if not cur_vers:
42+ # The package has not been installed yet do not attempt upgrade
43+ return False
44 if "swift" in package:
45 codename = get_os_codename_install_source(src)
46 avail_vers = get_os_version_codename_swift(codename)
47@@ -2058,7 +2067,7 @@
48
49 @param snaps: List of snaps
50 @param src: String of openstack-origin or source of the form
51- snap:channel-series-release
52+ snap:channel-series-track
53 @param mode: String classic, devmode or jailmode
54 @returns: Dictionary of snaps with channels and modes
55 """
56@@ -2068,13 +2077,14 @@
57 return {}
58
59 _src = src[5:]
60- channel, series, release = _src.split('-')
61+ _channel, _series, _release = _src.split('-')
62+ channel = '--channel={}/{}'.format(_release, _channel)
63
64 return {snap: {'channel': channel, 'mode': mode}
65 for snap in snaps}
66
67
68-def install_os_snaps(snaps):
69+def install_os_snaps(snaps, refresh=False):
70 """Install OpenStack snaps from channel and with mode
71
72 @param snaps: Dictionary of snaps with channels and modes of the form:
73@@ -2091,7 +2101,13 @@
74 return flag
75 return '--{}'.format(flag)
76
77- for snap in snaps.keys():
78- snap_install(snap,
79- _ensure_flag(snaps[snap]['channel']),
80- _ensure_flag(snaps[snap]['mode']))
81+ if refresh:
82+ for snap in snaps.keys():
83+ snap_refresh(snap,
84+ _ensure_flag(snaps[snap]['channel']),
85+ _ensure_flag(snaps[snap]['mode']))
86+ else:
87+ for snap in snaps.keys():
88+ snap_install(snap,
89+ _ensure_flag(snaps[snap]['channel']),
90+ _ensure_flag(snaps[snap]['mode']))
91
92=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
93--- tests/contrib/openstack/test_openstack_utils.py 2017-07-20 13:30:54 +0000
94+++ tests/contrib/openstack/test_openstack_utils.py 2017-07-24 18:57:46 +0000
95@@ -1935,7 +1935,7 @@
96 mode = 'jailmode'
97 src = 'snap:beta-xenial-ocata'
98 expected = {snaps[0]: {'mode': mode,
99- 'channel': 'beta'}}
100+ 'channel': '--channel=ocata/beta'}}
101 self.assertEqual(
102 expected,
103 openstack.get_snaps_install_info_from_origin(snaps, src,
104@@ -1950,7 +1950,7 @@
105 openstack.get_snaps_install_info_from_origin(
106 snaps, src, mode=mode))
107 mock_snap_install.assert_called_with(
108- 'os_project', '--beta', '--jailmode')
109+ 'os_project', '--channel=ocata/beta', '--jailmode')
110
111
112 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches