Example #1
0
 def test_create_storage_success_case01(
         self, idrac_connection_storage_volume_mock, idrac_default_args,
         mocker):
     idrac_default_args.update({
         "volumes": {
             "name": "volume1"
         },
         "controller_id": "x56y"
     })
     mocker.patch(
         "ansible_collections.dellemc.openmanage.plugins.modules.dellemc_idrac_storage_volume."
         "multiple_vd_config",
         return_value={
             "name": "volume1",
             "stripe_size": 1.3
         })
     obj = MagicMock()
     idrac_connection_storage_volume_mock.config_mgr.RaidHelper = obj
     obj.new_virtual_disk = Mock(return_value=[{
         "name": "volume1",
         "stripe_size": 1.3
     }])
     f_module = self.get_module_mock(params=idrac_default_args)
     result = self.module.create_storage(
         idrac_connection_storage_volume_mock, f_module)
     assert result == [{'name': 'volume1', 'stripe_size': 1.3}]
 def test_run_export_server_config_profile_runtimeerror_case(
         self, idrac_connection_server_configure_profile_mock,
         idrac_default_args, idrac_file_manager_server_config_profile_mock):
     idrac_default_args.update({
         "share_name": "sharename",
         "share_user": "******",
         "share_password": "******",
         "command": "export",
         "job_wait": True,
         "scp_components": "IDRAC",
         "scp_file": "scp_file.xml",
         "end_host_power_state": "On",
         "shutdown_type": "Graceful",
         "export_format": "XML",
         "export_use": "Default"
     })
     message = {"Status": "Failed"}
     f_module = self.get_module_mock(params=idrac_default_args)
     obj = MagicMock()
     idrac_connection_server_configure_profile_mock.config_mgr = obj
     obj.scp_export = Mock(return_value=message)
     with pytest.raises(Exception) as ex:
         self.module.run_export_server_config_profile(
             idrac_connection_server_configure_profile_mock, f_module)
     assert "Failed to export scp." == str(ex.value)
 def idrac_lc_status_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.config_mgr = idrac_obj
     type(idrac_obj).LCStatus = Mock(return_value="lcstatus")
     type(idrac_obj).LCReady = Mock(return_value="lcready")
     return idrac_obj
Example #4
0
 def _test_update_firmware_redfish(self, idrac_connection_firmware_mock, idrac_default_args, re_match_mock,
                                   mocker, idrac_connection_firmware_redfish_mock,
                                   fileonshare_idrac_firmware_mock):
     idrac_default_args.update({"share_name": "192.168.0.1:/share_name", "catalog_file_name": "catalog.xml",
                                "share_user": "******", "share_password": "******",
                                "share_mnt": "sharmnt",
                                "reboot": True, "job_wait": False, "ignore_cert_warning": True,
                                "share_type": "http", "idrac_ip": "idrac_ip", "idrac_user": "******",
                                "idrac_password": "******", "idrac_port": 443, 'apply_update': True
                                })
     mocker.patch(MODULE_PATH + "idrac_firmware.SHARE_TYPE",
                  return_value={"NFS": "NFS"})
     mocker.patch(MODULE_PATH + "idrac_firmware.eval",
                  return_value={"PackageList": []})
     mocker.patch(MODULE_PATH + "idrac_firmware.wait_for_job_completion", return_value=({}, None))
     f_module = self.get_module_mock(params=idrac_default_args)
     re_mock = mocker.patch(MODULE_PATH + "idrac_firmware.re",
                            return_value=MagicMock())
     re_mock.match(MagicMock(), MagicMock()).group.return_value = "3.60"
     mocker.patch(MODULE_PATH + "idrac_firmware.get_jobid",
                  return_value="23451")
     idrac_connection_firmware_mock.idrac.update_mgr.job_mgr.get_job_status_redfish.return_value = "23451"
     idrac_connection_firmware_mock.ServerGeneration = "14"
     upd_share = fileonshare_idrac_firmware_mock
     upd_share.remote_addr.return_value = "192.168.0.1"
     upd_share.remote.share_name.return_value = "share_name"
     upd_share.remote_share_type.name.lower.return_value = "NFS"
     result = self.module.update_firmware_redfish(idrac_connection_firmware_mock, f_module)
     assert result['update_msg'] == "Successfully triggered the job to update the firmware."
Example #5
0
 def re_match_mock(self, mocker):
     try:
         re_mock = mocker.patch(MODULE_PATH + 'idrac_firmware.re')
     except AttributeError:
         re_mock = MagicMock()
     obj = MagicMock()
     re_mock.match.group.return_value = obj
     return "3.30"
Example #6
0
 def ET_convert_mock(self, mocker):
     try:
         ET_mock = mocker.patch(MODULE_PATH + 'idrac_firmware.ET')
     except AttributeError:
         ET_mock = MagicMock()
     obj = MagicMock()
     ET_mock.fromstring.return_value = obj
     return ET_mock
Example #7
0
 def idrac_storage_volume_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.file_share_manager = idrac_obj
     omsdk_mock.config_mgr = idrac_obj
     type(idrac_obj).create_share_obj = Mock(return_value="servicesstatus")
     type(idrac_obj).set_liason_share = Mock(return_value="servicestatus")
     return idrac_obj
 def idrac_configure_eventing_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.file_share_manager = idrac_obj
     omsdk_mock.config_mgr = idrac_obj
     type(idrac_obj).create_share_obj = Mock(return_value="Status")
     type(idrac_obj).set_liason_share = Mock(return_value="Status")
     return idrac_obj
 def idrac_file_manager_system_lockdown_mock(self, mocker):
     try:
         file_manager_obj = mocker.patch(
             'ansible_collections.dellemc.openmanage.plugins.modules.dellemc_system_lockdown_mode.file_share_manager')
     except AttributeError:
         file_manager_obj = MagicMock()
     obj = MagicMock()
     file_manager_obj.create_share_obj.return_value = obj
     return file_manager_obj
Example #10
0
 def idrac_file_manager_config_bios_mock(self, mocker):
     try:
         file_manager_obj = mocker.patch(MODULE_PATH +
                                         'idrac_bios.file_share_manager')
     except AttributeError:
         file_manager_obj = MagicMock()
     obj = MagicMock()
     file_manager_obj.create_share_obj.return_value = obj
     return file_manager_obj
Example #11
0
 def os_mock(self, mocker):
     try:
         fi_mock = mocker.patch(MODULE_PATH +
                                'redfish_firmware.payload_file.get("file")')
     except AttributeError:
         fi_mock = MagicMock()
     obj = MagicMock()
     fi_mock.read.return_value = obj
     return fi_mock
 def is_changes_applicable_eventing_mock(self, mocker):
     try:
         changes_applicable_obj = mocker.patch(
             'ansible_collections.dellemc.openmanage.plugins.modules.dellemc_configure_idrac_eventing.config_mgr'
         )
     except AttributeError:
         changes_applicable_obj = MagicMock()
     obj = MagicMock()
     changes_applicable_obj.is_change_applicable.return_value = obj
     return changes_applicable_obj
Example #13
0
 def idrac_config_mngr_reset_mock(self, mocker):
     try:
         config_manager_obj = mocker.patch(MODULE_PATH +
                                           'idrac_reset.config_mgr')
     except AttributeError:
         config_manager_obj = MagicMock()
     obj = MagicMock()
     config_manager_obj.config_mgr.return_value = obj
     config_manager_obj.config_mgr.reset_idrac().return_value = obj
     return config_manager_obj
Example #14
0
 def test_delete_storage_case(self, idrac_connection_storage_volume_mock,
                              idrac_default_args):
     idrac_default_args.update({"volumes": [{"name": "nameofvolume"}]})
     msg = {"Status": "Success"}
     obj = MagicMock()
     idrac_connection_storage_volume_mock.config_mgr.RaidHelper = obj
     obj.delete_virtual_disk = Mock(return_value=msg)
     f_module = self.get_module_mock(params=idrac_default_args)
     result = self.module.delete_storage(
         idrac_connection_storage_volume_mock, f_module)
     assert result == {"Status": "Success"}
 def idrac_file_manager_export_lc_logs_mock(self, mocker):
     try:
         lclog_file_name_format = "%ip_%Y%m%d_%H%M%S_LC_Log.log"
         file_manager_obj = mocker.patch(
             MODULE_PATH +
             'idrac_lifecycle_controller_logs.file_share_manager')
     except AttributeError:
         file_manager_obj = MagicMock()
     obj = MagicMock()
     file_manager_obj.create_share_obj.return_value = obj
     file_manager_obj.myshare.new_file(
         lclog_file_name_format).return_value = obj
     return file_manager_obj
Example #16
0
    def get_module_mock(self, params=None, check_mode=False):
        if params is None:
            params = {}

        def fail_func(msg, **kwargs):
            raise AnsibleFailJSonException(msg, **kwargs)

        module = MagicMock()
        module.fail_json.side_effect = fail_func
        module.exit_json.side_effect = fail_func
        module.params = params
        module.check_mode = check_mode
        return module
Example #17
0
 def test_view_storage_success_case(self,
                                    idrac_connection_storage_volume_mock,
                                    idrac_default_args):
     idrac_default_args.update({
         "controller_id": "controller",
         "volume_id": "virtual_disk"
     })
     msg = {"Status": "Success"}
     obj = MagicMock()
     idrac_connection_storage_volume_mock.config_mgr.RaidHelper = obj
     obj.view_storage = Mock(return_value=msg)
     f_module = self.get_module_mock(params=idrac_default_args)
     result = self.module.view_storage(idrac_connection_storage_volume_mock,
                                       f_module)
     assert result == {"Status": "Success"}
Example #18
0
 def test_convert_xmltojson_case01(self, mocker,
                                   idrac_connection_firmware_mock,
                                   idrac_default_args, ET_convert_mock):
     idrac_default_args.update({
         "PackageList": [{
             "BaseLocation": None,
             "ComponentID": "18981",
             "ComponentType": "APAC",
             "Criticality": "3",
             "DisplayName": "Dell OS Driver Pack",
             "JobID": None,
             "PackageName":
             "Drivers-for-OS-Deployment_Application_X0DW6_WN64_19.10.12_A00.EXE",
             "PackagePath":
             "FOLDER05902898M/1/Drivers-for-OS-Deployment_Application_X0DW6_WN64_19.10.12_A00.EXE",
             "PackageVersion": "19.10.12"
         }]
     })
     mocker.patch(MODULE_PATH + "idrac_firmware.get_job_status",
                  return_value=("Component", False))
     mocker.patch(MODULE_PATH + 'idrac_firmware.ET')
     result = self.module._convert_xmltojson(
         {"PackageList": [{
             "INSTANCENAME": {
                 "PROPERTY": {
                     "NAME": "abc"
                 }
             }
         }]}, MagicMock(), None)
     assert result == ([], True, False)
Example #19
0
 def test_convert_xmltojson_case02(self, mocker, idrac_connection_firmware_mock, idrac_default_args):
     idrac_default_args.update({"Data": {"StatusCode": 200, "body": {"PackageList": [{}]}}})
     packagelist = {"PackageList": "INSTANCENAME"}
     mocker.patch(MODULE_PATH + "idrac_firmware.get_job_status", return_value=("Component", False))
     mocker.patch(MODULE_PATH + 'idrac_firmware.ET')
     result = self.module._convert_xmltojson(packagelist, MagicMock(), None)
     assert result == ([], True, False)
Example #20
0
 def test_get_user_account_2(self, idrac_connection_user_mock,
                             idrac_default_args, mocker):
     idrac_default_args.update({
         "state": "present",
         "new_user_name": "new_user_name",
         "user_name": "test",
         "user_password": "******",
         "privilege": "Administrator",
         "ipmi_lan_privilege": "Administrator",
         "ipmi_serial_privilege": "Administrator",
         "enable": True,
         "sol_enable": True,
         "protocol_enable": True,
         "authentication_protocol": "SHA",
         "privacy_protocol": "AES"
     })
     mocker.patch(MODULE_PATH + "idrac_user.iDRACRedfishAPI.export_scp",
                  return_value=MagicMock())
     mocker.patch(MODULE_PATH +
                  "idrac_user.iDRACRedfishAPI.get_idrac_local_account_attr",
                  return_value={
                      "Users.2#UserName": "******",
                      "Users.3#UserName": ""
                  })
     f_module = self.get_module_mock(params=idrac_default_args,
                                     check_mode=False)
     response = self.module.get_user_account(f_module,
                                             idrac_connection_user_mock)
     assert response[3] == 3
     assert response[
         4] == "/redfish/v1/Managers/iDRAC.Embedded.1/Accounts/3"
Example #21
0
 def test_view_storage_failed_case(self,
                                   idrac_connection_storage_volume_mock,
                                   idrac_default_args):
     idrac_default_args.update({
         "controller_id": "controller",
         "volume_id": "virtual_disk"
     })
     msg = {"Status": "Failed", "msg": "Failed to fetch storage details"}
     obj = MagicMock()
     idrac_connection_storage_volume_mock.config_mgr.RaidHelper = obj
     obj.view_storage = Mock(return_value=msg)
     f_module = self.get_module_mock(params=idrac_default_args)
     with pytest.raises(Exception) as ex:
         self.module.view_storage(idrac_connection_storage_volume_mock,
                                  f_module)
     assert "Failed to fetch storage details" == str(ex.value)
Example #22
0
    def test_run_bios_config_status_success_changed_false_case02(
            self, idrac_connection_configure_bios_mock, mocker,
            idrac_default_args, idrac_file_manager_config_bios_mock):
        idrac_default_args.update({
            "share_name": "sharename",
            "share_mnt": "mountname",
            "share_user": "******",
            "share_password": "******",
            "boot_sources": None,
            "boot_mode": "Bios",
            "nvme_mode": "NonRaid",
            "secure_boot_mode": "AuditMode",
            "onetime_boot_mode": "OneTimeBootSeq",
            "attributes": [""],
            "boot_sequence": None
        })
        message = {
            "Status": "Success",
            "Message": "No changes found to apply."
        }
        f_module = self.get_module_mock(params=idrac_default_args)
        f_module.deprecate.return_value = "boot_mode, nvme_mode, secure_boot_mode, onetime_boot_mode and " \
                                          "boot_sequence options have been deprecated, and will be removed. ' \
                                  'Please use the attributes option for Bios attributes configuration instead."

        f_module.check_mode = False
        obj = MagicMock()
        obj1 = MagicMock()
        obj2 = MagicMock()
        obj3 = MagicMock()
        idrac_connection_configure_bios_mock.config_mgr.configure_boot_mode = obj
        type(obj).BootModeTypes = PropertyMock(return_value="Bios")
        idrac_connection_configure_bios_mock.config_mgr.configure_nvme_mode = obj1
        type(obj).NvmeModeTypes = PropertyMock(return_value="NonRaid")
        idrac_connection_configure_bios_mock.config_mgr.configure_secure_boot_mode = obj2
        type(obj).SecureBootModeTypes = PropertyMock(return_value="AuditMode")
        idrac_connection_configure_bios_mock.config_mgr.configure_onetime_boot_mode = obj3
        type(obj).OneTimeBootModeTypes = PropertyMock(
            return_value="OneTimeBootSeq")
        idrac_connection_configure_bios_mock.config_mgr.configure_bios.return_value = message
        idrac_connection_configure_bios_mock.config_mgr.apply_changes.return_value = message
        msg = self.module.run_server_bios_config(
            idrac_connection_configure_bios_mock, f_module)
        assert msg == {
            'Message': 'No changes found to apply.',
            'Status': 'Success'
        }
Example #23
0
 def mock_response(self):
     mock_response = MagicMock()
     mock_response.getcode.return_value = 200
     mock_response.headers = mock_response.getheaders.return_value = {
         'X-Auth-Token': 'token_id'
     }
     mock_response.read.return_value = json.dumps({"value": "data"})
     return mock_response
Example #24
0
 def idrac_firmware_update_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.update_mgr = idrac_obj
     idrac_obj.update_from_repo = Mock(
         return_value={
             "update_status": {
                 "job_details": {
                     "Data": {
                         "StatusCode": 200,
                         "body": {
                             "PackageList": [{}]
                         }
                     }
                 }
             }
         })
     idrac_obj.update_from_repo_url = Mock(
         return_value={
             "job_details": {
                 "Data": {
                     "StatusCode": 200,
                     "body": {
                         "PackageList": [{}]
                     }
                 }
             }
         })
     return idrac_obj
 def test_main_get_lcstatus_success_case01(self,
                                           idrac_connection_lcstatus_mock,
                                           idrac_default_args):
     obj2 = MagicMock()
     idrac_connection_lcstatus_mock.config_mgr = obj2
     type(obj2).LCStatus = PropertyMock(return_value="lcstatus")
     type(obj2).LCReady = PropertyMock(return_value="lcready")
     result = self._run_module(idrac_default_args)
     assert result['lc_status_info']['LCReady'] == "lcready"
     assert result['lc_status_info']['LCStatus'] == "lcstatus"
 def test_main_idrac_get_firmware_inventory_faild_case01(
         self, idrac_get_firmware_inventory_connection_mock,
         idrac_default_args):
     error_msg = "Error occurs"
     obj2 = MagicMock()
     idrac_get_firmware_inventory_connection_mock.update_mgr = obj2
     type(obj2).InstalledFirmware = PropertyMock(
         side_effect=Exception(error_msg))
     result = self._run_module_with_fail_json(idrac_default_args)
     assert result['failed'] is True
     assert result['msg'] == "Error: {0}".format(error_msg)
 def test_run_get_firmware_inventory_failed_case01(
         self, idrac_get_firmware_inventory_connection_mock,
         idrac_default_args):
     f_module = self.get_module_mock(params=idrac_default_args)
     error_msg = "Error in Runtime"
     obj2 = MagicMock()
     idrac_get_firmware_inventory_connection_mock.update_mgr = obj2
     type(obj2).InstalledFirmware = PropertyMock(
         side_effect=Exception(error_msg))
     msg, err = self.module.run_get_firmware_inventory(
         idrac_get_firmware_inventory_connection_mock, f_module)
     assert msg['failed'] is True
     assert msg['msg'] == "Error: {0}".format(error_msg)
     assert err is True
 def test_main_idrac_get_firmware_info_success_case01(
         self, idrac_firmware_info_connection_mock, idrac_default_args):
     obj2 = MagicMock()
     idrac_firmware_info_connection_mock.update_mgr = obj2
     type(obj2).InstalledFirmware = PropertyMock(
         return_value={"Status": "Success"})
     result = self._run_module(idrac_default_args)
     assert result == {
         "firmware_info": {
             "Status": "Success"
         },
         "msg": "Successfully fetched the firmware inventory details.",
         "changed": False
     }
Example #29
0
 def test_set_liason_share_success_case(
         self, idrac_connection_storage_volume_mock, idrac_default_args,
         idrac_file_manager_storage_volume_mock):
     idrac_default_args.update({
         "share_name": "sharename",
         "state": "delete",
         "share_path": "sharpath"
     })
     message = {
         "Status": 'Failed',
         "Data": {
             'Message': "Failed to set Liason share"
         }
     }
     obj = MagicMock()
     idrac_connection_storage_volume_mock.tempfile.gettempdir() + os.sep
     idrac_connection_storage_volume_mock.file_share_manager.create_share_obj.return_value = message
     idrac_connection_storage_volume_mock.config_mgr = obj
     obj.set_liason_share = Mock(return_value=message)
     f_module = self.get_module_mock(params=idrac_default_args)
     with pytest.raises(Exception) as ex:
         self.module.set_liason_share(idrac_connection_storage_volume_mock,
                                      f_module)
     assert "Failed to set Liason share" == str(ex.value)
 def test_run_get_firmware_inventory_success_case01(
         self, idrac_get_firmware_inventory_connection_mock,
         idrac_default_args):
     obj2 = MagicMock()
     idrac_get_firmware_inventory_connection_mock.update_mgr = obj2
     type(obj2).InstalledFirmware = PropertyMock(return_value="msg")
     f_module = self.get_module_mock(params=idrac_default_args)
     msg, err = self.module.run_get_firmware_inventory(
         idrac_get_firmware_inventory_connection_mock, f_module)
     assert msg == {
         'failed':
         False,
         'msg':
         idrac_get_firmware_inventory_connection_mock.update_mgr.
         InstalledFirmware
     }
     assert msg['failed'] is False
     assert err is False