|
| 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 | + |
| 12 | +def main(): |
| 13 | + argument_parser = argparse.ArgumentParser( |
| 14 | + description="Run Fleet Provisioning test in CI") |
| 15 | + argument_parser.add_argument( |
| 16 | + "--input-uuid", required=False, help="UUID for thing name. UUID will be generated if this option is omit") |
| 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 | + "--mqtt-version", required=True, choices=[3, 5], type=int, help="MQTT protocol version to use") |
| 24 | + argument_parser.add_argument( |
| 25 | + "--use-csr", required=False, default=False, action='store_true', help="Create certificate from CSR") |
| 26 | + parsed_commands = argument_parser.parse_args() |
| 27 | + |
| 28 | + current_path = os.path.dirname(os.path.realpath(__file__)) |
| 29 | + cfg_file_mqtt_version = "mqtt3_" if parsed_commands.mqtt_version == 3 else "mqtt5_" |
| 30 | + cfg_file_csr = "with_csr_" if parsed_commands.use_csr else "" |
| 31 | + cfg_file = os.path.join(current_path, cfg_file_mqtt_version + "fleet_provisioning_" + cfg_file_csr + "cfg.json") |
| 32 | + input_uuid = parsed_commands.input_uuid if parsed_commands.input_uuid else str(uuid.uuid4()) |
| 33 | + |
| 34 | + # Perform fleet provisioning. If it's successful, a newly created thing should appear. |
| 35 | + test_result = run_in_ci.setup_and_launch(cfg_file, input_uuid) |
| 36 | + |
| 37 | + # Delete a thing created by fleet provisioning. If this fails, we assume that's because fleet provisioning failed to |
| 38 | + # create a thing. |
| 39 | + # NOTE We want to try to delete thing even if test was unsuccessful. |
| 40 | + thing_name = parsed_commands.thing_name_prefix + input_uuid |
| 41 | + try: |
| 42 | + delete_result = ci_iot_thing.delete_iot_thing(thing_name, parsed_commands.region) |
| 43 | + except Exception as e: |
| 44 | + print(f"ERROR: Failed to delete thing: {e}") |
| 45 | + test_result = -1 |
| 46 | + |
| 47 | + if test_result != 0: |
| 48 | + sys.exit(-1) |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + main() |
0 commit comments