Merge pull request #667 from cheng--zhang/CA-182881

CA-182881: Fix issue in schedule check in HealthCheckService
This commit is contained in:
Mihaela Stoica 2015-09-10 10:53:59 +01:00
commit d4f736d296
2 changed files with 23 additions and 2 deletions

View File

@ -183,13 +183,13 @@ namespace XenServerHealthCheck
}
int TimeOfDay = IntKey(config, HealthCheckSettings.TIME_OF_DAY, HealthCheckSettings.GetDefaultTime());
if (currentTime.DayOfWeek != dayOfWeek && currentTime.Hour != TimeOfDay)
if (currentTime.DayOfWeek != dayOfWeek || currentTime.Hour != TimeOfDay)
{
log.InfoFormat("Will not report for XenServer {0} for incorrect schedule", connection.Hostname);
return false;
}
log.InfoFormat("Upload schedule for {0} is {1}:{2}, meet current time {3}", connection.Hostname, dayOfWeek, TimeOfDay, currentTime.ToString());
}
return getLock(connection, session);
}

View File

@ -164,6 +164,27 @@ namespace XenServerHealthCheckTests
config[HealthCheckSettings.LAST_FAILED_UPLOAD] = "asd";
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
Assert.IsFalse (RequestUploadTask.Request(connection, _session));
//13. For schedule not meet the day
config = cleanStack();
config[HealthCheckSettings.DAY_OF_WEEK] = (DateTime.UtcNow.DayOfWeek +1).ToString();
config[HealthCheckSettings.TIME_OF_DAY] = DateTime.UtcNow.Hour.ToString();
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
Assert.IsFalse (RequestUploadTask.Request(connection, _session));
//14. For schedule not meet the hour
config = cleanStack();
config[HealthCheckSettings.DAY_OF_WEEK] = DateTime.UtcNow.DayOfWeek.ToString();
config[HealthCheckSettings.TIME_OF_DAY] = (DateTime.UtcNow.Hour + 1).ToString();
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
//15. For schedule all meet
config = cleanStack();
config[HealthCheckSettings.DAY_OF_WEEK] = DateTime.UtcNow.DayOfWeek.ToString();
config[HealthCheckSettings.TIME_OF_DAY] = (DateTime.UtcNow.Hour).ToString();
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
Assert.IsTrue(RequestUploadTask.Request(connection, _session));
}
catch (Exception)
{}