Merge lp://qastaging/~joeborg/charm-helpers/snap-install into lp://qastaging/charm-helpers

Proposed by Joseph Borg
Status: Merged
Merged at revision: 704
Proposed branch: lp://qastaging/~joeborg/charm-helpers/snap-install
Merge into: lp://qastaging/charm-helpers
Diff against target: 317 lines (+251/-14)
7 files modified
.bzrignore (+1/-0)
charmhelpers/fetch/snap.py (+122/-0)
docs/api/charmhelpers.fetch.archiveurl.rst (+7/-0)
docs/api/charmhelpers.fetch.bzrurl.rst (+7/-0)
docs/api/charmhelpers.fetch.rst (+22/-14)
docs/api/charmhelpers.fetch.snap.rst (+26/-0)
tests/fetch/test_snap.py (+66/-0)
To merge this branch: bzr merge lp://qastaging/~joeborg/charm-helpers/snap-install
Reviewer Review Type Date Requested Status
David Ames (community) Approve
Corey Bryant (community) Approve
Review via email: mp+318233@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Corey Bryant (corey.bryant) wrote :

Looking like a good start! One overarching comment and then some inline comments below. I think this code should live in charm-helpers/charmhelpers/fetch/ similar to how apt install etc lives there. Also can you think of any other snap commands we should support?

Revision history for this message
Joseph Borg (joeborg) wrote :
Download full text (8.1 KiB)

Yep, agree with all of that.

I mainly put the explicit args in the snap_install method for verbosity, but I’ll move these to the docs instead.

In terms of more commands; I would probably be a good idea to allow them all (and then we can make one abstract method to handle them all, rather than one for each snap command). Although I’m not sure many of them are relevant in terms of what need to be done on charm install. There’s then the question of implicit vs explicit if there’s a factory creating all these methods, or if you just have a static method with the snap command as an argument.

> On 24 Feb 2017, at 10:17, Corey Bryant <email address hidden> wrote:
>
> Looking like a good start! One overarching comment and then some inline comments below. I think this code should live in charm-helpers/charmhelpers/fetch/ similar to how apt install etc lives there. Also can you think of any other snap commands we should support?
>
> Diff comments:
>
>> === added directory 'charmhelpers/contrib/snap'
>> === added file 'charmhelpers/contrib/snap/__init__.py'
>> --- charmhelpers/contrib/snap/__init__.py 1970-01-01 00:00:00 +0000
>> +++ charmhelpers/contrib/snap/__init__.py 2017-02-24 14:37:30 +0000
>> @@ -0,0 +1,109 @@
>> +# Copyright 2014-2017 Canonical Limited.
>> +#
>> +# Licensed under the Apache License, Version 2.0 (the "License");
>> +# you may not use this file except in compliance with the License.
>> +# You may obtain a copy of the License at
>> +#
>> +# http://www.apache.org/licenses/LICENSE-2.0 <http://www.apache.org/licenses/LICENSE-2.0>
>> +#
>> +# Unless required by applicable law or agreed to in writing, software
>> +# distributed under the License is distributed on an "AS IS" BASIS,
>> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> +# See the License for the specific language governing permissions and
>> +# limitations under the License.
>> +"""
>> +Charm helpers snap for classic charms.
>> +
>> +If writing reactive charms, use the snap layer:
>> +https://lists.ubuntu.com/archives/snapcraft/2016-September/001114.html <https://lists.ubuntu.com/archives/snapcraft/2016-September/001114.html>
>
> Good idea putting this here. You could alternatively point to the Snap layer at http://interfaces.juju.solutions/ <http://interfaces.juju.solutions/>.
>
>> +"""
>> +import subprocess
>> +from charmhelpers.core.hookenv import log
>> +
>> +__author__ = 'Joseph Borg <<email address hidden> <mailto:<email address hidden>>>'
>> +
>> +
>> +def _snap_exec(commands):
>> + """
>> + Execute snap commands.
>> + :param commands: List commands
>> + :return: Integer exit code
>> + """
>> + assert type(commands) == list
>> + proc = subprocess.Popen(
>
> Is there any reason to not use subprocess.check_call here?
>
>> + ['snap'] + commands
>> + )
>> + proc.wait()
>> +
>> + if proc.returncode > 0:
>> + log('`snap %s` exited with a non-zero status' % ' '.join(commands),
>> + level='FATAL')
>> +
>> + return proc.returncode
>> +
>> +
>> +def snap_install(package, edge=False, beta=False, candidate=False, stable=False, devmode=False, jailmode=False,
>> + ...

Read more...

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Let's try to land snap_install/snap_remove/snap_refresh for now and if we find that we need any other commands later we can add them then. I'd say follow the lead of the apt functions in terms of parameters and code structure.

696. By Joseph Borg

A few updates before landing:
Removing fixed options for snap_install.
Adding snap_refresh.
Updating docs to include examples.
Finishing tests using mock.

697. By Joseph Borg

Correcting typo in doc string

Revision history for this message
Joseph Borg (joeborg) wrote :

Updates pushed

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Looking good Joe. Couple of comments inline below.

698. By Joseph Borg

Moving Snap helper into fetch module:
 - Wrapping call to snap in try / except to cope with lock.
 - Adjusting tests to cope with change of location and libraries mocked.
 - Re-organising docs to make fetch a bit more readable.

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Hey Joe, The unit tests are failing. I think you just need to mock out os.environ(). I gave the new functions a test run via the keystone charm and they worked as expected, no problems. I didn't test out the doc updates yet.

699. By Joseph Borg

Fixing tests under `make test` conditions

Revision history for this message
Joseph Borg (joeborg) wrote :

> Hey Joe, The unit tests are failing. I think you just need to mock out
> os.environ(). I gave the new functions a test run via the keystone charm and
> they worked as expected, no problems. I didn't test out the doc updates yet.

Fixed! Was running tests with `python -m unittest` which didn't flag the issue.

Revision history for this message
Corey Bryant (corey.bryant) wrote :

LGTM thanks!

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

Looks good. Just a couple of requests.

Please create a specific Exception to raise in line 66.

And please explicitly add log severity to to lines 91,112 and 133

log("MESSAGE", level='ERROR')

review: Needs Fixing
700. By Joseph Borg

Adding custom exception

Revision history for this message
Joseph Borg (joeborg) wrote :

Added!

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

Thanks for the work. Let me know if you need me to do the merge for this.

review: Approve
Revision history for this message
Joseph Borg (joeborg) wrote :

> Thanks for the work. Let me know if you need me to do the merge for this.

Yes please, I don't have the permissions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches