Skip to content

Commit 33016f1

Browse files
sbSteveKxiazhvera
andauthored
Switch to using a role for CI (#348)
* switch to using a role for integrated tests * separate python * setup permision&test against CI_PubSub_Role * test against iot account * update host * test host * use a ci job role for test * update role permission * update tests to use host argument * quick run discovery test * quick test for gg discovery * migrate gg discovery test * more comments --------- Co-authored-by: Vera Xia <[email protected]>
1 parent b1f495d commit 33016f1

14 files changed

+69
-59
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88

99
env:
1010
RUN: ${{ github.run_id }}-${{ github.run_number }}
11-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
12-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11+
AWS_DEFAULT_REGION: us-east-1
12+
CI_SDK_V1_ROLE: arn:aws:iam::180635532705:role/CI_SDK_V1_ROLE
1313
PACKAGE_NAME: aws-iot-device-sdk-python
1414
AWS_EC2_METADATA_DISABLED: true
1515

@@ -33,6 +33,9 @@ jobs:
3333
3434
integration-tests:
3535
runs-on: ubuntu-latest
36+
permissions:
37+
id-token: write # This is required for requesting the JWT
38+
contents: read # This is required for actions/checkout
3639
strategy:
3740
fail-fast: false
3841
matrix:
@@ -43,6 +46,10 @@ jobs:
4346
- uses: actions/setup-python@v5
4447
with:
4548
python-version: ${{ matrix.python-version }}
49+
- uses: aws-actions/configure-aws-credentials@v2
50+
with:
51+
role-to-assume: ${{ env.CI_SDK_V1_ROLE }}
52+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
4653
- name: Integration tests
4754
run: |
4855
pip install pytest
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name: HandleStaleDiscussions
22
on:
3-
schedule:
4-
- cron: '0 */4 * * *'
5-
discussion_comment:
6-
types: [created]
3+
schedule:
4+
- cron: '0 */4 * * *'
5+
discussion_comment:
6+
types: [created]
77

88
jobs:
9-
handle-stale-discussions:
10-
name: Handle stale discussions
11-
runs-on: ubuntu-latest
12-
permissions:
13-
discussions: write
14-
steps:
15-
- name: Stale discussions action
16-
uses: aws-github-ops/handle-stale-discussions@v1
17-
env:
18-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
9+
handle-stale-discussions:
10+
name: Handle stale discussions
11+
runs-on: ubuntu-latest
12+
permissions:
13+
discussions: write
14+
steps:
15+
- name: Stale discussions action
16+
uses: aws-github-ops/handle-stale-discussions@v1
17+
env:
18+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
19+

test-integration/IntegrationTests/IntegrationTestAsyncAPIGeneralNotificationCallbacks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
TOPIC = "topic/test/async_cb/"
3333
MESSAGE_PREFIX = "MagicMessage-"
3434
NUMBER_OF_PUBLISHES = 3
35-
HOST = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
3635
ROOT_CA = "./test-integration/Credentials/rootCA.crt"
3736
CERT = "./test-integration/Credentials/certificate.pem.crt"
3837
KEY = "./test-integration/Credentials/privateKey.pem.key"
@@ -102,9 +101,10 @@ def get_random_string(length):
102101
############################################################################
103102
# Main #
104103
# Check inputs
105-
my_check_in_manager = checkInManager(1)
104+
my_check_in_manager = checkInManager(2)
106105
my_check_in_manager.verify(sys.argv)
107106
mode = my_check_in_manager.mode
107+
host = my_check_in_manager.host
108108

109109
skip_when_match(ModeIsALPN(mode).And(
110110
Python2VersionLowerThan((2, 7, 10)).Or(Python3VersionLowerThan((3, 5, 0)))
@@ -115,7 +115,7 @@ def get_random_string(length):
115115
print("Connecting...")
116116
callback_manager = CallbackManager()
117117
sdk_mqtt_client = MQTTClientManager()\
118-
.create_nonconnected_mqtt_client(mode, CLIENT_ID, HOST, (ROOT_CA, CERT, KEY), callback_manager)
118+
.create_nonconnected_mqtt_client(mode, CLIENT_ID, host, (ROOT_CA, CERT, KEY), callback_manager)
119119
sdk_mqtt_client.connectAsync(keepAliveIntervalSecond=1, ackCallback=callback_manager.connack) # Add callback
120120
print("Wait some time to make sure we are connected...")
121121
time.sleep(10) # 10 sec

test-integration/IntegrationTests/IntegrationTestAutoReconnectResubscribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ def threadBRuntime(self, pyCoreClient, callback):
135135
############################################################################
136136
# Main #
137137
# Check inputs
138-
myCheckInManager = checkInManager.checkInManager(1)
138+
myCheckInManager = checkInManager.checkInManager(2)
139139
myCheckInManager.verify(sys.argv)
140140

141-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
142141
rootCA = "./test-integration/Credentials/rootCA.crt"
143142
certificate = "./test-integration/Credentials/certificate.pem.crt"
144143
privateKey = "./test-integration/Credentials/privateKey.pem.key"
145144
mode = myCheckInManager.mode
145+
host = myCheckInManager.host
146146

147147
skip_when_match(ModeIsALPN(mode).And(
148148
Python2VersionLowerThan((2, 7, 10)).Or(Python3VersionLowerThan((3, 5, 0)))

test-integration/IntegrationTests/IntegrationTestClientReusability.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
NUMBER_OF_MESSAGES_PER_LOOP = 3
4141
NUMBER_OF_LOOPS = 3
4242
SUB_WAIT_TIME_OUT_SEC = 20
43-
HOST = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
4443
ROOT_CA = "./test-integration/Credentials/rootCA.crt"
4544
CERT = "./test-integration/Credentials/certificate.pem.crt"
4645
KEY = "./test-integration/Credentials/privateKey.pem.key"
@@ -94,19 +93,20 @@ def verify(self):
9493

9594
############################################################################
9695
# Main #
97-
my_check_in_manager = checkInManager(1)
96+
my_check_in_manager = checkInManager(2)
9897
my_check_in_manager.verify(sys.argv)
9998
mode = my_check_in_manager.mode
99+
host = my_check_in_manager.host
100100

101101
skip_when_match(ModeIsALPN(mode).And(
102102
Python2VersionLowerThan((2, 7, 10)).Or(Python3VersionLowerThan((3, 5, 0)))
103103
), "This test is not applicable for mode %s and Python verison %s. Skipping..." % (mode, sys.version_info[:3]))
104104

105105
simple_thread_manager = simpleThreadManager()
106106

107-
client_pub = MQTTClientManager().create_nonconnected_mqtt_client(mode, CLIENT_ID_PUB, HOST, (ROOT_CA, CERT, KEY))
107+
client_pub = MQTTClientManager().create_nonconnected_mqtt_client(mode, CLIENT_ID_PUB, host, (ROOT_CA, CERT, KEY))
108108
print("Client publisher initialized.")
109-
client_sub = MQTTClientManager().create_nonconnected_mqtt_client(mode, CLIENT_ID_SUB, HOST, (ROOT_CA, CERT, KEY))
109+
client_sub = MQTTClientManager().create_nonconnected_mqtt_client(mode, CLIENT_ID_SUB, host, (ROOT_CA, CERT, KEY))
110110
print("Client subscriber initialized.")
111111
client_twins = ClientTwins(client_pub, client_sub)
112112
print("Client twins initialized.")

test-integration/IntegrationTests/IntegrationTestConfigurablePublishMessageQueueing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ def performConfigurableOfflinePublishQueueTest(clientPub, clientSub):
274274

275275

276276
# Check inputs
277-
myCheckInManager = checkInManager.checkInManager(1)
277+
myCheckInManager = checkInManager.checkInManager(2)
278278
myCheckInManager.verify(sys.argv)
279279

280-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
280+
host = myCheckInManager.host
281281
rootCA = "./test-integration/Credentials/rootCA.crt"
282282
certificate = "./test-integration/Credentials/certificate.pem.crt"
283283
privateKey = "./test-integration/Credentials/privateKey.pem.key"

test-integration/IntegrationTests/IntegrationTestDiscovery.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from TestToolLibrary.skip import ModeIsWebSocket
99

1010

11-
HOST = "arc9d2oott9lj-ats.iot.us-east-1.amazonaws.com" # <[email protected]> 003261610643
1211
PORT = 8443
1312
CA = "./test-integration/Credentials/rootCA.crt"
1413
CERT = "./test-integration/Credentials/certificate_drs.pem.crt"
1514
KEY = "./test-integration/Credentials/privateKey_drs.pem.key"
1615
TIME_OUT_SEC = 30
1716
# This is a pre-generated test data from DRS integration tests
17+
# The test resources point to account # <[email protected]> 003261610643
1818
ID_PREFIX = "Id-"
1919
GGC_ARN = "arn:aws:iot:us-east-1:003261610643:thing/DRS_GGC_0kegiNGA_0"
2020
GGC_PORT_NUMBER_BASE = 8080
@@ -108,10 +108,14 @@
108108
}
109109
'''
110110

111+
my_check_in_manager = checkInManager(2)
112+
my_check_in_manager.verify(sys.argv)
113+
mode = my_check_in_manager.mode
114+
host = my_check_in_manager.host
111115

112116
def create_discovery_info_provider():
113117
discovery_info_provider = DiscoveryInfoProvider()
114-
discovery_info_provider.configureEndpoint(HOST, PORT)
118+
discovery_info_provider.configureEndpoint(host, PORT)
115119
discovery_info_provider.configureCredentials(CA, CERT, KEY)
116120
discovery_info_provider.configureTimeout(TIME_OUT_SEC)
117121
return discovery_info_provider
@@ -196,9 +200,6 @@ def verify_group_object(discovery_info):
196200

197201
############################################################################
198202
# Main #
199-
my_check_in_manager = checkInManager(1)
200-
my_check_in_manager.verify(sys.argv)
201-
mode = my_check_in_manager.mode
202203

203204
skip_when_match(ModeIsWebSocket(mode), "This test is not applicable for mode: %s. Skipping..." % mode)
204205

test-integration/IntegrationTests/IntegrationTestJobsClient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ def _test_send_response_confirm(self, sendResult):
154154
############################################################################
155155
# Main #
156156
# Check inputs
157-
myCheckInManager = checkInManager.checkInManager(1)
157+
myCheckInManager = checkInManager.checkInManager(2)
158158
myCheckInManager.verify(sys.argv)
159159

160-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
160+
host = myCheckInManager.host
161161
rootCA = "./test-integration/Credentials/rootCA.crt"
162162
certificate = "./test-integration/Credentials/certificate.pem.crt"
163163
privateKey = "./test-integration/Credentials/privateKey.pem.key"

test-integration/IntegrationTests/IntegrationTestMQTTConnection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def _performPublish(self, pyCoreClient, topic, qos, payload):
8484
############################################################################
8585
# Main #
8686
# Check inputs
87-
myCheckInManager = checkInManager.checkInManager(2)
87+
myCheckInManager = checkInManager.checkInManager(3)
8888
myCheckInManager.verify(sys.argv)
8989

90-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
90+
host = myCheckInManager.host
9191
rootCA = "./test-integration/Credentials/rootCA.crt"
9292
certificate = "./test-integration/Credentials/certificate.pem.crt"
9393
privateKey = "./test-integration/Credentials/privateKey.pem.key"

test-integration/IntegrationTests/IntegrationTestOfflineQueueingForSubscribeUnsubscribe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def get_random_string(length):
4747
TOPIC_B = "topic/test/offline_sub_unsub/b" + get_random_string(4)
4848
MESSAGE_PREFIX = "MagicMessage-"
4949
NUMBER_OF_PUBLISHES = 3
50-
HOST = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
5150
ROOT_CA = "./test-integration/Credentials/rootCA.crt"
5251
CERT = "./test-integration/Credentials/certificate.pem.crt"
5352
KEY = "./test-integration/Credentials/privateKey.pem.key"
@@ -74,7 +73,7 @@ def __init__(self, mode):
7473
time.sleep(2) # Make sure the subscription is valid
7574

7675
def _create_connected_client(self, id_prefix):
77-
return MQTTClientManager().create_connected_mqtt_client(self.__mode, id_prefix, HOST, (ROOT_CA, CERT, KEY))
76+
return MQTTClientManager().create_connected_mqtt_client(self.__mode, id_prefix, host, (ROOT_CA, CERT, KEY))
7877

7978
def start(self):
8079
thread_client_sub_unsub = Thread(target=self._thread_client_sub_unsub_runtime)
@@ -192,9 +191,10 @@ def verify(self):
192191
############################################################################
193192
# Main #
194193
# Check inputs
195-
my_check_in_manager = checkInManager(1)
194+
my_check_in_manager = checkInManager(2)
196195
my_check_in_manager.verify(sys.argv)
197196
mode = my_check_in_manager.mode
197+
host = my_check_in_manager.host
198198

199199
skip_when_match(ModeIsALPN(mode).And(
200200
Python2VersionLowerThan((2, 7, 10)).Or(Python3VersionLowerThan((3, 5, 0)))

test-integration/IntegrationTests/IntegrationTestProgressiveBackoff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ def verifyBackoffTime(answerList, resultList):
220220
############################################################################
221221
# Main #
222222
# Check inputs
223-
myCheckInManager = checkInManager.checkInManager(2)
223+
myCheckInManager = checkInManager.checkInManager(3)
224224
myCheckInManager.verify(sys.argv)
225225

226226
#host via describe-endpoint on this OdinMS: com.amazonaws.iot.device.sdk.credentials.testing.websocket
227-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
227+
host = myCheckInManager.host
228228
rootCA = "./test-integration/Credentials/rootCA.crt"
229229
certificate = "./test-integration/Credentials/certificate.pem.crt"
230230
privateKey = "./test-integration/Credentials/privateKey.pem.key"

test-integration/IntegrationTests/IntegrationTestShadow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def randomString(lengthOfString):
150150
############################################################################
151151
# Main #
152152
# Check inputs
153-
myCheckInManager = checkInManager.checkInManager(2)
153+
myCheckInManager = checkInManager.checkInManager(3)
154154
myCheckInManager.verify(sys.argv)
155155

156-
host = "ajje7lpljulm4-ats.iot.us-east-1.amazonaws.com"
156+
host = myCheckInManager.host
157157
rootCA = "./test-integration/Credentials/rootCA.crt"
158158
certificate = "./test-integration/Credentials/certificate.pem.crt"
159159
privateKey = "./test-integration/Credentials/privateKey.pem.key"

test-integration/IntegrationTests/TestToolLibrary/checkInManager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ class checkInManager:
77
def __init__(self, numberOfInputParameters):
88
self._numberOfInputParameters = numberOfInputParameters
99
self.mode = None
10+
self.host = None
1011
self.customParameter = None
1112

1213
def verify(self, args):
1314
# Check if we got the correct command line params
1415
if len(args) != self._numberOfInputParameters + 1:
1516
exit(4)
1617
self.mode = str(args[1])
17-
if self._numberOfInputParameters + 1 > 2:
18-
self.customParameter = int(args[2])
18+
self.host = str(args[2])
19+
if self._numberOfInputParameters + 1 > 3:
20+
self.customParameter = int(args[3])

test-integration/run/run.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
# Define const
3434
USAGE="usage: run.sh <testMode> <NumberOfMQTTMessages> <LengthOfShadowRandomString> <NumberOfNetworkFailure>"
3535

36-
AWSMutualAuth_TodWorker_private_key="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestPrivateKey-vNUQU8"
37-
AWSMutualAuth_TodWorker_certificate="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestCertificate-vTRwjE"
36+
UnitTestHostArn="arn:aws:secretsmanager:us-east-1:180635532705:secret:unit-test/endpoint-HSpeEu"
37+
GreenGrassHostArn="arn:aws:secretsmanager:us-east-1:180635532705:secret:ci/greengrassv1/endpoint-DgM00X"
3838

39-
AWSGGDiscovery_TodWorker_private_key="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestGGDiscoveryPrivateKey-YHQI1F"
40-
AWSGGDiscovery_TodWorker_certificate="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestGGDiscoveryCertificate-TwlAcS"
39+
AWSMutualAuth_TodWorker_private_key="arn:aws:secretsmanager:us-east-1:180635532705:secret:ci/mqtt5/us/Mqtt5Prod/key-kqgyvf"
40+
AWSMutualAuth_TodWorker_certificate="arn:aws:secretsmanager:us-east-1:180635532705:secret:ci/mqtt5/us/Mqtt5Prod/cert-VDI1Gd"
4141

42-
AWSSecretForWebsocket_TodWorker_KeyId="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestWebsocketAccessKeyId-1YdB9z"
43-
AWSSecretForWebsocket_TodWorker_SecretKey="arn:aws:secretsmanager:us-east-1:123124136734:secret:V1IotSdkIntegrationTestWebsocketSecretAccessKey-MKTSaV"
42+
AWSGGDiscovery_TodWorker_private_key="arn:aws:secretsmanager:us-east-1:180635532705:secret:V1IotSdkIntegrationTestGGDiscoveryPrivateKey-BsLvNP"
43+
AWSGGDiscovery_TodWorker_certificate="arn:aws:secretsmanager:us-east-1:180635532705:secret:V1IotSdkIntegrationTestGGDiscoveryCertificate-DSwdhA"
4444

4545

4646
SDKLocation="./AWSIoTPythonSDK"
@@ -49,6 +49,8 @@ CREDENTIAL_DIR="./test-integration/Credentials/"
4949
TEST_DIR="./test-integration/IntegrationTests/"
5050
CA_CERT_URL="https://www.amazontrust.com/repository/AmazonRootCA1.pem"
5151
CA_CERT_PATH=${CREDENTIAL_DIR}rootCA.crt
52+
TestHost=$(python ${RetrieveAWSKeys} ${UnitTestHostArn})
53+
GreengrassHost=$(python ${RetrieveAWSKeys} ${GreenGrassHostArn})
5254

5355

5456

@@ -82,11 +84,7 @@ else
8284
python ${RetrieveAWSKeys} ${AWSDRSName_certificate} > ${CREDENTIAL_DIR}certificate_drs.pem.crt
8385
python ${RetrieveAWSKeys} ${AWSDRSName_privatekey} > ${CREDENTIAL_DIR}privateKey_drs.pem.key
8486
elif [ "$1"x == "Websocket"x ]; then
85-
ACCESS_KEY_ID_ARN=$(python ${RetrieveAWSKeys} ${AWSSecretForWebsocket_TodWorker_KeyId})
86-
ACCESS_SECRET_KEY_ARN=$(python ${RetrieveAWSKeys} ${AWSSecretForWebsocket_TodWorker_SecretKey})
8787
TestMode="Websocket"
88-
export AWS_ACCESS_KEY_ID=${ACCESS_KEY_ID_ARN}
89-
export AWS_SECRET_ACCESS_KEY=${ACCESS_SECRET_KEY_ARN}
9088
curl -s "${CA_CERT_URL}" > ${CA_CERT_PATH}
9189
echo -e "URL retrieved certificate data\n"
9290
elif [ "$1"x == "ALPN"x ]; then
@@ -115,11 +113,11 @@ else
115113
echo "***************************************************"
116114
for file in `ls ${TEST_DIR}`
117115
do
118-
# if [ ${file}x == "IntegrationTestMQTTConnection.py"x ]; then
119116
if [ ${file##*.}x == "py"x ]; then
120117
echo "[SUB] Running test: ${file}..."
121-
118+
122119
Scale=10
120+
Host=TestHost
123121
case "$file" in
124122
"IntegrationTestMQTTConnection.py") Scale=$2
125123
;;
@@ -131,7 +129,8 @@ else
131129
;;
132130
"IntegrationTestConfigurablePublishMessageQueueing.py") Scale=""
133131
;;
134-
"IntegrationTestDiscovery.py") Scale=""
132+
"IntegrationTestDiscovery.py") Scale=""
133+
Host=${GreengrassHost}
135134
;;
136135
"IntegrationTestAsyncAPIGeneralNotificationCallbacks.py") Scale=""
137136
;;
@@ -142,7 +141,7 @@ else
142141
"IntegrationTestJobsClient.py") Scale=""
143142
esac
144143

145-
python ${TEST_DIR}${file} ${TestMode} ${Scale}
144+
python ${TEST_DIR}${file} ${TestMode} ${TestHost} ${Scale}
146145
currentTestStatus=$?
147146
echo "[SUB] Test: ${file} completed. Exiting with status: ${currentTestStatus}"
148147
if [ ${currentTestStatus} -ne 0 ]; then

0 commit comments

Comments
 (0)