21
def bootstrapped_env(env, environment_name):
22
update_env(env, environment_name, series='precise')
21
def bootstrap_env(env):
23
22
env.destroy_environment()
24
23
juju_home = get_juju_home()
26
25
bootstrap_from_env(juju_home, env)
27
26
host = get_machine_dns_name(env, 0)
29
env.destroy_environment()
34
def dumping_env(env, host):
31
39
dump_logs(env, host, '.')
33
41
env.destroy_environment()
45
def prepare_dummy_env(env):
46
env.deploy('local:dummy-source')
47
env.deploy('local:dummy-sink')
48
token = get_random_string()
49
env.juju('set', 'dummy-source', 'token=%s' % token)
50
env.juju('add-relation', 'dummy-source', 'dummy-sink')
51
env.juju('expose', 'dummy-sink')
36
55
def assess_compatibility(old_juju, new_juju, base_env, environment_name):
37
env = Environment.from_config(base_env, juju_path=old_juju)
38
with bootstrapped_env(env, environment_name):
39
env.deploy('local:dummy-source')
40
env.deploy('local:dummy-sink')
41
token = get_random_string()
42
env.juju('set', 'dummy-source', 'token=%s' % token)
43
env.juju('add-relation', 'dummy-source', 'dummy-sink')
44
env.juju('expose', 'dummy-sink')
45
env.wait_for_started()
46
check_token(env, token)
47
new_client = JujuClientDevel.by_version(new_juju)
48
new_env = Environment(env.environment, new_client, env.config)
49
new_env.upgrade_juju()
50
new_env.wait_for_version(new_env.get_matching_agent_version(), 600)
51
uname = new_env.get_juju_output('ssh', 'uname', '-a')
52
raise ValueError(uname)
56
old_env = Environment.from_config(base_env, juju_path=old_juju)
57
update_env(old_env, environment_name, series='precise')
58
old_env.config.pop('tools-metadata-url', None)
59
new_client = JujuClientDevel.by_version(new_juju)
60
new_env = Environment(old_env.environment, new_client, old_env.config)
61
print('Test manipulating old environment with new client.')
62
test_control_foreign(old_env, new_env)
63
# print('Test manipulating new environment with old client.')
64
# test_control_foreign(new_env, old_env)
65
#print('Test upgrading old environment to new.')
66
#test_upgrade(old_juju, new_juju, base_env, environment_name)
69
def test_control_foreign(env, other_env):
70
host = bootstrap_env(env)
71
with dumping_env(other_env, host):
72
token = prepare_dummy_env(env)
73
env.wait_for_started()
74
check_token(env, token)
75
check_series(other_env)
76
other_env.juju('run', '--all', 'uname -a')
77
dummy_source = other_env.get_juju_output('get', 'dummy-source')
78
env_output = other_env.get_juju_output('get-env')
79
other_env.juju('remove-relation', 'dummy-source', 'dummy-sink')
80
status = other_env.get_status()
81
other_env.juju('unexpose', 'dummy-sink')
82
status = other_env.get_status()
83
other_env.juju('deploy', 'local:dummy-sink', 'sink2')
84
other_env.wait_for_started()
85
other_env.juju('add-relation', 'dummy-source', 'sink2')
86
status = other_env.get_status()
87
other_env.juju('expose', 'sink2')
88
status = other_env.get_status()
89
if 'sink2' not in status.status['services']:
90
raise AssertionError('Sink2 missing')
91
other_env.juju('destroy-service', 'sink2')
92
for ignored in until_timeout(30):
93
status = other_env.get_status()
94
if 'sink2' not in status.status['services']:
97
raise AssertionError('Sink2 not destroyed')
98
other_env.juju('add-relation', 'dummy-source', 'dummy-sink')
99
status = other_env.get_status()
100
other_env.juju('expose', 'dummy-sink')
101
status = other_env.get_status()
102
other_env.juju('add-unit', 'dummy-sink')
103
status = other_env.get_status()
104
other_env.juju('remove-unit', 'dummy-sink/1')
105
status = other_env.get_status()
106
other_env.juju('add-machine', 'lxc')
107
status = other_env.wait_for_started()
108
lxc_machine, = set(k for k, v in status.agent_items() if
109
k.endswith('/lxc/0'))
110
lxc_holder = lxc_machine.split('/')[0]
111
other_env.juju('remove-machine', lxc_machine)
112
wait_until_removed(other_env, lxc_machine)
113
other_env.juju('remove-machine', lxc_holder)
114
status = wait_until_removed(other_env, lxc_holder)
115
other_env.client.juju(
116
None, 'destroy-environment', (other_env.environment, '-y'))
120
def wait_until_removed(env, agent_id):
121
for ignored in until_timeout(30):
122
status = env.get_status()
123
if agent_id not in dict(status.agent_items()):
126
raise AssertionError('Machine not destroyed')
129
def get_agent_version(env):
130
return env.client.get_env_option(env, 'agent-version')
133
def test_upgrade(env, new_env, base_env, environment_name):
134
host = bootstrap_env(env)
135
with dumping_env(env, host):
136
token = prepare_dummy_env(env)
137
env.wait_for_started()
138
check_token(env, token)
139
matching_version = new_env.get_matching_agent_version().split('.')
140
old_agent_version = get_agent_version(new_env)
141
while old_agent_version.split('.') < matching_version:
142
new_env.upgrade_juju()
143
new_agent_version = get_agent_version(new_env)
144
if new_agent_version == old_agent_version:
146
new_env.wait_for_version(new_agent_version)
147
old_agent_version = new_agent_version
148
check_token(new_env, token)
149
new_env.destroy_environment()
152
def check_series(env):
153
result = env.get_juju_output('ssh', '0', 'lsb_release', '-c')
154
label, codename = result.rstrip().split('\t')
155
if label != 'Codename:':
156
raise AssertionError()
157
expected_codename = env.config['default-series']
158
if codename != expected_codename:
159
raise AssertionError(
160
'Series is {}, not {}'.format(codename, expected_codename))