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"
Beispiel #2
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'
        }
 def test_run_idrac_eventing_config_success_case05(
         self, idrac_connection_configure_eventing_mock,
         idrac_file_manager_config_eventing_mock, idrac_default_args):
     idrac_default_args.update({
         "share_name": "sharename",
         "share_mnt": "mountname",
         "share_user": "******",
         "share_password": "******",
         "destination_number": None,
         "destination": None,
         "snmp_v3_username": None,
         "snmp_trap_state": None,
         "alert_number": None,
         "email_alert_state": None,
         "address": None,
         "custom_message": None,
         "enable_alerts": None,
         "authentication": None,
         "smtp_ip_address": None,
         "smtp_port": None,
         "username": None,
         "password": None
     })
     message = {
         "changes_applicable": False,
         "Message": "No changes were applied",
         "changed": False,
         "Status": "Success"
     }
     obj = MagicMock()
     idrac_connection_configure_eventing_mock.config_mgr = obj
     type(obj).configure_snmp_trap_destination = PropertyMock(
         return_value=message)
     type(obj).configure_email_alerts = PropertyMock(return_value=message)
     type(obj).configure_idrac_alerts = PropertyMock(return_value=message)
     type(obj).configure_smtp_server_settings = PropertyMock(
         return_value=message)
     idrac_connection_configure_eventing_mock.config_mgr.apply_changes.return_value = message
     f_module = self.get_module_mock(params=idrac_default_args)
     f_module.check_mode = False
     result = self.module.run_idrac_eventing_config(
         idrac_connection_configure_eventing_mock, f_module)
     assert result['Message'] == 'No changes were applied'
 def test_idrac_get_firmware_info_exception_handling_case(
         self, idrac_firmware_info_connection_mock, exc_type, mocker,
         idrac_default_args):
     json_str = to_text(json.dumps({"data": "out"}))
     obj2 = MagicMock()
     idrac_firmware_info_connection_mock.update_mgr = obj2
     if exc_type not in [HTTPError, SSLValidationError]:
         type(obj2).InstalledFirmware = PropertyMock(
             side_effect=exc_type('test'))
     else:
         type(obj2).InstalledFirmware = PropertyMock(side_effect=exc_type(
             'http://testhost.com', 400, 'http error message',
             {"accept-type": "application/json"}, StringIO(json_str)))
     if not exc_type == URLError:
         result = self._run_module_with_fail_json(idrac_default_args)
         assert result['failed'] is True
     else:
         result = self._run_module(idrac_default_args)
     assert 'msg' in result
 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_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
     }
 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_get_lcstatus_exception_handling_case(
         self, exc_type, idrac_connection_lcstatus_mock,
         idrac_default_args):
     obj2 = MagicMock()
     idrac_connection_lcstatus_mock.config_mgr = obj2
     json_str = to_text(json.dumps({"data": "out"}))
     if exc_type == URLError:
         type(obj2).LCReady = PropertyMock(
             side_effect=exc_type("url open error"))
         result = self._run_module(idrac_default_args)
         assert result["unreachable"] is True
     elif exc_type not in [HTTPError, SSLValidationError]:
         type(obj2).LCReady = PropertyMock(
             side_effect=exc_type("exception message"))
         result = self._run_module_with_fail_json(idrac_default_args)
         assert result['failed'] is True
         assert 'msg' in result
     else:
         type(obj2).LCReady = PropertyMock(side_effect=exc_type(
             'http://testhost.com', 400, 'http error message',
             {"accept-type": "application/json"}, StringIO(json_str)))
         result = self._run_module_with_fail_json(idrac_default_args)
         assert result['failed'] is True
         assert 'msg' in result
 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
 def test_run_get_firmware_inventory_failed_case02(
         self, idrac_get_firmware_inventory_connection_mock,
         idrac_default_args):
     message = {'Status': "Failed", "Message": "Fetched..."}
     obj2 = MagicMock()
     idrac_get_firmware_inventory_connection_mock.update_mgr = obj2
     type(obj2).InstalledFirmware = PropertyMock(return_value=message)
     f_module = self.get_module_mock(params=idrac_default_args)
     result = self.module.run_get_firmware_inventory(
         idrac_get_firmware_inventory_connection_mock, f_module)
     assert result == ({
         'msg': {
             'Status': 'Failed',
             'Message': 'Fetched...'
         },
         'failed': True
     }, False)
     if "Status" in result[0]['msg']:
         if not result[0]['msg']['Status'] == "Success":
             assert result[0]['failed'] is True
 def idrac_firmware_info_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.update_mgr = idrac_obj
     type(idrac_obj).InstalledFirmware = PropertyMock(return_value="msg")
     return idrac_obj
Beispiel #12
0
 def idrac_mock(self, mocker):
     omsdk_mock = MagicMock()
     idrac_obj = MagicMock()
     omsdk_mock.job_mgr = idrac_obj
     type(idrac_obj).get_job_status = PropertyMock(return_value="job_id")
     return idrac_obj