protected override void TestCleanup() { if (pContext != IntPtr.Zero) { swnClientForWitness.WitnessrUnRegister(pContext); pContext = IntPtr.Zero; } try { swnClientForInterface.SwnUnbind(TestConfig.Timeout); } catch (Exception ex) { BaseTestSite.Log.Add( LogEntryKind.Warning, "TestCleanup: Unexpected Exception:", ex); } try { swnClientForWitness.SwnUnbind(TestConfig.Timeout); } catch (Exception ex) { BaseTestSite.Log.Add( LogEntryKind.Warning, "TestCleanup: Unexpected Exception:", ex); } base.TestCleanup(); }
// Use TestCleanup to run code after every test in a class have run protected override void TestCleanup() { if (smb2Client != null) { smb2Client.Disconnect(); } if (pContext != IntPtr.Zero) { swnClientForWitness.WitnessrUnRegister(pContext); pContext = IntPtr.Zero; } try { swnClientForInterface.SwnUnbind(TestConfig.Timeout); } catch (Exception ex) { BaseTestSite.Log.Add(LogEntryKind.Warning, "TestCleanup: Unexpected Exception: {0}", ex); } try { swnClientForWitness.SwnUnbind(TestConfig.Timeout); } catch (Exception ex) { BaseTestSite.Log.Add(LogEntryKind.Warning, "TestCleanup: Unexpected Exception: {0}", ex); } try { sutProtocolController.DeleteDirectory(uncSharePath, testDirectory); } catch (Exception ex) { BaseTestSite.Log.Add(LogEntryKind.Warning, "TestCleanup: Unexpected Exception: {0}", ex); } base.TestCleanup(); }
private void SWNRegister(SwnRegisterType registerType, SwnVersion expectedVersion) { WITNESS_INTERFACE_INFO registerInterface; IntPtr pDuplicateContext = IntPtr.Zero; swnClientForInterface = new SwnClient(); swnClientForWitness = new SwnClient(); string server = TestConfig.ClusteredFileServerName; IPAddress currentAccessIpAddr = SWNTestUtility.GetCurrentAccessIP(server); #region Get SWN witness interface list BaseTestSite.Log.Add(LogEntryKind.TestStep, "Get SWN witness interface list."); DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForInterface, currentAccessIpAddr, TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage, TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout, server), TestConfig.FailoverTimeout, "Retry BindServer until succeed within timeout span"); int ret; WITNESS_INTERFACE_LIST interfaceList = new WITNESS_INTERFACE_LIST(); DoUntilSucceed(() => { ret = swnClientForInterface.WitnessrGetInterfaceList(out interfaceList); BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrGetInterfaceList returns with result code = 0x{0:x8}", ret); return(SWNTestUtility.VerifyInterfaceList(interfaceList, TestConfig.Platform)); }, TestConfig.FailoverTimeout, "Retry to call WitnessrGetInterfaceList until succeed within timeout span"); swnClientForInterface.SwnUnbind(TestConfig.Timeout); swnClientForInterface = null; SWNTestUtility.GetRegisterInterface(interfaceList, out registerInterface); SWNTestUtility.CheckVersion(expectedVersion, (SwnVersion)registerInterface.Version); #endregion #region Register SWN witness BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register SWN witness with {0}.", registerType.ToString()); DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForWitness, (registerInterface.Flags & (uint)SwnNodeFlagsValue.IPv4) != 0 ? new IPAddress(registerInterface.IPV4) : SWNTestUtility.ConvertIPV6(registerInterface.IPV6), TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage, TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout), TestConfig.FailoverTimeout, "Retry BindServer until succeed within timeout span"); SwnVersion registerVersion; if (SwnVersion.SWN_VERSION_2 == expectedVersion) { registerVersion = (registerType == SwnRegisterType.InvalidVersion ? SwnVersion.SWN_VERSION_1 : SwnVersion.SWN_VERSION_2); } else { registerVersion = (registerType == SwnRegisterType.InvalidVersion ? SwnVersion.SWN_VERSION_2 : SwnVersion.SWN_VERSION_1); } string registerNetName = (registerType == SwnRegisterType.InvalidNetName ? "XXXXInvalid.contoso.comXXXX" : SWNTestUtility.GetPrincipleName(TestConfig.DomainName, server)); string accessIpAddr = (registerType == SwnRegisterType.InvalidIpAddress ? "255.255.255.255" : currentAccessIpAddr.ToString()); string registerClientName = Guid.NewGuid().ToString(); string shareName = (registerType == SwnRegisterType.InvalidShareName ? "XXXXInvalidShareNameXXXX" : TestConfig.ClusteredFileShare); uint keepAliveTimout = (registerType == SwnRegisterType.KeepAliveTimeout ? (uint)10 : (uint)120); BaseTestSite.Log.Add(LogEntryKind.Debug, "Register witness:"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tVersion: {0:x8}", (uint)registerVersion); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tNetName: {0}", registerNetName); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tShareName: {0}", shareName); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIpAddress: {0}", accessIpAddr); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tClientName: {0}", registerClientName); if (SwnVersion.SWN_VERSION_2 == expectedVersion) { ret = swnClientForWitness.WitnessrRegisterEx(registerVersion, registerNetName, shareName, accessIpAddr, registerClientName, WitnessrRegisterExFlagsValue.WITNESS_REGISTER_NONE, keepAliveTimout, out pContext); } else { ret = swnClientForWitness.WitnessrRegister(registerVersion, registerNetName, accessIpAddr, registerClientName, out pContext); } BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify server response for WitnessrRegister request."); // TDI to be filed, original fix for TDI 66777 and 69401 is not accurate, need clarify in new TDI // Windows server won't fail the request if the target resource being monitored is ScaleOut FS share when request containst invalid IP address or invalid share name // TODO: Test case should have ability to choose different server, otherwise we do not need such condition bool isScaleOutFsShare = ShareContainsSofs(server, Smb2Utility.GetUncPath(server, TestConfig.ClusteredFileShare)); if (registerType == SwnRegisterType.InvalidNetName) { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_INVALID_PARAMETER, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } else if (registerType == SwnRegisterType.InvalidVersion) { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_REVISION_MISMATCH, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } else if (registerType == SwnRegisterType.InvalidIpAddress) { if (!isScaleOutFsShare) { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } else { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_INVALID_STATE, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } } else if (registerType == SwnRegisterType.InvalidShareName) { if (!isScaleOutFsShare) { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } else { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_INVALID_STATE, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } } else { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); } if (registerType == SwnRegisterType.InvalidUnRegister) { ret = swnClientForWitness.WitnessrUnRegister(pContext); BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret); ret = swnClientForWitness.WitnessrUnRegister(pContext); if (TestConfig.Platform == Platform.WindowsServer2012) { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_NOT_FOUND, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret); } else { BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_INVALID_PARAMETER, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret); } pContext = IntPtr.Zero; swnClientForWitness.SwnUnbind(TestConfig.Timeout); } if (registerType == SwnRegisterType.InvalidRequest) { ret = swnClientForWitness.WitnessrUnRegister(pContext); BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret); uint callId; callId = swnClientForWitness.WitnessrAsyncNotify(pContext); BaseTestSite.Assert.AreNotEqual <uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId); RESP_ASYNC_NOTIFY respNotify; ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify); BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_NOT_FOUND, (SwnErrorCode)ret, "ExpectWitnessrAsyncNotify returns with result code = 0x{0:x8}", ret); pContext = IntPtr.Zero; swnClientForWitness.SwnUnbind(TestConfig.Timeout); } if (registerType == SwnRegisterType.KeepAliveTimeout) { uint callId; callId = swnClientForWitness.WitnessrAsyncNotify(pContext); BaseTestSite.Assert.AreNotEqual <uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId); RESP_ASYNC_NOTIFY respNotify; ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify); BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_TIMEOUT, (SwnErrorCode)ret, "ExpectWitnessrAsyncNotify returns with result code = 0x{0:x8}", ret); pContext = IntPtr.Zero; swnClientForWitness.SwnUnbind(TestConfig.Timeout); } #endregion #region Cleanup pContext = IntPtr.Zero; swnClientForWitness.SwnUnbind(TestConfig.Timeout); swnClientForWitness = null; #endregion }