Fixed exception thrown by actions without an API task (typically actions running synchronous calls).

Also, catch and log all exceptions and Failures.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2022-12-05 22:55:18 +00:00
parent 24c0714e02
commit 6dd175eab0
3 changed files with 13 additions and 36 deletions

View File

@ -2289,11 +2289,8 @@ namespace XenAdmin
{
if(!Program.RunInAutomatedTestMode)
{
if (a is AsyncAction)
{
AsyncAction aa = (AsyncAction) a;
aa.PrepareForLogReloadAfterRestart();
}
if (a is AsyncAction asyncAction)
asyncAction.PrepareForEventReloadAfterRestart();
if (!a.IsCompleted && a.CanCancel && !a.SafeToExit)
a.Cancel();

View File

@ -142,23 +142,24 @@ namespace XenAdmin.Actions
/// A call here just before exit will mean that the task will get picked
/// up as a meddling action on restart of xencenter, and thus reappear in the EventsTab.
/// </summary>
public void PrepareForLogReloadAfterRestart()
public void PrepareForEventReloadAfterRestart()
{
try
{
Task.RemoveXenCenterUUID(Session, RelatedTask.opaque_ref);
if (Session != null && !string.IsNullOrEmpty(RelatedTask?.opaque_ref))
Task.remove_from_other_config(Session, RelatedTask.opaque_ref, "XenCenterUUID");
}
catch(KeyNotFoundException)
catch (Failure f)
{
log.Debug("Removing XenCenterUUID failed - KeyNotFound");
// Read only user without task.other_config rights - just ignore this request
if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
return;
log.Debug($"Removing XenCenterUUID failed: {f.Message}");
}
catch(NullReferenceException)
catch (Exception e)
{
log.Debug("Removing XenCenterUUID failed - NullReference");
}
catch (WebException)
{
log.Debug("Removing XenCenterUUID failed - Could not connect through http");
log.Debug("Removing XenCenterUUID failed", e);
}
}

View File

@ -169,27 +169,6 @@ namespace XenAPI
}
}
public static void RemoveXenCenterUUID(Session session, string task)
{
if (session == null || string.IsNullOrEmpty(task))
return;
try
{
remove_from_other_config(session, task, "XenCenterUUID");
}
catch (Failure f)
{
if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
{
// Read only user without task.other_config rights - just ignore this request
return;
}
throw;
}
}
public override string Name()
{
return name_label.Replace("Async.", "");