59
60
test_case.assertEqual(args, (expected_args,))
60
61
kwarg_keys = ['env']
62
kwarg_keys = ['stderr'] + kwarg_keys
63
test_case.assertEqual(type(kwargs['stderr']), file)
63
with tempfile.TemporaryFile() as example:
64
# 'example' is a pragmatic way of checking file types in py2 and 3.
65
kwarg_keys = ['stderr'] + kwarg_keys
66
test_case.assertIsInstance(kwargs['stderr'], type(example))
64
67
test_case.assertItemsEqual(kwargs.keys(), kwarg_keys)
65
68
bin_dir = os.path.dirname(client.full_path)
66
69
test_case.assertRegexpMatches(kwargs['env']['PATH'],
83
86
self.pause_mock = patcher.start()
86
class TestEnvJujuClient24(ClientTest):
89
class TestEnvJujuClient25(ClientTest):
91
client_class = EnvJujuClient25
88
93
def test__shell_environ_not_cloudsigma(self):
89
client = EnvJujuClient24(
90
SimpleEnvironment('baz', {'type': 'ec2'}), '1.24-foobar', 'path')
94
client = self.client_class(
95
SimpleEnvironment('baz', {'type': 'ec2'}), '1.25-foobar', 'path')
91
96
env = client._shell_environ()
92
97
self.assertEqual(env.get(JUJU_DEV_FEATURE_FLAGS, ''), '')
94
99
def test__shell_environ_cloudsigma(self):
95
client = EnvJujuClient24(
100
client = self.client_class(
96
101
SimpleEnvironment('baz', {'type': 'cloudsigma'}),
97
'1.24-foobar', 'path')
102
'1.25-foobar', 'path')
98
103
env = client._shell_environ()
100
105
self.assertTrue('cloudsigma' in env[JUJU_DEV_FEATURE_FLAGS].split(","))
102
107
def test__shell_environ_juju_home(self):
103
108
client = EnvJujuClient24(
104
SimpleEnvironment('baz', {'type': 'ec2'}), '1.24-foobar', 'path')
109
SimpleEnvironment('baz', {'type': 'ec2'}), '1.25-foobar', 'path')
105
110
env = client._shell_environ(juju_home='asdf')
106
111
self.assertEqual(env['JUJU_HOME'], 'asdf')
117
122
def test__shell_environ_juju_home(self):
118
123
client = EnvJujuClient22(
119
SimpleEnvironment('baz', {'type': 'ec2'}), '1.24-foobar', 'path')
124
SimpleEnvironment('baz', {'type': 'ec2'}), '1.22-foobar', 'path')
120
125
env = client._shell_environ(juju_home='asdf')
121
126
self.assertEqual(env['JUJU_HOME'], 'asdf')
129
class TestEnvJujuClient24(TestEnvJujuClient25):
131
client_class = EnvJujuClient25
124
134
class TestEnvJujuClient(ClientTest):
126
136
def test_get_version(self):
199
210
self.assertIs(type(client), EnvJujuClient24)
200
211
self.assertEqual(client.version, '1.24.7')
201
212
client = EnvJujuClient.by_version(None)
213
self.assertIs(type(client), EnvJujuClient25)
214
self.assertEqual(client.version, '1.25.1')
215
client = EnvJujuClient.by_version(None)
202
216
self.assertIs(type(client), EnvJujuClient)
203
self.assertEqual(client.version, '1.25.1')
217
self.assertEqual(client.version, '1.26.1')
205
219
def test_by_version_path(self):
206
220
with patch('subprocess.check_output', return_value=' 4.3') as vsn:
231
245
self.assertEqual((
232
246
'juju', '--debug', 'bar', '-e', 'foo', 'baz', 'qux'), full)
248
def test_full_args_action(self):
249
env = Environment('foo', '')
250
client = EnvJujuClient(env, None, 'my/juju/bin')
251
full = client._full_args('action bar', False, ('baz', 'qux'))
253
'juju', '--show-log', 'action', 'bar', '-e', 'foo', 'baz', 'qux'),
234
256
def test_bootstrap_hpcloud(self):
235
257
env = Environment('hp', '')
236
258
with patch.object(env, 'hpcloud', lambda: True):
256
278
client = EnvJujuClient(env, None, None)
257
279
with patch.object(client.env, 'joyent', lambda: True):
258
280
client.bootstrap()
259
mock.assert_called_once_with(client,
262
'mem=2G cpu-cores=1'),
281
mock.assert_called_once_with(
282
client, 'bootstrap', ('--constraints', 'mem=2G cpu-cores=1'),
283
False, juju_home=None)
266
285
def test_bootstrap_non_sudo(self):
267
286
env = Environment('foo', '')
412
431
env = Environment('foo', '')
413
432
client = EnvJujuClient(env, None, '/foobar/bar')
414
433
with patch('subprocess.check_output') as sco_mock:
415
client.get_juju_output(env, 'baz')
434
client.get_juju_output('cmd', 'baz')
416
435
self.assertRegexpMatches(sco_mock.call_args[1]['env']['PATH'],
1340
'jenkins/1': {'baz': 'qux'}
1361
'sub': {'baz': 'qux'}
1346
('1', {'foo': 'bar'}), ('jenkins/1', {'baz': 'qux'})]
1369
('1', {'foo': 'bar'}),
1370
('jenkins/1', {'subordinates': {'sub': {'baz': 'qux'}}}),
1371
('sub', {'baz': 'qux'})]
1347
1372
self.assertItemsEqual(expected, status.agent_items())
1349
1374
def test_agent_items_containers(self):
1418
1446
with self.assertRaisesRegexp(KeyError, 'jenkins/3'):
1419
1447
status.get_unit('jenkins/3')
1449
def test_get_subordinate_units(self):
1460
'chaos-monkey/0': {'agent-state': 'started'},
1469
'chaos-monkey/1': {'agent-state': 'started'}
1474
'chaos-monkey/2': {'agent-state': 'started'}
1482
status.get_subordinate_units('ubuntu'),
1485
status.get_subordinate_units('jenkins'),
1486
[{'chaos-monkey/0': {'agent-state': 'started'}}])
1488
status.get_subordinate_units('dummy-sink'), [
1489
{'chaos-monkey/1': {'agent-state': 'started'}},
1490
{'chaos-monkey/2': {'agent-state': 'started'}}]
1492
with self.assertRaisesRegexp(KeyError, 'foo'):
1493
status.get_subordinate_units('foo')
1495
def test_get_subordinate_units_no_services(self):
1496
status = Status({}, '')
1497
with self.assertRaisesRegexp(KeyError, 'ubuntu'):
1498
status.get_subordinate_units('ubuntu')
1421
1500
def test_get_open_ports(self):
1422
1501
status = Status({
1488
'jenkins/1': {'agent-state': 'started'},
1571
'agent-state': 'started',
1574
'agent-state': 'started'
1489
1578
'jenkins/2': {'agent-state': 'started'},
1816
1905
'bundle:~juju-qa/some-bundle'), True
1908
def test_deployer_with_bundle_name(self):
1909
client = EnvJujuClient(SimpleEnvironment(None, {'type': 'local'}),
1910
'1.23-series-arch', None)
1911
with patch.object(EnvJujuClient, 'juju') as mock:
1912
client.deployer('bundle:~juju-qa/some-bundle', 'name')
1913
mock.assert_called_with(
1914
'deployer', ('--debug', '--deploy-delay', '10', '--config',
1915
'bundle:~juju-qa/some-bundle', 'name'), True
1819
1918
def test_quickstart_maas(self):
1820
1919
client = EnvJujuClient(SimpleEnvironment(None, {'type': 'maas'}),
1821
1920
'1.23-series-arch', None)