Merge ~zzehring/charm-mongodb:bugfix/lp1882641-trusty-charm-upgrade-fails-import-pip into charm-mongodb:master

Proposed by Zachary Zehring
Status: Rejected
Rejected by: Drew Freiberger
Proposed branch: ~zzehring/charm-mongodb:bugfix/lp1882641-trusty-charm-upgrade-fails-import-pip
Merge into: charm-mongodb:master
Diff against target: 44 lines (+12/-7)
1 file modified
hooks/hooks.py (+12/-7)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Drew Freiberger (community) Approve
Review via email: mp+386772@code.launchpad.net

Commit message

Add try/except around pip import and reorder distro import.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Andrea Ieri (aieri) wrote :

This looks fine, but I suspect hooks/install is run before hooks/hooks.py, so this could more simply become (in that file):

- declare -a DEPS=('apt' 'netaddr' 'netifaces' 'pip' 'yaml')
+ declare -a DEPS=('apt' 'netaddr' 'netifaces' 'pip' 'yaml' 'python3-pip')

Revision history for this message
Drew Freiberger (afreiberger) wrote :

While I believe @andrea's suggestion should be additionally added, I don't know that the install hook is run during an upgrade-charm event, and this is intended to solve upgrade-charm issues on already deployed trusty hosts.

Revision history for this message
Drew Freiberger (afreiberger) wrote :

+1 on this change.

I've created MR to add in code per Andrea's comment for future clean installs.

https://code.launchpad.net/~afreiberger/charm-mongodb/+git/mongodb-charm/+merge/387692

review: Approve
Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Failed to merge change (unable to merge source repository due to conflicts), setting status to needs review.

Revision history for this message
Drew Freiberger (afreiberger) wrote :

Unmerged commits

1c8fbf9... by Zachary Zehring

Add try/except around pip import and reorder distro import.

This ensures python3-pip is installed as this package is
missing from trusty series, which will break upgrades from
older charm revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index fab26b9..3df82d7 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -9,7 +9,6 @@ import collections
6 import distutils
7 import json
8 import os
9-import pip
10 import pprint
11 import re
12 import signal
13@@ -19,12 +18,6 @@ import sys
14 import time
15
16 try:
17- import distro # flake8: noqa
18-except ImportError:
19- pip.main(['install', "distro"])
20- import distro # flake8: noqa
21-
22-try:
23 import yaml # flake8: noqa
24 except ImportError:
25 if sys.version_info.major == 2:
26@@ -92,6 +85,18 @@ except ImportError:
27 from pymongo import MongoClient
28 from pymongo.errors import OperationFailure
29
30+try:
31+ import pip # flake8: noqa
32+except ImportError:
33+ apt_install('python3-pip', fatal=True)
34+ import pip # flake8: noqa
35+
36+try:
37+ import distro # flake8: noqa
38+except ImportError:
39+ pip.main(['install', "distro"])
40+ import distro # flake8: noqa
41+
42 from charmhelpers.contrib.charmsupport.nrpe import NRPE
43
44 hooks = Hooks()

Subscribers

People subscribed via source and target branches

to all changes: