mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 12:30:50 +01:00
CP-12627: Use new xapi field health_check_config for Call Home
Signed-off-by: Cheng Zhang <cheng.zhang@citrix.com>
This commit is contained in:
parent
9fd7a2d6cc
commit
9c7865b270
@ -348,9 +348,9 @@ namespace XenAdmin.ServerDBs
|
||||
case "get_allowed_operations":
|
||||
return new Response<string[]>(new string[0]);
|
||||
|
||||
case "get_gui_config":
|
||||
case "get_health_check_config":
|
||||
string uuid1 = (string)args[1];
|
||||
return new Response<object>(get_gui_config(pmi.TypeName, uuid1, true));
|
||||
return new Response<object>(get_health_check_config(pmi.TypeName, uuid1, true));
|
||||
|
||||
}
|
||||
|
||||
@ -512,7 +512,7 @@ namespace XenAdmin.ServerDBs
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object get_gui_config(String clazz, String opaqueRef, bool makeResponse)
|
||||
public Object get_health_check_config(String clazz, String opaqueRef, bool makeResponse)
|
||||
{
|
||||
Db.Table table = db.Tables[clazz];
|
||||
|
||||
@ -523,7 +523,7 @@ namespace XenAdmin.ServerDBs
|
||||
|
||||
throw new Exception(Failure.OBJECT_NO_LONGER_EXISTS);
|
||||
}
|
||||
return table.Rows[opaqueRef].Props["gui_config"].XapiObjectValue;
|
||||
return table.Rows[opaqueRef].Props["health_check_config"].XapiObjectValue;
|
||||
}
|
||||
|
||||
private void edit_record(EditTypes editType, string clazz, string opaqueRef, string field, params object[] args)
|
||||
|
@ -84,16 +84,16 @@ namespace XenServerHealthCheck
|
||||
string newUploadLock = System.Configuration.ConfigurationManager.AppSettings["UUID"];
|
||||
newUploadLock += "|" + DateTime.UtcNow.ToString();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = newUploadLock;
|
||||
Pool.set_gui_config(session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
System.Threading.Thread.Sleep(SleepForLockConfirm);
|
||||
config = Pool.get_gui_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
config = Pool.get_health_check_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
return config[CallHomeSettings.UPLOAD_LOCK] == newUploadLock;
|
||||
}
|
||||
|
||||
public static bool Request(IXenConnection connection, Session session)
|
||||
{
|
||||
bool needRetry = false;
|
||||
Dictionary<string, string> config = Pool.get_gui_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
Dictionary<string, string> config = Pool.get_health_check_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
if (BoolKey(config, CallHomeSettings.STATUS) == false)
|
||||
{
|
||||
log.InfoFormat("Will not report for XenServer {0} that was not Enroll", connection.Hostname);
|
||||
@ -190,7 +190,7 @@ namespace XenServerHealthCheck
|
||||
private static int DemandTimeOutMinutes = 30;
|
||||
public static bool OnDemandRequest(IXenConnection connection, Session session)
|
||||
{
|
||||
Dictionary<string, string> config = Pool.get_gui_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
Dictionary<string, string> config = Pool.get_health_check_config(session, connection.Cache.Pools[0].opaque_ref);
|
||||
if (BoolKey(config, CallHomeSettings.STATUS) == false)
|
||||
{
|
||||
log.InfoFormat("Will not report on demand for XenServer {0} that was not Enroll", connection.Hostname);
|
||||
|
@ -45,20 +45,20 @@ namespace XenServerHealthCheckTests
|
||||
//1. If XenServer has not enroll, lock will not been set.
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.STATUS] = "false";
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//2.If the lock has already set by current service and not due, the lock should not been set again.
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = UUID + "|" + DateTime.UtcNow.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
|
||||
//3. If the lock already due or no one set the lock, but current schedule DayOfWeek and TimeOfDay is not correct, the lock should not been set.
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = UUID + "|" + DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//4. For lock due or not set by others and schedule meet, lock should be set.
|
||||
@ -66,13 +66,13 @@ namespace XenServerHealthCheckTests
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = UUID + "|" + DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.DAY_OF_WEEK] = DateTime.UtcNow.DayOfWeek.ToString();
|
||||
config[CallHomeSettings.TIME_OF_DAY] = DateTime.UtcNow.Hour.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//5. For Lock set by other service and not due, the lock should not been set by us.
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = "test2-test2" + "|" + DateTime.UtcNow.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//6. For Lock set by other service but already due, the lock can be set by current service
|
||||
@ -80,33 +80,33 @@ namespace XenServerHealthCheckTests
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = "test2-test2" + "|" + DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.DAY_OF_WEEK] = DateTime.UtcNow.DayOfWeek.ToString();
|
||||
config[CallHomeSettings.TIME_OF_DAY] = DateTime.UtcNow.Hour.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//7 Check LastFailedUpload is not empty and > LastSuccessfulUpload && INTERVAL_IN_DAYS using default, lock can be set
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.LAST_FAILED_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(8)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//8 For not due uploading, lock should not been set
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(6)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//9 For failed upload, retry was needed but not meet RetryIntervalInDays, lock should not been set
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.LAST_FAILED_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(5)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//10 For failed upload, retry was needed and meet RetryIntervalInDays, lock should be set
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_FAILED_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
|
||||
@ -114,14 +114,14 @@ namespace XenServerHealthCheckTests
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = "";
|
||||
config[CallHomeSettings.LAST_FAILED_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(8)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
|
||||
|
||||
//12 For no LAST_FAILED_UPLOAD or invalid LAST_FAILED_UPLOAD, lock should not be set if not due
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = DateTime.UtcNow.Subtract(TimeSpan.FromDays(13)).ToString();
|
||||
config[CallHomeSettings.LAST_FAILED_UPLOAD] = "asd";
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse (RequestUploadTask.Request(connection, _session));
|
||||
}
|
||||
catch (Exception)
|
||||
@ -142,28 +142,28 @@ namespace XenServerHealthCheckTests
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = UUID + "|" + DateTime.UtcNow.ToString();
|
||||
config[CallHomeSettings.NEW_UPLOAD_REQUEST] = DateTime.UtcNow.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.OnDemandRequest(connection, _session));
|
||||
|
||||
//2 Uploading is inprocess by other service, demand will be ignore
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = "test2-test2" + "|" + DateTime.UtcNow.ToString();
|
||||
config[CallHomeSettings.NEW_UPLOAD_REQUEST] = DateTime.UtcNow.ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.OnDemandRequest(connection, _session));
|
||||
|
||||
//3 Uploading is not due and demand due, demand will be ignore
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = "test2-test2" + "|" + DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.NEW_UPLOAD_REQUEST] = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(31)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsFalse(RequestUploadTask.OnDemandRequest(connection, _session));
|
||||
|
||||
//4 Uploading is due and demand not due, lock will be set
|
||||
config = cleanStack();
|
||||
config[CallHomeSettings.UPLOAD_LOCK] = "test2-test2" + "|" + DateTime.UtcNow.Subtract(TimeSpan.FromDays(14)).ToString();
|
||||
config[CallHomeSettings.NEW_UPLOAD_REQUEST] = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(28)).ToString();
|
||||
Pool.set_gui_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
|
||||
Assert.IsTrue(RequestUploadTask.OnDemandRequest(connection, _session));
|
||||
}
|
||||
catch (Exception)
|
||||
|
Loading…
Reference in New Issue
Block a user