Skip to content

Commit

Permalink
Fleet Provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred2g committed Dec 5, 2023
1 parent 5b830a1 commit 765993f
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 0 deletions.
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": "CPP",
"runnable_file": "../build/servicetests/tests/fleet_provisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "",
"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": "CPP",
"runnable_file": "../build/servicetests/tests/fleet_provisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "",
"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": "CPP",
"runnable_file": "../build/servicetests/tests/fleet_provisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "",
"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": "CPP",
"runnable_file": "../build/servicetests/tests/fleet_provisioning",
"runnable_region": "us-east-1",
"runnable_main_class": "",
"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\"}"
}
]
}
50 changes: 50 additions & 0 deletions servicetests/test_cases/test_fleet_provisioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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(
"--config-file", required=True,
help="JSON file providing command-line arguments to a test")
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(
"--input-uuid", required=False, help="UUID for thing name. UUID will be generated if this option is omit")
parsed_commands = argument_parser.parse_args()

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.
try:
test_result = run_in_ci.setup_and_launch(parsed_commands.config_file, input_uuid)
except Exception as e:
print(f"ERROR: Failed to execute Fleet Provisioning test: {e}")
test_result = -1

# 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.
try:
thing_name = parsed_commands.thing_name_prefix + input_uuid
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()
28 changes: 28 additions & 0 deletions servicetests/tests/FleetProvisioning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.1)
# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12
project(fleet_provisioning CXX)

file(GLOB SRC_FILES
"*.cpp"
"../../../samples/utils/CommandLineUtils.cpp"
"../../../samples/utils/CommandLineUtils.h"
)

add_executable(${PROJECT_NAME} ${SRC_FILES})

set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 14)

#set warnings
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
else ()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

find_package(aws-crt-cpp REQUIRED)
find_package(IotJobs-cpp REQUIRED)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)

target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-crt-cpp AWS::IotJobs-cpp)
5 changes: 5 additions & 0 deletions servicetests/tests/FleetProvisioning/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

int main(int argc, char * argv[])
{
return 0;
}

0 comments on commit 765993f

Please sign in to comment.