Add test for precedence rules

This should cover both the OSC and the ansible incoming use cases.

Change-Id: I3fdc83837692d31c5579d91892a387a5d1023785
This commit is contained in:
Monty Taylor 2016-08-05 06:36:14 -05:00
parent ddfed7f2fb
commit cfa87b1e7f
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594

View File

@ -373,6 +373,59 @@ class TestConfigArgparse(base.TestCase):
self.assertEqual(cc.region_name, 'region2')
self.assertEqual(cc.snack_type, 'cookie')
def test_get_one_cloud_precedence(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
kwargs = {
'auth': {
'username': 'testuser',
'password': 'authpass',
'project-id': 'testproject',
'auth_url': 'http://example.com/v2',
},
'region_name': 'kwarg_region',
'password': 'ansible_password',
'arbitrary': 'value',
}
args = dict(
auth_url='http://example.com/v2',
username='user',
password='argpass',
project_name='project',
region_name='region2',
snack_type='cookie',
)
options = argparse.Namespace(**args)
cc = c.get_one_cloud(
argparse=options, **kwargs)
self.assertEqual(cc.region_name, 'region2')
self.assertEqual(cc.auth['password'], 'argpass')
self.assertEqual(cc.snack_type, 'cookie')
def test_get_one_cloud_precedence_no_argparse(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
kwargs = {
'auth': {
'username': 'testuser',
'password': 'authpass',
'project-id': 'testproject',
'auth_url': 'http://example.com/v2',
},
'region_name': 'kwarg_region',
'password': 'ansible_password',
'arbitrary': 'value',
}
cc = c.get_one_cloud(**kwargs)
self.assertEqual(cc.region_name, 'kwarg_region')
self.assertEqual(cc.auth['password'], 'authpass')
self.assertIsNone(cc.password)
def test_get_one_cloud_just_argparse(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])