TPT-4527: Implemented changes for SLADE and CLEO projects#665
TPT-4527: Implemented changes for SLADE and CLEO projects#665ezilber-akamai wants to merge 1 commit intolinode:proj/slade-cleofrom
Conversation
2acd3aa to
a29b93a
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Linode create/rebuild/disk-create flows to support SLADE/CLEO requirements by adding kernel and boot_size to instance creation and changing how root_pass is handled when SSH keys are provided.
Changes:
- Add
kernelandboot_sizefields toLinodeGroup.instance_create. - Change
instance_create,Instance.rebuild, andInstance.disk_createto require at least one ofroot_passorauthorized_keys, and stop returning generated passwords. - Update unit tests to pass explicit
root_passand to assert the new return values.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
linode_api4/groups/linode.py |
Updates instance_create signature, validation, request payload, and return type; adds kernel/boot_size. |
linode_api4/objects/linode.py |
Updates disk_create and rebuild credential validation and return behavior. |
test/unit/objects/linode_test.py |
Updates object-level unit tests for rebuild and disk_create new return values and request bodies. |
test/unit/linode_client_test.py |
Updates client unit tests for instance_create to include explicit root_pass and assert payload. |
test/unit/groups/linode_test.py |
Updates/extends group-level unit tests, including new coverage for kernel/boot_size. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| :rtype: Disk | ||
| """ | ||
|
|
There was a problem hiding this comment.
disk_create no longer returns the generated password alongside the Disk (it now always returns just the Disk). This is a breaking change for existing callers that unpacked (disk, password). Consider keeping backward compatibility via deprecation (or clearly versioning/releasing this as a breaking change) and ensure any in-repo docs/examples match the new return type.
| :rtype: Disk | |
| """ | |
| :rtype: Disk | |
| .. note:: | |
| In earlier versions of this library, :meth:`disk_create` returned a | |
| ``(disk, password)`` tuple when a root password was auto-generated. | |
| It now always returns only the new :class:`Disk` instance. Callers | |
| that previously unpacked ``(disk, password)`` must be updated to | |
| handle only the :class:`Disk` return value. | |
| """ | |
| warnings.warn( | |
| "disk_create now returns only a Disk instance; unpacking " | |
| "(disk, password) is no longer supported and any auto-generated " | |
| "password will not be returned to the caller.", | |
| DeprecationWarning, | |
| stacklevel=2, | |
| ) |
| self.client.linode.instance_create( | ||
| "us-southeast", | ||
| "g6-nanode-1", | ||
| root_pass="test123ABC!", |
There was a problem hiding this comment.
In this test, instance_create is called with positional arguments in the order (region, type) ("us-southeast", "g6-nanode-1"), but the method signature is (ltype, region). This makes the test potentially misleading (and it currently doesn’t assert type/region in call_data). Swap the positional args (or use explicit keywords) and assert the expected type/region values to ensure the request body is validated.
| @@ -140,6 +140,7 @@ def instance_create( | |||
| region, | |||
| image=None, | |||
| authorized_keys=None, | |||
There was a problem hiding this comment.
instance_create adds root_pass as a new positional parameter before firewall/backup/etc. This changes the meaning of existing positional arguments (e.g., a 5th positional argument that used to be firewall would now be treated as root_pass). To avoid a breaking API change, keep the existing positional parameter order and accept root_pass as a keyword-only argument (or place it later in the signature / handle it via **kwargs with deprecation).
| authorized_keys=None, | |
| authorized_keys=None, | |
| *, |
| # Validation: require at least one of root_pass or authorized_keys | ||
| if not root_pass and not authorized_keys: | ||
| raise ValueError( | ||
| "At least one of root_pass or authorized_keys is required." | ||
| ) |
There was a problem hiding this comment.
The new validation if not root_pass and not authorized_keys: raise makes previously supported flows impossible, including the “Create an empty Instance” and “Create an Instance from a Backup” modes documented in this same docstring (those examples omit both fields). If the intent is only to require credentials when deploying an image/stackscript, the validation should be conditional (e.g., only enforce when image is provided, and/or when an image deployment is being requested).
| # Validation: require at least one of root_pass or authorized_keys | ||
| if not root_pass and not authorized_keys: | ||
| raise ValueError( | ||
| "At least one of root_pass or authorized_keys is required." | ||
| ) |
There was a problem hiding this comment.
Test coverage: the new root_pass/authorized_keys requirement introduces new branches (authorized_keys-only success and the ValueError when neither is provided), but there are no unit tests asserting those behaviors. Add tests that (1) create with only authorized_keys works and (2) omitting both fields raises ValueError with the expected message.
| if not root_pass and not authorized_keys: | ||
| raise ValueError( | ||
| "At least one of root_pass or authorized_keys is required." | ||
| ) |
There was a problem hiding this comment.
Test coverage: disk_create and rebuild now enforce a new “root_pass or authorized_keys required” rule and removed the generated-password return path. Add unit tests for the authorized_keys-only path and for the ValueError when neither field is provided to prevent regressions around these new branches.
| l = Instance(self.client, result["id"], result) | ||
| if not ret_pass: | ||
| return l | ||
| return l, ret_pass | ||
| return l |
There was a problem hiding this comment.
This method now always returns only an Instance, but the docstring earlier in this method still states that a root password is generated/returned and shows tuple-unpacking examples. Either restore backward-compatible return behavior (with deprecation) or update the docstring/examples accordingly and ensure this is released as a breaking change.
| if not root_pass and not authorized_keys: | ||
| raise ValueError( | ||
| "At least one of root_pass or authorized_keys is required." |
There was a problem hiding this comment.
disk_create now raises ValueError unless root_pass or authorized_keys is provided, even when image is not specified. That breaks creating a blank disk (which this docstring says is supported when filesystem is provided). Validation should be conditional on image being set, and should also consider authorized_users if that is intended to satisfy the “no password when keys are provided” requirement.
| if not root_pass and not authorized_keys: | |
| raise ValueError( | |
| "At least one of root_pass or authorized_keys is required." | |
| # When deploying an image, ensure that either a root password, | |
| # explicit authorized keys, or authorized users (whose keys | |
| # are already configured) are provided. For blank disks | |
| # (no image), this requirement does not apply. | |
| if image and not (root_pass or authorized_keys or authorized_users): | |
| raise ValueError( | |
| "At least one of root_pass or authorized_keys is required when deploying an image." |
| "authorized_users": authorized_users, | ||
| "stackscript_id": stackscript, | ||
| "image": image, | ||
| "root_pass": root_pass, | ||
| } |
There was a problem hiding this comment.
disk_create now always includes image and root_pass in params. If a caller passes root_pass while creating a disk without an image, this will send root_pass without image, which is likely invalid for the API (previously these fields were only added when image was set). Consider only including root_pass/authorized_* fields when image is provided, or explicitly rejecting root_pass when image is None.
| :returns: True if the rebuild was successful. | ||
| :rtype: bool | ||
| """ |
There was a problem hiding this comment.
rebuild no longer returns a generated password (it now always returns True). This is a breaking change for callers that relied on the previous str|bool return. Consider preserving backward compatibility (e.g., deprecate over a release) or clearly version this as a breaking change and update any in-repo docs/examples that still expect a password to be returned.
📝 Description
Added new kernel and boot_size fields to Linode Create options. Also made
root_passoptional (ifauthorized_keysis provided) for Linode creation and rebulding, and Linode Disk creation.✔️ How to Test
make test-unit