Skip to content

Implement fleet provisioning test #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3d2f290
Implemented fleet provisioning test
sfodagain Oct 29, 2023
b6a19ee
Merge branch 'main' into add-fleet-provisioning-test
sfod Oct 30, 2023
9c7b40c
Merge branch 'main' into add-fleet-provisioning-test
sfod Nov 1, 2023
378a351
Move deleting thing to separate module
sfodagain Nov 6, 2023
0c6fc93
Fix error message
sfodagain Nov 6, 2023
6ca2256
Cleanup code
sfodagain Nov 6, 2023
f10641b
Fix log message
sfodagain Nov 6, 2023
7a74ae8
fixup
sfodagain Nov 6, 2023
0e1a11f
fixup
sfodagain Nov 6, 2023
5e1306e
Mqtt3 and mqtt5 fleet provisioning
sfodagain Nov 7, 2023
912e098
Working version
sfodagain Nov 7, 2023
8a5c6ea
Fix CI
sfodagain Nov 7, 2023
f2fec2a
wip
sfodagain Nov 7, 2023
8ee50d2
wip
sfodagain Nov 7, 2023
21ea38a
Merge branch 'main' into add-fleet-provisioning-test
sfodagain Nov 14, 2023
c5f377d
Simplify test
sfodagain Nov 14, 2023
e1bd1d8
FIx CI
sfodagain Nov 14, 2023
b1098dd
FIx CI
sfodagain Nov 14, 2023
da04c2b
Reorganize service tests
sfodagain Nov 14, 2023
111b98e
Fix CI
sfodagain Nov 14, 2023
c10b373
Fix CI
sfodagain Nov 14, 2023
c8ab0aa
Fix CI
sfodagain Nov 14, 2023
953941e
Use cmdutils from samples
sfodagain Nov 14, 2023
711f786
Fix CI
sfodagain Nov 14, 2023
e3b4ef4
Merge branch 'main' into add-fleet-provisioning-test
sfodagain Nov 14, 2023
9117603
Experiment
sfodagain Nov 15, 2023
77fb38b
Experiment
sfodagain Nov 15, 2023
fda955b
Revert experiment
sfodagain Nov 15, 2023
5138b1c
Extract connection creation
sfodagain Nov 15, 2023
b222b3f
CLen code
sfodagain Nov 15, 2023
a1369b5
Clean code
sfodagain Nov 15, 2023
d2615ba
Move main function
sfodagain Nov 15, 2023
bf6f3ad
cleanup
sfodagain Nov 15, 2023
c23d7bb
cleanup
sfodagain Nov 16, 2023
4444d01
Add CSR
sfodagain Nov 16, 2023
ba2d494
Fix CI
sfodagain Nov 16, 2023
c76ec17
Use exceptions
sfodagain Nov 16, 2023
18f70b7
Fix deleting thing
sfodagain Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,37 @@ jobs:
run: |
java -version
mvn install -Dmaven.test.skip
- name: Running samples in CI setup
- name: Running samples and service client tests in CI setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for a test purpose, we should run the tests for all possible platform instead just on ubuntu-latest.

This might not apply to Java here, while for other SDKs, if we use crt-builder to build the SDK, then we could directly use the build.json script to setup the test for each CI build. You can refer to Python SDK for an example: https://github.com/aws/aws-iot-device-sdk-python-v2/blob/fa4f4ad921748d6377827548b2663d1249cbdedb/builder.json#L90

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I enabled service client tests for one platform only, because we already test builder and connection methods on all platforms. But if you think it might be useful to run these tests on multiple platforms, I can place them near DeviceAdvisor tests.

run: |
python3 -m pip install boto3
sudo apt-get update -y
sudo apt-get install softhsm -y
softhsm2-util --version
- name: configure AWS credentials (Fleet provisioning)
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ env.CI_FLEET_PROVISIONING_ROLE }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: run Fleet Provisioning service client test for MQTT311
working-directory: ./servicetests
run: |
export PYTHONPATH=${{ github.workspace }}/utils
python3 ./test_cases/test_fleet_provisioning.py --thing-name-prefix Fleet_Thing_ --mqtt-version 3
- name: run Fleet Provisioning service client test for MQTT5
working-directory: ./servicetests
run: |
export PYTHONPATH=${{ github.workspace }}/utils
python3 ./test_cases/test_fleet_provisioning.py --thing-name-prefix Fleet_Thing_ --mqtt-version 5
- name: run Fleet Provisioning with CSR service client test for MQTT311
working-directory: ./servicetests
run: |
export PYTHONPATH=${{ github.workspace }}/utils
python3 ./test_cases/test_fleet_provisioning.py --thing-name-prefix Fleet_Thing_ --mqtt-version 3 --use-csr
- name: run Fleet Provisioning with CSR service client test for MQTT5
working-directory: ./servicetests
run: |
export PYTHONPATH=${{ github.workspace }}/utils
python3 ./test_cases/test_fleet_provisioning.py --thing-name-prefix Fleet_Thing_ --mqtt-version 5 --use-csr
- name: configure AWS credentials (Connect and PubSub)
uses: aws-actions/configure-aws-credentials@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,6 @@ bin/

# docs are updated automatically by .github/workflows/docs.yml
docs/

# Python cache
__pycache__
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ private void parseCommonLoggingCommands(SampleCommandLineData returnData){
}
}

private void parseMqttVersion(SampleCommandLineData returnData) {
returnData.input_mqtt_version = Integer.parseInt(getCommandOrDefault(m_cmd_mqtt_version, "3"));
}

private void parseCommonMQTTCommands(SampleCommandLineData returnData) {
returnData.input_endpoint = getCommandRequired(m_cmd_endpoint);
returnData.input_ca = getCommandOrDefault(m_cmd_ca_file, "");
Expand Down Expand Up @@ -290,6 +294,7 @@ public class SampleCommandLineData
public String input_ca;
public String input_clientId;
public int input_port;
public int input_mqtt_version;
// Proxy
public String input_proxyHost;
public int input_proxyPort;
Expand Down Expand Up @@ -458,6 +463,7 @@ public SampleCommandLineData parseSampleInputFleetProvisioning(String [] args)
sendArguments(args);

SampleCommandLineData returnData = new SampleCommandLineData();
parseMqttVersion(returnData);
parseCommonLoggingCommands(returnData);
parseCommonMQTTCommands(returnData);
parseKeyAndCertCommands(returnData);
Expand Down Expand Up @@ -749,6 +755,7 @@ public static SampleCommandLineData getInputForIoTSample(String sampleName, Stri
/**
* Constants for commonly used/needed commands
*/
private static final String m_cmd_mqtt_version = "mqtt_version";
private static final String m_cmd_log_destination = "log_destination";
private static final String m_cmd_log_file_name = "log_file_name";
private static final String m_cmd_verbosity = "verbosity";
Expand Down
29 changes: 29 additions & 0 deletions servicetests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>ServiceClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>aws-iot-device-sdk</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<modules>
<module>tests/FleetProvisioning</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</build>
</project>
34 changes: 34 additions & 0 deletions servicetests/test_cases/mqtt3_fleet_provisioning_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"language": "Java",
"runnable_file": "tests/FleetProvisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "fleetProvisioning.FleetProvisioning",
"arguments": [
{
"name": "--mqtt_version",
"data": 3
},
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/FleetProvisioning/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/FleetProvisioning/key",
"filename": "tmp_key.pem"
},
{
"name": "--template_name",
"data": "CI_FleetProvisioning_Template"
},
{
"name": "--template_parameters",
"data": "{SerialNumber:$INPUT_UUID}"
}
]
}
39 changes: 39 additions & 0 deletions servicetests/test_cases/mqtt3_fleet_provisioning_with_csr_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"language": "Java",
"runnable_file": "tests/FleetProvisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "fleetProvisioning.FleetProvisioning",
"arguments": [
{
"name": "--mqtt_version",
"data": 3
},
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/FleetProvisioning/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/FleetProvisioning/key",
"filename": "tmp_key.pem"
},
{
"name": "--csr",
"secret": "ci/FleetProvisioning/csr",
"filename": "tmp_csr.pem"
},
{
"name": "--template_name",
"data": "CI_FleetProvisioning_Template"
},
{
"name": "--template_parameters",
"data": "{SerialNumber:$INPUT_UUID}"
}
]
}
34 changes: 34 additions & 0 deletions servicetests/test_cases/mqtt5_fleet_provisioning_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"language": "Java",
"runnable_file": "tests/FleetProvisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "fleetProvisioning.FleetProvisioning",
"arguments": [
{
"name": "--mqtt_version",
"data": 5
},
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/FleetProvisioning/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/FleetProvisioning/key",
"filename": "tmp_key.pem"
},
{
"name": "--template_name",
"data": "CI_FleetProvisioning_Template"
},
{
"name": "--template_parameters",
"data": "{SerialNumber:$INPUT_UUID}"
}
]
}
39 changes: 39 additions & 0 deletions servicetests/test_cases/mqtt5_fleet_provisioning_with_csr_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"language": "Java",
"runnable_file": "tests/FleetProvisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "fleetProvisioning.FleetProvisioning",
"arguments": [
{
"name": "--mqtt_version",
"data": 5
},
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/FleetProvisioning/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/FleetProvisioning/key",
"filename": "tmp_key.pem"
},
{
"name": "--csr",
"secret": "ci/FleetProvisioning/csr",
"filename": "tmp_csr.pem"
},
{
"name": "--template_name",
"data": "CI_FleetProvisioning_Template"
},
{
"name": "--template_parameters",
"data": "{SerialNumber:$INPUT_UUID}"
}
]
}
52 changes: 52 additions & 0 deletions servicetests/test_cases/test_fleet_provisioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

import argparse
import uuid
import os
import sys
import run_in_ci
import ci_iot_thing


def main():
argument_parser = argparse.ArgumentParser(
description="Run Fleet Provisioning test in CI")
argument_parser.add_argument(
"--input-uuid", required=False, help="UUID for thing name. UUID will be generated if this option is omit")
argument_parser.add_argument(
"--thing-name-prefix", required=False, default="",
help="Prefix for a thing name, should be the same that Fleet Provisioning template uses")
argument_parser.add_argument(
"--region", required=False, default="us-east-1", help="The name of the region to use")
argument_parser.add_argument(
"--mqtt-version", required=True, choices=[3, 5], type=int, help="MQTT protocol version to use")
argument_parser.add_argument(
"--use-csr", required=False, default=False, action='store_true', help="Create certificate from CSR")
parsed_commands = argument_parser.parse_args()

current_path = os.path.dirname(os.path.realpath(__file__))
cfg_file_mqtt_version = "mqtt3_" if parsed_commands.mqtt_version == 3 else "mqtt5_"
cfg_file_csr = "with_csr_" if parsed_commands.use_csr else ""
cfg_file = os.path.join(current_path, cfg_file_mqtt_version + "fleet_provisioning_" + cfg_file_csr + "cfg.json")
input_uuid = parsed_commands.input_uuid if parsed_commands.input_uuid else str(uuid.uuid4())

# Perform fleet provisioning. If it's successful, a newly created thing should appear.
test_result = run_in_ci.setup_and_launch(cfg_file, input_uuid)

# Delete a thing created by fleet provisioning. If this fails, we assume that's because fleet provisioning failed to
# create a thing.
# NOTE We want to try to delete thing even if test was unsuccessful.
thing_name = parsed_commands.thing_name_prefix + input_uuid
try:
delete_result = ci_iot_thing.delete_iot_thing(thing_name, parsed_commands.region)
except Exception as e:
print(f"ERROR: Failed to delete thing: {e}")
test_result = -1

if test_result != 0:
sys.exit(-1)


if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions servicetests/tests/FleetProvisioning/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>FleetProvisioningServiceTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java bindings for the AWS IoT Core Service</description>
<url>https://github.com/awslabs/aws-iot-device-sdk-java-v2</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>aws-iot-device-sdk</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>../../../samples/Utils/CommandLineUtils</source>
<source>../Utils/MqttClientConnectionWrapper</source>
<source>../ServiceTestLifecycleEvents</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading