CP-42155: Removed HealthCheck tests.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2023-02-14 22:07:03 +00:00
parent 3a71ff29eb
commit b49481b83b
6 changed files with 0 additions and 836 deletions

View File

@ -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"};
}
}

View File

@ -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<ServerInfo> 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<ServerInfo> 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");
}
}
}

View File

@ -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<string, string> cleanStack()
{
Dictionary<string, string> config = new Dictionary<string, string>();
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<string, string> 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<ServerInfo> 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<string, string> 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<string, string> 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));
}
}
}

View File

@ -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");
}
}
}

View File

@ -76,7 +76,6 @@
<Compile Include="Controls\DecentGroupBoxTests.cs" />
<Compile Include="Controls\Folders\FolderListItemTests.cs" />
<Compile Include="Controls\LongStringComboBoxTest.cs" />
<Compile Include="HealthCheckTests\CredentialTests.cs" />
<Compile Include="LicensingTests\LicenceTimerTests.cs" />
<Compile Include="LicensingTests\ProductColumnComparerTests.cs" />
<Compile Include="MainWindowWrapper\MockMainWindow.cs" />
@ -112,7 +111,6 @@
<Compile Include="UnitTests\CPUMaskingTest.cs" />
<Compile Include="UnitTests\EmailAddressValidatorTests.cs" />
<Compile Include="UnitTests\ExceptionSerializationTest.cs" />
<Compile Include="UnitTests\HealthCheckAnalysisProgressTest.cs" />
<Compile Include="UnitTests\NamesAndMessagesTests.cs" />
<Compile Include="UnitTests\NaturalCompareTest.cs" />
<Compile Include="UnitTests\RpmVersionTests.cs" />
@ -181,10 +179,6 @@
<Project>{2D78AC6C-B867-484A-A447-3C6FC8B8EAF7}</Project>
<Name>XenOvfApi</Name>
</ProjectReference>
<ProjectReference Include="..\XenServerHealthCheck\XenServerHealthCheck.csproj">
<Project>{deb3208d-1153-407c-8c99-0d8899be25a5}</Project>
<Name>XenServerHealthCheck</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="WizardTests\Patching\" />

View File

@ -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<string, string> cleanStack()
{
Dictionary<string, string> config = new Dictionary<string, string>();
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<string, string> 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<ServerInfo> 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<string, string> 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<string, string> 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)
{ }
}
}
}