CP-13080: Run Health Check Tests as part of xenadmin build

Signed-off-by: Cheng Zhang <cheng.zhang@citrix.com>
This commit is contained in:
Cheng Zhang 2015-10-08 16:40:01 +08:00
parent 8c451255d0
commit 491e6318ee
9 changed files with 418 additions and 285 deletions

View File

@ -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

View File

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

View File

@ -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<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;
}
[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<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();
}
[Test]
public void checkUploadLock()
{
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);
//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<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));
}
}
}

View File

@ -65,6 +65,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HealthCheckTests\CredentialTests.cs" />
<Compile Include="HealthCheckTests\RequestUploadTaskTests.cs" />
<Compile Include="UnitTests\SubnetworkMaskValidatorTest.cs" />
<Compile Include="UnitTests\ExceptionSerializationTest.cs" />
<Compile Include="XenModelTests\ActionTests\ActionTest.cs" />
@ -506,7 +508,12 @@
<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 />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -1,127 +0,0 @@
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 CredentialTests
{
private const char SEPARATOR = '\x202f'; // narrow non-breaking space.
public static void CredentialReceiverTests()
{
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
string HostName = "Host1";
string UserName = "User1";
string Password = "password1";
int conSize = ServerListHelper.instance.GetServerList().Count;
try
{
//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 }));
pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
pipeClient.Close();
List<ServerInfo> 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);
}
catch (Exception)
{ }
CredentialReceiver.instance.UnInit();
}
}
}

View File

@ -1,18 +0,0 @@
using System;
using XenServerHealthCheck;
namespace XenServerHealthCheckTests
{
class Program
{
static void Main(string[] args)
{
CredentialTests.CredentialReceiverTests();
RequestUploadTaskTests requestUploadTaskTests = new RequestUploadTaskTests();
requestUploadTaskTests.CheckUnenrolledHostShouldRemoved();
requestUploadTaskTests.checkUploadLock();
requestUploadTaskTests.checkDemandLock();
}
}
}

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XenServerHealthCheckTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XenServerHealthCheckTests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e55043e3-585d-4c44-ac7d-f898263b8bfa")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,89 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{23A30214-8F15-4C9D-A354-3E822A175B71}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XenServerHealthCheckTests</RootNamespace>
<AssemblyName>XenServerHealthCheckTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CookComputing.XmlRpcV2">
<HintPath>..\xml-rpc.net\obj\Release\CookComputing.XmlRpcV2.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CredentialTests.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestUploadTaskTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XenAdminTests\XenAdminTests.csproj">
<Project>{21B9482C-D255-40D5-ABA7-C8F00F99547C}</Project>
<Name>XenAdminTests</Name>
</ProjectReference>
<ProjectReference Include="..\XenAdmin\XenAdmin.csproj">
<Project>{70BDA4BC-F062-4302-8ACD-A15D8BF31D65}</Project>
<Name>XenAdmin</Name>
</ProjectReference>
<ProjectReference Include="..\XenCenterLib\XenCenterLib.csproj">
<Project>{9861DFA1-B41F-432D-A43F-226257DEBBB9}</Project>
<Name>XenCenterLib</Name>
</ProjectReference>
<ProjectReference Include="..\XenModel\XenModel.csproj">
<Project>{B306FC59-4441-4A5F-9F54-D3F68D4EE38D}</Project>
<Name>XenModel</Name>
</ProjectReference>
<ProjectReference Include="..\XenServerHealthCheck\XenServerHealthCheck.csproj">
<Project>{DEB3208D-1153-407C-8C99-0D8899BE25A5}</Project>
<Name>XenServerHealthCheck</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>