[Python] Add greengrassv2 Basics scenario + Hello - #8147
RuiqiGao-aws wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🤖 AI Code Example Review
This PR is mostly well-structured and functional, but has several issues that need to be addressed before it can be approved: the tests are integration-only with no unit/mock tests (unlike comparable examples), an unused import base64 in the wrapper, a missing README.md, missing conftest.py, and the scenario does not use demo_tools.question for user interaction as is standard for Python basics scenarios in this repo.
Detailed Review
-
No unit tests (blocking): The test file
test_greengrassv2_basics.pycontains only@pytest.mark.integintegration tests that hit live AWS. Comparable examples (e.g.,controltower,medical-imaging) always include unit tests using pytest stubs/mocks in addition to integration tests. Aconftest.pyand stub-based unit tests should be added so CI can run without AWS credentials. -
Missing
README.md(blocking): Every comparable Python basics example (controltower,medical-imaging, etc.) includes aREADME.mdwith prerequisites, instructions for setting up a virtual environment, and how to run the scenario. This is absent here. -
Unused import
base64ingreengrassv2_wrapper.py:import base64is imported at the top but never used anywhere in the file. This will trigger a linter warning and should be removed. -
No
demo_tools.questionfor interactivity: Comparable Python basics scenarios (e.g.,scenario_controltower.py,imaging_set_and_frames.py) usedemo_tools.questionto prompt users before each step, making scenarios genuinely interactive. This scenario runs non-interactively without any user prompts or theq.ask()pattern. Thedemo_toolspath setup (sys.path.append('../..')) is also missing. -
Missing
conftest.py: Thetest/directory lacks aconftest.py. Every comparable example has one to set upsys.pathand shared fixtures cleanly, rather than usingsys.path.insertinline in the test file. -
ARN parsing is fragile: In
_step2_create_component_v1and in the test, the component ARN (without version) is derived by splitting on:versions:. This is brittle. The ARN format for Greengrass components isarn:aws:greengrass:<region>:<account>:components:<name>:versions:<version>— splitting on:versions:is reasonable but the approach should be documented, or better yet, thelist_component_versionsmethod should accept the full versioned ARN and strip the version internally, or the API should be called with the known name instead. -
time.sleep(3)in integration test: Using a hard-coded sleep to wait for a component to becomeDEPLOYABLEis fragile and may still fail in slow environments. A polling loop with a timeout and exponential backoff would be more robust and is consistent with the guideline about using waiters/polling where needed. -
cancel_deploymentmay fail silently in cleanup scenario: In_step10_cancel_deployment, if the deployment is alreadyCOMPLETEDorINACTIVE(which is plausible since there are no real devices), thecancel_deploymentcall will raise aConflictException. The scenario does not handle this case gracefully with a user-friendly message — it will propagate and likely prevent the completion message from printing (thefinallyblock will still run, which is good, but the scenario will not print "complete!"). -
pytestinrequirements.txtis not a runtime dependency:pytest>=7.0.0is a test/dev dependency and should not be in the mainrequirements.txt. It should either be in a separaterequirements-test.txtor the test directory should have its ownrequirements.txt. -
Good aspects: The wrapper class is well-structured with good docstrings, proper pagination for all list operations, specific
ClientErrorcode handling per method, snippet tags are correctly placed, metadata YAML is complete and well-formed,_cleanup()is in afinallyblock, and unique suffixes are used to avoid resource name collisions. The Hello example is clean and follows the expected pattern.
This review was generated automatically using Amazon Bedrock. It compares your changes against existing examples and coding guidelines. Please use your judgment — this is advisory, not authoritative.
| """ | ||
|
|
||
| import base64 | ||
| import json |
There was a problem hiding this comment.
🤖 Unused import: base64 is never used anywhere in this file. Remove it to avoid linter warnings.
| """ | ||
|
|
||
| import sys | ||
| import os |
There was a problem hiding this comment.
🤖 Prefer a conftest.py to handle sys.path manipulation rather than doing it inline here. See comparable examples like controltower/test/conftest.py.
| "timeoutInSeconds": 60, | ||
| }, | ||
| } | ||
| deploy_response = wrapper.create_deployment( |
There was a problem hiding this comment.
🤖 time.sleep(3) is fragile. Consider polling with a timeout (e.g., retry up to 10 times with 2-second intervals checking component status) to wait for the component to become DEPLOYABLE, rather than a fixed sleep.
| @@ -0,0 +1,3 @@ | |||
| boto3>=1.26.0 | |||
| botocore>=1.29.0 | |||
| pytest>=7.0.0 | |||
There was a problem hiding this comment.
🤖 pytest is a test/development dependency, not a runtime dependency. Consider moving it to a requirements-test.txt or a test/requirements.txt file to follow the convention used in comparable examples.
| """ | ||
|
|
||
| import json | ||
| import logging |
There was a problem hiding this comment.
🤖 Comparable Python basics scenarios import and use demo_tools.question (e.g., import demo_tools.question as q) to prompt users before each step. Without q.ask() calls, this scenario is not interactive. Add sys.path.append('../..') and use q.ask() to pause between steps as the pattern requires.
| ) | ||
| print(f" ARN: {version.get('arn')}") | ||
|
|
||
| print("\nNote: Versions are listed with the greatest (newest) version first.") |
There was a problem hiding this comment.
🤖 The cancel_deployment call may raise ConflictException if the deployment has already reached a terminal state (COMPLETED, CANCELED, FAILED). Since there are no real devices in this scenario, the deployment will likely complete or go INACTIVE almost immediately. Add handling here or in _step10_cancel_deployment to catch this gracefully and inform the user.
| message="Hello from Greengrass Basics v2.0.0 - Enhanced Edition", | ||
| log_level="INFO", | ||
| ) | ||
| response = self.wrapper.create_component_version(recipe) |
There was a problem hiding this comment.
🤖 The ARN splitting logic self.v1_arn.rsplit(':versions:', 1) is fragile and undocumented. Consider adding a comment explaining the ARN format arn:aws:greengrass:<region>:<account>:components:<name>:versions:<version> to clarify why this split is safe.
|
Closing: end-to-end diagnostic run of the CodeLoom PRAgent with a classic PAT instead of device flow, to confirm the auth path. Not for review. |
Auto-generated Python code examples for greengrassv2 (Hello + Basics scenario + wrapper + tests)