Fix bugs caught by tests, and clean up some of the tests

This commit is contained in:
rallytime 2015-06-18 14:02:13 -06:00
parent 6d57ceba9e
commit 1e85bb9792
2 changed files with 55 additions and 40 deletions

View file

@ -1757,16 +1757,16 @@ def apply_cloud_config(overrides, defaults=None):
alias
)
)
elif 'provider' in detail:
elif 'provider' in details:
salt.utils.warn_until(
'Nitrogen',
'The term \'provider\' is being deprecated in favor of \'driver\' and support for '
'\'provider\' will be removed in Salt Nitrogen. Please convert your cloud provider'
'configuration files to use \'driver\'.'
)
driver = detail['provider']
elif 'driver' in detail:
driver = detail['driver']
driver = details['provider']
elif 'driver' in details:
driver = details['driver']
if ':' in driver:
# Weird, but...
alias, driver = driver.split(':')
@ -1809,6 +1809,11 @@ def old_to_new(opts):
lprovider = provider.lower()
if provider_config:
# Since using "provider: <provider-engine>" is deprecated, alias provider
# to use driver: "driver: <provider-engine>"
if 'provider' in provider_config:
provider_config['driver'] = provider_config.pop('provider')
provider_config['provider'] = lprovider
opts.setdefault('providers', {})
# provider alias
@ -2033,7 +2038,13 @@ def apply_cloud_providers_config(overrides, defaults=None):
'definition referenced.'
)
continue
if details['driver'] in handled_providers or details['provider'] in handled_providers:
# Since using "provider: <provider-engine>" is deprecated, alias provider
# to use driver: "driver: <provider-engine>"
if 'provider' in details:
details['driver'] = details.pop('provider')
if details['driver'] in handled_providers:
log.error(
'You can only have one entry per cloud provider. For '
'example, if you have a cloud provider configuration '
@ -2043,9 +2054,9 @@ def apply_cloud_providers_config(overrides, defaults=None):
)
raise salt.exceptions.SaltCloudConfigError(
'The cloud provider alias {0!r} has multiple entries '
'for the {1[provider]!r} driver.'.format(key, details)
'for the {1[driver]!r} driver.'.format(key, details)
)
handled_providers.add(details['provider'])
handled_providers.add(details['driver'])
for entry in val:
# Since using "provider: <provider-engine>" is deprecated, alias provider
@ -2074,8 +2085,12 @@ def apply_cloud_providers_config(overrides, defaults=None):
while True:
keep_looping = False
for provider_alias, entries in six.iteritems(providers.copy()):
for driver, details in six.iteritems(entries):
# Since using "provider: <provider-engine>" is deprecated, alias provider
# to use driver: "driver: <provider-engine>"
if 'provider' in details:
details['driver'] = details.pop('provider')
# Set a holder for the defined profiles
providers[provider_alias][driver]['profiles'] = {}
@ -2092,7 +2107,7 @@ def apply_cloud_providers_config(overrides, defaults=None):
'trying to extend data from {2!r} though {2!r} '
'is not defined in the salt cloud providers '
'loaded data.'.format(
details['provider'],
details['driver'],
provider_alias,
alias
)
@ -2103,7 +2118,7 @@ def apply_cloud_providers_config(overrides, defaults=None):
'The {0!r} cloud provider entry in {1!r} is '
'trying to extend data from \'{2}:{3}\' though '
'{3!r} is not defined in {1!r}'.format(
details['provider'],
details['driver'],
provider_alias,
alias,
provider
@ -2111,13 +2126,13 @@ def apply_cloud_providers_config(overrides, defaults=None):
)
details['extends'] = '{0}:{1}'.format(alias, provider)
# change provider details '-only-extendable-' to extended provider name
details['provider'] = provider
details['driver'] = provider
elif providers.get(extends):
raise salt.exceptions.SaltCloudConfigError(
'The {0!r} cloud provider entry in {1!r} is trying '
'to extend from {2!r} and no provider was specified. '
'Not extending!'.format(
details['provider'], provider_alias, extends
details['driver'], provider_alias, extends
)
)
elif extends not in providers:
@ -2126,7 +2141,7 @@ def apply_cloud_providers_config(overrides, defaults=None):
'to extend data from {2!r} though {2!r} is not '
'defined in the salt cloud providers loaded '
'data.'.format(
details['provider'], provider_alias, extends
details['driver'], provider_alias, extends
)
)
else:
@ -2229,11 +2244,11 @@ def get_cloud_config_value(name, vm_, opts, default=None, search_global=True):
else:
value = deepcopy(opts['profiles'][vm_['profile']][name])
# Since using "provider: <provider-engine>" is deprecated, alias provider
# Since using "provider: <provider-engine>" is deprecated, alias provider
# to use driver: "driver: <provider-engine>"
if 'provider' in vm_:
vm_['driver'] = vm_.pop('provider')
# Let's get the value from the provider, if present.
if ':' in vm_['driver']:
# The provider is defined as <provider-alias>:<driver-name>

View file

@ -486,27 +486,27 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
@patch('salt.config.old_to_new',
MagicMock(return_value={'default_include': 'path/to/some/cloud/conf/file',
'providers': {'foo': {'bar': {
'provider': 'foo:bar'}}}}))
'driver': 'foo:bar'}}}}))
def test_apply_cloud_config_success_list(self):
'''
Tests success when valid data is passed into the function as a list
'''
overrides = {'providers': {'foo': [{'provider': 'bar'}]}}
overrides = {'providers': {'foo': [{'driver': 'bar'}]}}
ret = {'default_include': 'path/to/some/cloud/conf/file',
'providers': {'foo': {'bar': {'provider': 'foo:bar'}}}}
'providers': {'foo': {'bar': {'driver': 'foo:bar'}}}}
self.assertEqual(sconfig.apply_cloud_config(overrides, defaults=DEFAULT), ret)
@patch('salt.config.old_to_new',
MagicMock(return_value={'default_include': 'path/to/some/cloud/conf/file',
'providers': {'foo': {'bar': {
'provider': 'foo:bar'}}}}))
'driver': 'foo:bar'}}}}))
def test_apply_cloud_config_success_dict(self):
'''
Tests success when valid data is passed into function as a dictionary
'''
overrides = {'providers': {'foo': {'provider': 'bar'}}}
overrides = {'providers': {'foo': {'driver': 'bar'}}}
ret = {'default_include': 'path/to/some/cloud/conf/file',
'providers': {'foo': {'bar': {'provider': 'foo:bar'}}}}
'providers': {'foo': {'bar': {'driver': 'foo:bar'}}}}
self.assertEqual(sconfig.apply_cloud_config(overrides, defaults=DEFAULT), ret)
# apply_vm_profiles_config tests
@ -525,7 +525,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'''
providers = {'test-provider':
{'digital_ocean':
{'provider': 'digital_ocean', 'profiles': {}}}}
{'driver': 'digital_ocean', 'profiles': {}}}}
overrides = {'test-profile':
{'provider': 'test-provider',
'image': 'Ubuntu 12.10 x64',
@ -544,7 +544,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'''
Tests profile extends functionality with valid provider and profile configs
'''
providers = {'test-config': {'ec2': {'profiles': {}, 'provider': 'ec2'}}}
providers = {'test-config': {'ec2': {'profiles': {}, 'driver': 'ec2'}}}
overrides = {'Amazon': {'image': 'test-image-1',
'extends': 'dev-instances'},
'Fedora': {'image': 'test-image-2',
@ -576,10 +576,10 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
overrides = {'my-dev-envs':
[{'id': 'ABCDEFGHIJKLMNOP',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2'},
'driver': 'ec2'},
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'password': 'supersecret',
'provider': 'ec2'}],
'driver': 'ec2'}],
'conf_file': PATH}
self.assertRaises(SaltCloudConfigError,
sconfig.apply_cloud_providers_config,
@ -600,11 +600,11 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2'
'driver': 'ec2'
},
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'password': 'supersecret',
'provider': 'linode'
'driver': 'linode'
}],
'conf_file': PATH}
ret = {'my-production-envs':
@ -612,7 +612,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
{'profiles': {},
'location': 'us-east-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2',
'driver': 'ec2',
'id': 'ABCDEFGHIJKLMNOP',
'user': 'ec2-user@mycorp.com'}},
'my-dev-envs':
@ -620,12 +620,12 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'password': 'supersecret',
'profiles': {},
'provider': 'linode'},
'driver': 'linode'},
'ec2':
{'profiles': {},
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2',
'driver': 'ec2',
'id': 'ABCDEFGHIJKLMNOP',
'user': 'user@mycorp.com'}}}
self.assertEqual(ret,
@ -650,22 +650,22 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2'},
'driver': 'ec2'},
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'password': 'supersecret',
'provider': 'linode'}],
'driver': 'linode'}],
'conf_file': PATH}
ret = {'my-production-envs':
{'linode':
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'profiles': {},
'location': 'Salt Lake City',
'provider': 'linode',
'driver': 'linode',
'password': 'new-password'},
'ec2':
{'user': 'ec2-user@mycorp.com',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2',
'driver': 'ec2',
'id': 'ABCDEFGHIJKLMNOP',
'profiles': {},
'location': 'us-east-1'}},
@ -674,12 +674,12 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
{'apikey': 'abcdefghijklmnopqrstuvwxyz',
'password': 'supersecret',
'profiles': {},
'provider': 'linode'},
'driver': 'linode'},
'ec2':
{'profiles': {},
'user': 'user@mycorp.com',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2',
'driver': 'ec2',
'id': 'ABCDEFGHIJKLMNOP',
'location': 'ap-southeast-1'}}}
self.assertEqual(ret, sconfig.apply_cloud_providers_config(
@ -699,7 +699,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2'}],
'driver': 'ec2'}],
'conf_file': PATH}
self.assertRaises(SaltCloudConfigError,
sconfig.apply_cloud_providers_config,
@ -719,7 +719,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'ec2'}],
'driver': 'ec2'}],
'conf_file': PATH}
self.assertRaises(SaltCloudConfigError,
sconfig.apply_cloud_providers_config,
@ -739,7 +739,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'linode'}],
'driver': 'linode'}],
'conf_file': PATH}
self.assertRaises(SaltCloudConfigError,
sconfig.apply_cloud_providers_config,
@ -759,7 +759,7 @@ class ConfigTestCase(TestCase, integration.AdaptedConfigurationTestCaseMixIn):
'user': 'user@mycorp.com',
'location': 'ap-southeast-1',
'key': 'supersecretkeysupersecretkey',
'provider': 'linode'}],
'driver': 'linode'}],
'conf_file': PATH}
self.assertRaises(SaltCloudConfigError,
sconfig.apply_cloud_providers_config,