def create_dbaas_client(user): """Creates a rich client for the RedDwarf API using the test config.""" auth_strategy = None kwargs = { 'service_type': 'reddwarf', 'insecure': test_config.values['reddwarf_client_insecure'], } def set_optional(kwargs_name, test_conf_name): value = test_config.values.get(test_conf_name, None) if value is not None: kwargs[kwargs_name] = value force_url = 'override_reddwarf_api_url' in test_config.values service_url = test_config.get('override_reddwarf_api_url', None) if user.requirements.is_admin: service_url = test_config.get('override_admin_reddwarf_api_url', service_url) if service_url: kwargs['service_url'] = service_url auth_strategy = None if user.requirements.is_admin: auth_strategy = test_config.get('admin_auth_strategy', test_config.auth_strategy) else: auth_strategy = test_config.auth_strategy set_optional('region_name', 'reddwarf_client_region_name') if test_config.values.get('override_reddwarf_api_url_append_tenant', False): kwargs['service_url'] += "/" + user.tenant if auth_strategy == 'fake': from reddwarfclient import auth class FakeAuth(auth.Authenticator): def authenticate(self): class FakeCatalog(object): def __init__(self, auth): self.auth = auth def get_public_url(self): return "%s/%s" % (test_config.dbaas_url, self.auth.tenant) def get_token(self): return self.auth.tenant return FakeCatalog(self) auth_strategy = FakeAuth if auth_strategy: kwargs['auth_strategy'] = auth_strategy if not user.requirements.is_admin: auth_url = test_config.reddwarf_auth_url else: auth_url = test_config.values.get('reddwarf_admin_auth_url', test_config.reddwarf_auth_url) dbaas = Dbaas(user.auth_user, user.auth_key, tenant=user.tenant, auth_url=auth_url, **kwargs) dbaas.authenticate() with Check() as check: check.is_not_none(dbaas.client.auth_token, "Auth token not set!") if not force_url and user.requirements.is_admin: expected_prefix = test_config.dbaas_url actual = dbaas.client.service_url msg = "Dbaas management url was expected to start with %s, but " \ "was %s." % (expected_prefix, actual) check.true(actual.startswith(expected_prefix), msg) return TestClient(dbaas)
index += 1 # Many of the test decorators depend on configuration values, so before # start importing modules we have to load the test config followed by the # flag files. from tests.config import CONFIG # Find config file. if not "TEST_CONF" in os.environ: raise RuntimeError("Please define an environment variable named " + "TEST_CONF with the location to a conf file.") file_path = os.path.expanduser(os.environ["TEST_CONF"]) if not os.path.exists(file_path): raise RuntimeError("Could not find TEST_CONF at " + file_path + ".") # Load config file and then any lines we read from the arguments. CONFIG.load_from_file(file_path) for line in extra_test_conf_lines: CONFIG.load_from_line(line) # Reset values imported into tests/__init__. # TODO(tim.simpson): Stop importing them from there. from tests import initialize_globals initialize_globals() from tests import WHITE_BOX if WHITE_BOX: # If white-box testing, set up the flags. # Handle loading up RDL's config file madness. initialize_rdl_config(rdl_config_file) # Set up the report, and print out how we're running the tests.
index += 1 # Many of the test decorators depend on configuration values, so before # start importing modules we have to load the test config followed by the # flag files. from tests.config import CONFIG # Find config file. if not "TEST_CONF" in os.environ: raise RuntimeError("Please define an environment variable named " + "TEST_CONF with the location to a conf file.") file_path = os.path.expanduser(os.environ["TEST_CONF"]) if not os.path.exists(file_path): raise RuntimeError("Could not find TEST_CONF at " + file_path + ".") # Load config file and then any lines we read from the arguments. CONFIG.load_from_file(file_path) for line in extra_test_conf_lines: CONFIG.load_from_line(line) # Reset values imported into tests/__init__. # TODO(tim.simpson): Stop importing them from there. from tests import initialize_globals initialize_globals() from tests import WHITE_BOX if WHITE_BOX: # If white-box testing, set up the flags. # Handle loading up RDL's config file madness. initialize_rdl_config(rdl_config_file) if nova_flag_file: initialize_nova_flags(nova_flag_file)