Beispiel #1
0
    def test_mgmt_client_with_incorrect_creds(mocker):
        """Test: Initialize mgmt client with wrong credentials

        Assertions
        ----------
        - Mgmt client throws exception InvalidAuthError
        """
        mocker.patch(REQ).side_effect = HTTPError(constants.BAD_REQUEST_BODY)
        with pytest.raises(InvalidAuthError):
            ManagementClient(user=USER, password=USER_PWD)
Beispiel #2
0
def get_mgmt_client():
    """ Get Management Client """

    auth_client = AuthConfigurationClient()
    auth = auth_client.read_auth(constants.AUTHENTICATION_PROVIDERS['CS'])

    management_kwargs = dict(user=auth['user'],
                             password=auth['password'],
                             api_endpoint=auth.pop('api_endpoint', None))
    return ManagementClient(**management_kwargs)
def run_example():
    """ Show F5 Cloud Services Beacon Declaration (Applications, Monitors, etc.) """
    # create management client
    mgmt_client = ManagementClient(
        user=os.environ['F5_CS_USER'],
        password=os.environ['F5_CS_PWD']
    )

    # create declare client
    declare_client = DeclareClient(mgmt_client)

    # get subscription details
    return declare_client.create(config={'action': 'get'})
Beispiel #4
0
    def test_custom_api_endpoint(mocker):
        """Test: Custom API endpoint is used as expected
        Assertions
        ----------
        - Validates that CloudService api endpoint is set to custom value
        """
        # pylint: disable=protected-access

        mocker.patch(REQ).return_value.json = Mock(return_value=LOGIN_RESPONSE)

        mgmt_client = ManagementClient(user=USER,
                                       password=USER_PWD,
                                       api_endpoint=CUSTOM_API_ENDPOINT)

        assert mgmt_client._api_endpoint == constants.CUSTOM_API_ENDPOINT
def run_example():
    """ Get Cloud Services configuration """
    # create management client
    mgmt_client = ManagementClient(user=os.environ['F5_CS_USER'],
                                   password=os.environ['F5_CS_PWD'])

    # create account/subscription client
    account_client = AccountClient(mgmt_client)
    subscription_client = SubscriptionClient(mgmt_client)

    # discover account/subscription ID
    account_id = account_client.show_user()['primary_account_id']
    subscription_id = subscription_client.list(
        query_parameters={'account_id': account_id
                          })['subscriptions'][0]['subscription_id']

    # get subscription details
    return subscription_client.show(name=subscription_id)
Beispiel #6
0
    def test_api_endpoint_no_api_endpoint_value(mocker):
        """Test: Default API endpoint is used as expected
            when api_endpoint is provided with a None value

        Assertions
        ----------
        - Validates that CloudService has api_endpoint set to default value
        """
        # pylint: disable=protected-access

        mocker.patch(REQ).return_value.json = Mock(return_value=LOGIN_RESPONSE)

        mgmt_client = ManagementClient(user=USER,
                                       password=USER_PWD,
                                       api_endpoint=None)

        assert mgmt_client._api_endpoint == project_constants.F5_CS[
            'API_ENDPOINT']
def mgmt_client(mocker):
    """ Test fixture: create mgmt client """
    mocker.patch(REQ).return_value.json = Mock(return_value=LOGIN_RESPONSE)

    return ManagementClient(user=USER, password=USER_PWD)