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
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2017-07-12 15:52:38 +0000
+++ charmhelpers/contrib/openstack/utils.py 2017-07-24 18:57:46 +0000
@@ -94,6 +94,7 @@
9494
95from charmhelpers.fetch.snap import (95from charmhelpers.fetch.snap import (
96 snap_install,96 snap_install,
97 snap_refresh,
97 SNAP_CHANNELS,98 SNAP_CHANNELS,
98)99)
99100
@@ -408,7 +409,16 @@
408 '''Derive OpenStack release codename from an installed package.'''409 '''Derive OpenStack release codename from an installed package.'''
409410
410 if snap_install_requested():411 if snap_install_requested():
411 return None412 cmd = ['snap', 'list', package]
413 try:
414 out = subprocess.check_output(cmd)
415 except subprocess.CalledProcessError as e:
416 return None
417 lines = out.split('\n')
418 for line in lines:
419 if package in line:
420 # Second item in list is Version
421 return line.split()[1]
412422
413 import apt_pkg as apt423 import apt_pkg as apt
414424
@@ -623,13 +633,12 @@
623 a newer version of package.633 a newer version of package.
624 """634 """
625635
626 # TODO make upgrades snap aware
627 if snap_install_requested():
628 return False
629
630 import apt_pkg as apt636 import apt_pkg as apt
631 src = config('openstack-origin')637 src = config('openstack-origin')
632 cur_vers = get_os_version_package(package)638 cur_vers = get_os_version_package(package)
639 if not cur_vers:
640 # The package has not been installed yet do not attempt upgrade
641 return False
633 if "swift" in package:642 if "swift" in package:
634 codename = get_os_codename_install_source(src)643 codename = get_os_codename_install_source(src)
635 avail_vers = get_os_version_codename_swift(codename)644 avail_vers = get_os_version_codename_swift(codename)
@@ -2058,7 +2067,7 @@
20582067
2059 @param snaps: List of snaps2068 @param snaps: List of snaps
2060 @param src: String of openstack-origin or source of the form2069 @param src: String of openstack-origin or source of the form
2061 snap:channel-series-release2070 snap:channel-series-track
2062 @param mode: String classic, devmode or jailmode2071 @param mode: String classic, devmode or jailmode
2063 @returns: Dictionary of snaps with channels and modes2072 @returns: Dictionary of snaps with channels and modes
2064 """2073 """
@@ -2068,13 +2077,14 @@
2068 return {}2077 return {}
20692078
2070 _src = src[5:]2079 _src = src[5:]
2071 channel, series, release = _src.split('-')2080 _channel, _series, _release = _src.split('-')
2081 channel = '--channel={}/{}'.format(_release, _channel)
20722082
2073 return {snap: {'channel': channel, 'mode': mode}2083 return {snap: {'channel': channel, 'mode': mode}
2074 for snap in snaps}2084 for snap in snaps}
20752085
20762086
2077def install_os_snaps(snaps):2087def install_os_snaps(snaps, refresh=False):
2078 """Install OpenStack snaps from channel and with mode2088 """Install OpenStack snaps from channel and with mode
20792089
2080 @param snaps: Dictionary of snaps with channels and modes of the form:2090 @param snaps: Dictionary of snaps with channels and modes of the form:
@@ -2091,7 +2101,13 @@
2091 return flag2101 return flag
2092 return '--{}'.format(flag)2102 return '--{}'.format(flag)
20932103
2094 for snap in snaps.keys():2104 if refresh:
2095 snap_install(snap,2105 for snap in snaps.keys():
2096 _ensure_flag(snaps[snap]['channel']),2106 snap_refresh(snap,
2097 _ensure_flag(snaps[snap]['mode']))2107 _ensure_flag(snaps[snap]['channel']),
2108 _ensure_flag(snaps[snap]['mode']))
2109 else:
2110 for snap in snaps.keys():
2111 snap_install(snap,
2112 _ensure_flag(snaps[snap]['channel']),
2113 _ensure_flag(snaps[snap]['mode']))
20982114
=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
--- tests/contrib/openstack/test_openstack_utils.py 2017-07-20 13:30:54 +0000
+++ tests/contrib/openstack/test_openstack_utils.py 2017-07-24 18:57:46 +0000
@@ -1935,7 +1935,7 @@
1935 mode = 'jailmode'1935 mode = 'jailmode'
1936 src = 'snap:beta-xenial-ocata'1936 src = 'snap:beta-xenial-ocata'
1937 expected = {snaps[0]: {'mode': mode,1937 expected = {snaps[0]: {'mode': mode,
1938 'channel': 'beta'}}1938 'channel': '--channel=ocata/beta'}}
1939 self.assertEqual(1939 self.assertEqual(
1940 expected,1940 expected,
1941 openstack.get_snaps_install_info_from_origin(snaps, src,1941 openstack.get_snaps_install_info_from_origin(snaps, src,
@@ -1950,7 +1950,7 @@
1950 openstack.get_snaps_install_info_from_origin(1950 openstack.get_snaps_install_info_from_origin(
1951 snaps, src, mode=mode))1951 snaps, src, mode=mode))
1952 mock_snap_install.assert_called_with(1952 mock_snap_install.assert_called_with(
1953 'os_project', '--beta', '--jailmode')1953 'os_project', '--channel=ocata/beta', '--jailmode')
19541954
19551955
1956if __name__ == '__main__':1956if __name__ == '__main__':

Subscribers

People subscribed via source and target branches