def test_main_run_boot_to_network_iso_failure_case(self, idrac_connection_mock, idrac_mock, module_mock,
                                                    fileonshare_mock, omsdk_mock, minutes_to_cim_format_mock):
     idrac_mock.config_mgr.boot_to_network_iso.return_value = {"Status": "Failure"}
     params = {"idrac_ip": "idrac_ip", "idrac_user": "******", "idrac_password": "******",
               "share_name": "dummy_share_name", "share_password": "******",
               "iso_image": "dummy_iso_image", "expose_duration": "100"
               }
     set_module_args(params)
     result = self._run_module_with_fail_json(params)
     assert result['failed'] is True
 def test_main_run_boot_to_network_iso_success_case01(self, idrac_connection_mock, idrac_mock, module_mock,
                                                      fileonshare_mock, omsdk_mock, minutes_to_cim_format_mock):
     idrac_connection_mock.return_value.__enter__.return_value = idrac_mock
     idrac_mock.config_mgr.boot_to_network_iso.return_value = {"Status": "Success"}
     params = {"idrac_ip": "idrac_ip", "idrac_user": "******", "idrac_password": "******",
               "share_name": "dummy_share_name", "share_password": "******",
               "iso_image": "dummy_iso_image", "expose_duration": "100"
               }
     set_module_args(params)
     result = self._run_module(params)
     assert result == {'changed': True, 'boot_status': {'Status': 'Success'}}
 def test_main_run_boot_to_network_iso_fleonshare_failure_case(self, idrac_connection_mock, idrac_mock, module_mock,
                                                               fileonshare_mock, omsdk_mock,
                                                               minutes_to_cim_format_mock):
     idrac_connection_mock.return_value.__enter__.return_value = idrac_mock
     fileonshare_mock.side_effect = RuntimeError("Error in Runtime")
     params = {"idrac_ip": "idrac_ip", "idrac_user": "******", "idrac_password": "******",
               "share_name": "invalid_share_name", "share_password": "******",
               "iso_image": "dummy_iso_image", "expose_duration": "100"
               }
     set_module_args(params)
     result = self._run_module_with_fail_json(params)
     assert result == {'failed': True, 'msg': 'Error in Runtime'}
Example #4
0
 def execute_module(self, module_args, check_mode=False):
     """[workaround]: generic exception handling in module will
      be caught here and extracted the result for exit_json case"""
     module_args.update({'_ansible_check_mode': check_mode})
     set_module_args(module_args)
     result = {}
     try:
         with pytest.raises(AnsibleExitJson) as ex:
             self.module.main()
     except Exception as err:
         result = ast.literal_eval(err.args[0]['msg'])
     return result
 def test_minutes_to_cim_format_failure_case(self):
     fmodule = self.get_module_mock()
     with pytest.raises(Exception) as exc:
         set_module_args({})
         self.module.minutes_to_cim_format(fmodule, -1)
     assert exc.value.args[0] == "Invalid value for ExposeDuration."
Example #6
0
 def _run_module_with_fail_json(self, module_args):
     set_module_args(module_args)
     with pytest.raises(AnsibleFailJson) as exc:
         self.module.main()
     result = exc.value.args[0]
     return result
Example #7
0
 def _run_module(self, module_args, check_mode=False):
     module_args.update({'_ansible_check_mode': check_mode})
     set_module_args(module_args)
     with pytest.raises(AnsibleExitJson) as ex:
         self.module.main()
     return ex.value.args[0]