예제 #1
0
    def test_delphix_client_wrong_login(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header,
            status=401)

        dc = delphix_client.DelphixClient('test-engine.com')

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.login(engine_api, 'admin2', 'delphix')

        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 401
        assert error['details'] == 'Invalid username or password.'
        assert error['action'] == 'Try with a different set of credentials.'
        assert message == (
            'API request failed with HTTP Status 401'
            '\nDetails: Invalid username or password.'
            '\nAction: Try with a different set of credentials.')

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u'/resources/json/delphix/login'
        assert history[-2].path == u'/resources/json/delphix/session'
예제 #2
0
    def test_delphix_client_wrong_api(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        dc = delphix_client.DelphixClient("test-engine.com")

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.login(engine_api, "admin", "delphix")

        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 200
        assert error["details"] == 'Invalid API version "2.11.0".'
        assert error["action"] == ("Change the API version to one supported"
                                   " by your version of the Delphix Engine."
                                   " Review the Release Notes for your"
                                   " Delphix Engine version to determine which"
                                   " API version is supported.")

        assert message == ("API request failed with HTTP Status 200"
                           '\nDetails: Invalid API version "2.11.0".'
                           "\nAction: Change the API version to one supported"
                           " by your version of the Delphix Engine."
                           " Review the Release Notes for your"
                           " Delphix Engine version to determine which"
                           " API version is supported.")

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u"/resources/json/delphix/session"
예제 #3
0
    def test_delphix_client_upload_fail(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header)

        token_body, token_header = TestDelphixClient.TOKEN_RESP_SUCCESS
        httpretty.register_uri(httpretty.POST,
                               'http://test-engine.com/resources/'
                               'json/delphix/toolkit/requestUploadToken',
                               body=token_body,
                               forcing_headers=token_header)

        upload_body, upload_header = TestDelphixClient.UPLOAD_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/data/upload',
            body=upload_body,
            forcing_headers=upload_header)

        dc = delphix_client.DelphixClient('test-engine.com')
        dc.login(engine_api, 'admin', 'delphix')

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.upload_plugin('plugin name', artifact_content)
        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 200
        assert error['details'] == ('The schema "repositorySchema" in the'
                                    ' "DiscoveryDefinition" cannot be updated'
                                    ' because there exist objects that conform'
                                    ' to the original schema.')
        assert error['action'] == ('Delete the following objects and try'
                                   ' again: db_centos75_157_2,'
                                   'db_centos75_157_1,db_centos75_157_0')

        assert message == ('API request failed with HTTP Status 200'
                           '\nDetails: The schema "repositorySchema" in the'
                           ' "DiscoveryDefinition" cannot be updated because'
                           ' there exist objects that conform to the original'
                           ' schema.'
                           '\nAction: Delete the following objects and try'
                           ' again: db_centos75_157_2,db_centos75_157_1,'
                           'db_centos75_157_0')

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u'/resources/json/delphix/data/upload'
        assert (history[-2].path ==
                u'/resources/json/delphix/toolkit/requestUploadToken')
        assert history[-3].path == u'/resources/json/delphix/login'
        assert history[-4].path == u'/resources/json/delphix/session'
예제 #4
0
    def test_delphix_client_wrong_api(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        dc = delphix_client.DelphixClient('test-engine.com')

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.login(engine_api, 'admin', 'delphix')

        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 200
        assert error['details'] == 'Invalid API version "2.11.0".'
        assert error['action'] == ('Change the API version to one supported'
                                   ' by your version of the Delphix Engine.'
                                   ' Review the Release Notes for your'
                                   ' Delphix Engine version to determine which'
                                   ' API version is supported.')

        assert message == ('API request failed with HTTP Status 200'
                           '\nDetails: Invalid API version "2.11.0".'
                           '\nAction: Change the API version to one supported'
                           ' by your version of the Delphix Engine.'
                           ' Review the Release Notes for your'
                           ' Delphix Engine version to determine which'
                           ' API version is supported.')

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u'/resources/json/delphix/session'
예제 #5
0
def download_logs(engine, plugin_config, user, password, directory):
    """
    Download plugin logs from a Delphix Engine.

    Args:
        engine: Delphix Engine hostname or IP address
        plugin_config: Config file to fetch plugin name
        user: User to log in to the Delphix Engine
        password: Password for the user to log in to the Delphix Engine
        directory: Directory of where plugin logs should be downloaded

    Raises specifically:
        UserError
        HttpError
        UnexpectedError
    """
    logger.debug('Download parameters include'
                 ' engine: {},'
                 ' plugin_config: {}'
                 ' user: {},'
                 ' directory: {}'.format(engine, plugin_config, user,
                                         directory))
    logger.info('Downloading plugin logs from {} to: {}'.format(
        engine, directory))

    # Create a new delphix session.
    client = delphix_client.DelphixClient(engine)
    client.login(package_util.get_engine_api_version(), user, password)
    client.download_plugin_logs(directory, plugin_config)
예제 #6
0
    def test_delphix_client_download_success(engine_api, src_dir,
                                             plugin_config_file):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header)

        plugin_body = TestDelphixClient.PLUGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.GET,
            'http://test-engine.com/resources/json/delphix/toolkit',
            body=plugin_body)

        download_token_body, download_token_header = (
            TestDelphixClient.DOWNLOAD_TOKEN_RESP_SUCCESS)
        httpretty.register_uri(httpretty.POST,
                               'http://test-engine.com/resources/json/delphix/'
                               'service/support/bundle/generate',
                               body=download_token_body,
                               forcing_headers=download_token_header)

        httpretty.register_uri(
            httpretty.GET, 'http://test-engine.com/resources/json/delphix/'
            'data/downloadOutputStream'
            '?token=5d6d5bb8-0f71-4304-8922-49c4c95c2387',
            forcing_headers=TestDelphixClient.DOWNLOAD_HEADER)

        dc = delphix_client.DelphixClient('test-engine.com')
        dc.login(engine_api, 'admin', 'delphix')
        dc.download_plugin_logs(src_dir, plugin_config_file)

        history = httpretty.HTTPretty.latest_requests
        assert (history[-1].path ==
                u'/resources/json/delphix/data/downloadOutputStream'
                u'?token=5d6d5bb8-0f71-4304-8922-49c4c95c2387')
        assert history[-2].path == (
            u'/resources/json/delphix/service/support/bundle/generate')
        assert history[-3].path == u'/resources/json/delphix/toolkit'
        assert history[-4].path == u'/resources/json/delphix/login'
        assert history[-5].path == u'/resources/json/delphix/session'
        assert os.path.isfile(
            os.path.join(
                src_dir, 'dlpx-plugin-logs-python_vfiles-'
                '5d6d5bb8-0f71-4304-8922-49c4c95c2387.tar.gz'))
예제 #7
0
def upload(engine, user, upload_artifact, password, wait):
    """
    Takes in the engine hostname/ip address, logs on and uploads the artifact
    passed in. The upload artifact should have been generated via the build
    command from a plugin. The file is expected to contain the delphix api
    version as well as be in the json format. During the process, print any
    errors that occur cleanly.

    Raises specifically:
        UserError
        InvalidArtifactError
        HttpError
        UnexpectedError
        PluginUploadJobFailed
        PluginUploadWaitTimedOut
    """
    logger.debug('Upload parameters include'
                 ' engine: {},'
                 ' user: {},'
                 ' upload_artifact: {},'
                 ' wait: {}'.format(engine, user, upload_artifact, wait))
    logger.info('Uploading plugin artifact {} ...'.format(upload_artifact))

    # Read content of upload artifact
    try:
        with open(upload_artifact, 'rb') as f:
            try:
                content = json.load(f)
            except ValueError:
                raise exceptions.UserError(
                    'Upload failed because the upload artifact was not a valid'
                    ' json file. Verify the file was built using the delphix'
                    ' build command.')
    except IOError as err:
        raise exceptions.UserError(
            'Unable to read upload artifact file \'{}\''
            '\nError code: {}. Error message: {}'.format(
                upload_artifact, err.errno,
                errno.errorcode.get(err.errno, UNKNOWN_ERR)))

    # Create a new delphix session.
    client = delphix_client.DelphixClient(engine)
    engine_api = client.get_engine_api(content)
    client.login(engine_api, user, password)
    client.upload_plugin(os.path.basename(upload_artifact), content, wait)
예제 #8
0
    def test_delphix_client_wait_for_job_to_complete_timed_out(
            engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header)

        token_body, token_header = TestDelphixClient.TOKEN_RESP_SUCCESS
        httpretty.register_uri(httpretty.POST,
                               'http://test-engine.com/resources/'
                               'json/delphix/toolkit/requestUploadToken',
                               body=token_body,
                               forcing_headers=token_header)

        job_body, job_header = TestDelphixClient.JOB_RESP_TIMED_OUT
        httpretty.register_uri(httpretty.GET,
                               'http://test-engine.com/resources/json/'
                               'delphix/action/ACTION-161/getJob',
                               body=job_body)

        dc = delphix_client.DelphixClient('test-engine.com', 0)
        dc.login(engine_api, 'admin', 'delphix')

        with pytest.raises(exceptions.PluginUploadWaitTimedOut) as err_info:
            dc._wait_for_upload_to_complete('nix_direct_python', 'ACTION-161',
                                            'JOB-38')

        assert err_info.value.message == ('Timed out waiting for upload of '
                                          'plugin nix_direct_python to '
                                          'complete.')

        history = httpretty.HTTPretty.latest_requests
        assert (history[-1].path ==
                u'/resources/json/delphix/action/ACTION-161/getJob')
        assert history[-2].path == u'/resources/json/delphix/login'
        assert history[-3].path == u'/resources/json/delphix/session'
예제 #9
0
    def test_delphix_client_get_token_fail(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
        )

        token_body, token_header = TestDelphixClient.TOKEN_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/"
            "json/delphix/toolkit/requestUploadToken",
            body=token_body,
            forcing_headers=token_header,
            status=403,
        )

        dc = delphix_client.DelphixClient("test-engine.com")
        dc.login(engine_api, "admin", "delphix")

        with pytest.raises(exceptions.UnexpectedError) as err_info:
            dc.upload_plugin("plugin name", artifact_content)

        assert err_info.value.status_code == 403
        assert err_info.value.response == token_body
        assert err_info.value.message == (
            "Received an unexpected error with HTTP Status 403,\nDumping full"
            " response:\n{}".format(token_body))

        history = httpretty.HTTPretty.latest_requests
        assert history[
            -1].path == u"/resources/json/delphix/toolkit/requestUploadToken"
        assert history[-2].path == u"/resources/json/delphix/login"
        assert history[-3].path == u"/resources/json/delphix/session"
예제 #10
0
    def test_delphix_client_upload_success(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
        )

        token_body, token_header = TestDelphixClient.TOKEN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/"
            "json/delphix/toolkit/requestUploadToken",
            body=token_body,
            forcing_headers=token_header,
        )

        upload_body, upload_header = TestDelphixClient.UPLOAD_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/data/upload",
            body=upload_body,
            forcing_headers=upload_header,
        )

        dc = delphix_client.DelphixClient("test-engine.com")
        dc.login(engine_api, "admin", "delphix")
        dc.upload_plugin("plugin name", artifact_content)

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u"/resources/json/delphix/data/upload"
        assert history[
            -2].path == u"/resources/json/delphix/toolkit/requestUploadToken"
        assert history[-3].path == u"/resources/json/delphix/login"
        assert history[-4].path == u"/resources/json/delphix/session"
예제 #11
0
    def test_request_timeout(mock_post, engine_api):
        mock_post.side_effect = requests.Timeout('Connection timed out.')

        dc = delphix_client.DelphixClient('test-engine.com')

        with pytest.raises(exceptions.UserError) as err_info:
            dc.login(engine_api, 'admin', 'delphix')

        message = err_info.value.message
        assert message == ('Encountered a http request failure.'
                           '\nConnection timed out.')

        mock_post.assert_called_once_with(
            data=json.dumps({
                'version': engine_api,
                'type': 'APISession'
            }),
            headers={'Content-type': 'application/json'},
            url='http://test-engine.com/resources/json/delphix/session')
예제 #12
0
    def test_request_timeout(mock_post, engine_api):
        mock_post.side_effect = requests.Timeout("Connection timed out.")

        dc = delphix_client.DelphixClient("test-engine.com")

        with pytest.raises(exceptions.UserError) as err_info:
            dc.login(engine_api, "admin", "delphix")

        message = err_info.value.message
        assert message == ("Encountered a http request failure."
                           "\nConnection timed out.")

        mock_post.assert_called_once_with(
            data=json.dumps({
                "version": engine_api,
                "type": "APISession"
            }),
            headers={"Content-type": "application/json"},
            url="http://test-engine.com/resources/json/delphix/session",
        )
예제 #13
0
    def test_delphix_client_wrong_login_no_detail(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_NO_DETAIL_FAIL
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
            status=401,
        )

        dc = delphix_client.DelphixClient("test-engine.com")

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.login(engine_api, "admin2", "delphix")

        message = err_info.value.message
        assert err_info.value.status_code == 401
        assert message == ("API request failed with HTTP Status 401"
                           "\nUnable to parse details of error."
                           " Dumping full response: {"
                           '\n  "commandOutput": null, '
                           '\n  "diagnoses": [], '
                           '\n  "type": "APIError", '
                           '\n  "id": "exception.webservices.login.failed", '
                           '\n  "error": "Not a real error: Invalid username'
                           " or password. Try with a different set of"
                           ' credentials."'
                           "\n}")

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u"/resources/json/delphix/login"
        assert history[-2].path == u"/resources/json/delphix/session"
예제 #14
0
    def test_delphix_client_get_token_fail(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header)

        token_body, token_header = TestDelphixClient.TOKEN_RESP_FAIL
        httpretty.register_uri(httpretty.POST,
                               'http://test-engine.com/resources/'
                               'json/delphix/toolkit/requestUploadToken',
                               body=token_body,
                               forcing_headers=token_header,
                               status=403)

        dc = delphix_client.DelphixClient('test-engine.com')
        dc.login(engine_api, 'admin', 'delphix')

        with pytest.raises(exceptions.UnexpectedError) as err_info:
            dc.upload_plugin('plugin name', artifact_content, False)

        assert err_info.value.status_code == 403
        assert err_info.value.response == token_body
        assert err_info.value.message == (
            'Received an unexpected error with HTTP Status 403,\nDumping full'
            ' response:\n{}'.format(token_body))

        history = httpretty.HTTPretty.latest_requests
        assert (history[-1].path ==
                u'/resources/json/delphix/toolkit/requestUploadToken')
        assert history[-2].path == u'/resources/json/delphix/login'
        assert history[-3].path == u'/resources/json/delphix/session'
예제 #15
0
    def test_delphix_client_upload_success(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header)

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/login',
            body=login_body,
            forcing_headers=login_header)

        token_body, token_header = TestDelphixClient.TOKEN_RESP_SUCCESS
        httpretty.register_uri(httpretty.POST,
                               'http://test-engine.com/resources/'
                               'json/delphix/toolkit/requestUploadToken',
                               body=token_body,
                               forcing_headers=token_header)

        upload_body, upload_header = TestDelphixClient.UPLOAD_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/data/upload',
            body=upload_body,
            forcing_headers=upload_header)

        dc = delphix_client.DelphixClient('test-engine.com')
        dc.login(engine_api, 'admin', 'delphix')
        dc.upload_plugin('plugin name', artifact_content)

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u'/resources/json/delphix/data/upload'
        assert (history[-2].path ==
                u'/resources/json/delphix/toolkit/requestUploadToken')
        assert history[-3].path == u'/resources/json/delphix/login'
        assert history[-4].path == u'/resources/json/delphix/session'
예제 #16
0
    def test_delphix_client_unknown_error(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_UNKNOWN_FAIL
        httpretty.register_uri(
            httpretty.POST,
            'http://test-engine.com/resources/json/delphix/session',
            body=session_body,
            forcing_headers=session_header,
            status=404)

        dc = delphix_client.DelphixClient('test-engine.com')

        with pytest.raises(exceptions.UnexpectedError) as err_info:
            dc.login(engine_api, 'admin', 'delphix')

        assert err_info.value.status_code == 404
        assert err_info.value.response == (
            '{\n  "status": "UNKNOWN", \n  "blob": "Unknown"\n}')
        assert err_info.value.message == (
            'Received an unexpected error with HTTP Status 404,\nDumping full'
            ' response:\n{\n  "status": "UNKNOWN", \n  "blob": "Unknown"\n}')

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u'/resources/json/delphix/session'
예제 #17
0
    def test_delphix_client_wrong_login(engine_api):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
            status=401,
        )

        dc = delphix_client.DelphixClient("test-engine.com")

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.login(engine_api, "admin2", "delphix")

        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 401
        assert error["details"] == "Invalid username or password."
        assert error["action"] == "Try with a different set of credentials."
        assert message == (
            "API request failed with HTTP Status 401"
            "\nDetails: Invalid username or password."
            "\nAction: Try with a different set of credentials.")

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u"/resources/json/delphix/login"
        assert history[-2].path == u"/resources/json/delphix/session"
예제 #18
0
    def test_delphix_client_download_success(engine_api, src_dir,
                                             plugin_config_file):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
        )

        plugin_body = TestDelphixClient.PLUGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.GET,
            "http://test-engine.com/resources/json/delphix/toolkit",
            body=plugin_body,
        )

        download_token_body, download_token_header = (
            TestDelphixClient.DOWNLOAD_TOKEN_RESP_SUCCESS)
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/"
            "service/support/bundle/generate",
            body=download_token_body,
            forcing_headers=download_token_header,
        )

        httpretty.register_uri(
            httpretty.GET,
            "http://test-engine.com/resources/json/delphix/"
            "data/downloadOutputStream"
            "?token=5d6d5bb8-0f71-4304-8922-49c4c95c2387",
            forcing_headers=TestDelphixClient.DOWNLOAD_HEADER,
        )

        dc = delphix_client.DelphixClient("test-engine.com")
        dc.login(engine_api, "admin", "delphix")
        dc.download_plugin_logs(src_dir, plugin_config_file)

        history = httpretty.HTTPretty.latest_requests
        assert (history[-1].path ==
                u"/resources/json/delphix/data/downloadOutputStream"
                u"?token=5d6d5bb8-0f71-4304-8922-49c4c95c2387")
        assert history[-2].path == (
            u"/resources/json/delphix/service/support/bundle/generate")
        assert history[-3].path == u"/resources/json/delphix/toolkit"
        assert history[-4].path == u"/resources/json/delphix/login"
        assert history[-5].path == u"/resources/json/delphix/session"
        assert os.path.isfile(
            os.path.join(
                src_dir,
                "dlpx-plugin-logs-python_vfiles-"
                "5d6d5bb8-0f71-4304-8922-49c4c95c2387.tar.gz",
            ))
예제 #19
0
    def test_delphix_client_upload_fail(engine_api, artifact_content):
        session_body, session_header = TestDelphixClient.SES_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/session",
            body=session_body,
            forcing_headers=session_header,
        )

        login_body, login_header = TestDelphixClient.LOGIN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/login",
            body=login_body,
            forcing_headers=login_header,
        )

        token_body, token_header = TestDelphixClient.TOKEN_RESP_SUCCESS
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/"
            "json/delphix/toolkit/requestUploadToken",
            body=token_body,
            forcing_headers=token_header,
        )

        upload_body, upload_header = TestDelphixClient.UPLOAD_RESP_FAIL
        httpretty.register_uri(
            httpretty.POST,
            "http://test-engine.com/resources/json/delphix/data/upload",
            body=upload_body,
            forcing_headers=upload_header,
        )

        dc = delphix_client.DelphixClient("test-engine.com")
        dc.login(engine_api, "admin", "delphix")

        with pytest.raises(exceptions.HttpError) as err_info:
            dc.upload_plugin("plugin name", artifact_content)
        error = err_info.value.error
        message = err_info.value.message
        assert err_info.value.status_code == 200
        assert error["details"] == ('The schema "repositorySchema" in the'
                                    ' "DiscoveryDefinition" cannot be updated'
                                    " because there exist objects that conform"
                                    " to the original schema.")
        assert error["action"] == ("Delete the following objects and try"
                                   " again: db_centos75_157_2,"
                                   "db_centos75_157_1,db_centos75_157_0")

        assert message == ("API request failed with HTTP Status 200"
                           '\nDetails: The schema "repositorySchema" in the'
                           ' "DiscoveryDefinition" cannot be updated because'
                           " there exist objects that conform to the original"
                           " schema."
                           "\nAction: Delete the following objects and try"
                           " again: db_centos75_157_2,db_centos75_157_1,"
                           "db_centos75_157_0")

        history = httpretty.HTTPretty.latest_requests
        assert history[-1].path == u"/resources/json/delphix/data/upload"
        assert history[
            -2].path == u"/resources/json/delphix/toolkit/requestUploadToken"
        assert history[-3].path == u"/resources/json/delphix/login"
        assert history[-4].path == u"/resources/json/delphix/session"