Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennifer-John committed Oct 9, 2023
1 parent 371494f commit 3c3493e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
39 changes: 24 additions & 15 deletions plugins/modules/idrac_server_config_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@
'''

import os
import logging
import json
import copy
from datetime import datetime
Expand All @@ -525,6 +526,7 @@
from ansible.module_utils.six.moves.urllib.parse import urlparse


logging.basicConfig(filename='example.log', level=logging.INFO)
REDFISH_SCP_BASE_URI = "/redfish/v1/Managers/iDRAC.Embedded.1"
CHANGES_FOUND = "Changes found to be applied."
NO_CHANGES_FOUND = "No changes found to be applied."
Expand Down Expand Up @@ -655,8 +657,7 @@ def run_export_import_scp_http(idrac, module):
job_wait=module.params["job_wait"], share=share,
include_in_export=include_in_export)
scp_response = response_format_change(scp_response, module.params, scp_file_name_format)
if isinstance(scp_response, dict) and scp_response.get("TaskStatus") == "Critical":
module.fail_json(msg=FAIL_MSG.format(command), scp_status=scp_response)
exit_on_failure(module, scp_response, command)
return scp_response


Expand Down Expand Up @@ -703,19 +704,20 @@ def export_scp_redfish(module, idrac):
scp_components = ",".join(module.params["scp_components"])
include_in_export = IN_EXPORTS[module.params["include_in_export"]]
if share["share_type"] == "LOCAL":
logging.info("11")
scp_response = idrac.export_scp(export_format=module.params["export_format"],
export_use=module.params["export_use"],
target=scp_components, include_in_export=include_in_export,
job_wait=False, share=share, )
logging.info("12")
scp_response = wait_for_response(scp_response, module, share, idrac)
else:
scp_response = idrac.export_scp(export_format=module.params["export_format"],
export_use=module.params["export_use"],
target=scp_components, include_in_export=include_in_export,
job_wait=module.params["job_wait"], share=share, )
scp_response = response_format_change(scp_response, module.params, scp_file_name_format)
if isinstance(scp_response, dict) and scp_response.get("TaskStatus") == "Critical":
module.fail_json(msg=FAIL_MSG.format(command), scp_status=scp_response)
exit_on_failure(module, scp_response, command)
return scp_response


Expand Down Expand Up @@ -760,11 +762,16 @@ def preview_scp_redfish(module, idrac, http_share, import_job_wait=False):
else:
scp_response = idrac.import_preview(import_buffer=import_buffer, target=scp_targets, job_wait=job_wait_option)
scp_response = response_format_change(scp_response, module.params, share.get("file_name"))
if isinstance(scp_response, dict) and scp_response.get("TaskStatus") == "Critical":
module.fail_json(msg=FAIL_MSG.format(command), scp_status=scp_response)
exit_on_failure(module, scp_response, command)
return scp_response


def exit_on_failure(module, scp_response, command):
if isinstance(scp_response, dict) and (scp_response.get("TaskStatus") == "Critical" or
scp_response.get("JobState") == "Failed"):
module.fail_json(msg=FAIL_MSG.format(command), scp_status=scp_response)


def get_buffer_text(module, share):
buffer_text = None
if share["share_type"] == "LOCAL":
Expand Down Expand Up @@ -799,8 +806,7 @@ def import_scp_redfish(module, idrac, http_share):
else:
scp_response = idrac.import_scp(import_buffer=import_buffer, target=scp_targets, job_wait=module.params["job_wait"])
scp_response = response_format_change(scp_response, module.params, share.get("file_name"))
if isinstance(scp_response, dict) and scp_response.get("TaskStatus") == "Critical":
module.fail_json(msg=FAIL_MSG.format(command), scp_status=scp_response)
exit_on_failure(module, scp_response, command)
return scp_response


Expand All @@ -817,14 +823,14 @@ def idrac_import_scp_share(module, idrac, job_params):


def validate_input(module, scp_components):
if len(scp_components) != 1 and "ALL" in scp_components:
if len(scp_components) != 1 and "ALL" in scp_components:
module.fail_json(msg=SCP_ALL_ERR_MSG)
if module.params["command"] in ["import", "preview"]:
if module.params.get("import_buffer") is not None:
if module.params.get("scp_file") is not None:
module.fail_json(msg=MUTUALLY_EXCLUSIVE.format("scp_file"))
if module.params.get("share_name") is not None:
module.fail_json(msg=MUTUALLY_EXCLUSIVE.format("share_name"))
if module.params["command"] in ["import", "preview"]:
if module.params.get("import_buffer") is not None:
if module.params.get("scp_file") is not None:
module.fail_json(msg=MUTUALLY_EXCLUSIVE.format("scp_file"))
if module.params.get("share_name") is not None:
module.fail_json(msg=MUTUALLY_EXCLUSIVE.format("share_name"))


class ImportCommand():
Expand Down Expand Up @@ -892,12 +898,15 @@ def main():
http_share = False
if module.params.get("share_name") is not None:
http_share = module.params["share_name"].lower().startswith(('http://', 'https://'))
logging.info("0")
with iDRACRedfishAPI(module.params) as idrac:
logging.info("1")
command = module.params['command']
if command == 'import':
command_obj = ImportCommand(idrac, http_share, module)
elif command == 'export':
command_obj = ExportCommand(idrac, http_share, module)
logging.info("1")
else:
command_obj = PreviewCommand(idrac, http_share, module)
scp_status, changed = command_obj.execute()
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/plugins/modules/test_idrac_server_config_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_run_export_scp(self, params, idrac_scp_redfish_mock, idrac_default_args
"share_password": "sharepswd", "job_wait": False, "scp_components": "IDRAC",
"scp_file": "scp_file1.xml", "end_host_power_state": "On",
"shutdown_type": "Graceful"}},
{"message": SUCCESS_MSG.format("import"), "success": True,
{"message": SUCCESS_MSG.format("import"),
"json_data": {"Id": "JID_932024672685", "Message": NO_CHANGES_FOUND, "MessageId": "SYS043",
"PercentComplete": 100, "file": "http://{SCP SHARE PATH}/{SCP FILE NAME}.json"},
"mparams": {"share_name": "/share", "share_user": "sharename",
Expand Down Expand Up @@ -163,26 +163,26 @@ def test_import_scp_http_throws_exception(self, idrac_scp_redfish_mock, idrac_de
assert result['failed']

@pytest.mark.parametrize("params", [
{"message": "Invalid file path provided.", "success": False,
{"message": "Invalid file path provided.",
"mparams": {"share_name": "/share/", "share_user": "sharename",
"share_password": "sharepswd", "command": "import",
"job_wait": False, "scp_components": "IDRAC",
"scp_file": "scp_file3.xml", "end_host_power_state": "On",
"shutdown_type": "Graceful"}},
{"message": "proxy_support is enabled but all of the following are missing: proxy_server", "success": False,
{"message": "proxy_support is enabled but all of the following are missing: proxy_server",
"mparams": {"share_name": "http://10.10.10.10/myshare/", "proxy_type": "http",
"proxy_support": True, "job_wait": True, "scp_components": "IDRAC",
"proxy_port": 80, "export_format": "JSON",
"proxy_username": "proxy_username", "proxy_password": "proxy_password"}},
{"message": "import_buffer is mutually exclusive with share_name", "success": False,
{"message": "import_buffer is mutually exclusive with share_name",
"mparams": {"share_name": "192.168.0.1:/nfsshare", "command": "preview", "job_wait": False,
"import_buffer": "<SystemConfiguration><Component FQDD='iDRAC.Embedded.1'><Attribute Name='IPMILan.1#Enable'> \
<Value>Disabled</Value></Attribute></Component><Component FQDD='iDRAC.Embedded.1'>"}},
{"message": "import_buffer is mutually exclusive with scp_file", "success": False,
{"message": "import_buffer is mutually exclusive with scp_file",
"mparams": {"scp_file": "example.json", "job_wait": False, "command": "import",
"import_buffer": "<SystemConfiguration><Component FQDD='iDRAC.Embedded.1'><Attribute Name='IPMILan.1#Enable'> \
<Value>Disabled</Value></Attribute></Component><Component FQDD='iDRAC.Embedded.1'>"}},
{"message": "The option ALL cannot be used with options IDRAC, BIOS, NIC, or RAID.", "success": False,
{"message": "The option ALL cannot be used with options IDRAC, BIOS, NIC, or RAID.",
"mparams": {"share_name": "http://100.96.20.175/myshare/", "share_user": "sharename",
"share_password": "sharepswd", "command": "import",
"job_wait": True, "scp_components": ["IDRAC", "ALL"],
Expand Down

0 comments on commit 3c3493e

Please sign in to comment.