Skip to content

Commit 4e1eb04

Browse files
[load] locust tests support (#8409)
* [load] support multi-region load test configuration * refactor * update recordings * azdev style load * refactor yaml keys to constants file * refactor test load test * update recordings * azdev style load * update help text * update help text * action on comments * refactor test regional-load autostop * check for valid region names client-side * [load] support advanced url tests * action on comments * action on comments * action on comments * update recordings * action on comments * update test and recordings * refactor test exception scenarios * azdev style load * [load] dashboard reports | debug mode | copy artifacts sas url * action on comments * update recordings * set copy artifacts ut live-only * change copy-artifacts to get-artifacts * update recordings * [load] download-files high scale test update console message * [load] download-files high scale test update console message * remove unused import * update texts * update texts * [load] convert test to jmx * update comment * update prompt text * [load] baseline trends | sas download * unit tests and recordings * trends aggregate param,unit tests, recordings * update HISTORY.rst * remove faulty recording * action copilot review Co-authored-by: Copilot <[email protected]> * undo faulty commit by copilot * test instruction * action on comments * [load] locust test type support * [load] locust test type support * azdev mask recordings * update HISTORY.rst * copyright in locust script * azdev scan fix for locust file * fix history order * rerun locust test * run azdev scan --------- Co-authored-by: Copilot <[email protected]>
1 parent 4ba829a commit 4e1eb04

File tree

13 files changed

+3093
-4
lines changed

13 files changed

+3093
-4
lines changed

src/load/HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
33
Release History
44
===============
5+
6+
7+
1.5.0
8+
++++++
9+
* Add support for Locust based load tests.
10+
11+
512
1.4.3
613
++++++
714
* Updated the vendored_sdks to include 2024-12-01-preview data plane API version.

src/load/azext_load/data_plane/load_test/custom.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os
99

10+
from azext_load.data_plane.utils.constants import LoadTestConfigKeys
1011
from azext_load.data_plane.utils.utils import (
1112
convert_yaml_to_test,
1213
create_autostop_criteria_from_args,
@@ -16,6 +17,7 @@
1617
generate_trends_row,
1718
get_admin_data_plane_client,
1819
get_testrun_data_plane_client,
20+
infer_test_type_from_test_plan,
1921
load_yaml,
2022
upload_file_to_test,
2123
upload_files_helper,
@@ -71,6 +73,8 @@ def create_test(
7173
autostop_criteria = create_autostop_criteria_from_args(
7274
autostop=autostop, error_rate=autostop_error_rate, time_window=autostop_error_rate_time_window)
7375
if load_test_config_file is None:
76+
test_type = test_type or infer_test_type_from_test_plan(test_plan)
77+
logger.debug("Inferred test type: %s", test_type)
7478
body = create_or_update_test_without_config(
7579
test_id,
7680
body,
@@ -91,6 +95,13 @@ def create_test(
9195
else:
9296
yaml = load_yaml(load_test_config_file)
9397
yaml_test_body = convert_yaml_to_test(cmd, yaml)
98+
test_type = (
99+
test_type or
100+
yaml.get(LoadTestConfigKeys.TEST_TYPE) or
101+
infer_test_type_from_test_plan(test_plan) or
102+
infer_test_type_from_test_plan(yaml.get(LoadTestConfigKeys.TEST_PLAN))
103+
)
104+
logger.debug("Inferred test type: %s", test_type)
94105
body = create_or_update_test_with_config(
95106
test_id,
96107
body,

src/load/azext_load/data_plane/load_test/help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
- name: Create an advanced URL test with multiple HTTP requests using a JSON file.
4444
text: |
4545
az load test create --test-id sample-test-id --load-test-resource sample-alt-resource --resource-group sample-rg --test-plan ~/resources/sample-url-requests.json --test-type URL
46+
- name: Create a Locust based load test
47+
text: |
48+
az load test create --test-id sample-test-id --load-test-resource sample-alt-resource --resource-group sample-rg --test-plan ~/resources/sample-locust-file.py --test-type Locust --env LOCUST_HOST="https://azure.microsoft.com" LOCUST_SPAWN_RATE=0.3 LOCUST_RUN_TIME=120 LOCUST_USERS=4
4649
"""
4750

4851
helps[

src/load/azext_load/data_plane/utils/argtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
validator=validators.validate_test_plan_path,
9393
options_list=["--test-plan"],
9494
type=str,
95-
help="Reference to the test plan file. If `testType: JMX`: path to the JMeter script. If `testType: URL`: path to the requests JSON file.",
95+
help="Reference to the test plan file. If `testType: JMX`: path to the JMeter script. If `testType: URL`: path to the requests JSON file. If `testType: Locust`: path to the Locust test script.",
9696
)
9797

9898
test_type = CLIArgumentType(

src/load/azext_load/data_plane/utils/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ class AllowedMetricNamespaces(str, Enum):
3636
class AllowedTestTypes(str, Enum):
3737
JMX = "JMX"
3838
URL = "URL"
39+
LOCUST = "Locust"
3940

4041

4142
class AllowedTestPlanFileExtensions(str, Enum):
4243
JMX = ".jmx"
4344
URL = ".json"
45+
LOCUST = ".py"
4446

4547

4648
class AllowedTrendsResponseTimeAggregations(str, Enum):

src/load/azext_load/data_plane/utils/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id
2121
from knack.log import get_logger
2222

23-
from .models import IdentityType, AllowedFileTypes, AllowedTestTypes
23+
from .models import IdentityType, AllowedFileTypes, AllowedTestTypes, AllowedTestPlanFileExtensions
2424

2525
logger = get_logger(__name__)
2626

@@ -754,6 +754,19 @@ def upload_zipped_artifacts_helper(
754754
)
755755

756756

757+
def infer_test_type_from_test_plan(test_plan):
758+
if test_plan is None:
759+
return None
760+
_, file_extension = os.path.splitext(test_plan)
761+
if file_extension.casefold() == AllowedTestPlanFileExtensions.JMX.value:
762+
return AllowedTestTypes.JMX.value
763+
if file_extension.casefold() == AllowedTestPlanFileExtensions.URL.value:
764+
return AllowedTestTypes.URL.value
765+
if file_extension.casefold() == AllowedTestPlanFileExtensions.LOCUST.value:
766+
return AllowedTestTypes.LOCUST.value
767+
return None
768+
769+
757770
def _evaluate_file_type_for_test_script(test_type, test_plan):
758771
if test_type == AllowedTestTypes.URL.value:
759772
_, file_extension = os.path.splitext(test_plan)

src/load/azext_load/tests/latest/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class LoadConstants:
121121

122122
HIGH_SCALE_LOAD_TEST_CONFIG_FILE = os.path.join(TEST_RESOURCES_DIR, r"config-high-scale-load.yaml")
123123

124+
LOCUST_TEST_CONFIG_FILE = os.path.join(TEST_RESOURCES_DIR, r"config-locust.yaml")
125+
LOCUST_ENV_VARIABLES = 'LOCUST_HOST="https://www.google.com" LOCUST_SPAWN_RATE=0.3 LOCUST_RUN_TIME=120 LOCUST_USERS=4'
126+
LOCUST_TEST_PLAN = os.path.join(TEST_RESOURCES_DIR, r"sample-locust-file.py")
127+
LOCUST_TEST_PLAN_FILENAME = "sample-locust-file.py"
128+
124129

125130
class LoadTestConstants(LoadConstants):
126131
# Test IDs for load test commands
@@ -142,6 +147,7 @@ class LoadTestConstants(LoadConstants):
142147
LOAD_TEST_ADVANCED_URL_ID = "loadtest-advanced-url-case"
143148
LOAD_TEST_CONVERT_TO_JMX_ID = "loadtest-convert-to-jmx-case"
144149
LOAD_TEST_BASELINE_TRENDS_ID = "loadtest-baseline-trends-case"
150+
LOCUST_LOAD_TEST_ID = "loadtest-locust-case"
145151

146152
INVALID_UPDATE_TEST_ID = "invalid-update-test-case"
147153
INVALID_PF_TEST_ID = "invalid-pf-test-case"

0 commit comments

Comments
 (0)