forked from openstack/rally
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* (сheck-random-request) Add Multiple Http request scenario which takes as input a list of Requests and compares response of random picked request from the list with the expected Response. * (сheck-request) Improve flexiblity of check-response scenario and rename check-response to check-request. Co-Authored-By: kumar rishabh <shailrishabh@gmail.com> Co-Authored-By: Roman Vasilets <rvasilets@mirantis.com> Change-Id: Id70935616c013271392219b1e642b5b87ddb4b9c
- Loading branch information
1 parent
5c3a289
commit 260701f
Showing
11 changed files
with
205 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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 | ||
from rally.common.i18n import _ | ||
|
||
|
||
class RequestScenario(base.Scenario): | ||
"""Base class for Request scenarios with basic atomic actions.""" | ||
|
||
@base.atomic_action_timer("requests.check_request") | ||
def _check_request(self, url, method, status_code, **kwargs): | ||
"""Compare request status code with specified code | ||
:param status_code: Expected status code of request | ||
:param url: Uniform resource locator | ||
:param method: Type of request method (GET | POST ..) | ||
:param kwargs: Optional additional request parameters | ||
:raises: ValueError if return http status code | ||
not equal to expected status code | ||
""" | ||
|
||
resp = requests.request(method, url, **kwargs) | ||
if status_code != resp.status_code: | ||
error_msg = _("Expected HTTP request code is `%s` actual `%s`") | ||
raise ValueError( | ||
error_msg % (status_code, resp.status_code)) |
17 changes: 17 additions & 0 deletions
17
samples/tasks/scenarios/requests/check-random-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"HttpRequests.check_random_request": [ | ||
{ | ||
"args": { | ||
"requests": [{"url": "http://www.example.com", "method": "GET", | ||
"status_code": 200}, | ||
{"url": "http://www.openstack.org", "method": "GET"}], | ||
"status_code": 200 | ||
}, | ||
"runner": { | ||
"type": "constant", | ||
"times": 20, | ||
"concurrency": 5 | ||
} | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
samples/tasks/scenarios/requests/check-random-request.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
HttpRequests.check_random_request: | ||
- | ||
args: | ||
requests: | ||
- | ||
url: "http://www.example.com" | ||
method: "GET" | ||
status_code: 200 | ||
- | ||
url: "http://www.openstack.org" | ||
method: "GET" | ||
status_code: 200 | ||
runner: | ||
type: "constant" | ||
times: 20 | ||
concurrency: 5 |
8 changes: 5 additions & 3 deletions
8
...ks/scenarios/requests/check_response.json → ...sks/scenarios/requests/check-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
HttpRequests.check_request: | ||
- | ||
args: | ||
url: "http://www.example.com" | ||
method: "GET" | ||
status_code: 200 | ||
allow_redirects: False | ||
runner: | ||
type: "constant" | ||
times: 20 | ||
concurrency: 5 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 mock | ||
|
||
from rally.benchmark.scenarios.requests import utils | ||
from tests.unit import test | ||
|
||
SCN = "rally.benchmark.scenarios" | ||
|
||
|
||
class RequestsTestCase(test.TestCase): | ||
|
||
@mock.patch("requests.request") | ||
def test__check_request(self, mock_requests): | ||
mock_requests.return_value = mock.MagicMock(status_code=200) | ||
scenario = utils.RequestScenario() | ||
scenario._check_request(status_code=200, url="sample", method="GET") | ||
|
||
self._test_atomic_action_timer(scenario.atomic_actions(), | ||
"requests.check_request") | ||
mock_requests.assert_called_once_with("GET", "sample") | ||
|
||
@mock.patch("requests.request") | ||
def test_check_wrong_request(self, mock_requests): | ||
mock_requests.return_value = mock.MagicMock(status_code=200) | ||
scenario = utils.RequestScenario() | ||
|
||
self.assertRaises(ValueError, scenario._check_request, | ||
status_code=201, url="sample", method="GET") |