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
    set_optional('auth_strategy', 'auth_strategy')
    set_optional('region_name', 'reddwarf_client_region_name')
    set_optional('service_url', 'override_reddwarf_api_url')

    dbaas = Dbaas(user.auth_user, user.auth_key, user.tenant,
                  test_config.reddwarf_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.management_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)
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'],
        'auth_strategy':test_config.values['auth_strategy'],
        'region_name':test_config.values['reddwarf_client_region_name']
    }
    force_url = test_config.values.get('override_reddwarf_api_url', None)
    if force_url:
        # In some test environments the catalog returned by auth is poppycock
        # so use this instead.
        kwargs['service_url'] = force_url
    dbaas = Dbaas(user.auth_user, user.auth_key, user.tenant,
                  test_config.reddwarf_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.management_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)
示例#3
0
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
    set_optional('auth_strategy', 'auth_strategy')
    set_optional('region_name', 'reddwarf_client_region_name')
    set_optional('service_url', 'override_reddwarf_api_url')

    dbaas = Dbaas(user.auth_user, user.auth_key, user.tenant,
                  test_config.reddwarf_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.management_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)
def create_dbaas_client(user):
    """Creates a rich client for the RedDwarf API using the test config."""
    test_config.nova.ensure_started()
    dbaas = Dbaas(user.auth_user, user.auth_key, user.tenant, test_config.reddwarf_auth_url, service_type="reddwarf")
    dbaas.authenticate()
    with Check() as check:
        check.is_not_none(dbaas.client.auth_token, "Auth token not set!")
        if user.requirements.is_admin:
            expected_prefix = test_config.dbaas_url
            actual = dbaas.client.management_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)
示例#5
0
    def login(self, user, apikey, tenant="dbaas", auth_url="http://localhost:5000/v1.1",
              service_name="reddwarf", service_url=None):
        """Login to retrieve an auth token to use for other api calls"""
        try:
            dbaas = Dbaas(user, apikey, tenant, auth_url=auth_url,
                          service_name=service_name, service_url=service_url)
            dbaas.authenticate()
            apitoken = APIToken(user, apikey, tenant, dbaas.client.auth_token,
                                auth_url, service_name, service_url)

            with open(APITOKEN, 'wb') as token:
                pickle.dump(apitoken, token, protocol=2)
            print apitoken._token
        except:
            print sys.exc_info()[1]
def create_client(cls=ReddwarfHTTPClient):
    client = Dbaas(conf.username,
                   conf.password,
                   tenant=conf.tenant,
                   auth_url="blah/",
                   auth_strategy='fake',
                   insecure=True,
                   service_type='reddwarf',
                   service_url=conf.dbaas_url,
                   client_cls=cls)
    return client
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)
示例#8
0
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)