diff --git a/doc/samples/tasks/scenarios/requests/check_response.json b/doc/samples/tasks/scenarios/requests/check_response.json new file mode 100644 index 0000000000..45cd72beaa --- /dev/null +++ b/doc/samples/tasks/scenarios/requests/check_response.json @@ -0,0 +1,15 @@ +{ + "Requests.check_response": [ + { + "args": { + "url": "http://www.google.com", + "response": 302 + }, + "runner": { + "type": "constant", + "times": 20, + "concurrency": 5 + }, + } + ] +} diff --git a/doc/samples/tasks/scenarios/requests/check_response.yaml b/doc/samples/tasks/scenarios/requests/check_response.yaml new file mode 100644 index 0000000000..732285b6b4 --- /dev/null +++ b/doc/samples/tasks/scenarios/requests/check_response.yaml @@ -0,0 +1,10 @@ +--- + Requests.check_response: + - + args: + url: "http://www.google.com" + response: 302 + runner: + type: "constant" + times: 20 + concurrency: 5 diff --git a/rally-scenarios/rally.yaml b/rally-scenarios/rally.yaml index a6c48c84be..67349616c9 100644 --- a/rally-scenarios/rally.yaml +++ b/rally-scenarios/rally.yaml @@ -846,3 +846,13 @@ users_per_tenant: 1 sla: max_failure_percent: 0 + + Requests.check_response: + - + args: + url: "http://www.google.com" + response: 302 + runner: + type: "constant" + times: 10 + concurrency: 5 diff --git a/rally/benchmark/scenarios/requests/__init__.py b/rally/benchmark/scenarios/requests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rally/benchmark/scenarios/requests/http_requests.py b/rally/benchmark/scenarios/requests/http_requests.py new file mode 100644 index 0000000000..3779a9fa9d --- /dev/null +++ b/rally/benchmark/scenarios/requests/http_requests.py @@ -0,0 +1,40 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import requests + +from rally.benchmark.scenarios import base as scenario_base +from rally import exceptions +from rally.openstack.common.gettextutils import _ + + +class WrongStatusException(exceptions.RallyException): + msg_fmt = _("Requests scenario exception: '%(message)s'") + + +class Requests(scenario_base.Scenario): + """This class should contain all the http_request scenarios.""" + + @scenario_base.scenario() + def check_response(self, url, response=None): + """Standard way to benchmark web services. + + This benchmark is used to GET a URL and check it with expected + Response. + + :param url: URL to be fetched + :param response: Expected Response Code + """ + resp = requests.head(url) + if response and response != resp.status_code: + error = "Expected Response and Actual Response not equal" + raise WrongStatusException(error) diff --git a/tests/benchmark/scenarios/requests/__init__.py b/tests/benchmark/scenarios/requests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/benchmark/scenarios/requests/test_http_requests.py b/tests/benchmark/scenarios/requests/test_http_requests.py new file mode 100644 index 0000000000..72fc7303a2 --- /dev/null +++ b/tests/benchmark/scenarios/requests/test_http_requests.py @@ -0,0 +1,31 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import mock + +from rally.benchmark.scenarios.requests import http_requests +from tests import test + +SCN = "rally.benchmark.scenarios" + + +class RequestsTestCase(test.TestCase): + + @mock.patch("%s.requests.http_requests.requests" % SCN) + def test_check_response(self, mock_requests): + mock_requests.head(mock.MagicMock()).status_code = 200 + Requests = http_requests.Requests() + + self.assertRaises(http_requests.WrongStatusException, + Requests.check_response, url="sample_url", + response=302)