Merge lp:~makyo/juju-quickstart/ensure-juju-lxc into lp:juju-quickstart
- ensure-juju-lxc
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 19 |
Proposed branch: | lp:~makyo/juju-quickstart/ensure-juju-lxc |
Merge into: | lp:juju-quickstart |
Diff against target: |
126 lines (+94/-0) 3 files modified
quickstart/app.py (+30/-0) quickstart/manage.py (+2/-0) quickstart/tests/test_app.py (+62/-0) |
To merge this branch: | bzr merge lp:~makyo/juju-quickstart/ensure-juju-lxc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju GUI Hackers | Pending | ||
Review via email:
|
Commit message
Description of the change
Ensure juju and lxc are installed
To test: make check
To QA:
- Create an lxc or vm without juju installed
- Clone this branch
- Run `make sysdeps`
- Run `make run`
It should install juju, lxc, and dependencies, then prompt you to run again after initializing your juju environments.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Madison Scott-Clary (makyo) wrote : | # |
- 21. By Madison Scott-Clary
-
Clarified message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Madison Scott-Clary (makyo) wrote : | # |
Please take a look.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Gary Poster (gary) wrote : | # |
LGTM. I'm afraid I won't have time for a QA today, but will do it
tomorrow if requested. Thank you!
https:/
File quickstart/
https:/
quickstart/
and
PEP8 style says that the first line should not break. Maybe this?
Easily use `call` and `sudo_call` from quickstart.utils.
- 22. By Madison Scott-Clary
-
Fix old docstring
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Madison Scott-Clary (makyo) wrote : | # |
Please take a look.
https:/
File quickstart/
https:/
quickstart/
and
On 2013/11/20 21:41:20, gary.poster wrote:
> PEP8 style says that the first line should not break. Maybe this?
> Easily use `call` and `sudo_call` from quickstart.utils.
Reverting, left over from my previous solution. Good to know, though!
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Madison Scott-Clary (makyo) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Madison Scott-Clary (makyo) wrote : | # |
On 2013/11/20 21:46:39, matthew.scott wrote:
Thanks, RV. That was supposed to be a reply to Gary - the comment was
old, reverted.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Francesco Banconi (frankban) wrote : | # |
Nice branch Matthew, thank you!
LGTM with changes (see below).
Will QA later.
https:/
File quickstart/app.py (right):
https:/
quickstart/
ISTM that this is a good place to inform the user about what's
happening, e.g.: 'juju is not installed', 'sudo privileges required to
install juju'. It could be nice to give an idea about why we need sudo.
https:/
quickstart/
You can either add sudo in the cmds above (and make cmds a list of
tuples) or just "retcode, _, error = utils.call('sudo', *cmd)" below
(and make cmds a list of tuples :-). <shrug>
https:/
quickstart/
run `juju init` and '
I am not sure about exiting with an error here.
What if the user has a juju home properly set up but juju is not
installed? This is not uncommon, e.g. he removed the package, or he is
working in a lxc sharing his home directory. Moreover this code is never
reached if the envs.yaml is not properly set up, so we are just
preventing users with a configured juju home to proceed. I think we
should just continue with the normal execution here: in the future we
will guide the user setting up the environment.
https:/
File quickstart/
https:/
quickstart/
What do you think about making this a logging.debug call? I am not sure
about how much this is informative after the first run.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Brad Crittenden (bac) wrote : | # |
Changes made. Having to re-propose to a new merge proposal before
landing.
https:/
File quickstart/app.py (right):
https:/
quickstart/
On 2013/11/21 12:02:03, frankban wrote:
> ISTM that this is a good place to inform the user about what's
happening, e.g.:
> 'juju is not installed', 'sudo privileges required to install juju'.
It could be
> nice to give an idea about why we need sudo.
Done.
https:/
quickstart/
On 2013/11/21 12:02:03, frankban wrote:
> You can either add sudo in the cmds above (and make cmds a list of
tuples) or
> just "retcode, _, error = utils.call('sudo', *cmd)" below (and make
cmds a list
> of tuples :-). <shrug>
Done.
https:/
quickstart/
run `juju init` and '
On 2013/11/21 12:02:03, frankban wrote:
> I am not sure about exiting with an error here.
> What if the user has a juju home properly set up but juju is not
installed? This
> is not uncommon, e.g. he removed the package, or he is working in a
lxc sharing
> his home directory. Moreover this code is never reached if the
envs.yaml is not
> properly set up, so we are just preventing users with a configured
juju home to
> proceed. I think we should just continue with the normal execution
here: in the
> future we will guide the user setting up the environment.
Done.
https:/
File quickstart/
https:/
quickstart/
On 2013/11/21 12:02:03, frankban wrote:
> What do you think about making this a logging.debug call? I am not
sure about
> how much this is informative after the first run.
Done.
Preview Diff
1 | === modified file 'quickstart/app.py' | |||
2 | --- quickstart/app.py 2013-11-20 11:35:30 +0000 | |||
3 | +++ quickstart/app.py 2013-11-20 21:43:48 +0000 | |||
4 | @@ -45,6 +45,36 @@ | |||
5 | 45 | return 'juju-quickstart: error: {}'.format(self.message) | 45 | return 'juju-quickstart: error: {}'.format(self.message) |
6 | 46 | 46 | ||
7 | 47 | 47 | ||
8 | 48 | def ensure_dependencies(): | ||
9 | 49 | """Ensure that Juju and LXC are installed. | ||
10 | 50 | |||
11 | 51 | If juju is not found in the PATH, then add the juju stable PPA and install | ||
12 | 52 | both juju and lxc. | ||
13 | 53 | |||
14 | 54 | Return when juju is available. | ||
15 | 55 | Raise a ProgramExit if an error occurs installing. | ||
16 | 56 | """ | ||
17 | 57 | retcode = utils.call('juju', 'version')[0] | ||
18 | 58 | retcode += utils.call('lxc-ls')[0] | ||
19 | 59 | if retcode > 0: | ||
20 | 60 | cmds = [ | ||
21 | 61 | ['apt-add-repository', '-y', 'ppa:juju/stable'], | ||
22 | 62 | ['apt-get', 'update'], | ||
23 | 63 | ['apt-get', 'install', '-y', 'juju-core', 'lxc'] | ||
24 | 64 | ] | ||
25 | 65 | for cmd in cmds: | ||
26 | 66 | cmd.insert(0, 'sudo') | ||
27 | 67 | retcode, _, error = utils.call(*cmd) | ||
28 | 68 | if retcode: | ||
29 | 69 | raise ProgramExit(error) | ||
30 | 70 | # XXX Makyo #1247214: | ||
31 | 71 | # Here, we should guide the user through cloud credentials and | ||
32 | 72 | # juju init. | ||
33 | 73 | raise ProgramExit('Juju is now installed; please run `juju init` and ' | ||
34 | 74 | 'then the same juju quickstart command again to ' | ||
35 | 75 | 'proceed.') | ||
36 | 76 | |||
37 | 77 | |||
38 | 48 | def bootstrap(env_name, is_local=False, debug=False): | 78 | def bootstrap(env_name, is_local=False, debug=False): |
39 | 49 | """Bootstrap the Juju environment with the given name. | 79 | """Bootstrap the Juju environment with the given name. |
40 | 50 | 80 | ||
41 | 51 | 81 | ||
42 | === modified file 'quickstart/manage.py' | |||
43 | --- quickstart/manage.py 2013-11-20 11:35:30 +0000 | |||
44 | +++ quickstart/manage.py 2013-11-20 21:43:48 +0000 | |||
45 | @@ -218,6 +218,8 @@ | |||
46 | 218 | def run(options): | 218 | def run(options): |
47 | 219 | """Run the application.""" | 219 | """Run the application.""" |
48 | 220 | print('juju quickstart v{}'.format(version)) | 220 | print('juju quickstart v{}'.format(version)) |
49 | 221 | print('ensuring juju and lxc are installed') | ||
50 | 222 | app.ensure_dependencies() | ||
51 | 221 | print('bootstrapping the {} environment (type: {})'.format( | 223 | print('bootstrapping the {} environment (type: {})'.format( |
52 | 222 | options.env_name, options.env_type)) | 224 | options.env_name, options.env_type)) |
53 | 223 | is_local = options.env_type == 'local' | 225 | is_local = options.env_type == 'local' |
54 | 224 | 226 | ||
55 | === modified file 'quickstart/tests/test_app.py' | |||
56 | --- quickstart/tests/test_app.py 2013-11-20 11:35:30 +0000 | |||
57 | +++ quickstart/tests/test_app.py 2013-11-20 21:43:48 +0000 | |||
58 | @@ -61,6 +61,68 @@ | |||
59 | 61 | return jujuclient.EnvError({'Error': message}) | 61 | return jujuclient.EnvError({'Error': message}) |
60 | 62 | 62 | ||
61 | 63 | 63 | ||
62 | 64 | class TestEnsureDependencies( | ||
63 | 65 | helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase): | ||
64 | 66 | |||
65 | 67 | def call_ensure_dependencies(self, call_effects): | ||
66 | 68 | with self.patch_multiple_calls(call_effects) as mock_call: | ||
67 | 69 | app.ensure_dependencies() | ||
68 | 70 | return mock_call | ||
69 | 71 | |||
70 | 72 | def test_success_install(self): | ||
71 | 73 | # XXX Makyo #1247214: | ||
72 | 74 | # Here, we should guide the user through cloud credentials and | ||
73 | 75 | # juju init. | ||
74 | 76 | with self.assert_program_exit('Juju is now installed; please run ' | ||
75 | 77 | '`juju init` and then the same juju ' | ||
76 | 78 | 'quickstart command again to ' | ||
77 | 79 | 'proceed.'): | ||
78 | 80 | call = self.call_ensure_dependencies( | ||
79 | 81 | [ | ||
80 | 82 | (127, '', 'no juju'), | ||
81 | 83 | (127, '', 'no lxc'), | ||
82 | 84 | (0, 'add repo', ''), | ||
83 | 85 | (0, 'update', ''), | ||
84 | 86 | (0, 'install', ''), | ||
85 | 87 | ] | ||
86 | 88 | ) | ||
87 | 89 | self.assertEqual(call.call_count, 5) | ||
88 | 90 | call.assert_has_calls([ | ||
89 | 91 | mock.call('juju', 'version'), | ||
90 | 92 | mock.call('lxc-ls'), | ||
91 | 93 | mock.call('sudo', 'apt-add-repository', '-y', | ||
92 | 94 | 'ppa:juju/stable'), | ||
93 | 95 | mock.call('sudo', 'apt-get', 'update'), | ||
94 | 96 | mock.call('sudo', 'apt-get', 'install', '-y', 'juju-core', | ||
95 | 97 | 'lxc'), | ||
96 | 98 | ]) | ||
97 | 99 | |||
98 | 100 | def test_success_no_install(self): | ||
99 | 101 | call = self.call_ensure_dependencies( | ||
100 | 102 | [ | ||
101 | 103 | (0, '1.16', ''), | ||
102 | 104 | (0, '', ''), | ||
103 | 105 | (0, 'add repo', ''), | ||
104 | 106 | (0, 'update', ''), | ||
105 | 107 | (0, 'install', ''), | ||
106 | 108 | ] | ||
107 | 109 | ) | ||
108 | 110 | self.assertEqual(call.call_count, 2) | ||
109 | 111 | |||
110 | 112 | def test_failure(self): | ||
111 | 113 | with self.assert_program_exit('install failure'): | ||
112 | 114 | call = self.call_ensure_dependencies( | ||
113 | 115 | [ | ||
114 | 116 | (127, '', ''), | ||
115 | 117 | (127, '', ''), | ||
116 | 118 | (1, 'add repo', 'install failure'), | ||
117 | 119 | (1, 'update', 'uh-oh'), | ||
118 | 120 | (1, 'install', 'oh no'), | ||
119 | 121 | ] | ||
120 | 122 | ) | ||
121 | 123 | self.assertEqual(call.call_count, 3) | ||
122 | 124 | |||
123 | 125 | |||
124 | 64 | @mock_print | 126 | @mock_print |
125 | 65 | class TestBootstrap( | 127 | class TestBootstrap( |
126 | 66 | helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase): | 128 | helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase): |
Reviewers: mp+196011_ code.launchpad. net,
Message:
Please take a look.
Description:
Ensure juju and lxc are installed
To test: make check
To QA:
- Create an lxc or vm without juju installed
- Clone this branch
- Run `make sysdeps`
- Run `make run`
It should install juju, lxc, and dependencies, then prompt you to run
again after initializing your juju environments.
https:/ /code.launchpad .net/~makyo/ juju-quickstart /ensure- juju-lxc/ +merge/ 196011
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/29980043/
Affected files (+96, -1 lines): manage. py tests/helpers. py tests/test_ app.py
A [revision details]
M quickstart/app.py
M quickstart/
M quickstart/
M quickstart/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision: <email address hidden>
Index: quickstart/app.py self.message)
=== modified file 'quickstart/app.py'
--- quickstart/app.py 2013-11-20 11:35:30 +0000
+++ quickstart/app.py 2013-11-20 20:36:24 +0000
@@ -45,6 +45,35 @@
return 'juju-quickstart: error: {}'.format(
+def ensure_ dependencies( ): 'lxc-ls' )[0] repository' , '-y', 'ppa:juju/stable'],
+ """Ensure that Juju and LXC are installed.
+
+ If juju is not found in the PATH, then add the juju stable PPA and
install
+ both juju and lxc.
+
+ Return when juju is available.
+ Raise a ProgramExit if an error occurs installing.
+ """
+ retcode = utils.call('juju', 'version')[0]
+ retcode += utils.call(
+ if retcode > 0:
+ cmds = [
+ ['apt-add-
+ ['apt-get', 'update'],
+ ['apt-get', 'install', '-y', 'juju-core', 'lxc']
+ ]
+ for cmd in cmds:
+ cmd.insert(0, 'sudo')
+ retcode, _, error = utils.call(*cmd)
+ if retcode:
+ raise ProgramExit(error)
+ # XXX Makyo #1247214:
+ # Here, we should guide the user through cloud credentials and
+ # juju init.
+ raise ProgramExit('Juju is now installed; please run the same
juju '
+ 'quickstart command again to proceed.')
+
+
def bootstrap(env_name, is_local=False, debug=False):
"""Bootstrap the Juju environment with the given name.
Index: quickstart/ manage. py manage. py' manage. py 2013-11-20 11:35:30 +0000 manage. py 2013-11-20 20:30:08 +0000 version) ) dependencies( ) 'bootstrapping the {} environment (type: {})'.format(
options. env_name, options.env_type))
=== modified file 'quickstart/
--- quickstart/
+++ quickstart/
@@ -218,6 +218,8 @@
def run(options):
"""Run the application."""
print('juju quickstart v{}'.format(
+ print('ensuring juju and lxc are installed')
+ app.ensure_
print(
is_local = options.env_type == 'local'
Index: quickstart/ tests/helpers. py tests/helpers. py' tests/helpers. py 2013-11-18 11:42:15 +0000 tests/helpers. py 201...
=== modified file 'quickstart/
--- quickstart/
+++ quickstart/