Skip to content

CI Adjustment #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1712a13
Initial commit for using new CI workflow in C++
TwistedTwigleg Sep 26, 2022
2262e2d
Fix YAML formatting
TwistedTwigleg Sep 26, 2022
06e60bb
Fix issue in Shadow sample, make all samples use C style comments con…
TwistedTwigleg Sep 26, 2022
b065c1d
Fix IPC sample compile issue
TwistedTwigleg Sep 26, 2022
795d29d
Get proper permissions to GitHub actions for tokens, send shadow upda…
TwistedTwigleg Sep 26, 2022
f8365e2
Use proper paths to utils
TwistedTwigleg Sep 26, 2022
d6896d4
Fix paths in CI file
TwistedTwigleg Sep 27, 2022
f3b2b4a
Fix DeviceAdvisor path, fix path to PubSub sample on MacOS
TwistedTwigleg Sep 27, 2022
859637c
Use CI role for cycle pub-sub, fix file path on Mac CI, adjust sample…
TwistedTwigleg Sep 27, 2022
09a7eb5
Initial test for Linux Smoke tests in CI
TwistedTwigleg Sep 27, 2022
03eb77c
Update submodules before building to see if that fixes the issue
TwistedTwigleg Sep 27, 2022
d263016
Download source to hopefully fix builder issue
TwistedTwigleg Sep 27, 2022
79960e0
Use Python builder
TwistedTwigleg Sep 27, 2022
d34df55
Fix not passing parameter to CMAKE
TwistedTwigleg Sep 27, 2022
1cdee56
Disable PKCS11 for now, run Device Advisor on Linux
TwistedTwigleg Sep 27, 2022
8df52c2
Add Shadow, Jobs, and Fleet Provisioning to CI run for Linux Smoke Tests
TwistedTwigleg Sep 27, 2022
30bdc35
Added DeviceDefender to CI, fixed Shadows, Jobs, and Fleet provisioni…
TwistedTwigleg Sep 27, 2022
3581ce2
Fix shadow sample not running and DeviceDefender failing
TwistedTwigleg Sep 27, 2022
d63f8fa
Add number to shadow payload
TwistedTwigleg Sep 27, 2022
1dd959e
Add print statements around setting promises to see where the double …
TwistedTwigleg Sep 27, 2022
e7cde69
Adjust shadow sample to use correct promise for disconnecting
TwistedTwigleg Sep 27, 2022
092fa26
Remove debug prints on Shadow, do not stop Windows CI in progress so …
TwistedTwigleg Sep 27, 2022
6935980
Fix inserting UUID
TwistedTwigleg Sep 27, 2022
5d5e237
Print the template parameters to see what is being passed
TwistedTwigleg Sep 27, 2022
7d394b8
Try formatting JSON different for fleet provisioning sample
TwistedTwigleg Sep 27, 2022
440268c
Another attempt at fixing the JSON for fleet provisioning
TwistedTwigleg Sep 27, 2022
315c49d
Remove debug print in fleet provisioning, add back PKCS11 to CI
TwistedTwigleg Sep 27, 2022
a45292d
Initial attempt at adding secure tunnel sample to CI
TwistedTwigleg Sep 28, 2022
d3b7f77
Remove space so role secret is correct for secure tunneling
TwistedTwigleg Sep 28, 2022
22b4111
Add print statements to see where the hang is in the Secure Tunnel sa…
TwistedTwigleg Sep 28, 2022
ff2633d
Print to stderr, run sample directly instead of via Python
TwistedTwigleg Sep 28, 2022
6a33d6f
Run secure tunnel sample via Python and Boto3 client
TwistedTwigleg Sep 28, 2022
b022365
Use the right filename for the Python secure tunnel utility
TwistedTwigleg Sep 28, 2022
7e3934d
Check why a secure tunnel client cannot be created
TwistedTwigleg Sep 28, 2022
6f2e01c
Use the right Boto3 client name
TwistedTwigleg Sep 28, 2022
836033f
Remove debug print statements in Secure Tunnel sample, fix running se…
TwistedTwigleg Sep 28, 2022
4aed884
Format fix
TwistedTwigleg Sep 28, 2022
87a5c13
Description correction for utility scripts
TwistedTwigleg Sep 28, 2022
bb07106
Only run PubSub in Codebuild now that we are using GitHub actions, up…
TwistedTwigleg Sep 28, 2022
ba17227
Code Review Changes
TwistedTwigleg Sep 29, 2022
d6d0c77
Some more comment changes I missed
TwistedTwigleg Sep 29, 2022
9257a77
Fix ci.yml mistake
TwistedTwigleg Sep 29, 2022
488c6f1
Use environment variable for samples folder
TwistedTwigleg Sep 29, 2022
ef690d7
Forgot to add .env
TwistedTwigleg Sep 29, 2022
d2620ce
Attach policy to DeviceAdvisor thing, fix secret value getting
TwistedTwigleg Sep 29, 2022
fd44f1a
Sync run_sample_ci
TwistedTwigleg Sep 30, 2022
1bc22f3
Run Windows Cert Connect in CI
TwistedTwigleg Oct 3, 2022
b53fd4f
Windows certificate connect sample executable name adjustment
TwistedTwigleg Oct 3, 2022
3135b7b
Move installing Boto3 to independent step
TwistedTwigleg Oct 4, 2022
77b0e96
Fix yml format mistake
TwistedTwigleg Oct 4, 2022
ddd020f
Merge branch 'main' into NewCIWorkflow
TwistedTwigleg Oct 4, 2022
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
319 changes: 304 additions & 15 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
"crt"
],
"env": {
"DA_TOPIC": "test/da",
"DA_SHADOW_PROPERTY": "datest",
"DA_SHADOW_VALUE_SET": "ON",
"DA_SHADOW_VALUE_DEFAULT": "OFF",
"DA_S3_NAME": "aws-iot-sdk-deviceadvisor-logs"
},
"hosts": {
"manylinux": {
Expand All @@ -28,13 +23,8 @@
"build",
"build-samples"
],
"test_steps": [
"python3 -m pip install boto3",
"python3 deviceadvisor/script/DATestRun.py",
"python3 devicedefender/script/DDTestRun.py"],
"variants" : {
"skip_sample": {
"!test_steps": [],
"!build_steps": [
"build"
]
Expand Down
21 changes: 0 additions & 21 deletions codebuild/samples/connect-custom-authorizer-linux.sh

This file was deleted.

19 changes: 0 additions & 19 deletions codebuild/samples/connect-websocket-linux.sh

This file was deleted.

4 changes: 0 additions & 4 deletions codebuild/samples/linux-smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ phases:
- echo Build started on `date`
- $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh
- $CODEBUILD_SRC_DIR/codebuild/samples/pubsub-linux.sh
- $CODEBUILD_SRC_DIR/codebuild/samples/connect-websocket-linux.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need codebuild at all anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need it for running samples, but there are webhooks for running Codebuild that we cannot remove without removing it for the entire repository. I also need to look at migrating Codebuild as well in the future, so I'm leaving just the PubSub Codebuild for that step in the migration.

- $CODEBUILD_SRC_DIR/codebuild/samples/pkcs11-connect-linux.sh
- $CODEBUILD_SRC_DIR/codebuild/samples/securetunnel-linux.sh
- $CODEBUILD_SRC_DIR/codebuild/samples/connect-custom-authorizer-linux.sh
post_build:
commands:
- echo Build completed on `date`
42 changes: 0 additions & 42 deletions codebuild/samples/pkcs11-connect-linux.sh

This file was deleted.

29 changes: 0 additions & 29 deletions codebuild/samples/securetunnel-linux.sh

This file was deleted.

10 changes: 5 additions & 5 deletions deviceadvisor/script/DATestConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"tests" :[ "MQTT Connect", "MQTT Publish", "MQTT Subscribe", "Shadow Publish", "Shadow Update"],
"test_suite_ids" :
{
"MQTT Connect" : "ejbdzmo3hf3v",
"MQTT Publish" : "euw7favf6an4",
"MQTT Subscribe" : "01o8vo6no7sd",
"Shadow Publish" : "elztm2jebc1q",
"Shadow Update" : "vuydgrbbbfce"
"MQTT Connect" : "mxn32qkm8npn",
"MQTT Publish" : "gcjhujhhz50p",
"MQTT Subscribe" : "nyiuiwx5yxtj",
"Shadow Publish" : "fttdr8ufljnf",
"Shadow Update" : "ng9t8am2jnry"
},
"test_exe_path" :
{
Expand Down
108 changes: 82 additions & 26 deletions deviceadvisor/script/DATestRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,50 @@ def process_logs(log_group, log_stream, thing_name):
logGroupName=log_group,
logStreamName=log_stream
)
log_file = thing_name + ".log"
log_file = "DA_Log_CPP_" + thing_name + ".log"
f = open(log_file, 'w')
for event in response["events"]:
f.write(event['message'])
f.close()
s3.Bucket(os.environ['DA_S3_NAME']).upload_file(log_file, log_file)

try:
secrets_client = boto3.client(
"secretsmanager", region_name=os.environ["AWS_DEFAULT_REGION"])
s3_bucket_name = secrets_client.get_secret_value(SecretId="ci/DeviceAdvisor/s3bucket")["SecretString"]
s3.Bucket(s3_bucket_name).upload_file(log_file, log_file)
print("[Device Advisor] Device Advisor Log file uploaded to "+ log_file)

except Exception:
print ("[Device Advisor] Error: could not store log in S3 bucket!")

os.remove(log_file)
print("[Device Advisor] Issues on test " + test_name + ". Please check out the logs at "+thing_name+".log on S3.")

# Sleep for a random time
def sleep_with_backoff(base, max):
sleep(random.randint(base,max))


##############################################
# Initialize variables
# create aws clients
client = boto3.client('iot')
dataClient = boto3.client('iot-data')
deviceAdvisor = boto3.client('iotdeviceadvisor')
s3 = boto3.resource('s3')
try:
client = boto3.client('iot')
dataClient = boto3.client('iot-data')
deviceAdvisor = boto3.client('iotdeviceadvisor')
s3 = boto3.resource('s3')
except Exception:
print ("[Device Advisor] Error: could not create boto3 clients")
exit(-1)

# const
BACKOFF_BASE = 5
BACKOFF_MAX = 10
# 60 minutes divided by the maximum back-off = longest time a DA run can last with this script.
MAXIMUM_CYCLE_COUNT = (3600 / BACKOFF_MAX)

# Did Device Advisor fail a test? If so, this should be true
did_at_least_one_test_fail = False

# load test config
f = open('deviceadvisor/script/DATestConfig.json')
Expand Down Expand Up @@ -80,21 +100,21 @@ def sleep_with_backoff(base, max):
# 'thingArn': 'string',
# 'thingId': 'string'
# }
print("[Device Advisor]Info: Started to create thing...")
print("[Device Advisor] Info: Started to create thing...")
create_thing_response = client.create_thing(
thingName=thing_name
)
os.environ["DA_THING_NAME"] = thing_name

except Exception as e:
print("[Device Advisor]Error: Failed to create thing: " + thing_name)
except Exception:
print("[Device Advisor] Error: Failed to create thing: " + thing_name)
exit(-1)


##############################################
# create certificate and keys used for testing
try:
print("[Device Advisor]Info: Started to create certificate...")
print("[Device Advisor] Info: Started to create certificate...")
# create_cert_response:
# {
# 'certificateArn': 'string',
Expand Down Expand Up @@ -123,25 +143,44 @@ def sleep_with_backoff(base, max):
os.environ["DA_CERTI"] = certificate_path
os.environ["DA_KEY"] = key_path

except:
client.delete_thing(thingName = thing_name)
print("[Device Advisor]Error: Failed to create certificate.")
except Exception:
try:
client.delete_thing(thingName = thing_name)
except Exception:
print ("[Device Advisor] Error: Could not delete thing.")
print("[Device Advisor] Error: Failed to create certificate.")
exit(-1)

certificate_arn = create_cert_response['certificateArn']
certificate_id = create_cert_response['certificateId']

##############################################
# attach policy to certificate
try:
secrets_client = boto3.client(
"secretsmanager", region_name=os.environ["AWS_DEFAULT_REGION"])
policy_name = secrets_client.get_secret_value(SecretId="ci/DeviceAdvisor/policy_name")["SecretString"]
client.attach_policy (
policyName= policy_name,
target = certificate_arn
)
except Exception as ex:
print (ex)
delete_thing_with_certi(thing_name, certificate_id, certificate_arn )
print("[Device Advisor] Error: Failed to attach policy.")
exit(-1)

##############################################
# attach certification to thing
try:
print("[Device Advisor]Info: Attach certificate to test thing...")
print("[Device Advisor] Info: Attach certificate to test thing...")
# attache the certificate to thing
client.attach_thing_principal(
thingName = thing_name,
principal = create_cert_response['certificateArn']
)

certificate_arn = create_cert_response['certificateArn']
certificate_id = create_cert_response['certificateId']

except:
except Exception:
delete_thing_with_certi(thing_name, certificate_id ,certificate_arn )
print("[Device Advisor]Error: Failed to attach certificate.")
exit(-1)
Expand All @@ -153,6 +192,7 @@ def sleep_with_backoff(base, max):
######################################
# set default shadow, for shadow update, if the
# shadow does not exists, update will fail
print("[Device Advisor] Info: About to update shadow.")
payload_shadow = json.dumps(
{
"state": {
Expand All @@ -169,6 +209,7 @@ def sleep_with_backoff(base, max):
payload = payload_shadow)
get_shadow_response = dataClient.get_thing_shadow(thingName = thing_name)
# make sure shadow is created before we go to next step
print("[Device Advisor] Info: About to wait for shadow update.")
while(get_shadow_response is None):
get_shadow_response = dataClient.get_thing_shadow(thingName = thing_name)

Expand All @@ -179,24 +220,31 @@ def sleep_with_backoff(base, max):
# 'suiteRunArn': 'string',
# 'createdAt': datetime(2015, 1, 1)
# }
print("[Device Advisor]Info: Start device advisor test: " + test_name)
print("[Device Advisor] Info: Start device advisor test: " + test_name)
sleep_with_backoff(BACKOFF_BASE, BACKOFF_MAX)
test_start_response = deviceAdvisor.start_suite_run(
suiteDefinitionId=DATestConfig['test_suite_ids'][test_name],
suiteRunConfiguration={
'primaryDevice': {
'thingArn': create_thing_response['thingArn'],
},
'parallelRun': True
suiteDefinitionId=DATestConfig['test_suite_ids'][test_name],
suiteRunConfiguration={
'primaryDevice': {
'thingArn': create_thing_response['thingArn'],
},
'parallelRun': True
})

# get DA endpoint
print("[Device Advisor] Info: Getting Device Advisor endpoint.")
endpoint_response = deviceAdvisor.get_endpoint(
thingArn = create_thing_response['thingArn']
)
os.environ['DA_ENDPOINT'] = endpoint_response['endpoint']

cycle_number = 0
while True:
cycle_number += 1
if (cycle_number >= MAXIMUM_CYCLE_COUNT):
print(f"[Device Advisor] Error: {cycle_number} of cycles lasting {BACKOFF_BASE} to {BACKOFF_MAX} seconds have passed.")
raise Exception(f"ERROR - {cycle_number} of cycles lasting {BACKOFF_BASE} to {BACKOFF_MAX} seconds have passed.")

# sleep for 1s every loop to avoid TooManyRequestsException
sleep_with_backoff(BACKOFF_BASE, BACKOFF_MAX)
test_result_responds = deviceAdvisor.get_suite_run(
Expand All @@ -214,6 +262,7 @@ def sleep_with_backoff(base, max):
elif (test_result_responds['status'] == 'RUNNING' and
test_result_responds['testResult']['groups'][0]['tests'][0]['status'] == 'RUNNING'):
try:
print ("[Device Advisor] Info: About to get start Device Advisor companion test application.")
exe_path = os.path.join("build/deviceadvisor/tests/",DATestConfig['test_exe_path'][test_name])
# Windows and MAC/LINUX has a different build folder structure
if platform.system() == 'Windows':
Expand All @@ -230,6 +279,7 @@ def sleep_with_backoff(base, max):
test_result[test_name] = test_result_responds['status']
# If the test failed, upload the logs to S3 before clean up
if(test_result[test_name] != "PASS"):
print ("[Device Advisor] Info: About to upload log to S3.")
log_url = test_result_responds['testResult']['groups'][0]['tests'][0]['logUrl']
group_string = re.search('group=(.*);', log_url)
log_group = group_string.group(1)
Expand All @@ -238,9 +288,11 @@ def sleep_with_backoff(base, max):
process_logs(log_group, log_stream, thing_name)
delete_thing_with_certi(thing_name, certificate_id ,certificate_arn )
break
except Exception as e:
except Exception:
delete_thing_with_certi(thing_name, certificate_id ,certificate_arn )
print("[Device Advisor]Error: Failed to test: "+ test_name)
did_at_least_one_test_fail = True
sleep_with_backoff(BACKOFF_BASE, BACKOFF_MAX)

##############################################
# print result and cleanup things
Expand All @@ -255,4 +307,8 @@ def sleep_with_backoff(base, max):
# if the test failed, we dont clean the Thing so that we can track the error
exit(-1)

if (did_at_least_one_test_fail == True):
print("[Device Advisor] At least one test failed!")
exit(-1)

exit(0)
Loading