Skip to content

Commit 9223c8a

Browse files
authored
Fleet Provisioning Service Tests (#540)
* Fleet Provisioning Service Tests * Add CSR config files * fix pythong file path * Fix config path names * Add support for mqtt version parameter * add thing name previs * Add mqtt5 support * add mqtt5 variables * Fix syntax error * Fix syntax * Fix syntax * remove is ci flag and print statements
1 parent e297944 commit 9223c8a

9 files changed

+632
-1
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,32 @@ jobs:
208208
chmod a+x builder
209209
./builder build -p ${{ env.PACKAGE_NAME }}
210210
211+
- name: configure AWS credentials (service tests Fleet Provisioning)
212+
uses: aws-actions/configure-aws-credentials@v2
213+
with:
214+
role-to-assume: ${{ env.CI_FLEET_PROVISIONING_ROLE}}
215+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
216+
- name: run MQTT3 Fleet Provisioning
217+
working-directory: ./aws-iot-device-sdk-python-v2/servicetests
218+
run: |
219+
export PYTHONPATH=${{ github.workspace }}/aws-iot-device-sdk-python-v2/utils:${{ github.workspace }}/aws-iot-device-sdk-python-v2/samples
220+
python3 ./test_cases/test_fleet_provisioning.py --config-file test_cases/mqtt3_fleet_provisioning_cfg.json --thing-name-prefix Fleet_Thing_
221+
- name: run MQTT5 Fleet Provisioning
222+
working-directory: ./aws-iot-device-sdk-python-v2/servicetests
223+
run: |
224+
export PYTHONPATH=${{ github.workspace }}/aws-iot-device-sdk-python-v2/utils:${{ github.workspace }}/aws-iot-device-sdk-python-v2/samples
225+
python3 ./test_cases/test_fleet_provisioning.py --config-file test_cases/mqtt5_fleet_provisioning_cfg.json --thing-name-prefix Fleet_Thing_
226+
- name: run MQTT3 Fleet Provisioning with CSR
227+
working-directory: ./aws-iot-device-sdk-python-v2/servicetests
228+
run: |
229+
export PYTHONPATH=${{ github.workspace }}/aws-iot-device-sdk-python-v2/utils:${{ github.workspace }}/aws-iot-device-sdk-python-v2/samples
230+
python3 ./test_cases/test_fleet_provisioning.py --config-file test_cases/mqtt3_fleet_provisioning_with_csr_cfg.json --thing-name-prefix Fleet_Thing_
231+
- name: run MQTT5 Fleet Provisioning with CSR
232+
working-directory: ./aws-iot-device-sdk-python-v2/servicetests
233+
run: |
234+
export PYTHONPATH=${{ github.workspace }}/aws-iot-device-sdk-python-v2/utils:${{ github.workspace }}/aws-iot-device-sdk-python-v2/samples
235+
python3 ./test_cases/test_fleet_provisioning.py --config-file test_cases/mqtt5_fleet_provisioning_with_csr_cfg.json --thing-name-prefix Fleet_Thing_
236+
211237
- name: configure AWS credentials (service tests Shadow)
212238
uses: aws-actions/configure-aws-credentials@v2
213239
with:

samples/utils/command_line_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ def parse_sample_input_fleet_provisioning():
436436
cmdUtils.register_command(CommandLineUtils.m_cmd_csr, "<path>", "Path to CSR in Pem format (optional).")
437437
cmdUtils.register_command(CommandLineUtils.m_cmd_template_name, "<str>", "The name of your provisioning template.")
438438
cmdUtils.register_command(CommandLineUtils.m_cmd_template_parameters, "<json>", "Template parameters json.")
439+
cmdUtils.register_command(CommandLineUtils.m_cmd_mqtt_version, "<int>", "MQTT Version")
439440
cmdUtils.get_args()
440441

441442
cmdData = CommandLineUtils.CmdData()
@@ -451,6 +452,7 @@ def parse_sample_input_fleet_provisioning():
451452
cmdData.input_template_name = cmdUtils.get_command_required(CommandLineUtils.m_cmd_template_name)
452453
cmdData.input_template_parameters = cmdUtils.get_command_required(CommandLineUtils.m_cmd_template_parameters)
453454
cmdData.input_is_ci = cmdUtils.get_command(CommandLineUtils.m_cmd_is_ci, None) != None
455+
cmdData.input_mqtt_version = int(cmdUtils.get_command(CommandLineUtils.m_cmd_mqtt_version, 5))
454456
return cmdData
455457

456458
def parse_sample_input_jobs():
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"language": "Python",
3+
"runnable_file": "./tests/FleetProvisioning/fleet_provisioning.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--mqtt_version",
9+
"data": "3"
10+
},
11+
{
12+
"name": "--endpoint",
13+
"secret": "ci/endpoint"
14+
},
15+
{
16+
"name": "--cert",
17+
"secret": "ci/FleetProvisioning/cert",
18+
"filename": "tmp_certificate.pem"
19+
},
20+
{
21+
"name": "--key",
22+
"secret": "ci/FleetProvisioning/key",
23+
"filename": "tmp_key.pem"
24+
},
25+
{
26+
"name": "--template_name",
27+
"data": "CI_FleetProvisioning_Template"
28+
},
29+
{
30+
"name": "--template_parameters",
31+
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
32+
}
33+
]
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"language": "Python",
3+
"runnable_file": "./tests/FleetProvisioning/fleet_provisioning.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--mqtt_version",
9+
"data": "3"
10+
},
11+
{
12+
"name": "--endpoint",
13+
"secret": "ci/endpoint"
14+
},
15+
{
16+
"name": "--cert",
17+
"secret": "ci/FleetProvisioning/cert",
18+
"filename": "tmp_certificate.pem"
19+
},
20+
{
21+
"name": "--key",
22+
"secret": "ci/FleetProvisioning/key",
23+
"filename": "tmp_key.pem"
24+
},
25+
{
26+
"name": "--csr",
27+
"secret": "ci/FleetProvisioning/csr",
28+
"filename": "tmp_csr.pem"
29+
},
30+
{
31+
"name": "--template_name",
32+
"data": "CI_FleetProvisioning_Template"
33+
},
34+
{
35+
"name": "--template_parameters",
36+
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
37+
}
38+
]
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"language": "Python",
3+
"runnable_file": "./tests/FleetProvisioning/fleet_provisioning.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--mqtt_version",
9+
"data": "5"
10+
},
11+
{
12+
"name": "--endpoint",
13+
"secret": "ci/endpoint"
14+
},
15+
{
16+
"name": "--cert",
17+
"secret": "ci/FleetProvisioning/cert",
18+
"filename": "tmp_certificate.pem"
19+
},
20+
{
21+
"name": "--key",
22+
"secret": "ci/FleetProvisioning/key",
23+
"filename": "tmp_key.pem"
24+
},
25+
{
26+
"name": "--template_name",
27+
"data": "CI_FleetProvisioning_Template"
28+
},
29+
{
30+
"name": "--template_parameters",
31+
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
32+
}
33+
]
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"language": "Python",
3+
"runnable_file": "./tests/FleetProvisioning/fleet_provisioning.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--mqtt_version",
9+
"data": "5"
10+
},
11+
{
12+
"name": "--endpoint",
13+
"secret": "ci/endpoint"
14+
},
15+
{
16+
"name": "--cert",
17+
"secret": "ci/FleetProvisioning/cert",
18+
"filename": "tmp_certificate.pem"
19+
},
20+
{
21+
"name": "--key",
22+
"secret": "ci/FleetProvisioning/key",
23+
"filename": "tmp_key.pem"
24+
},
25+
{
26+
"name": "--csr",
27+
"secret": "ci/FleetProvisioning/csr",
28+
"filename": "tmp_csr.pem"
29+
},
30+
{
31+
"name": "--template_name",
32+
"data": "CI_FleetProvisioning_Template"
33+
},
34+
{
35+
"name": "--template_parameters",
36+
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
37+
}
38+
]
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0.
3+
4+
import argparse
5+
import uuid
6+
import os
7+
import sys
8+
import run_in_ci
9+
import ci_iot_thing
10+
11+
def main():
12+
argument_parser = argparse.ArgumentParser(
13+
description="Run Fleet Provisioning test in CI")
14+
argument_parser.add_argument(
15+
"--config-file", required=True,
16+
help="JSON file providing command-line arguments to a test")
17+
argument_parser.add_argument(
18+
"--thing-name-prefix", required=False, default="",
19+
help="Prefix for a thing name, should be the same that Fleet Provisioning template uses")
20+
argument_parser.add_argument(
21+
"--region", required=False, default="us-east-1", help="The name of the region to use")
22+
argument_parser.add_argument(
23+
"--input-uuid", required=False, help="UUID for thing name. UUID will be generated if this option is omit")
24+
parsed_commands = argument_parser.parse_args()
25+
26+
input_uuid = parsed_commands.input_uuid if parsed_commands.input_uuid else str(uuid.uuid4())
27+
28+
# Perform fleet provisioning. If it's successful, a newly created thing should appear.
29+
try:
30+
test_result = run_in_ci.setup_and_launch(parsed_commands.config_file, input_uuid)
31+
except Exception as e:
32+
print(f"ERROR: Failed to execute Fleet Provisioning test: {e}")
33+
test_result = -1
34+
35+
# Delete a thing created by fleet provisioning. If this fails, we assume that's because fleet provisioning failed to
36+
# create a thing.
37+
# NOTE We want to try to delete thing even if test was unsuccessful.
38+
try:
39+
thing_name = parsed_commands.thing_name_prefix + input_uuid
40+
ci_iot_thing.delete_iot_thing(thing_name, parsed_commands.region)
41+
except Exception as e:
42+
print(f"ERROR: Failed to delete thing: {e}")
43+
test_result = -1
44+
45+
if test_result != 0:
46+
sys.exit(-1)
47+
48+
if __name__ == "__main__":
49+
main()

0 commit comments

Comments
 (0)