Merge lp:~veebers/juju-ci-tools/remove_-c_from_migration into lp:juju-ci-tools

Proposed by Christopher Lee
Status: Merged
Merged at revision: 2013
Proposed branch: lp:~veebers/juju-ci-tools/remove_-c_from_migration
Merge into: lp:juju-ci-tools
Diff against target: 145 lines (+73/-15)
2 files modified
assess_model_migration.py (+59/-15)
tests/test_assess_model_migration.py (+14/-0)
To merge this branch: bzr merge lp:~veebers/juju-ci-tools/remove_-c_from_migration
Reviewer Review Type Date Requested Status
Burton Swan (community) Approve
Review via email: mp+323728@code.launchpad.net

Commit message

Remove the -c argument from migrate command due to changes in 2.2-beta4.

Description of the change

Remove the -c argument from migrate command due to changes in 2.2-beta4.

Retains it's backwards compatibility with version checks.

To post a comment you must log in.
Revision history for this message
Burton Swan (burton-swan) wrote :

Code looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_model_migration.py'
2--- assess_model_migration.py 2017-03-21 22:35:12 +0000
3+++ assess_model_migration.py 2017-05-07 20:29:33 +0000
4@@ -5,6 +5,7 @@
5
6 import argparse
7 from contextlib import contextmanager
8+from distutils.version import LooseVersion
9 import logging
10 import os
11 from subprocess import CalledProcessError
12@@ -91,6 +92,10 @@
13 return not isinstance(client, ModelClient2_0)
14
15
16+def after_22beta4(client_version):
17+ return LooseVersion(client_version) >= LooseVersion('2.2-beta4')
18+
19+
20 def parse_args(argv):
21 """Parse all arguments."""
22 parser = argparse.ArgumentParser(
23@@ -337,9 +342,15 @@
24 attempt_client.env.environment,
25 attempt_client.env.user_name)
26
27- source_client.controller_juju(
28- 'migrate',
29- (user_qualified_model_name, dest_client.env.controller.name))
30+ if after_22beta4(source_client.version):
31+ source_client.juju(
32+ 'migrate',
33+ (user_qualified_model_name, dest_client.env.controller.name),
34+ include_e=False)
35+ else:
36+ source_client.controller_juju(
37+ 'migrate',
38+ (user_qualified_model_name, dest_client.env.controller.name))
39
40 migration_client = dest_client.clone(
41 dest_client.env.clone(user_qualified_model_name))
42@@ -394,12 +405,30 @@
43 source_client, dest_client, include_user_name=False):
44 log.info('Initiating migration process')
45 if include_user_name:
46- model_name = '{}/{}'.format(
47- source_client.env.user_name, source_client.env.environment)
48- else:
49- model_name = source_client.env.environment
50- source_client.controller_juju(
51- 'migrate', (model_name, dest_client.env.controller.name))
52+ if after_22beta4(source_client.version):
53+ model_name = '{}:{}/{}'.format(
54+ source_client.env.controller.name,
55+ source_client.env.user_name,
56+ source_client.env.environment)
57+ else:
58+ model_name = '{}/{}'.format(
59+ source_client.env.user_name, source_client.env.environment)
60+ else:
61+ if after_22beta4(source_client.version):
62+ model_name = '{}:{}'.format(
63+ source_client.env.controller.name,
64+ source_client.env.environment)
65+ else:
66+ model_name = source_client.env.environment
67+
68+ if after_22beta4(source_client.version):
69+ source_client.juju(
70+ 'migrate',
71+ (model_name, dest_client.env.controller.name),
72+ include_e=False)
73+ else:
74+ source_client.controller_juju(
75+ 'migrate', (model_name, dest_client.env.controller.name))
76 migration_target_client = dest_client.clone(
77 dest_client.env.clone(source_client.env.environment))
78 wait_for_model(migration_target_client, source_client.env.environment)
79@@ -490,10 +519,15 @@
80 """
81 test_model, application = deploy_simple_server_to_new_model(
82 source_client, 'rollmeback')
83- test_model.controller_juju(
84- 'migrate',
85- (test_model.env.environment,
86- dest_client.env.controller.name))
87+ if after_22beta4(source_client.version):
88+ test_model.juju(
89+ 'migrate',
90+ (test_model.env.environment, dest_client.env.controller.name),
91+ include_e=False)
92+ else:
93+ test_model.controller_juju(
94+ 'migrate',
95+ (test_model.env.environment, dest_client.env.controller.name))
96 # Once migration has started interrupt it
97 wait_for_migrating(test_model)
98 log.info('Disrupting target controller to force rollback')
99@@ -599,9 +633,19 @@
100 appears in test logs.
101 """
102 try:
103- args = ['-c', source_client.env.controller.name,
104+ if after_22beta4(source_client.version):
105+ args = [
106+ '{}:{}'.format(
107+ source_client.env.controller.name,
108+ source_client.env.environment),
109+ dest_client.env.controller.name
110+ ]
111+ else:
112+ args = [
113+ '-c', source_client.env.controller.name,
114 source_client.env.environment,
115- dest_client.env.controller.name]
116+ dest_client.env.controller.name
117+ ]
118 log_output = source_client.get_juju_output(
119 'migrate', *args, merge_stderr=True, include_e=False)
120 except CalledProcessError as e:
121
122=== modified file 'tests/test_assess_model_migration.py'
123--- tests/test_assess_model_migration.py 2017-02-25 06:09:40 +0000
124+++ tests/test_assess_model_migration.py 2017-05-07 20:29:33 +0000
125@@ -88,6 +88,20 @@
126 "Test model migration feature", fake_stdout.getvalue())
127
128
129+class TestAfter22Beta4(TestCase):
130+
131+ def test_returns_True_when_newer(self):
132+ self.assertTrue(amm.after_22beta4('2.2-beta8-xenial-amd64'))
133+ self.assertTrue(amm.after_22beta4('2.3-beta4-xenial-amd64'))
134+
135+ def test_returns_True_when_equal(self):
136+ self.assertTrue(amm.after_22beta4('2.2-beta4-xenial-amd64'))
137+
138+ def test_returns_False_when_older(self):
139+ self.assertFalse(amm.after_22beta4('2.1-beta8-xenial-amd64'))
140+ self.assertFalse(amm.after_22beta4('2.2-beta2-xenial-amd64'))
141+
142+
143 class TestDeploySimpleResourceServer(TestCase):
144
145 def test_deploys_with_resource(self):

Subscribers

People subscribed via source and target branches