Пример #1
0
def test_fail_auth(*args):
    """ Tests Auth Failure """
    # Scenario:
    #
    # 1) Get a bad context object with empty auth_url
    # 2) Check AuthValuesError is raised

    context = _get_bad_context()
    shipyard_helper = ShipyardHelper(context)

    with pytest.raises(util.shipyard_helper.AuthValuesError):
        ShipyardHelper(context).validate_auth_vars()
Пример #2
0
def test_upload_documents(*args):
    """ Tests upload document """
    # Scenario:
    #
    # 1) Get a dummy context Object
    # 2) Mock external calls
    # 3) Check documents uploaded to Shipyard with correct parameters

    context = _get_context()
    with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
                    autospec=True) as mock_shipyard:
        mock_api_client = mock_shipyard.return_value
        mock_api_client.post_configdocs.return_value = 'Success'
        result = ShipyardHelper(context, 'replace').upload_documents()

        # Validate Shipyard call to post configdocs was invoked with correct
        # collection name and buffer mode.
        expected_data = '---\n'.join(
            [
                _get_deployment_data_as_yaml(context.obj['site_name']),
                _get_data_as_collection(MULTI_REPO_DATA)
            ])
        mock_api_client.post_configdocs.assert_called_with(
            collection_id='test-site',
            buffer_mode='replace',
            document_data=expected_data)
        mock_api_client.post_configdocs.assert_called_once()
Пример #3
0
def test_upload_documents_fail(*args):
    """ Tests Document upload error """
    # Scenario:
    #
    # 1) Get a bad context object with empty auth_url
    # 2) Mock external calls
    # 3) Check DocumentUploadError is raised

    context = _get_context()
    shipyard_helper = ShipyardHelper(context)

    with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
                    autospec=True) as mock_shipyard:
        mock_api_client = mock_shipyard.return_value
        mock_api_client.post_configdocs.return_value = FakeResponse()
        with pytest.raises(util.shipyard_helper.DocumentUploadError):
            ShipyardHelper(context).upload_documents()
Пример #4
0
def test_commit_documents(*args):
    """Tests commit document """
    # Scenario:
    #
    # 1) Get a dummy context Object
    # 2) Mock external calls
    # 3) Check commit documents was called

    context = _get_context()
    shipyard_helper = ShipyardHelper(context)

    with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
                    autospec=True) as mock_shipyard:
        mock_api_client = mock_shipyard.return_value
        mock_api_client.commit_configdocs.return_value = 'Success'
        result = ShipyardHelper(context).commit_documents()

        mock_api_client.commit_configdocs.assert_called_once()
Пример #5
0
def test_shipyard_helper_init_():
    """ Tests ShipyardHelper init method """
    # Scenario:
    #
    # 1) Get a dummy context Object
    # 2) Check that site name is as expected
    # 3) Check api client is instance of ShipyardClient

    context = _get_context()
    shipyard_helper = ShipyardHelper(context)

    assert shipyard_helper.site_name == context.obj['site_name']
    assert isinstance(shipyard_helper.api_client, ShipyardClient)
Пример #6
0
def run_upload(buffer_mode, collection, context_marker, ctx, os_auth_token,
               os_auth_url, os_domain_name, os_password,
               os_project_domain_name, os_project_name, os_user_domain_name,
               os_username, site_name):
    """Uploads a collection of documents to shipyard

    :param buffer_mode: mode used when uploading documents
    :param collection: specifies the name to use for uploaded collection
    :param context_marker: UUID used to correlate logs, transactions, etc...
    :param ctx: dictionary containing various data used by shipyard
    :param os_auth_token: authentication token
    :param os_auth_url: authentication url
    :param os_domain_name: domain name
    :param os_password: password
    :param os_project_domain_name: project domain name
    :param os_project_name: project name
    :param os_user_domain_name: user domain name
    :param os_username: username
    :param site_name: site name to process
    :return: response from shipyard instance
    """
    _run_precommand_decrypt(site_name)
    if not ctx.obj:
        ctx.obj = {}
    # Build API parameters required by Shipyard API Client.
    if os_auth_token:
        os.environ['OS_AUTH_TOKEN'] = os_auth_token
        auth_vars = {'token': os_auth_token, 'auth_url': os_auth_url}
    else:
        auth_vars = {
            'user_domain_name': os_user_domain_name,
            'project_name': os_project_name,
            'username': os_username,
            'password': os_password,
            'auth_url': os_auth_url
        }
    # Domain-scoped params
    if os_domain_name:
        auth_vars['domain_name'] = os_domain_name
        auth_vars['project_domain_name'] = None
    # Project-scoped params
    else:
        auth_vars['project_domain_name'] = os_project_domain_name
    ctx.obj['API_PARAMETERS'] = {'auth_vars': auth_vars}
    ctx.obj['context_marker'] = str(context_marker)
    ctx.obj['site_name'] = site_name
    ctx.obj['collection'] = collection
    config.set_global_enc_keys(site_name)
    return ShipyardHelper(ctx, buffer_mode).upload_documents()