Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Working IPC
  • Loading branch information
sfodagain committed Jun 5, 2024
commit 8eee9b8ed8cdaaa616902000db548a87856a8298
32 changes: 14 additions & 18 deletions .github/workflows/ci_run_greengrass_discovery_cfg.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
{
"language": "Python",
"sample_file": "./aws-iot-device-sdk-python-v2/samples/basic_discovery.py",
"sample_region": "us-east-1",
"sample_main_class": "",
"language": "CPP",
"runnable_file": "basic-discovery",
"runnable_region": "us-east-1",
"runnable_main_class": "",
"arguments": [
{
"name": "--cert",
"secret": "ci/Greengrass/cert",
"secret": "ci/GreengrassDiscovery/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/Greengrass/key",
"secret": "ci/GreengrassDiscovery/key",
"filename": "tmp_key.pem"
},
{
"name": "--ca_file",
"secret": "ci/Greengrass/ca",
"filename": "tmp_ca.pem"
"name": "--thing_name",
"data": "CI_Greengrass_Discovery_Thing"
},
{
"name": "--region",
"data": "us-east-1"
},
{
"name": "--thing_name",
"data": "CI_GreenGrass_Thing"
},
{
"name": "--is_ci",
"data": "true"
"name": "--topic",
"data": "clients/CI_Greengrass_Discovery_Thing/hello/world/$INPUT_UUID"
},
{
"name": "--print_discover_resp_only",
"data": ""
"name": "--mode",
"data": "publish"
}
]
],
"stdin_file": "messages.txt"
}
56 changes: 31 additions & 25 deletions samples/ipc_greengrass.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,39 @@
import json
import time
import os
import sys

import awsiot.greengrasscoreipc
import awsiot.greengrasscoreipc.model as model

if __name__ == '__main__':
ipc_client = awsiot.greengrasscoreipc.connect()

while True:
telemetry_data = {
"timestamp": int(round(time.time() * 1000)),
"battery_state_of_charge": 42.5,
"location": {
"longitude": 48.15743,
"latitude": 11.57549,
},
}

op = ipc_client.new_publish_to_iot_core()
op.activate(model.PublishToIoTCoreRequest(
topic_name="my/iot/{}/telemetry".format(os.getenv("AWS_IOT_THING_NAME")),
qos=model.QOS.AT_LEAST_ONCE,
payload=json.dumps(telemetry_data).encode(),
))
try:
result = op.get_response().result(timeout=5.0)
print("successfully published message:", result)
except Exception as e:
print("failed to publish message:", e)

time.sleep(5)
try:
print("Connecting to Greengrass...")
ipc_client = awsiot.greengrasscoreipc.connect()

for i in range(0, 10):
telemetry_data = {
"timestamp": int(round(time.time() * 1000)),
"battery_state_of_charge": 42.5,
"location": {
"longitude": 48.15743,
"latitude": 11.57549,
},
}

op = ipc_client.new_publish_to_iot_core()
op.activate(model.PublishToIoTCoreRequest(
topic_name="my/iot/{}/telemetry".format(os.getenv("AWS_IOT_THING_NAME")),
qos=model.QOS.AT_LEAST_ONCE,
payload=json.dumps(telemetry_data).encode(),
))
try:
result = op.get_response().result(timeout=5.0)
print("Successfully published message: {}".format(result))
except Exception as e:
print("Failed to publish message: {}".format(e))
sys.exit(1)

except Exception as e:
print("Sample failed: {}".format(e))
sys.exit(1)
3 changes: 3 additions & 0 deletions test/greengrass/ipc/copy_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cp ../../../samples/ipc_greengrass.py .
cp ../../../utils/run_in_ci.py .
cp ../../../.github/workflows/ci_run_greengrass_ipc_cfg.json .
22 changes: 22 additions & 0 deletions test/greengrass/ipc/gdk-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"component": {
"software.amazon.awssdk.sdk-gg-ipc": {
"author": "iot-device-sdk",
"version": "NEXT_PATCH",
"build": {
"build_system": "custom",
"custom_build_command": ["bash", "copy_files.sh"]
},
"publish": {
"bucket": "<PLACEHOLDER_BUCKET>",
"region": "<PLACEHOLDER_REGION>"
}
}
},
"gdk_version": "1.3.0",
"test-e2e": {
"gtf_options": {
"tags": "testgg"
}
}
}
63 changes: 63 additions & 0 deletions test/greengrass/ipc/gg-e2e-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.aws.greengrass</groupId>
<artifactId>uat-features</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>OTF</name>

<properties>
<otf.version>1.2.0-SNAPSHOT</otf.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>greengrass-common</id>
<name>greengrass common</name>
<!-- CloudFront url fronting the aws-greengrass-testing-standalone in S3-->
<url>https://d2jrmugq4soldf.cloudfront.net/snapshots</url>
</repository>
</repositories>

<dependencies>
<!-- Open Testing Framework dependency - Source Code: https://github.com/aws-greengrass/aws-greengrass-testing -->
<dependency>
<groupId>com.aws.greengrass</groupId>
<artifactId>aws-greengrass-testing-standalone</artifactId>
<version>${otf.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.aws.greengrass.testing.launcher.TestLauncher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Testing features of Greengrassv2 IPC sample

@testgg
Scenario: As a developer, I can create a component and deploy it on my device
Given my device is registered as a Thing
And my device is running Greengrass
When I create a Greengrass deployment with components
| software.amazon.awssdk.sdk-gg-ipc | file:recipe.yaml |
And I deploy the Greengrass deployment configuration
Then the Greengrass deployment is COMPLETED on the device after 180 seconds
And the software.amazon.awssdk.sdk-gg-ipc log on the device contains the line "Successfully published message" within 20 seconds
28 changes: 28 additions & 0 deletions test/greengrass/ipc/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
RecipeFormatVersion: "2020-01-25"
ComponentName: software.amazon.awssdk.sdk-gg-ipc
ComponentVersion: "1.0.0"
ComponentDescription: "This is test for the Greengrass IPC sample"
ComponentPublisher: "iot-device-sdk"
ComponentConfiguration:
DefaultConfiguration:
accessControl:
aws.greengrass.ipc.mqttproxy:
software.amazon.awssdk.sdk-gg-ipc:mqttproxy:1:
policyDescription: "Allows access to publish and subscribe to a Greengrass IPC test topic"
operations:
- aws.greengrass#PublishToIoTCore
- aws.greengrass#SubscribeToIoTCore
resources:
- "my/iot/*/telemetry"
Manifests:
- Platform:
os: all
Artifacts:
- URI: "file:ipc_greengrass.py"
- URI: "file:run_in_ci.py"
- URI: "file:ci_run_greengrass_ipc_cfg.json"
Lifecycle:
Run: |
echo "GG core:" {iot:thingName}
python3 {artifacts:path}/run_in_ci.py --runnable_dir {artifacts:path} --file {artifacts:path}/ci_run_greengrass_ipc_cfg.json
Loading