From b49481b83bd908e431bf73d2174ef947fbc2fc71 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 14 Feb 2023 22:07:03 +0000 Subject: [PATCH] CP-42155: Removed HealthCheck tests. Signed-off-by: Konstantina Chremmou --- XenAdminTests/CodeTests/AssemblyTests.cs | 1 - .../HealthCheckTests/CredentialTests.cs | 240 ---------------- .../RequestUploadTaskTests.cs | 256 ----------------- .../HealthCheckAnalysisProgressTest.cs | 68 ----- XenAdminTests/XenAdminTests.csproj | 6 - .../RequestUploadTaskTests.cs | 265 ------------------ 6 files changed, 836 deletions(-) delete mode 100755 XenAdminTests/HealthCheckTests/CredentialTests.cs delete mode 100755 XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs delete mode 100644 XenAdminTests/UnitTests/HealthCheckAnalysisProgressTest.cs delete mode 100755 XenServerHealthCheckTests/RequestUploadTaskTests.cs diff --git a/XenAdminTests/CodeTests/AssemblyTests.cs b/XenAdminTests/CodeTests/AssemblyTests.cs index b37797a20..b926443d6 100644 --- a/XenAdminTests/CodeTests/AssemblyTests.cs +++ b/XenAdminTests/CodeTests/AssemblyTests.cs @@ -71,7 +71,6 @@ namespace XenAdminTests.CodeTests { yield return new TestDataClass {AssemblyName = MainAssemblyName}; yield return new TestDataClass {AssemblyName = "XenOvf"}; - yield return new TestDataClass {AssemblyName = "XenServerHealthCheck"}; } } diff --git a/XenAdminTests/HealthCheckTests/CredentialTests.cs b/XenAdminTests/HealthCheckTests/CredentialTests.cs deleted file mode 100755 index d1ad567ec..000000000 --- a/XenAdminTests/HealthCheckTests/CredentialTests.cs +++ /dev/null @@ -1,240 +0,0 @@ -/* Copyright (c) Cloud Software Group, Inc. - * - * 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.Text; -using XenServerHealthCheck; -using XenCenterLib; -using System.IO.Pipes; -using XenAdmin.Model; -using NUnit.Framework; - -namespace XenAdminTests.HealthCheckTests -{ - [TestFixture, Category(TestCategories.Unit)] - public class CredentialTests - { - [OneTimeSetUp] - public void FixtureSetup() - { - CredentialReceiver.instance.Init(); - ServerListHelper.instance.Init(); - } - - [OneTimeTearDown] - public void FixtureTearDown() - { - CredentialReceiver.instance.UnInit(); - } - - [Test] - public void CredentialOp() - { - string HostName = "Host1"; - string UserName = "User1"; - string Password = "password1"; - - // Empty list - ServerListHelper.instance.ClearServerList(); - int conSize = 0; - List con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - - //1. Empty credential - NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.SEPARATOR.ToString(), new[] { HostName, null, null })); - 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. Send credential and check result - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.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(ServerListHelper.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(ServerListHelper.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(ServerListHelper.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(ServerListHelper.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. send 2 credentials - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - HostName = "host3"; - credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.SEPARATOR.ToString(), new[] { HostName, UserName, Password })); - pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); - HostName = "host4"; - credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.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 credentials - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - HostName = "host3"; - credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.SEPARATOR.ToString(), new[] { HostName })); - pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length); - HostName = "host4"; - credential = EncryptionUtils.ProtectForLocalMachine(String.Join(ServerListHelper.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); - } - - string metadata = "{\"XenCenter\":{\"System\":{\"Version\":\"0.0.0.0\",\"DotNetVersion\":\"4.0.30319.42000\",\"Culture\":\"English (United States)\"," + - "\"OsVersion\":\"Microsoft Windows NT 6.1.7601 Service Pack 1\",\"OsCulture\":\"English (United States)\",\"IpAddress\":\"\"}," + - "\"Settings\":{\"CFU\":{\"AllowXenCenterUpdates\":true,\"AllowPatchesUpdates\":true,\"AllowXenServerUpdates\":true}," + - "\"Proxy\":{\"UseProxy\":true,\"UseIEProxy\":false,\"BypassProxyForServers\":false,\"ProxyAuthentication\":true,\"ProxyAuthenticationMethod\":\"Digest\"}," + - "\"SaveAndRestore\":{\"SaveSessionCredentials\":true,\"RequireMainPassword\":false},\"HelpLastUsed\":\"2017-06-09T11:57:49.4046357Z\"}," + - "\"Infrastructure\":{\"TotalConnections\":22,\"Connected\":8},\"Plugins\":[],\"SourceOfData\":\"HealthCheck\",\"Created\":\"2017-07-03 14:24:14Z\"," + - "\"Reported\":\"@HealthCheckReportTime@\"}}"; - - [Test] - public void TestMetadata() - { - // Empty server list - ServerListHelper.instance.ClearServerList(); - int conSize = 0; - List con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - - // Send metadata, then check that it has been received and processed and that the server list remained unchanged - NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - byte[] metadataBytes = Encoding.UTF8.GetBytes(String.Join(ServerListHelper.SEPARATOR.ToString(), HealthCheckSettings.XENCENTER_METADATA, EncryptionUtils.ProtectForLocalMachine(metadata))); - pipeClient.Write(metadataBytes, 0, metadataBytes.Length); - pipeClient.Close(); - System.Threading.Thread.Sleep(1000); - con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - Assert.IsTrue(ServerListHelper.instance.XenCenterMetadata == metadata, "\"Send metadata\" test failed"); - - // Send metadata containing the separator - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - int separatorPosition = new Random().Next(0, metadata.Length); - metadata = metadata.Insert(separatorPosition, ServerListHelper.SEPARATOR.ToString()); - metadataBytes = Encoding.UTF8.GetBytes(String.Join(ServerListHelper.SEPARATOR.ToString(), HealthCheckSettings.XENCENTER_METADATA, EncryptionUtils.ProtectForLocalMachine(metadata))); - pipeClient.Write(metadataBytes, 0, metadataBytes.Length); - pipeClient.Close(); - System.Threading.Thread.Sleep(1000); - con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - Assert.IsTrue(ServerListHelper.instance.XenCenterMetadata == metadata, "\"Send metadata containing the separator\" test failed (separator at position {0})", separatorPosition); - - // Send empty metadata - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - metadataBytes = Encoding.UTF8.GetBytes(String.Join(ServerListHelper.SEPARATOR.ToString(), HealthCheckSettings.XENCENTER_METADATA, EncryptionUtils.ProtectForLocalMachine(""))); - pipeClient.Write(metadataBytes, 0, metadataBytes.Length); - pipeClient.Close(); - System.Threading.Thread.Sleep(1000); - con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - Assert.IsTrue(ServerListHelper.instance.XenCenterMetadata.Length == 0, "\"Send empty metadata\" test failed"); - - // Send metadata unencrypted - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - metadataBytes = Encoding.UTF8.GetBytes(String.Join(ServerListHelper.SEPARATOR.ToString(), HealthCheckSettings.XENCENTER_METADATA, metadata)); - pipeClient.Write(metadataBytes, 0, metadataBytes.Length); - pipeClient.Close(); - System.Threading.Thread.Sleep(1000); - con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - Assert.IsTrue(ServerListHelper.instance.XenCenterMetadata.Length == 0, "\"Send metadata unencrypted\" test failed"); - - // Send something else - pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out); - pipeClient.Connect(); - var someText = "Some random text"; - metadataBytes = Encoding.UTF8.GetBytes(String.Join(ServerListHelper.SEPARATOR.ToString(), "SomethingElse", EncryptionUtils.ProtectForLocalMachine(someText))); - pipeClient.Write(metadataBytes, 0, metadataBytes.Length); - pipeClient.Close(); - System.Threading.Thread.Sleep(1000); - con = ServerListHelper.instance.GetServerList(); - Assert.IsTrue(con.Count == conSize); - Assert.IsTrue(ServerListHelper.instance.XenCenterMetadata.Length == 0, "\"Send something else\" test failed"); - } - } -} diff --git a/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs b/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs deleted file mode 100755 index f05f0bb09..000000000 --- a/XenAdminTests/HealthCheckTests/RequestUploadTaskTests.cs +++ /dev/null @@ -1,256 +0,0 @@ -/* Copyright (c) Cloud Software Group, Inc. - * - * 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 XenServerHealthCheck; -using XenAPI; -using XenCenterLib; -using XenAdmin.Network; -using System.IO.Pipes; -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 = "TampaTwoHostPoolSelectioniSCSI.xml"; - private const string nonEmptyPassword = "nonemptypassword"; // needed when the credentials are sent to the HealthCheck, as the credential receiver will othrwise ignore them - - 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; - } - [TestFixtureSetUp] - public void FixtureSetup() - { - CredentialReceiver.instance.Init(); - ServerListHelper.instance.Init(); - } - - [TestFixtureTearDown] - public void FixtureTearDown() - { - CredentialReceiver.instance.UnInit(); - } - - [Test] - public void CheckUnenrolledHostShouldRemoved() - { - IXenConnection connection = DatabaseManager.ConnectionFor(dbName); - Session _session = DatabaseManager.ConnectionFor(dbName).Session; - Dictionary config = cleanStack(); - - ServerListHelper.instance.ClearServerList(); - 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, nonEmptyPassword })); - 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); - - } - - [Test, Timeout( 100 * 1000 )] - public void checkUploadLock() - { - IXenConnection connection = DatabaseManager.ConnectionFor(dbName); - Session _session = DatabaseManager.ConnectionFor(dbName).Session; - - Dictionary config = cleanStack(); - - //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() - { - IXenConnection connection = DatabaseManager.ConnectionFor(dbName); - Session _session = DatabaseManager.ConnectionFor(dbName).Session; - Dictionary config = cleanStack(); - - //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/UnitTests/HealthCheckAnalysisProgressTest.cs b/XenAdminTests/UnitTests/HealthCheckAnalysisProgressTest.cs deleted file mode 100644 index 1b5522511..000000000 --- a/XenAdminTests/UnitTests/HealthCheckAnalysisProgressTest.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (c) Cloud Software Group, Inc. - * - * 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 NUnit.Framework; -using XenAdmin.Actions; - -namespace XenAdminTests.UnitTests -{ - [TestFixture, Category(TestCategories.Unit)] - public class HealthCheckAnalysisProgressTest - { - [Test] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 0 }", ExpectedResult = 0)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 10 }", ExpectedResult = 10)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 100 }", ExpectedResult = 100)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 100.0 }", ExpectedResult = 100)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 0.01 }", ExpectedResult = 0.01)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 99.99 }", ExpectedResult = 99.99)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 10, \"131-435\" : 12 }", ExpectedResult = 10)] - [TestCase("{ \"30253b07-138a-1b17-80a1\" : 12, \"30253b07-138a-1b17-80a1-117317ded3ca\" : 10 }", ExpectedResult = 10)] - [TestCase("{ 30253b07-138a-1b17-80a1-117317ded3ca : 10 }", ExpectedResult = 10)] - [TestCase("{ 30253b07-138a-1b17-80a1-117317ded3ca : 10, 2345: 25 }", ExpectedResult = 10)] - [TestCase("{ 2345: 25, 30253b07-138a-1b17-80a1-117317ded3ca : 10 }", ExpectedResult = 10)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : not a number }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : \"not a number\" }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : \"10\" }", ExpectedResult = 10)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : \"-10\" }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : -0.56 }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : -10 }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : -100 }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 123 }", ExpectedResult = -1)] - [TestCase("{ \"30253b07-138a-1b17-80a1-117317ded3ca\" : 123.89 }", ExpectedResult = -1)] - [TestCase("", ExpectedResult = -1)] - [TestCase(" ", ExpectedResult = -1)] - [TestCase("{ }", ExpectedResult = -1)] - public double Run(string input) - { - return GetHealthCheckAnalysisResultAction.ParseAnalysisProgress(input, "30253b07-138a-1b17-80a1-117317ded3ca"); - } - } -} diff --git a/XenAdminTests/XenAdminTests.csproj b/XenAdminTests/XenAdminTests.csproj index 8ef89100f..e6be5fce3 100644 --- a/XenAdminTests/XenAdminTests.csproj +++ b/XenAdminTests/XenAdminTests.csproj @@ -76,7 +76,6 @@ - @@ -112,7 +111,6 @@ - @@ -181,10 +179,6 @@ {2D78AC6C-B867-484A-A447-3C6FC8B8EAF7} XenOvfApi - - {deb3208d-1153-407c-8c99-0d8899be25a5} - XenServerHealthCheck - diff --git a/XenServerHealthCheckTests/RequestUploadTaskTests.cs b/XenServerHealthCheckTests/RequestUploadTaskTests.cs deleted file mode 100755 index 86556744f..000000000 --- a/XenServerHealthCheckTests/RequestUploadTaskTests.cs +++ /dev/null @@ -1,265 +0,0 @@ -/* Copyright (c) Cloud Software Group, Inc. - * - * 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 Microsoft.VisualStudio.TestTools.UnitTesting; -using XenAdminTests; -using System.IO.Pipes; -using System.IO; -using XenAdmin.Model; - -namespace XenServerHealthCheckTests -{ - - class RequestUploadTaskTests: DatabaseTester_TestFixture - { - 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; - } - private const char SEPARATOR = '\x202f'; // narrow non-breaking space. - public void CheckUnenrolledHostShouldRemoved() - { - try - { - 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(); - } - catch (Exception) - { } - } - - public void checkUploadLock() - { - DatabaseManager.CreateNewConnection(dbName); - IXenConnection connection = DatabaseManager.ConnectionFor(dbName); - Session _session = DatabaseManager.ConnectionFor(dbName).Session; - DatabaseManager.ConnectionFor(dbName).LoadCache(_session); - try - { - 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)); - } - catch (Exception) - {} - } - - public void checkDemandLock() - { - DatabaseManager.CreateNewConnection(dbName); - IXenConnection connection = DatabaseManager.ConnectionFor(dbName); - Session _session = DatabaseManager.ConnectionFor(dbName).Session; - DatabaseManager.ConnectionFor(dbName).LoadCache(_session); - try - { - 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)); - } - catch (Exception) - { } - } - } -}