553
553
client.env.load_yaml.assert_called_once_with()
554
554
self.assertIsInstance(client.env, JujuData)
555
555
self.assertEqual(client.env.environment, 'foo')
556
self.assertEqual(client.env.config, {'type': 'bar'})
556
self.assertEqual(client.env._config, {'type': 'bar'})
557
557
self.assertEqual(client.env.juju_home, 'baz')
559
559
def test_get_version(self):
2157
2157
controller_env = controller_client.env
2158
2158
self.assertEqual('controller', controller_env.environment)
2159
2159
self.assertEqual(
2160
{'bar': 'baz', 'name': 'controller'}, controller_env.config)
2160
{'bar': 'baz', 'name': 'controller'}, controller_env._config)
2162
2162
def test_list_controllers(self):
2163
2163
client = EnvJujuClient(JujuData('foo'), None, None)
3673
3673
client.get_bootstrap_args(upload_tools=True,
3674
3674
bootstrap_series='angsty')
3675
env.config['default-series'] = 'angsty'
3675
env.update_config({'default-series': 'angsty'})
3676
3676
args = client.get_bootstrap_args(upload_tools=True,
3677
3677
bootstrap_series='angsty')
3678
3678
self.assertEqual(args, ('--upload-tools', '--constraints', 'mem=2G'))
5175
5175
def test_uniquify_local_empty(self):
5176
5176
env = SimpleEnvironment('foo', {'type': 'local'})
5177
5177
uniquify_local(env)
5178
self.assertEqual(env.config, {
5178
self.assertEqual(env._config, {
5179
5179
'type': 'local',
5180
5180
'api-port': 17071,
5181
5181
'state-port': 37018,
5281
5281
juju_home='foo'))
5282
5282
client.bootstrap_replaces = {'agent-version'}
5283
5283
self.assertNotIn('agent-version', make_safe_config(client))
5284
client.env.config['agent-version'] = '1.23'
5284
client.env.update_config({'agent-version': '1.23'})
5285
5285
self.assertNotIn('agent-version', make_safe_config(client))
5297
5297
with bootstrap_context(client) as fake_home:
5298
5298
with temp_bootstrap_env(fake_home, client):
5299
5299
stub_bootstrap(client)
5300
self.assertEqual(env.config, {'type': 'local'})
5300
self.assertEqual(env.provider, 'local')
5302
5302
def test_temp_bootstrap_env_environment(self):
5303
5303
env = SimpleEnvironment('qux', {'type': 'local'})
6513
6513
self.assertIs(SimpleEnvironment, type(copy))
6514
6514
self.assertIsNot(orig, copy)
6515
6515
self.assertEqual(copy.environment, 'foo')
6516
self.assertIsNot(orig.config, copy.config)
6517
self.assertEqual({'type': 'bar'}, copy.config)
6516
self.assertIsNot(orig._config, copy._config)
6517
self.assertEqual({'type': 'bar'}, copy._config)
6518
6518
self.assertEqual('myhome', copy.juju_home)
6519
6519
self.assertEqual('local1', copy.local)
6520
6520
self.assertEqual('kvm1', copy.kvm)
6528
6528
copy = orig.clone(model_name='newname')
6529
6529
self.assertEqual('newname', copy.environment)
6530
self.assertEqual('newname', copy.config['name'])
6530
self.assertEqual('newname', copy.get_option('name'))
6532
6532
def test_set_model_name(self):
6533
6533
env = SimpleEnvironment('foo', {})
6534
6534
env.set_model_name('bar')
6535
6535
self.assertEqual(env.environment, 'bar')
6536
6536
self.assertEqual(env.controller.name, 'bar')
6537
self.assertEqual(env.config['name'], 'bar')
6537
self.assertEqual(env.get_option('name'), 'bar')
6539
6539
def test_set_model_name_not_controller(self):
6540
6540
env = SimpleEnvironment('foo', {})
6541
6541
env.set_model_name('bar', set_controller=False)
6542
6542
self.assertEqual(env.environment, 'bar')
6543
6543
self.assertEqual(env.controller.name, 'foo')
6544
self.assertEqual(env.config['name'], 'bar')
6544
self.assertEqual(env.get_option('name'), 'bar')
6546
6546
def test_local_from_config(self):
6547
6547
env = SimpleEnvironment('local', {'type': 'openstack'})
6560
6560
with temp_config():
6561
6561
env = SimpleEnvironment.from_config('foo')
6562
6562
self.assertIs(SimpleEnvironment, type(env))
6563
self.assertEqual({'type': 'local'}, env.config)
6563
self.assertEqual({'type': 'local'}, env._config)
6565
6565
def test_from_bogus_config(self):
6566
6566
with temp_config():
6606
6606
{'baz': 'qux'}) as jes_home:
6607
6607
self.assertFalse(os.path.exists(foo_path))
6609
def test_discard_option(self):
6610
env = SimpleEnvironment('foo', {'type': 'foo', 'bar': 'baz'})
6611
discarded = env.discard_option('bar')
6612
self.assertEqual('baz', discarded)
6613
self.assertEqual({'type': 'foo'}, env._config)
6615
def test_discard_option_not_present(self):
6616
env = SimpleEnvironment('foo', {'type': 'foo'})
6617
discarded = env.discard_option('bar')
6618
self.assertIs(None, discarded)
6619
self.assertEqual({'type': 'foo'}, env._config)
6609
6621
def test_get_option(self):
6610
6622
env = SimpleEnvironment('foo', {'type': 'azure', 'foo': 'bar'})
6611
6623
self.assertEqual(env.get_option('foo'), 'bar')
6632
6644
def test_update_config(self):
6633
6645
env = SimpleEnvironment('foo', {'type': 'azure'})
6634
6646
env.update_config({'bar': 'baz', 'qux': 'quxx'})
6635
self.assertEqual(env.config, {
6647
self.assertEqual(env._config, {
6636
6648
'type': 'azure', 'bar': 'baz', 'qux': 'quxx'})
6638
6650
def test_update_config_region(self):
6639
6651
env = SimpleEnvironment('foo', {'type': 'azure'})
6640
6652
env.update_config({'region': 'foo1'})
6641
self.assertEqual(env.config, {
6653
self.assertEqual(env._config, {
6642
6654
'type': 'azure', 'location': 'foo1'})
6643
6655
self.assertEqual('WARNING Using set_region to set region to "foo1".\n',
6644
6656
self.log_stream.getvalue())
6646
6658
def test_update_config_type(self):
6647
6659
env = SimpleEnvironment('foo', {'type': 'azure'})
6648
6660
env.update_config({'type': 'foo1'})
6649
self.assertEqual(env.config, {'type': 'foo1'})
6661
self.assertEqual(env.provider, 'foo1')
6650
6662
self.assertEqual('WARNING Setting type is not 2.x compatible.\n',
6651
6663
self.log_stream.getvalue())
6699
6711
def test_set_region(self):
6700
6712
env = SimpleEnvironment('foo', {'type': 'bar'}, 'home')
6701
6713
env.set_region('baz')
6702
self.assertEqual(env.config['region'], 'baz')
6714
self.assertEqual(env.get_option('region'), 'baz')
6703
6715
self.assertEqual(env.get_region(), 'baz')
6705
6717
def test_set_region_no_provider(self):
6706
6718
env = SimpleEnvironment('foo', {}, 'home')
6707
6719
env.set_region('baz')
6708
self.assertEqual(env.config['region'], 'baz')
6720
self.assertEqual(env.get_option('region'), 'baz')
6710
6722
def test_set_region_joyent(self):
6711
6723
env = SimpleEnvironment('foo', {'type': 'joyent'}, 'home')
6712
6724
env.set_region('baz')
6713
self.assertEqual(env.config['sdc-url'],
6725
self.assertEqual(env.get_option('sdc-url'),
6714
6726
'https://baz.api.joyentcloud.com')
6715
6727
self.assertEqual(env.get_region(), 'baz')
6717
6729
def test_set_region_azure(self):
6718
6730
env = SimpleEnvironment('foo', {'type': 'azure'}, 'home')
6719
6731
env.set_region('baz')
6720
self.assertEqual(env.config['location'], 'baz')
6732
self.assertEqual(env.get_option('location'), 'baz')
6721
6733
self.assertEqual(env.get_region(), 'baz')
6723
6735
def test_set_region_lxd(self):
6724
6736
env = SimpleEnvironment('foo', {'type': 'lxd'}, 'home')
6725
6737
env.set_region('baz')
6726
self.assertEqual(env.config['region'], 'baz')
6738
self.assertEqual(env.get_option('region'), 'baz')
6728
6740
def test_set_region_manual(self):
6729
6741
env = SimpleEnvironment('foo', {'type': 'manual'}, 'home')
6730
6742
env.set_region('baz')
6731
self.assertEqual(env.config['bootstrap-host'], 'baz')
6743
self.assertEqual(env.get_option('bootstrap-host'), 'baz')
6732
6744
self.assertEqual(env.get_region(), 'baz')
6734
6746
def test_set_region_maas(self):
6746
6758
'aws': {'credentials': {'aws': True}},
6747
6759
'azure': {'credentials': {'azure': True}},
6749
self.assertEqual(env.config, env.get_cloud_credentials())
6761
self.assertEqual(env._config, env.get_cloud_credentials())
6751
6763
def test_dump_yaml(self):
6752
6764
env = SimpleEnvironment('baz', {'type': 'qux'}, 'home')
6773
6785
data_writer.credentials)
6774
6786
self.assertEqual('bar', data_reader.get_cloud())
6775
6787
self.assertEqual(region, data_reader.get_region())
6788
self.assertEqual('bar', data_reader._cloud_name)
6777
6790
def test_from_cloud_region_openstack(self):
6778
6791
self.from_cloud_region('openstack', 'baz')
6784
6797
self.from_cloud_region('vsphere', None)
6786
6799
def test_clone(self):
6787
orig = JujuData('foo', {'type': 'bar'}, 'myhome')
6800
orig = JujuData('foo', {'type': 'bar'}, 'myhome',
6801
cloud_name='cloudname')
6788
6802
orig.credentials = {'secret': 'password'}
6789
6803
orig.clouds = {'name': {'meta': 'data'}}
6790
6804
copy = orig.clone()
6791
6805
self.assertIs(JujuData, type(copy))
6792
6806
self.assertIsNot(orig, copy)
6793
6807
self.assertEqual(copy.environment, 'foo')
6794
self.assertIsNot(orig.config, copy.config)
6795
self.assertEqual({'type': 'bar'}, copy.config)
6808
self.assertIsNot(orig._config, copy._config)
6809
self.assertEqual({'type': 'bar'}, copy._config)
6796
6810
self.assertEqual('myhome', copy.juju_home)
6797
6811
self.assertIsNot(orig.credentials, copy.credentials)
6798
6812
self.assertEqual(orig.credentials, copy.credentials)
6799
6813
self.assertIsNot(orig.clouds, copy.clouds)
6800
6814
self.assertEqual(orig.clouds, copy.clouds)
6815
self.assertEqual('cloudname', copy._cloud_name)
6802
6817
def test_clone_model_name(self):
6803
6818
orig = JujuData('foo', {'type': 'bar', 'name': 'oldname'}, 'myhome')
6805
6820
orig.clouds = {'name': {'meta': 'data'}}
6806
6821
copy = orig.clone(model_name='newname')
6807
6822
self.assertEqual('newname', copy.environment)
6808
self.assertEqual('newname', copy.config['name'])
6823
self.assertEqual('newname', copy.get_option('name'))
6810
6825
def test_update_config(self):
6811
6826
env = JujuData('foo', {'type': 'azure'}, juju_home='')
6812
6827
env.update_config({'bar': 'baz', 'qux': 'quxx'})
6813
self.assertEqual(env.config, {
6828
self.assertEqual(env._config, {
6814
6829
'type': 'azure', 'bar': 'baz', 'qux': 'quxx'})
6816
6831
def test_update_config_region(self):
6817
6832
env = JujuData('foo', {'type': 'azure'}, juju_home='')
6818
6833
env.update_config({'region': 'foo1'})
6819
self.assertEqual(env.config, {
6834
self.assertEqual(env._config, {
6820
6835
'type': 'azure', 'location': 'foo1'})
6821
6836
self.assertEqual('WARNING Using set_region to set region to "foo1".\n',
6822
6837
self.log_stream.getvalue())
6827
6842
ValueError, 'type cannot be set via update_config.'):
6828
6843
env.update_config({'type': 'foo1'})
6845
def test_update_config_cloud_name(self):
6846
env = JujuData('foo', {'type': 'azure'}, juju_home='',
6848
for endpoint_key in ['maas-server', 'auth-url', 'host']:
6849
with self.assertRaisesRegexp(
6850
ValueError, '{} cannot be changed with'
6851
' explicit cloud name.'.format(endpoint_key)):
6852
env.update_config({endpoint_key: 'foo1'})
6830
6854
def test_get_cloud_random_provider(self):
6831
6855
self.assertEqual(
6832
6856
'bar', JujuData('foo', {'type': 'bar'}, 'home').get_cloud())
6906
6930
self.assertEqual({'aws': True}, juju_data.get_cloud_credentials())
6932
def test_get_cloud_name_with_cloud_name(self):
6933
juju_data = JujuData('foo', {'type': 'bar'}, 'home')
6934
self.assertEqual('bar', juju_data.get_cloud())
6935
juju_data = JujuData('foo', {'type': 'bar'}, 'home', cloud_name='baz')
6936
self.assertEqual('baz', juju_data.get_cloud())
6908
6938
def test_dump_yaml(self):
6909
6939
cloud_dict = {'clouds': {'foo': {}}}
6910
6940
credential_dict = {'credential': {'bar': {}}}