def test_module_args(self, mock_module, mock_client): """ hpe3par online clone - test module arguments """ PARAMS_FOR_PRESENT = { 'storage_system_ip': '192.168.0.1', 'storage_system_username': '******', 'storage_system_password': '******', 'snapshot_name': 'test_snapshot', 'base_volume_name': 'base_volume', 'read_only': False, 'expiration_time': 0, 'retention_time': 0, 'expiration_unit': 'Hours', 'retention_unit': 'Hours', 'expiration_hours': 0, 'retention_hours': 0, 'priority': 'MEDIUM', 'allow_remote_copy_parent': False, 'new_name': 'snapshot_new', 'rm_exp_time': False, 'state': 'present', 'schedule_name': 'test_schedule', 'task_freq': 'hourly', 'task_freq_custom': '0 * * * *' } mock_module.params = PARAMS_FOR_PRESENT mock_module.return_value = mock_module hpe3par_snapshot.main() mock_module.assert_called_with(argument_spec=self.fields)
def test_main_exit_online_snapshot(self, mock_restore_snapshot_online, mock_module, mock_client): """ hpe3par snapshot - success check """ PARAMS_FOR_PRESENT = { 'storage_system_ip': '192.168.0.1', 'storage_system_name': '3PAR', 'storage_system_username': '******', 'storage_system_password': '******', 'snapshot_name': 'test_snapshot', 'base_volume_name': None, 'read_only': None, 'expiration_time': None, 'retention_time': None, 'expiration_unit': None, 'retention_unit': None, 'expiration_hours': None, 'retention_hours': None, 'priority': None, 'allow_remote_copy_parent': False, 'new_name': None, 'rm_exp_time': None, 'state': 'restore_online', 'schedule_name': 'test_schedule', 'task_freq': 'hourly', 'task_freq_custom': '0 * * * *' } # This creates a instance of the AnsibleModule mock. mock_module.params = PARAMS_FOR_PRESENT mock_module.return_value = mock_module instance = mock_module.return_value mock_restore_snapshot_online.return_value = ( True, True, "Restored online snapshot test_snapshot successfully.", {}) hpe3par_snapshot.main() # AnsibleModule.exit_json should be called instance.exit_json.assert_called_with( changed=True, msg="Restored online snapshot test_snapshot successfully.") # AnsibleModule.fail_json should not be called self.assertEqual(instance.fail_json.call_count, 0)