def test_delete(self): if do_not_delete_instance(): CONFIG.get_report().log("TESTS_DO_NOT_DELETE_INSTANCE=True was " "specified, skipping delete...") raise SkipTest("TESTS_DO_NOT_DELETE_INSTANCE was specified.") global dbaas if not hasattr(instance_info, "initial_result"): raise SkipTest("Instance was never created, skipping test...") if CONFIG.white_box: # Change this code to get the volume using the API. # That way we can keep it while keeping it black box. admin_context = context.get_admin_context() volumes = db.volume_get_all_by_instance(admin_context(), instance_info.local_id) instance_info.volume_id = volumes[0].id # Update the report so the logs inside the instance will be saved. CONFIG.get_report().update() dbaas.instances.delete(instance_info.id) attempts = 0 try: time.sleep(1) result = True while result is not None: attempts += 1 time.sleep(1) result = dbaas.instances.get(instance_info.id) assert_equal(200, dbaas.last_http_code) assert_equal("SHUTDOWN", result.status) except exceptions.NotFound: pass except Exception as ex: fail("A failure occured when trying to GET instance %s for the %d" " time: %s" % (str(instance_info.id), attempts, str(ex)))
def __cb(*args, **kwargs): # While %s turns a var into a string but in some rare cases explicit # str() is less likely to raise an exception. arg_strs = [repr(arg) for arg in args] arg_strs += ['%s=%s' % (repr(key), repr(value)) for (key, value) in kwargs.items()] CONFIG.get_reporter().log("[RDC] Calling : %s(%s)..." % (name, ','.join(arg_strs))) value = func(*args, **kwargs) CONFIG.get_reporter.log("[RDC] returned %s." % str(value)) return value
def load_tests(loader, config=None, stuff=None): # @test # def test_hi(): # assert_false("hi") from reddwarf.tests.config import CONFIG CONFIG.load_from_file("/Users/nath5505/dbaas/test-qa.conf") from proboscis.decorators import DEFAULT_REGISTRY plan = TestPlan.create_from_registry(DEFAULT_REGISTRY) return plan.create_test_suite(config, loader)
def resize_should_not_delete_users(self): """Resize should not delete users.""" # Resize has an incredibly weird bug where users are deleted after # a resize. The code below is an attempt to catch this while proceeding # with the rest of the test (note the use of runs_after). if USE_IP: self.connection.connect() if not self.connection.is_connected(): # Ok, this is def. a failure, but before we toss up an error # lets recreate to see how far we can get. CONFIG.get_report().log( "Having to recreate the test_user! Resizing killed it!") self.log_current_users() self.create_user() fail("Somehow, the resize made the test user disappear.")
def test_instance_size_too_big(self): vol_ok = CONFIG.get('reddwarf_volume_support', False) if 'reddwarf_max_accepted_volume_size' in CONFIG.values and vol_ok: too_big = CONFIG.reddwarf_max_accepted_volume_size assert_raises(exceptions.OverLimit, dbaas.instances.create, "way_too_large", instance_info.dbaas_flavor_href, {'size': too_big + 1}, []) assert_equal(413, dbaas.last_http_code)
def test_instance_size_too_big(self): vol_ok = CONFIG.get('reddwarf_volume_support', False) if 'reddwarf_max_accepted_volume_size' in CONFIG.values and vol_ok: too_big = CONFIG.reddwarf_max_accepted_volume_size self.test_info.volume = {'size': too_big + 1} self.test_info.name = "way_too_large" assert_raises(exceptions.OverLimit, dbaas.instances.create, self.test_info.name, self.test_info.dbaas_flavor_href, self.test_info.volume)
def call_xmllint(name, body): try: with open(CONFIG.xml_temp_file, 'w') as file: file.write(body) #if CONFIG.get('xml_xsd', None): args = [CONFIG.xml_temp_file] if CONFIG.get('xml_xsd', None): args += ["--schema", CONFIG.xml_xsd] output = processutils.execute(CONFIG.xmllint_bin, *args, check_exit_code=0, shell=False) except processutils.ProcessExecutionError as pe: fail("Error validating XML! %s" % pe)
def test_instance_created(self): # This version just checks the REST API status. def result_is_active(): instance = dbaas.instances.get(instance_info.id) if instance.status == "ACTIVE": return True else: # If its not ACTIVE, anything but BUILD must be # an error. assert_equal("BUILD", instance.status) if instance_info.volume is not None: assert_equal(instance.volume.get('used', None), None) return False poll_until(result_is_active) result = dbaas.instances.get(instance_info.id) report = CONFIG.get_report() report.log("Created an instance, ID = %s." % instance_info.id) report.log("TIP:") report.log("Rerun the tests with TESTS_USE_INSTANCE_ID=%s " "to skip ahead to this point." % instance_info.id) report.log("Add TESTS_DO_NOT_DELETE_INSTANCE=True to avoid deleting " "the instance at the end of the tests.")
try: wsgi_install() add_support_for_localization() replace_poll_until() # Load Reddwarf app # Paste file needs absolute path config_file = os.path.realpath('etc/reddwarf/reddwarf.conf.test') # 'etc/reddwarf/test-api-paste.ini' app = initialize_reddwarf(config_file) # Initialize sqlite database. initialize_database() # Swap out WSGI, httplib, and several sleep functions with test doubles. initialize_fakes(app) # Initialize the test configuration. test_config_file = parse_args_for_test_config() CONFIG.load_from_file(test_config_file) from reddwarf.tests.api import header from reddwarf.tests.api import limits from reddwarf.tests.api import flavors from reddwarf.tests.api import versions from reddwarf.tests.api import instances from reddwarf.tests.api import instances_actions from reddwarf.tests.api import instances_delete from reddwarf.tests.api import instances_mysql_down from reddwarf.tests.api import instances_resize from reddwarf.tests.api import databases from reddwarf.tests.api import root from reddwarf.tests.api import users from reddwarf.tests.api import user_access from reddwarf.tests.api.mgmt import accounts
def test_create(self): databases = [] databases.append({"name": "firstdb", "character_set": "latin2", "collate": "latin2_general_ci"}) databases.append({"name": "db2"}) instance_info.databases = databases users = [] users.append({"name": "lite", "password": "******", "databases": [{"name": "firstdb"}]}) instance_info.users = users if CONFIG.values['reddwarf_volume_support']: instance_info.volume = {'size': 1} else: instance_info.volume = None if create_new_instance(): instance_info.initial_result = dbaas.instances.create( instance_info.name, instance_info.dbaas_flavor_href, instance_info.volume, databases, users) assert_equal(200, dbaas.last_http_code) else: id = existing_instance() instance_info.initial_result = dbaas.instances.get(id) result = instance_info.initial_result instance_info.id = result.id if CONFIG.white_box: instance_info.local_id = dbapi.localid_from_uuid(result.id) report = CONFIG.get_report() report.log("Instance UUID = %s" % instance_info.id) if create_new_instance(): if CONFIG.white_box: building = dbaas_mapping[power_state.BUILDING] assert_equal(result.status, building) assert_equal("BUILD", instance_info.initial_result.status) else: report.log("Test was invoked with TESTS_USE_INSTANCE_ID=%s, so no " "instance was actually created." % id) # Check these attrs only are returned in create response expected_attrs = ['created', 'flavor', 'addresses', 'id', 'links', 'name', 'status', 'updated'] if CONFIG.values['reddwarf_volume_support']: expected_attrs.append('volume') if CONFIG.reddwarf_dns_support: expected_attrs.append('hostname') with CheckInstance(result._info) as check: if create_new_instance(): check.attrs_exist(result._info, expected_attrs, msg="Create response") # Don't CheckInstance if the instance already exists. check.flavor() check.links(result._info['links']) if CONFIG.values['reddwarf_volume_support']: check.volume()
def log_current_users(self): users = self.dbaas.users.list(self.instance_id) CONFIG.get_report().log("Current user count = %d" % len(users)) for user in users: CONFIG.get_report().log("\t" + str(user))
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 reddwarf.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)
def create_dbaas_client(user): """Creates a rich client for the RedDwarf API using the test config.""" auth_strategy = None kwargs = { 'service_type': 'database', '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) if test_config.values.get('reddwarf_client_cls'): cls_name = test_config.reddwarf_client_cls kwargs['client_cls'] = import_class(cls_name) 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)
if __name__=="__main__": wsgi_install() add_support_for_localization() replace_poll_until() # Load Reddwarf app # Paste file needs absolute path config_file = os.path.realpath('etc/reddwarf/reddwarf.conf.test') # 'etc/reddwarf/test-api-paste.ini' app = initialize_reddwarf(config_file) # Initialize sqlite database. initialize_database() # Swap out WSGI, httplib, and several sleep functions with test doubles. initialize_fakes(app) # Initialize the test configuration. CONFIG.load_from_file('etc/tests/localhost.test.conf') from reddwarf.tests.api import flavors from reddwarf.tests.api import versions from reddwarf.tests.api import instances from reddwarf.tests.api import instances_actions from reddwarf.tests.api import instances_delete from reddwarf.tests.api import instances_mysql_down from reddwarf.tests.api import instances_resize from reddwarf.tests.api import databases from reddwarf.tests.api import root from reddwarf.tests.api import users from reddwarf.tests.api.mgmt import accounts from reddwarf.tests.api.mgmt import admin_required from reddwarf.tests.api.mgmt import instances from reddwarf.tests.api.mgmt import storage
try: wsgi_install() add_support_for_localization() replace_poll_until() # Load Reddwarf app # Paste file needs absolute path config_file = os.path.realpath('etc/reddwarf/reddwarf.conf.test') # 'etc/reddwarf/test-api-paste.ini' app = initialize_reddwarf(config_file) # Initialize sqlite database. initialize_database() # Swap out WSGI, httplib, and several sleep functions with test doubles. initialize_fakes(app) # Initialize the test configuration. test_config_file = parse_args_for_test_config() CONFIG.load_from_file(test_config_file) from reddwarf.tests.api import backups from reddwarf.tests.api import header from reddwarf.tests.api import limits from reddwarf.tests.api import flavors from reddwarf.tests.api import versions from reddwarf.tests.api import instances from reddwarf.tests.api import instances_actions from reddwarf.tests.api import instances_delete from reddwarf.tests.api import instances_mysql_down from reddwarf.tests.api import instances_resize from reddwarf.tests.api import databases from reddwarf.tests.api import root from reddwarf.tests.api import users from reddwarf.tests.api import user_access
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)