コード例 #1
0
ファイル: conftest.py プロジェクト: LaVLaS/hansei
def pytest_report_header(config):
    """Display the api version and git commit the koku server is running under"""

    koku_config = hansei_config.get_config().get('koku', {})

    report_header = ""

    try:
        client = hansei_api.Client(username=koku_config.get('username'),
                                   password=koku_config.get('password'))
        client.server_status()
        server_status = client.last_response.json()

        report_header = " - API Version: {}\n - Git Commit: {}".format(
            server_status['api_version'], server_status['commit'])

        if config.pluginmanager.hasplugin("junitxml") and hasattr(
                config, '_xml'):
            config._xml.add_global_property('Koku Server Id',
                                            server_status['server_id'])
            config._xml.add_global_property('Koku API Version',
                                            server_status['api_version'])
            config._xml.add_global_property('Koku Git Commit',
                                            server_status['commit'])
            config._xml.add_global_property('Koku Python Version',
                                            server_status['python_version'])

    except HTTPError:
        report_header = " - Unable to retrieve the server status"

    return "Koku Server Info:\n{}".format(report_header)
コード例 #2
0
def get_koku_url():
    """Return the base url for the koku server."""
    cfg = get_config().get('koku', {})
    hostname = cfg.get('hostname')

    if not hostname:
        raise exceptions.KokuBaseUrlNotFound(
            'Make sure you have a "koku" section and `hostname`is specified in '
            'the hansei config file')

    scheme = 'https' if cfg.get('https', False) else 'http'
    port = str(cfg.get('port', ''))
    netloc = hostname + ':{}'.format(port) if port else hostname
    return urlunparse((scheme, netloc, '', '', '', ''))
コード例 #3
0
def test_api_client():
    koku_cfg = config.get_config().get('koku', {})

    client = api.Client(username=koku_cfg.get('username'),
                        password=koku_cfg.get('password'))
    assert client.token, 'No token provided after logging in'

    response = client.get_user()

    assert response.json()['username'] == koku_cfg['username'], (
        'Current user does not match expected \'admin\' user')

    response = client.server_status()
    assert len(response.json()) > 0, 'Server status is unavailable'
コード例 #4
0
ファイル: test_provider.py プロジェクト: nachandr/hansei
    def provider(self, user):
        """Create a new KokuProvder"""
        uniq_string = fauxfactory.gen_string('alphanumeric', 8)
        #Grab the first AWS provider
        provider_config = [
            prov for prov in config.get_config().get('providers', {}) if prov['type'] == 'AWS'][0]

        #TODO: Implement lazy authentication of the client for new KokuObject() fixtures
        provider = user.create_provider(
            name='Provider {} for user {}'.format(uniq_string, user.username),
            authentication=provider_config.get('authentication'),
            provider_type=provider_config.get('type'),
            billing_source=provider_config.get('billing_source'))

        return provider
コード例 #5
0
ファイル: koku_models.py プロジェクト: nachandr/hansei
    def __init__(self, client=None, username=None, password=None):
        """
        Arguments:
            client - existing ``hansei.api.Client`` instance used to communicate with the Koku
                server. client authenticaton credentials will be used even if username & password
                are provided
            username - username to use for authentication
            password - password to use for authentication
        """
        cfg = config.get_config().get('koku', {})
        self.username = username or cfg.get('username', KOKU_DEFAULT_USER)
        self.password = password or cfg.get('password', KOKU_DEFAULT_PASSWORD)

        self.client = client if client else api.Client(username=self.username,
                                                       password=self.password)

        self.uuid = None
コード例 #6
0
def pytest_configure(config):
    koku_admin = config.getoption('koku_admin_username')
    koku_admin_pw = config.getoption('koku_admin_password')
    koku_hostname = config.getoption('koku_hostname')
    koku_host_port = config.getoption('koku_host_port')

    koku_config = hansei_config.get_config().get('koku', {})

    if koku_admin:
        koku_config['username'] = koku_admin

    if koku_admin_pw:
        koku_config['password'] = koku_admin_pw

    if koku_hostname:
        koku_config['hostname'] = koku_hostname

    if koku_host_port:
        koku_config['port'] = koku_host_port
コード例 #7
0
ファイル: conftest.py プロジェクト: nachandr/hansei
def koku_config():
    return config.get_config().get('koku', {})
コード例 #8
0
    def __init__(self,
                 response_handler=None,
                 url=None,
                 authenticate=True,
                 username=None,
                 password=None):
        """Initialize this object, collecting base URL from config file.

        If no response handler is specified, use the `code_handler` which will
        raise an exception for 'bad' return codes.


        If no URL is specified, then the config file will be parsed and the URL
        will be built by reading the hostname, port and https values. You can
        configure the default URL by including the following on your hansei
        configuration file::

            koku:
                hostname: <machine_hostname_or_ip_address>
                port: <port>  # if not defined will take the default port
                              # depending on the https config: 80 if https is
                              # false and 443 if https is true.
                https: false  # change to true if server is published over
                              # https. Defaults to false if not defined

        Arguments: 
            response_handler - Customer handler wrapper for formatting response
            url - Url for the Koku server. Default is localhost (127.0.0.1)
            authenticate - If True, login to the server during initialization
            username - Username used for server authentication
            password - Password used for server authentication
        """
        # Stores the response of the last request made.
        self._last_response = None
        self.url = url
        self.token = None
        cfg = config.get_config().get('koku', {})
        self.verify = cfg.get('ssl-verify', False)

        if not self.url:
            hostname = cfg.get('hostname')

            if not hostname:
                raise exceptions.KokuBaseUrlNotFound(
                    "\n'koku' section specified in hansei config file, but"
                    "no 'hostname' key found.")

            scheme = 'https' if cfg.get('https', False) else 'http'
            port = str(cfg.get('port', ''))
            netloc = hostname + ':{}'.format(port) if port else hostname
            self.url = urlunparse(
                (scheme, netloc, KOKU_API_VERSION, '', '', ''))

        if not self.url:
            raise exceptions.KOKUBaseUrlNotFound(
                'No base url was specified to the client either with the '
                'url="host" option or with the hansei config file.')

        if response_handler is None:
            self.response_handler = code_handler
        else:
            self.response_handler = response_handler

        if authenticate:
            self.login(username=username, password=password)
コード例 #9
0
ファイル: test_provider.py プロジェクト: nachandr/hansei
    def service_admin(self):
        koku_config = config.get_config().get('koku', {})

        return KokuServiceAdmin(
            username=koku_config.get('username'), password=koku_config.get('password'))