Ejemplo n.º 1
0
    def __call__(self):
        request = HTTPRequest(url="http://localhost:7001")
        Test(1, "Basic request").record(request)

        # Example 1. You can get the time of the last test as follows.
        result = request.GET("index.html")

        grinder.logger.info("The last test took %d milliseconds" %
                            grinder.statistics.forLastTest.time)

        # Example 2. Normally test results are reported automatically
        # when the test returns. If you want to alter the statistics
        # after a test has completed, you must set delayReports = 1 to
        # delay the reporting before performing the test. This only
        # affects the current worker thread.
        grinder.statistics.delayReports = 1

        result = request.GET("index.html")

        if grinder.statistics.forLastTest.time > 5:
            # We set success = 0 to mark the test as a failure. The test
            # time will be reported to the data log, but not included
            # in the aggregate statistics sent to the console or the
            # summary table.
            grinder.statistics.forLastTest.success = 0

        # With delayReports = 1 you can call report() to explicitly.
        grinder.statistics.report()

        # You can also turn the automatic reporting back on.
        grinder.statistics.delayReports = 0

        # Example 3.
        # getForCurrentTest() accesses statistics for the current test.
        # getForLastTest() accesses statistics for the last completed test.

        def page(self):
            resourceRequest = HTTPRequest(url="http://localhost:7001")
            Test(2, "Request resource").record(resourceRequest)

            resourceRequest.GET("index.html")
            resourceRequest.GET("foo.css")

            grinder.logger.info("GET foo.css returned a %d byte body" %
                                grinder.statistics.forLastTest.getLong(
                                    "httpplugin.responseLength"))

            grinder.logger.info("Page has taken %d ms so far" %
                                grinder.statistics.forCurrentTest.time)

            if grinder.statistics.forLastTest.time > 10:
                grinder.statistics.forCurrentTest.success = 0

            resourceRequest.GET("image.gif")

        instrumentedPage = page
        Test(3, "Page").record(instrumentedPage)

        instrumentedPage(self)
Ejemplo n.º 2
0
def httpGet(url, params=None):
    try:
        request = HTTPRequest()
        if params is not None:
            return request.GET(url, params)
        else:
            return request.GET(url)

    except SSLProtocolException, e:
        log("SSL error for %s: %s" % (url, e))
        return None
Ejemplo n.º 3
0
        def page(self):
            resourceRequest = HTTPRequest(url="http://localhost:7001")
            Test(2, "Request resource").record(resourceRequest)

            resourceRequest.GET("index.html")
            resourceRequest.GET("foo.css")

            grinder.logger.info("GET foo.css returned a %d byte body" %
                                grinder.statistics.forLastTest.getLong(
                                    "httpplugin.responseLength"))

            grinder.logger.info("Page has taken %d ms so far" %
                                grinder.statistics.forCurrentTest.time)

            if grinder.statistics.forLastTest.time > 10:
                grinder.statistics.forCurrentTest.success = 0

            resourceRequest.GET("image.gif")
Ejemplo n.º 4
0
    def __call__(self):

        grinder.SSLControl.setKeyStoreFile("mykeystore.jks", "123456")

        for index in range(len(vo_keys)):
            vo = vo_keys[index]
            test = Test(index, "VOMS AC for VO " + vo)
            request = HTTPRequest()
            test.record(request)
            port = list_vo[vo]
            url = "https://" + host + ":" + str(port) + resource

            grinder.statistics.delayReports = 1

            result = str(request.GET(url))

            if not '200 OK' in result:
                grinder.statistics.forLastTest.success = 0
                grinder.statistics.report()

            grinder.statistics.delayReports = 0
Ejemplo n.º 5
0
    def http_open(self, req):
        greq = HTTPRequest()

        url = req.get_full_url()
        payload = req.get_data()
        headers = []
        for k, v in req.headers.items():
            headers.append(NVPair(k, v))

        if req.get_method() == 'GET':
            gresp = greq.GET(url, payload, headers)
        elif req.get_method() == 'POST':
            gresp = greq.POST(url, payload, headers)
        elif req.get_method() == 'PUT':
            gresp = greq.PUT(url, payload, headers)
        elif req.get_method() == 'DELETE':
            gresp = greq.DELETE(url, payload, headers)
        else:
            raise ValueError("HTTP method " + req.get_method() +
                             " isn't supported")

        return self.GrinderHTTPResponse(gresp)
Ejemplo n.º 6
0
class G2HTTPTest:
    """Parses parameters for an individual test and records the test
    invocation using a G3 Test."""
    def __init__(self, testNumber, properties):
        self.sleepTime = properties["sleepTime"]

        headers = []
        seenContentType = 0

        for e in properties.getPropertySubset("parameter.header.").entrySet():
            headers.append(NVPair(e.key, e.value))
            if not seenContentType and e.key.lower() == "content-type":
                seenContentType = 1

        postDataFilename = properties["parameter.post"]

        if postDataFilename:
            file = open(postDataFilename)
            self.postData = file.read()
            file.close()

            if not seenContentType:
                headers.append(
                    NVPair("Content-type",
                           "application/x-www-form-urlencoded"))

        else:
            self.postData = None

        self.okString = properties["parameter.ok"]
        self.url = properties["parameter.url"]

        realm = properties["basicAuthenticationRealm"]
        user = properties["basicAuthenticationUser"]
        password = properties["basicAuthenticationPassword"]

        if realm and user and password:
            self.basicAuthentication = (realm, user, password)

        elif not realm and not user and not password:
            self.basicAuthentication = None

        else:
            raise "If you specify one of { basicAuthenticationUser, basicAuthenticationRealm, basicAuthenticationPassword } you must specify all three."

        self.request = HTTPRequest(headers=headers)
        self.test = Test(testNumber, properties["description"])
        self.test.record(self.request)

    def doTest(self, iteration):

        if self.basicAuthentication:
            connection = HTTPPluginControl.getThreadConnection(self.url)

            connection.addBasicAuthorization(self.basicAuthentication[0],
                                             self.basicAuthentication[1],
                                             self.basicAuthentication[2])

        grinder.statistics.delayReports = 1

        if self.postData:
            page = self.request.POST(self.url, self.postData).text
        else:
            page = self.request.GET(self.url).text

        if not page:
            error = self.okString
        else:
            error = self.okString and page.find(self.okString) == -1

            if error or logHTML:
                if self.test.description:
                    description = "_%s" % self.test.description
                else:
                    description = ""

                filename = grinder.filenameFactory.createFilename(
                    "page",
                    "_%d_%.3d%s" % (iteration, self.test.number, description))

                file = open(filename, "w")
                print >> file, page
                file.close()

                if error:
                    grinder.logger.error(
                        "The 'ok' string ('%s') was not found in the page "
                        "received. The output has been written to '%s'." %
                        (self.okString, filename))

        if error:
            grinder.statistics.forLastTest.success = 0

        if self.sleepTime:
            grinder.sleep(long(self.sleepTime))
Ejemplo n.º 7
0
from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPPlugin
from net.grinder.plugin.http import HTTPRequest

request = HTTPRequest()
output.startMeasure("Grinder_Demo_Transaction1")
result = request.GET(input.getString("url"))
output.stopMeasure()
output.add("out", result.text)