From 491e6318eebf06e8ac4dd8ffff4ae57197686b7e Mon Sep 17 00:00:00 2001 From: Cheng Zhang Date: Thu, 8 Oct 2015 16:40:01 +0800 Subject: [PATCH] CP-13080: Run Health Check Tests as part of xenadmin build Signed-off-by: Cheng Zhang --- XenAdmin.sln | 12 - .../HealthCheckTests/CredentialTests.cs | 156 +++++++++++ .../RequestUploadTaskTests.cs | 255 ++++++++++++++++++ XenAdminTests/XenAdminTests.csproj | 7 + XenServerHealthCheckTests/CredentialTests.cs | 127 --------- XenServerHealthCheckTests/Program.cs | 18 -- .../Properties/AssemblyInfo.cs | 36 --- .../XenServerHealthCheckTests.csproj | 89 ------ XenServerHealthCheckTests/app.config | 3 - 9 files changed, 418 insertions(+), 285 deletions(-) create mode 100755 XenAdminTests/HealthCheckTests/CredentialTests.cs create mode 100755 XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs delete mode 100755 XenServerHealthCheckTests/CredentialTests.cs delete mode 100755 XenServerHealthCheckTests/Program.cs delete mode 100755 XenServerHealthCheckTests/Properties/AssemblyInfo.cs delete mode 100755 XenServerHealthCheckTests/XenServerHealthCheckTests.csproj delete mode 100755 XenServerHealthCheckTests/app.config diff --git a/XenAdmin.sln b/XenAdmin.sln index 8e049cc83..06e583414 100644 --- a/XenAdmin.sln +++ b/XenAdmin.sln @@ -31,8 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CFUValidator", "CFUValidato EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XenServerHealthCheck", "XenServerHealthCheck\XenServerHealthCheck.csproj", "{DEB3208D-1153-407C-8C99-0D8899BE25A5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XenServerHealthCheckTests", "XenServerHealthCheckTests\XenServerHealthCheckTests.csproj", "{23A30214-8F15-4C9D-A354-3E822A175B71}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -167,16 +165,6 @@ Global {DEB3208D-1153-407C-8C99-0D8899BE25A5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {DEB3208D-1153-407C-8C99-0D8899BE25A5}.Release|Mixed Platforms.Build.0 = Release|Any CPU {DEB3208D-1153-407C-8C99-0D8899BE25A5}.Release|Win32.ActiveCfg = Release|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Debug|Win32.ActiveCfg = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Release|Any CPU.Build.0 = Debug|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {23A30214-8F15-4C9D-A354-3E822A175B71}.Release|Win32.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XenAdminTests/HealthCheckTests/CredentialTests.cs b/XenAdminTests/HealthCheckTests/CredentialTests.cs new file mode 100755 index 000000000..322d4812b --- /dev/null +++ b/XenAdminTests/HealthCheckTests/CredentialTests.cs @@ -0,0 +1,156 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using XenAdmin; +using XenServerHealthCheck; +using XenAPI; +using XenAdmin.Core; +using XenAdmin.Network; +using XenAdminTests; +using System.IO.Pipes; +using System.IO; +using XenAdmin.Model; +using NUnit.Framework; + +namespace XenAdminTests.HealthCheckTests +{ + public class CredentialTests : UnitTester_TestFixture + { + private const char SEPARATOR = '\x202f'; // narrow non-breaking space. + + [Test] + public void CredentialOp() + { + CredentialReceiver.instance.Init(); + ServerListHelper.instance.Init(); + string HostName = "Host1"; + string UserName = "User1"; + string Password = "password1"; + int conSize = ServerListHelper.instance.GetServerList().Count; + //1. Empty credential + NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, null, null })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + List con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize); + + //2. Send credential and check result + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, UserName, Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize + 1); + + //3. Send credential twice and check result + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, UserName, Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize + 1); + + //4. remove credential and check result + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize); + + //5. add long credential size + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + HostName = "Host01234546789012345467890123454678901234546789012345467890123454678901234546789012345467890123454678901234546789"; + UserName = "User01234546789012345467890123454678901234546789012345467890123454678901234546789012345467890123454678901234546789"; + Password = "password101234546789012345467890123454678901234546789012345467890123454678901234546789012345467890123454678901234546789"; + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, UserName, Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize + 1); + + //6. remove long credential size + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize); + + + //7. semd 2 credential + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + HostName = "host3"; + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, UserName, Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + HostName = "host4"; + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName, UserName, Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize + 2); + + //8. remove 2 credential + pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + HostName = "host3"; + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + HostName = "host4"; + credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { HostName })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize); + + CredentialReceiver.instance.UnInit(); + } + } +} diff --git a/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs b/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs new file mode 100755 index 000000000..15f8fabfc --- /dev/null +++ b/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs @@ -0,0 +1,255 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using XenAdmin; +using XenServerHealthCheck; +using XenAPI; +using XenAdmin.Core; +using XenAdmin.Network; +using XenAdminTests; +using System.IO.Pipes; +using System.IO; +using XenAdmin.Model; +using NUnit.Framework; + +namespace XenAdminTests.HealthCheckTests +{ + public class RequestUploadTaskTests : DatabaseTester_TestFixture + { + private const char SEPARATOR = '\x202f'; // narrow non-breaking space. + private const string dbName = "state1.xml"; + public RequestUploadTaskTests() : base(dbName) { } + private static string UUID = "test-test"; + + public Dictionary cleanStack() + { + Dictionary config = new Dictionary(); + config[HealthCheckSettings.STATUS] = "true"; + config[HealthCheckSettings.UPLOAD_LOCK] = ""; + config[HealthCheckSettings.INTERVAL_IN_DAYS] = HealthCheckSettings.DEFAULT_INTERVAL_IN_DAYS.ToString(); + config[HealthCheckSettings.DAY_OF_WEEK] = "0"; + config[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = ""; + config[HealthCheckSettings.LAST_FAILED_UPLOAD] = ""; + return config; + } + + [Test] + public void CheckUnenrolledHostShouldRemoved() + { + CredentialReceiver.instance.Init(); + ServerListHelper.instance.Init(); + DatabaseManager.CreateNewConnection(dbName); + IXenConnection connection = DatabaseManager.ConnectionFor(dbName); + Session _session = DatabaseManager.ConnectionFor(dbName).Session; + DatabaseManager.ConnectionFor(dbName).LoadCache(_session); + Dictionary config = cleanStack(); + connection.LoadCache(_session); + + int conSize = ServerListHelper.instance.GetServerList().Count; + + NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); + pipeClient.Connect(); + string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { connection.Hostname, connection.Username, connection.Password })); + pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); + pipeClient.Close(); + System.Threading.Thread.Sleep(1000); + List con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize + 1); + + + //1. If XenServer has not enroll, lock will not been set. + config = cleanStack(); + config[HealthCheckSettings.STATUS] = "false"; + Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config); + Assert.IsFalse(RequestUploadTask.Request(connection, _session)); + con = ServerListHelper.instance.GetServerList(); + Assert.IsTrue(con.Count == conSize); + CredentialReceiver.instance.UnInit(); + } + + [Test] + public void checkUploadLock() + { + DatabaseManager.CreateNewConnection(dbName); + IXenConnection connection = DatabaseManager.ConnectionFor(dbName); + Session _session = DatabaseManager.ConnectionFor(dbName).Session; + DatabaseManager.ConnectionFor(dbName).LoadCache(_session); + + Dictionary config = cleanStack(); + connection.LoadCache(_session); + + //1. If XenServer has not enroll, lock will not been set. + config = cleanStack(); + config[HealthCheckSettings.STATUS] = "false"; + 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[HealthCheckSettings.UPLOAD_LOCK] = UUID + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + 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[HealthCheckSettings.UPLOAD_LOCK] = UUID + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + 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. + config = cleanStack(); + config[HealthCheckSettings.UPLOAD_LOCK] = UUID + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.DAY_OF_WEEK] = DateTime.Now.DayOfWeek.ToString(); + config[HealthCheckSettings.TIME_OF_DAY] = DateTime.Now.Hour.ToString(); + 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[HealthCheckSettings.UPLOAD_LOCK] = "test2-test2" + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + 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 + config = cleanStack(); + config[HealthCheckSettings.UPLOAD_LOCK] = "test2-test2" + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.DAY_OF_WEEK] = DateTime.Now.DayOfWeek.ToString(); + config[HealthCheckSettings.TIME_OF_DAY] = DateTime.Now.Hour.ToString(); + 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[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.LAST_FAILED_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(8))); + 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[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(6))); + 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[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.LAST_FAILED_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(5))); + 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[HealthCheckSettings.LAST_FAILED_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(7))); + Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config); + Assert.IsTrue(RequestUploadTask.Request(connection, _session)); + + + //11 Retry needed because no LAST_SUCCESSFUL_UPLOAD but not meet RetryIntervalInDays, lock should not be set + config = cleanStack(); + config[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = ""; + config[HealthCheckSettings.LAST_FAILED_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(8))); + 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[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(13))); + 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.Now.DayOfWeek + 1).ToString(); + config[HealthCheckSettings.TIME_OF_DAY] = DateTime.Now.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.Now.DayOfWeek.ToString(); + config[HealthCheckSettings.TIME_OF_DAY] = (DateTime.Now.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.Now.DayOfWeek.ToString(); + config[HealthCheckSettings.TIME_OF_DAY] = (DateTime.Now.Hour).ToString(); + Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config); + Assert.IsTrue(RequestUploadTask.Request(connection, _session)); + } + + [Test] + public void checkDemandLock() + { + DatabaseManager.CreateNewConnection(dbName); + IXenConnection connection = DatabaseManager.ConnectionFor(dbName); + Session _session = DatabaseManager.ConnectionFor(dbName).Session; + DatabaseManager.ConnectionFor(dbName).LoadCache(_session); + Dictionary config = cleanStack(); + connection.LoadCache(_session); + //1 Uploading is inprocess by current service, demand will be ignore + config = cleanStack(); + config[HealthCheckSettings.UPLOAD_LOCK] = UUID + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + config[HealthCheckSettings.NEW_UPLOAD_REQUEST] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + 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[HealthCheckSettings.UPLOAD_LOCK] = "test2-test2" + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + config[HealthCheckSettings.NEW_UPLOAD_REQUEST] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow); + 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[HealthCheckSettings.UPLOAD_LOCK] = "test2-test2" + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.NEW_UPLOAD_REQUEST] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(31))); + 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[HealthCheckSettings.UPLOAD_LOCK] = "test2-test2" + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromDays(14))); + config[HealthCheckSettings.NEW_UPLOAD_REQUEST] = HealthCheckSettings.DateTimeToString(DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(28))); + Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config); + Assert.IsTrue(RequestUploadTask.OnDemandRequest(connection, _session)); + } + } +} diff --git a/XenAdminTests/XenAdminTests.csproj b/XenAdminTests/XenAdminTests.csproj index e1610deb1..16542a31f 100644 --- a/XenAdminTests/XenAdminTests.csproj +++ b/XenAdminTests/XenAdminTests.csproj @@ -65,6 +65,8 @@ + + @@ -506,7 +508,12 @@ {2D78AC6C-B867-484A-A447-3C6FC8B8EAF7} XenOvfApi + + {deb3208d-1153-407c-8c99-0d8899be25a5} + XenServerHealthCheck + + - \ No newline at end of file diff --git a/XenServerHealthCheckTests/app.config b/XenServerHealthCheckTests/app.config deleted file mode 100755 index b7a7ef166..000000000 --- a/XenServerHealthCheckTests/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - -