def test_register_argparse_bad_plugin(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) parser = argparse.ArgumentParser() self.assertRaises(exceptions.OpenStackConfigException, c.register_argparse_arguments, parser, ['--os-auth-type', 'foo'])
def test_get_one_cloud_bad_region_no_regions(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) self.assertRaises( exceptions.OpenStackConfigException, c.get_one_cloud, cloud='_test-cloud_', region_name='bad_region')
def test_get_one_cloud_infer_user_domain(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud('_test-cloud-int-project_') self.assertEqual('awesome-domain', cc.auth['user_domain_id']) self.assertEqual('awesome-domain', cc.auth['project_domain_id']) self.assertNotIn('domain_id', cc.auth)
def __init__(self, config_name): opts = Opts(cloud_name=config_name) cc = cloud_config.OpenStackConfig() LOG.debug("defaults: %s", cc.defaults) # clouds.yaml file should either be in the # current directory or # ~/.config/openstack directory or # /etc/openstack directory. cloud = cc.get_one_cloud(opts.cloud) LOG.debug("cloud cfg: %s", cloud.config) # Create a context for a connection to the cloud provider self.conn = connection.from_config(cloud_config=cloud, options=opts) identity_api_version = cloud.config['identity_api_version'] if identity_api_version != '3': LOG.error('Only Identity version 3 is supported.') # We still need to use aodhclient until alarming APIs # are added to openstackclient self.aodh_conn = aodh_client.Client( session=cloud.get_session_client('alarming')) self.aodh_conn.alarm.url = '/alarms'
def test_backwards_network(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cloud = { 'external_network': 'public', 'internal_network': 'private', } result = c._fix_backwards_networks(cloud) expected = { 'external_network': 'public', 'internal_network': 'private', 'networks': [ { 'name': 'public', 'routes_externally': True, 'nat_destination': False, 'default_interface': True }, { 'name': 'private', 'routes_externally': False, 'nat_destination': True, 'default_interface': False }, ] } self.assertEqual(expected, result)
def test_get_one_cloud_no_yaml_no_cloud(self): c = config.OpenStackConfig(load_yaml_config=False) self.assertRaises( exceptions.OpenStackConfigException, c.get_one_cloud, cloud='_test_cloud_regions', region_name='region2', argparse=None)
def test_get_region_invalid_region(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml], secure_files=[self.no_yaml]) self.assertRaises( exceptions.OpenStackConfigException, c._get_region, cloud='_test_cloud_regions', region_name='invalid-region')
def setUp(self): super(BaseIntegrationTests, self).setUp() # Extract credentials so that we can build authentication requests. cloud_cfg = cloud_config.OpenStackConfig() # Extract authentication information for the Rackspace cloud. rackspace_cloud = cloud_cfg.get_one_cloud('rackspace') rackspace_args = rackspace_cloud.get_auth_args() # Extract authentication information for the Keystone cloud. keystone_cloud = cloud_cfg.get_one_cloud('keystone') keystone_args = keystone_cloud.get_auth_args() # Store common request information that is used to build and make # authentication request. self.headers = {'Content-Type': 'application/json'} self.user_id = rackspace_args['user_id'] self.username = rackspace_args['username'] self.password = rackspace_args['password'] self.project_id = rackspace_args['project_id'] self.domain_id = rackspace_args['user_domain_id'] self.rackspace_token_endpoint = ( rackspace_args['auth_url'].rstrip('/') + '/tokens') self.keystone_token_endpoint = (keystone_args['auth_url'].rstrip('/') + '/auth/tokens') self.keystone_users_endpoint = (keystone_args['auth_url'].rstrip('/') + '/users')
def test_get_region_no_region(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml], secure_files=[self.no_yaml]) region = c._get_region(cloud='_test-cloud_no_region', region_name='override-region') self.assertEqual(region, {'name': 'override-region', 'values': {}})
def __init__(self, config_name): opts = Opts(cloud_name=config_name) cc = cloud_config.OpenStackConfig() LOG.debug("defaults: %s", cc.defaults) # clouds.yaml file should either be in the # current directory or # ~/.config/openstack directory or # /etc/openstack directory. cloud = cc.get_one_cloud(opts.cloud) LOG.debug("cloud cfg: %s", cloud.config) # Create a context for a connection to the cloud provider self.conn = connection.from_config(cloud_config=cloud, options=opts) identity_api_version = cloud.config['identity_api_version'] if identity_api_version != '3': LOG.error('This version of OpenStack User Management Library ' 'only supports Identity version 3.') # We still need to use neutronclient until openstackclient # is able to add interface router, and keystoneclient # until openstackclient is able to grant roles to users self.neutron_conn = neutron_client.Client( session=cloud.get_session_client('network')) self.keystone_conn = keystone_client.Client( session=cloud.get_session_client('identity'))
def test_get_one_cloud_domain_scoped(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud('_test-cloud-domain-scoped_') self.assertEqual('12345', cc.auth['domain_id']) self.assertNotIn('user_domain_id', cc.auth) self.assertNotIn('project_domain_id', cc.auth)
def test_register_argparse_network_service_types(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) parser = argparse.ArgumentParser() args = [ '--os-compute-service-name', 'cloudServers', '--os-network-service-type', 'badtype', '--os-endpoint-type', 'admin', '--network-api-version', '4', ] c.register_argparse_arguments( parser, args, ['compute', 'network', 'volume']) opts, _remain = parser.parse_known_args(args) self.assertEqual(opts.os_network_service_type, 'badtype') self.assertIsNone(opts.os_compute_service_type) self.assertIsNone(opts.os_volume_service_type) self.assertEqual(opts.os_service_type, 'compute') self.assertEqual(opts.os_compute_service_name, 'cloudServers') self.assertEqual(opts.os_endpoint_type, 'admin') self.assertIsNone(opts.os_network_api_version) self.assertEqual(opts.network_api_version, '4') cloud = c.get_one_cloud(argparse=opts, validate=False) self.assertEqual(cloud.config['service_type'], 'compute') self.assertEqual(cloud.config['network_service_type'], 'badtype') self.assertEqual(cloud.config['interface'], 'admin') self.assertEqual(cloud.config['network_api_version'], '4') self.assertNotIn('volume_service_type', cloud.config) self.assertNotIn('http_timeout', cloud.config)
def test_get_one_cloud_precedence_osc(self): c = config.OpenStackConfig( config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml], ) kwargs = { 'auth': { 'username': '******', 'password': '******', 'project-id': 'testproject', 'auth_url': 'http://example.com/v2', }, 'region_name': 'kwarg_region', 'password': '******', 'arbitrary': 'value', } args = dict( auth_url='http://example.com/v2', username='******', password='******', project_name='project', region_name='region2', snack_type='cookie', ) options = argparse.Namespace(**args) cc = c.get_one_cloud_osc( argparse=options, **kwargs ) self.assertEqual(cc.region_name, 'region2') self.assertEqual(cc.auth['password'], 'argpass') self.assertEqual(cc.snack_type, 'cookie')
def test_register_argparse_cloud(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) parser = argparse.ArgumentParser() c.register_argparse_arguments(parser, []) opts, _remain = parser.parse_known_args(['--os-cloud', 'foo']) self.assertEqual(opts.os_cloud, 'foo')
def test_get_one_cloud_bad_region_argparse(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) self.assertRaises( exceptions.OpenStackConfigException, c.get_one_cloud, cloud='_test-cloud_', argparse=self.options)
def test_get_one_cloud_no_networks(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud('_test-cloud-domain-scoped_') self.assertEqual([], cc.get_external_networks()) self.assertEqual([], cc.get_internal_networks()) self.assertIsNone(cc.get_nat_destination()) self.assertIsNone(cc.get_default_network())
def test_get_one_cloud_just_argparse(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(argparse=self.options, validate=False) self.assertIsNone(cc.cloud) self.assertEqual(cc.region_name, 'region2') self.assertEqual(cc.snack_type, 'cookie')
def test_envvar_prefer_ipv6_override(self): self.useFixture(fixtures.EnvironmentVariable('OS_PREFER_IPV6', 'false')) c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml], secure_files=[self.secure_yaml]) cc = c.get_one_cloud('_test-cloud_') self.assertFalse(cc.prefer_ipv6)
def test_get_region_many_regions(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml], secure_files=[self.no_yaml]) region = c._get_region(cloud='_test_cloud_regions', region_name='region2') self.assertEqual(region, {'name': 'region2', 'values': {'external_network': 'my-network'}})
def test_config_file_override(self): self.useFixture( fixtures.EnvironmentVariable('OS_CLIENT_CONFIG_FILE', self.cloud_yaml)) c = config.OpenStackConfig(config_files=[], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud('_test-cloud_') self._assert_cloud_details(cc)
def test_test_envvars(self): self.useFixture(fixtures.EnvironmentVariable('NOVA_USERNAME', 'nova')) self.useFixture( fixtures.EnvironmentVariable('OS_STDERR_CAPTURE', 'True')) c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) self.assertRaises(exceptions.OpenStackConfigException, c.get_one_cloud, 'envvars')
def test_fix_env_args(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) env_args = {'os-compute-api-version': 1} fixed_args = c._fix_args(env_args) self.assertDictEqual({'compute_api_version': 1}, fixed_args)
def test_env_argparse_precedence(self): self.useFixture( fixtures.EnvironmentVariable('OS_TENANT_NAME', 'tenants-are-bad')) c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(cloud='envvars', argparse=self.options) self.assertEqual(cc.auth['project_name'], 'project')
def test_get_one_cloud_just_kwargs(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(**self.args) self.assertIsNone(cc.cloud) self.assertEqual(cc.region_name, 'region2') self.assertEqual(cc.snack_type, 'cookie')
def test_get_one_cloud_no_argparse_regions(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(cloud='_test_cloud_regions', argparse=None) self._assert_cloud_details(cc) self.assertEqual(cc.region_name, 'region1') self.assertIsNone(cc.snack_type)
def test_get_one_cloud_argparse(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(cloud='_test_cloud_regions', argparse=self.options) self.assertEqual(cc.region_name, 'region2') self.assertEqual(cc.snack_type, 'cookie')
def test_fallthrough(self): c = config.OpenStackConfig(config_files=[self.no_yaml], vendor_files=[self.no_yaml], secure_files=[self.no_yaml]) for k in os.environ.keys(): if k.startswith('OS_'): self.useFixture(fixtures.EnvironmentVariable(k)) c.get_one_cloud(cloud='defaults', validate=False)
def test_get_one_cloud_per_region_network(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud( cloud='_test_cloud_regions', region_name='region2', argparse=None) self._assert_cloud_details(cc) self.assertEqual(cc.region_name, 'region2') self.assertEqual('my-network', cc.config['external_network'])
def test_get_one_cloud_networks(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud('_test-cloud-networks_') self.assertEqual( ['a-public', 'another-public'], cc.get_external_networks()) self.assertEqual( ['a-private', 'another-private'], cc.get_internal_networks()) self.assertEqual('another-private', cc.get_nat_destination()) self.assertEqual('another-public', cc.get_default_network())
def test_argparse_action_append_no_underscore(self): c = config.OpenStackConfig(config_files=[self.no_yaml], vendor_files=[self.no_yaml], secure_files=[self.no_yaml]) parser = argparse.ArgumentParser() parser.add_argument('--foo', action='append') argv = ['--foo', '1', '--foo', '2'] c.register_argparse_arguments(parser, argv=argv) opts, _remain = parser.parse_known_args(argv) self.assertEqual(opts.foo, ['1', '2'])