Skip to content

Added ND 4.1 version support to the nd_backup and nd_backup_restore module (DCNE-452) #141

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sajagana
Copy link
Collaborator

@sajagana sajagana commented Jul 15, 2025

fixes: DCNE-452

@sajagana sajagana changed the title 452 nd backup Added ND 4.1 version support to the nd_backup and nd_backup_restore module Jul 17, 2025
@sajagana sajagana force-pushed the 452_nd_backup branch 2 times, most recently from db14bd9 to f912c37 Compare July 18, 2025 15:48
@sajagana sajagana marked this pull request as ready for review July 18, 2025 15:49
@sajagana sajagana changed the title Added ND 4.1 version support to the nd_backup and nd_backup_restore module Added ND 4.1 version support to the nd_backup and nd_backup_restore module (DCNE-452) Jul 18, 2025
if not file_location and state in ["backup", "download"]:
nd.fail_json("Parameter 'file_location' is required when state is 'backup|download' for ND versions < 3.2.1.")
nd_backup_before_3_2_1(module, nd, name, encryption_key, file_location, backup_key, state)
elif nd.version >= "3.2.1":
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not else here?

Comment on lines +181 to +184
if len(encryption_key) < 8:
nd.fail_json("Please provide a minimum of 8 alphanumeric characters for the encryption key.")
elif not (any(char.isalpha() for char in encryption_key) and any(char.isdigit() for char in encryption_key) and encryption_key.isalnum()):
nd.fail_json("The encryption_key must contain at least one letter and one number, and have a minimum length of 8 characters.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

is ND not failing on these errors? I thought the agreement was made before to do the least amount of validation and let ND API handle it

if file_location:
response = nd.request("{0}/{1}/actions/download".format(path, name), method="GET", data=None, output_format="raw")
write_file(module, file_location, to_bytes(response))
elif module.check_mode:
Copy link
Collaborator

Choose a reason for hiding this comment

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

else?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also if nd.previous = nd.existing was set during query then elif state == "backup": could be combined with and not nd.existing: like you do for the download case

nd.existing = backups.get("backups", [])

if state == "absent" and nd.existing:
nd.previous = nd.existing
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it intended to do this here instead of already in the querying part?

Comment on lines +227 to +228
elif state == "download" and file_location and nd.existing:
if not module.check_mode:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not combine this when you are already making a complicated elif

elif state == "restore" and (not nd.existing or nd.existing.get("state") != "processing"):

if not module.check_mode: # Need to delete the imported file before starting the restore process
nd.request(import_path, method="DELETE")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we wait or verify that the file is deleted? How is ND handling this process? Could it have issues that the process is still running on ND, or you get response from API it is deleted?


if not module.check_mode:
nd.request(import_path, method="POST", data=import_payload)
time.sleep(10)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we sleep here? should we do validation of task completion? Assume there is some delay on ND, what if it takes longer then 10s?


# Operation not allowed if backup status is processing
elif state != "query" and nd.existing and nd.existing.get("state") == "processing":
nd.fail_json(
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we fail or provide a retry mechanism for this case?


def nd_backup_restore_before_3_2_1(nd, name, encryption_key, file_location, restore_key, state, module):
if state == "restore" and not (name and encryption_key and file_location):
nd.fail_json("state is restore but all/one of the following are missing: name, encryption_key, file_location")
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we make explicit what is missing?

Comment on lines 259 to +260
if method in ("PUT", "DELETE", "PATCH"):
nd.existing = nd.previous = sanitize(nd.query_obj(path, ignore_not_found_error=True), ND_REST_KEYS_TO_SANITIZE)
if not ignore_previous_state:
Copy link
Collaborator

Choose a reason for hiding this comment

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

combine conditional like you do in other conditionals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants