Skip to content

Commit 6b063b5

Browse files
authored
Run Greengrass samples in CI (#585)
- Add tests for Greengrass samples: IPC and discovery. - Add new CI job for Greengrass tests.
1 parent 8f60ff8 commit 6b063b5

34 files changed

+782
-120
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ env:
2929
CI_JOBS_ROLE: arn:aws:iam::180635532705:role/CI_Jobs_Role
3030
CI_FLEET_PROVISIONING_ROLE: arn:aws:iam::180635532705:role/service-role/CI_FleetProvisioning_Role
3131
CI_GREENGRASS_ROLE: arn:aws:iam::180635532705:role/CI_Greengrass_Role
32+
CI_GREENGRASS_INSTALLER_ROLE: arn:aws:iam::180635532705:role/CI_GreengrassInstaller_Role
3233
CI_DEVICE_ADVISOR: arn:aws:iam::180635532705:role/CI_DeviceAdvisor_Role
3334
CI_MQTT5_ROLE: arn:aws:iam::180635532705:role/CI_MQTT5_Role
3435
CI_BUILD_AND_TEST_ROLE: arn:aws:iam::180635532705:role/V2_SDK_Unit_Testing
@@ -393,14 +394,66 @@ jobs:
393394
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
394395
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_fleet_provisioning_cfg.json --input_uuid ${Sample_UUID}
395396
python3 ${{ env.CI_UTILS_FOLDER }}/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
396-
- name: configure AWS credentials (Greengrass)
397+
398+
linux-greengrass-tests:
399+
runs-on: ubuntu-22.04
400+
permissions:
401+
id-token: write # This is required for requesting the JWT
402+
steps:
403+
- name: Setup environment
404+
run: |
405+
python3 -m pip install boto3
406+
- name: configure AWS credentials (containers)
397407
uses: aws-actions/configure-aws-credentials@v2
398408
with:
399-
role-to-assume: ${{ env.CI_GREENGRASS_ROLE }}
409+
role-to-assume: ${{ env.CI_BUILD_AND_TEST_ROLE }}
400410
aws-region: ${{ env.AWS_DEFAULT_REGION }}
401-
- name: run Greengrass Discovery sample
411+
- name: Build ${{ env.PACKAGE_NAME }}
412+
run: |
413+
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
414+
chmod a+x builder
415+
./builder build -p ${{ env.PACKAGE_NAME }}
416+
- name: Install Greengrass Development Kit
402417
run: |
403-
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_greengrass_discovery_cfg.json
418+
python3 -m pip install awsiotsdk
419+
python3 -m pip install -U git+https://github.com/aws-greengrass/[email protected]
420+
- name: Configure AWS credentials (Greengrass)
421+
uses: aws-actions/configure-aws-credentials@v2
422+
with:
423+
role-to-assume: ${{ env.CI_GREENGRASS_INSTALLER_ROLE }}
424+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
425+
- name: Build and run Greengrass basic discovery sample
426+
working-directory: ./aws-iot-device-sdk-python-v2/test/greengrass/basic_discovery
427+
run: |
428+
export PYTHONPATH=${{ github.workspace }}/aws-iot-device-sdk-python-v2/samples
429+
gdk component build
430+
gdk test-e2e build
431+
gdk test-e2e run
432+
- name: Show logs
433+
working-directory: ./aws-iot-device-sdk-python-v2/test/greengrass/basic_discovery
434+
# Print logs unconditionally to provide more details on Greengrass run even if the test failed.
435+
if: always()
436+
run: |
437+
echo "=== greengrass.log"
438+
cat testResults/gg*/greengrass.log
439+
echo "=== software.amazon.awssdk.sdk-gg-test-discovery.log"
440+
cat testResults/gg*/software.amazon.awssdk.sdk-gg-test-discovery.log
441+
- name: Build and run Greengrass IPC sample
442+
working-directory: ./aws-iot-device-sdk-python-v2/test/greengrass/ipc
443+
run: |
444+
gdk component build
445+
gdk test-e2e build
446+
gdk test-e2e run
447+
- name: Show logs
448+
working-directory: ./aws-iot-device-sdk-python-v2/test/greengrass/ipc
449+
# Print logs unconditionally to provide more details on Greengrass run even if the test failed.
450+
if: always()
451+
run: |
452+
echo "=== greengrass.log"
453+
cat testResults/gg*/greengrass.log
454+
echo "=== software.amazon.awssdk.sdk-gg-ipc.log"
455+
cat testResults/gg*/software.amazon.awssdk.sdk-gg-ipc.log
456+
404457
405458
# check that docs can still build
406459
check-docs:

.github/workflows/ci_run_basic_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"name": "--key",
1818
"secret": "ci/PubSub/key",
1919
"filename": "tmp_key.pem"
20+
},
21+
{
22+
"name": "--is_ci",
23+
"data": "true"
2024
}
2125
]
2226
}

.github/workflows/ci_run_cognito_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"name": "--cognito_identity",
1717
"secret": "ci/Cognito/identity_id"
18+
},
19+
{
20+
"name": "--is_ci",
21+
"data": "true"
1822
}
1923
]
2024
}

.github/workflows/ci_run_custom_authorizer_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"name": "--custom_auth_password",
1717
"secret": "ci/CustomAuthorizer/password"
18+
},
19+
{
20+
"name": "--is_ci",
21+
"data": "true"
1822
}
1923
]
2024
}

.github/workflows/ci_run_fleet_provisioning_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
{
2626
"name": "--template_parameters",
2727
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
28+
},
29+
{
30+
"name": "--is_ci",
31+
"data": "true"
2832
}
2933
]
3034
}
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
{
22
"language": "Python",
3-
"sample_file": "./aws-iot-device-sdk-python-v2/samples/basic_discovery.py",
4-
"sample_region": "us-east-1",
5-
"sample_main_class": "",
3+
"runnable_file": "basic_discovery.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
66
"arguments": [
77
{
88
"name": "--cert",
9-
"secret": "ci/Greengrass/cert",
9+
"secret": "ci/GreengrassDiscovery/cert",
1010
"filename": "tmp_certificate.pem"
1111
},
1212
{
1313
"name": "--key",
14-
"secret": "ci/Greengrass/key",
14+
"secret": "ci/GreengrassDiscovery/key",
1515
"filename": "tmp_key.pem"
1616
},
1717
{
18-
"name": "--ca_file",
19-
"secret": "ci/Greengrass/ca",
20-
"filename": "tmp_ca.pem"
18+
"name": "--thing_name",
19+
"data": "CI_Greengrass_Discovery_Thing"
2120
},
2221
{
2322
"name": "--region",
2423
"data": "us-east-1"
2524
},
2625
{
27-
"name": "--thing_name",
28-
"data": "CI_GreenGrass_Thing"
29-
},
30-
{
31-
"name": "--is_ci",
32-
"data": "true"
26+
"name": "--topic",
27+
"data": "clients/CI_Greengrass_Discovery_Thing/hello/world/$INPUT_UUID"
3328
},
3429
{
35-
"name": "--print_discover_resp_only",
36-
"data": ""
30+
"name": "--mode",
31+
"data": "publish"
3732
}
3833
]
3934
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"language": "Python",
3+
"runnable_file": "ipc_greengrass.py",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--topic",
9+
"data": "test/gg-ipc-topic"
10+
},
11+
{
12+
"name": "--message",
13+
"data": "hello"
14+
},
15+
{
16+
"name": "--is_ci",
17+
"data": "true"
18+
}
19+
]
20+
}

.github/workflows/ci_run_jobs_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
{
2222
"name": "--thing_name",
2323
"data": "CI_Jobs_Thing"
24+
},
25+
{
26+
"name": "--is_ci",
27+
"data": "true"
2428
}
2529
]
2630
}

.github/workflows/ci_run_mqtt5_custom_authorizer_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"name": "--custom_auth_password",
1717
"secret": "ci/CustomAuthorizer/password"
18+
},
19+
{
20+
"name": "--is_ci",
21+
"data": "true"
1822
}
1923
]
2024
}

.github/workflows/ci_run_mqtt5_custom_authorizer_websockets_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
{
2020
"name": "--use_websockets",
2121
"data": "true"
22+
},
23+
{
24+
"name": "--is_ci",
25+
"data": "true"
2226
}
2327
]
2428
}

.github/workflows/ci_run_mqtt5_fleet_provisioning_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
{
2626
"name": "--template_parameters",
2727
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
28+
},
29+
{
30+
"name": "--is_ci",
31+
"data": "true"
2832
}
2933
]
3034
}

.github/workflows/ci_run_mqtt5_jobs_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
{
2222
"name": "--thing_name",
2323
"data": "CI_Jobs_Thing"
24+
},
25+
{
26+
"name": "--is_ci",
27+
"data": "true"
2428
}
2529
]
2630
}

.github/workflows/ci_run_mqtt5_pkcs11_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
{
3535
"name": "--key_label",
3636
"data": "my-key"
37+
},
38+
{
39+
"name": "--is_ci",
40+
"data": "true"
3741
}
3842
]
3943
}

.github/workflows/ci_run_pkcs11_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
{
3535
"name": "--key_label",
3636
"data": "my-key"
37+
},
38+
{
39+
"name": "--is_ci",
40+
"data": "true"
3741
}
3842
]
3943
}

.github/workflows/ci_run_pkcs12_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"name": "--pkcs12_password",
1717
"secret": "ci/PubSub/key_pkcs12_password"
18+
},
19+
{
20+
"name": "--is_ci",
21+
"data": "true"
1822
}
1923
]
2024
}

.github/workflows/ci_run_websocket_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"name": "--signing_region",
1313
"data": "us-east-1"
14+
},
15+
{
16+
"name": "--is_ci",
17+
"data": "true"
1418
}
1519
]
1620
}

.github/workflows/ci_run_windows_cert_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"windows_cert_key": "ci/PubSub/key",
1616
"windows_cert_key_path": "tmp_key.pem",
1717
"windows_cert_pfx_key_path": "tmp_pfx.pem"
18+
},
19+
{
20+
"name": "--is_ci",
21+
"data": "true"
1822
}
1923
]
2024
}

.github/workflows/ci_run_x509_connect_cfg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
{
3434
"name": "--x509_thing_name",
3535
"data": "CI_PubSub_Thing"
36+
},
37+
{
38+
"name": "--is_ci",
39+
"data": "true"
3640
}
3741
]
3842
}

samples/basic_discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def on_publish(topic, payload, dup, qos, retain, **kwargs):
102102
message['message'] = cmdData.input_message
103103
message['sequence'] = loop_count
104104
messageJson = json.dumps(message)
105-
pub_future, _ = mqtt_connection.publish(cmdData.input_topic, messageJson, QoS.AT_MOST_ONCE)
106-
pub_future.result()
107-
print('Published topic {}: {}\n'.format(cmdData.input_topic, messageJson))
105+
pub_future, _ = mqtt_connection.publish(cmdData.input_topic, messageJson, QoS.AT_LEAST_ONCE)
106+
publish_completion_data = pub_future.result()
107+
print('Published topic {}: {} (puback reason: {})\n'.format(cmdData.input_topic, messageJson, repr(publish_completion_data.puback.reason_code)))
108108

109109
loop_count += 1
110110
time.sleep(1)

samples/ipc_greengrass.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,39 @@
2222
import json
2323
import time
2424
import os
25+
import sys
2526

2627
import awsiot.greengrasscoreipc
2728
import awsiot.greengrasscoreipc.model as model
2829

2930
if __name__ == '__main__':
30-
ipc_client = awsiot.greengrasscoreipc.connect()
31-
32-
while True:
33-
telemetry_data = {
34-
"timestamp": int(round(time.time() * 1000)),
35-
"battery_state_of_charge": 42.5,
36-
"location": {
37-
"longitude": 48.15743,
38-
"latitude": 11.57549,
39-
},
40-
}
41-
42-
op = ipc_client.new_publish_to_iot_core()
43-
op.activate(model.PublishToIoTCoreRequest(
44-
topic_name="my/iot/{}/telemetry".format(os.getenv("AWS_IOT_THING_NAME")),
45-
qos=model.QOS.AT_LEAST_ONCE,
46-
payload=json.dumps(telemetry_data).encode(),
47-
))
48-
try:
49-
result = op.get_response().result(timeout=5.0)
50-
print("successfully published message:", result)
51-
except Exception as e:
52-
print("failed to publish message:", e)
53-
54-
time.sleep(5)
31+
try:
32+
print("Connecting to Greengrass...")
33+
ipc_client = awsiot.greengrasscoreipc.connect()
34+
35+
for i in range(0, 10):
36+
telemetry_data = {
37+
"timestamp": int(round(time.time() * 1000)),
38+
"battery_state_of_charge": 42.5,
39+
"location": {
40+
"longitude": 48.15743,
41+
"latitude": 11.57549,
42+
},
43+
}
44+
45+
op = ipc_client.new_publish_to_iot_core()
46+
op.activate(model.PublishToIoTCoreRequest(
47+
topic_name="my/iot/{}/telemetry".format(os.getenv("AWS_IOT_THING_NAME")),
48+
qos=model.QOS.AT_LEAST_ONCE,
49+
payload=json.dumps(telemetry_data).encode(),
50+
))
51+
try:
52+
result = op.get_response().result(timeout=5.0)
53+
print("Successfully published message: {}".format(result))
54+
except Exception as e:
55+
print("Failed to publish message: {}".format(e))
56+
sys.exit(1)
57+
58+
except Exception as e:
59+
print("Sample failed: {}".format(e))
60+
sys.exit(1)

0 commit comments

Comments
 (0)