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
10 changes: 0 additions & 10 deletions ggtest/corruptFiles/hello_world.py

This file was deleted.

110 changes: 54 additions & 56 deletions test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def monitor_journalctl_for_message(self, service_name, message, timeout):

output = process.stdout.readline()
if output:
print(output.strip())
if message in output.strip():
print(f"Found log")
return True
Expand Down Expand Up @@ -98,7 +97,8 @@ def _get_things_in_thing_group(self, thing_group_name):
client = boto3.client("iot", region_name=self._region)
try:
response = client.list_things_in_thing_group(
thingGroupName=thing_group_name)
thingGroupName=thing_group_name
)
things = [thing for thing in response.get("things", [])]
return things
except Exception as e:
Expand All @@ -114,24 +114,23 @@ def _check_greengrass_group_deployment_status(self, deployment_id):
"""
try:
# Get the deployment status
response = self._ggClient.get_deployment(
deploymentId=deployment_id)
response = self._ggClient.get_deployment(deploymentId=deployment_id)

# Extract relevant information
deployment_status = response["deploymentStatus"]
target_arn = response["targetArn"]
creation_timestamp = response["creationTimestamp"]

things_list = self._get_things_in_thing_group(
target_arn.split("/")[-1])
things_list = self._get_things_in_thing_group(target_arn.split("/")[-1])

statistics_list = []

for thing in things_list:
try:
# Get deployment statistics
statistic = self._ggClient.list_effective_deployments(
coreDeviceThingName=thing)["effectiveDeployments"]
coreDeviceThingName=thing
)["effectiveDeployments"]
if statistic:
statistics_list.append({thing: statistic})
except Exception as e:
Expand All @@ -151,19 +150,13 @@ def _check_greengrass_group_deployment_status(self, deployment_id):
print(f"An error occurred: {e}")
return None

def create_deployment(self,
thingArn,
component_name,
component_version,
deployment_name="UATinPython"):
def create_deployment(
self, thingArn, component_name, component_version, deployment_name="UATinPython"
):
result = self._ggClient.create_deployment(
targetArn=thingArn,
deploymentName=deployment_name,
components={
component_name: {
"componentVersion": component_version
}
},
components={component_name: {"componentVersion": component_version}},
)

if result is not None:
Expand All @@ -173,22 +166,24 @@ def create_deployment(self,

def wait_for_deployment_till_timeout(self, timeout, deployment_id) -> str:
while timeout > 0:
result = self._check_greengrass_group_deployment_status(
deployment_id)
result = self._check_greengrass_group_deployment_status(deployment_id)
if result:
if result["statistics"]:
for entry in result["statistics"]:
for thing in entry:
for deployment in entry[thing]:
if str(deployment["deploymentId"]) == str(
deployment_id):
if (str(deployment[
"coreDeviceExecutionStatus"]) ==
"SUCCEEDED"):
deployment_id
):
if (
str(deployment["coreDeviceExecutionStatus"])
== "SUCCEEDED"
):
return "SUCCEEDED"
elif (str(deployment[
"coreDeviceExecutionStatus"]) ==
"FAILED"):
elif (
str(deployment["coreDeviceExecutionStatus"])
== "FAILED"
):
return "FAILED"
else:
pass
Expand All @@ -212,8 +207,9 @@ def _upload_files_to_s3(self, files, bucket_name):

try:
# Upload the file
response = self._s3Client.upload_file(file_path, bucket_name,
object_name)
response = self._s3Client.upload_file(
file_path, bucket_name, object_name
)
self._ggS3ObjToDelete.append(object_name)
except Exception as e:
print(f"Error uploading file: {e}")
Expand All @@ -235,12 +231,11 @@ def _upload_component_to_gg(self, recipe):
recipe_name = yaml.safe_load(recipe_content)["ComponentName"]

cloud_recipe_name = recipe_name + cloud_addition
modified_content = recipe_content.replace("$bucketName$",
self._bucket)
modified_content = modified_content.replace(
"$testArtifactsDirectory$", S3_ARTIFACT_DIR)
modified_content = recipe_content.replace("$bucketName$", self._bucket)
modified_content = modified_content.replace(
recipe_name, cloud_recipe_name)
"$testArtifactsDirectory$", S3_ARTIFACT_DIR
)
modified_content = modified_content.replace(recipe_name, cloud_recipe_name)

# Parse the modified content as YAML and convert it to JSON.
recipe_yaml = yaml.safe_load(modified_content)
Expand All @@ -249,11 +244,10 @@ def _upload_component_to_gg(self, recipe):
try:
# Create component version using the recipe
response = self._ggClient.create_component_version(
inlineRecipe=recipe_json)

print(
f"Successfully uploaded component with ARN: {response['arn']}"
inlineRecipe=recipe_json
)

print(f"Successfully uploaded component with ARN: {response['arn']}")
self._ggComponentToDeleteArn.append(response["arn"])
return cloud_recipe_name

Expand Down Expand Up @@ -289,12 +283,10 @@ def _create_corrupt_file(self, file_path):
os.makedirs(output_dir, exist_ok=True)

# Construct the new file path
new_file_path = os.path.join(output_dir,
os.path.basename(file_path))
new_file_path = os.path.join(output_dir, os.path.basename(file_path))

# Read the original file and write the corrupted version
with open(file_path, "rb") as f_in, open(new_file_path,
"wb") as f_out:
with open(file_path, "rb") as f_in, open(new_file_path, "wb") as f_out:
content = f_in.read()
f_out.write(content)
f_out.write(b"#corruption comment")
Expand Down Expand Up @@ -348,7 +340,8 @@ def get_ggcore_device_status(self, timeout, thing_group_name):

while timeout > 0:
return_val = self._ggClient.get_core_device(
coreDeviceThingName=things_in_group["things"][0])
coreDeviceThingName=things_in_group["things"][0]
)

if return_val == None or return_val["status"] != "HEALTHY":
time.sleep(1)
Expand Down Expand Up @@ -394,7 +387,8 @@ def system_interface(pytestconfig):
def test_Component_12_T1(gg_util_obj, system_interface):
# I upload component "MultiPlatform" version "1.0.0" from the local store
component_cloud_name = gg_util_obj.upload_component_with_version(
"MultiPlatform", "1.0.0")
"MultiPlatform", "1.0.0"
)

# And I create a deployment configuration with components and configuration
# | MultiPlatform | 1.0.0 |
Expand All @@ -406,8 +400,9 @@ def test_Component_12_T1(gg_util_obj, system_interface):
)["deploymentId"]

# Then the deployment completes with SUCCEEDED within 180 seconds
assert (gg_util_obj.wait_for_deployment_till_timeout(
180, deployment_id) == "SUCCEEDED")
assert (
gg_util_obj.wait_for_deployment_till_timeout(180, deployment_id) == "SUCCEEDED"
)

# And I can check the cli to see the status of component MultiPlatform is RUNNING
""" GG LITE CLI DOESN"T SUPPORT THIS YET. """
Expand All @@ -425,7 +420,8 @@ def test_Component_12_T1(gg_util_obj, system_interface):
def test_Component_16_T1(gg_util_obj, system_interface):
# I upload component "HelloWorld" version "1.0.0" from the local store
component_cloud_name = gg_util_obj.upload_component_with_version(
"HelloWorld", "1.0.0")
"HelloWorld", "1.0.0"
)

# Give 5 sec for cloud to calculate artifact checksum and make it "DEPLOYABLE"
time.sleep(5)
Expand All @@ -440,8 +436,9 @@ def test_Component_16_T1(gg_util_obj, system_interface):
)["deploymentId"]

# Then the deployment completes with SUCCEEDED within 120 seconds
assert (gg_util_obj.wait_for_deployment_till_timeout(
120, deployment_id) == "SUCCEEDED")
assert (
gg_util_obj.wait_for_deployment_till_timeout(120, deployment_id) == "SUCCEEDED"
)

# Then I can check the cli to see the status of component HelloWorld is RUNNING
""" GG LITE CLI DOESN"T SUPPORT THIS YET. """
Expand All @@ -464,14 +461,14 @@ def test_Component_27_T1(gg_util_obj, system_interface):
# And kernel registered as a Thing
# And my device is running the evergreen-kernel
component_cloud_name = gg_util_obj.upload_component_with_version(
"HelloWorld", "1.0.0")
"HelloWorld", "1.0.0"
)

# Give 5 sec for cloud to calculate artifact checksum and make it "DEPLOYABLE"
time.sleep(5)

# When I corrupt the contents of the component HelloWorld version 1.0.0 in the S3 bucket
assert gg_util_obj.upload_corrupt_artifacts_to_s3("HelloWorld",
"1.0.0") == True
assert gg_util_obj.upload_corrupt_artifacts_to_s3("HelloWorld", "1.0.0") == True
Copy link
Member

Choose a reason for hiding this comment

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

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

The == and != operators use the compared objects' __eq__ method to test if they are equal. To check if an object is a singleton, such as None, we recommend that you use the is identity comparison operator.

Learn more

Similar issue at line number 488.


# When I create a deployment configuration with components
# | HelloWorld | 1.0.0 |
Expand All @@ -484,8 +481,7 @@ def test_Component_27_T1(gg_util_obj, system_interface):

# Greengrass retries 10 times with a 1 minute interval
# Then the deployment completes with FAILED within 630 seconds
assert gg_util_obj.wait_for_deployment_till_timeout(
630, deployment_id) == "FAILED"
assert gg_util_obj.wait_for_deployment_till_timeout(630, deployment_id) == "FAILED"

# the greengrass log eventually contains the line "Failed to verify digest." within 30 seconds
assert (
Expand All @@ -502,7 +498,8 @@ def test_Component_27_T1(gg_util_obj, system_interface):
def test_FleetStatus_1_T1(gg_util_obj):
# When I upload component "HelloWorld" version "1.0.0" from the local store
component_cloud_name = gg_util_obj.upload_component_with_version(
"HelloWorld", "1.0.0")
"HelloWorld", "1.0.0"
)

# Give 5 sec for cloud to calculate artifact checksum and make it "DEPLOYABLE"
time.sleep(5)
Expand All @@ -518,8 +515,9 @@ def test_FleetStatus_1_T1(gg_util_obj):
)["deploymentId"]

# Then the deployment FirstDeployment completes with SUCCEEDED within 180 seconds
assert (gg_util_obj.wait_for_deployment_till_timeout(
180, deployment_id) == "SUCCEEDED")
assert (
gg_util_obj.wait_for_deployment_till_timeout(180, deployment_id) == "SUCCEEDED"
)

# And I can get the thing status as "HEALTHY" with all uploaded components within 60 seconds with groups
# | FssThingGroup |
Expand Down
Loading