/// <summary> /// SWN client invoke WitnessrGetInterfaceList method to retrieve information about the interfaces to which witness client connections can be made. /// </summary> /// <param name="InterfaceList">A pointer to a PWITNESS_INTERFACE_LIST, as specified in section 2.2.1.9.</param> /// <returns>Return zero if success, otherwise return nonzero.</returns> public int WitnessrGetInterfaceList(out WITNESS_INTERFACE_LIST InterfaceList) { Int3264[] paramList; int retVal = 0; paramList = new Int3264[] { IntPtr.Zero, //out param IntPtr.Zero //return value }; using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrGetInterfaceList)) { WITNESS_INTERFACE_LIST_RPC rpcList = TypeMarshal.ToStruct <WITNESS_INTERFACE_LIST_RPC>(Marshal.ReadIntPtr(outParamList[0])); WITNESS_INTERFACE_INFO[] infoList = new WITNESS_INTERFACE_INFO[rpcList.NumberOfInterfaces]; int sizeInByte = Marshal.SizeOf(typeof(WITNESS_INTERFACE_INFO)); for (int i = 0; i < rpcList.NumberOfInterfaces; i++) { IntPtr pInfo = IntPtrUtility.Add(rpcList.InterfaceInfo, i * sizeInByte); infoList[i] = (WITNESS_INTERFACE_INFO)Marshal.PtrToStructure(pInfo, typeof(WITNESS_INTERFACE_INFO)); } InterfaceList = new WITNESS_INTERFACE_LIST(); InterfaceList.NumberOfInterfaces = rpcList.NumberOfInterfaces; InterfaceList.InterfaceInfo = infoList; retVal = outParamList[paramList.Length - 1].ToInt32(); } return(retVal); }
private void FileServerFailoverTest(string server, FileServerType fsType, bool reconnectWithoutFailover = false) { int ret = 0; uint callId = 0; IPAddress currentAccessIpAddr = null; WITNESS_INTERFACE_INFO registerInterface = new WITNESS_INTERFACE_INFO(); WITNESS_INTERFACE_LIST interfaceList = new WITNESS_INTERFACE_LIST(); currentAccessIpAddr = SWNTestUtility.GetCurrentAccessIP(server); BaseTestSite.Log.Add(LogEntryKind.Debug, "Get current file server IP: {0}.", currentAccessIpAddr); #region Register SWN witness if (witnessType == WitnessType.SwnWitness) { if (TestConfig.IsWindowsPlatform && fsType == FileServerType.ScaleOutFileServer) { // Windows Server: when stopping a non-owner node of ScaleOutFS, no notication will be sent by SMB witness. // So get one IP of the owner node of ScaleOutFS to access. string resourceOwnerNode = sutController.GetClusterResourceOwner(server); IPAddress[] ownerIpList = Dns.GetHostEntry(resourceOwnerNode).AddressList; foreach (var ip in ownerIpList) { BaseTestSite.Log.Add(LogEntryKind.Debug, "Owner IP: {0}", ip); } if (!ownerIpList.Contains(currentAccessIpAddr)) { currentAccessIpAddr = null; IPAddress[] accessIpList = Dns.GetHostEntry(server).AddressList; foreach (var ip in accessIpList) { if (ownerIpList.Contains(ip)) { currentAccessIpAddr = ip; break; } } BaseTestSite.Assert.IsNotNull(currentAccessIpAddr, "IP should not be null."); BaseTestSite.Log.Add(LogEntryKind.Debug, "Get the owner IP {0} as file server IP.", currentAccessIpAddr); } DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForInterface, currentAccessIpAddr, TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage, TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout, resourceOwnerNode), TestConfig.FailoverTimeout, "Retry BindServer until succeed within timeout span"); } else { 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"); } 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."); SWNTestUtility.GetRegisterInterface(interfaceList, out registerInterface); 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, registerInterface.InterfaceGroupName), TestConfig.FailoverTimeout, "Retry BindServer until succeed within timeout span"); string clientName = Guid.NewGuid().ToString(); BaseTestSite.Log.Add(LogEntryKind.Debug, "Register witness:"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tNetName: {0}", SWNTestUtility.GetPrincipleName(TestConfig.DomainName, server)); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddress: {0}", currentAccessIpAddr.ToString()); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tClient Name: {0}", clientName); ret = swnClientForWitness.WitnessrRegister(SwnVersion.SWN_VERSION_1, SWNTestUtility.GetPrincipleName(TestConfig.DomainName, server), currentAccessIpAddr.ToString(), clientName, out pContext); BaseTestSite.Assert.AreEqual<SwnErrorCode>( SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrRegister returns with result code = 0x{0:x8}", ret); BaseTestSite.Assert.IsNotNull( pContext, "Expect pContext is not null."); callId = swnClientForWitness.WitnessrAsyncNotify(pContext); BaseTestSite.Assert.AreNotEqual<uint>( 0, callId, "WitnessrAsyncNotify returns callId = {0}", callId); } #endregion #region Create a file and write content string uncSharePath = Smb2Utility.GetUncPath(server, TestConfig.ClusteredFileShare); string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb); string testDirectory = CreateTestDirectory(uncSharePath); string file = Path.Combine(testDirectory, Guid.NewGuid().ToString()); Guid clientGuid = Guid.NewGuid(); Guid createGuid = Guid.NewGuid(); DoUntilSucceed(() => WriteContentBeforeFailover(fsType, server, currentAccessIpAddr, uncSharePath, file, content, clientGuid, createGuid), TestConfig.FailoverTimeout, "Before failover, retry Write content until succeed within timeout span."); #endregion #region Disable accessed node if (TestConfig.IsWindowsPlatform) { AssignCurrentAccessNode(server, fsType, currentAccessIpAddr); } if (!reconnectWithoutFailover) { BaseTestSite.Log.Add( LogEntryKind.TestStep, "Disable owner node for general file server or the node currently provides the access for scale-out file server."); FailoverServer(currentAccessIpAddr, server, fsType); } #endregion #region Wait for available server BaseTestSite.Log.Add(LogEntryKind.TestStep, "Wait for available server."); if (witnessType == WitnessType.None) { if (fsType == FileServerType.GeneralFileServer) { currentAccessIpAddr = null; IPAddress[] accessIpList = Dns.GetHostEntry(server).AddressList; DoUntilSucceed(() => { foreach (IPAddress ipAddress in accessIpList) { Smb2FunctionalClient pingClient = new Smb2FunctionalClient(TestConfig.FailoverTimeout, TestConfig, BaseTestSite); try { pingClient.ConnectToServerOverTCP(ipAddress); pingClient.Disconnect(); pingClient = null; currentAccessIpAddr = ipAddress; return true; } catch { } } return false; }, TestConfig.FailoverTimeout, "Retry to ping to server until succeed within timeout span"); } else { currentAccessIpAddr = null; IPAddress[] accessIpList = Dns.GetHostEntry(server).AddressList; foreach (IPAddress ipAddress in accessIpList) { if (TestConfig.IsWindowsPlatform) { // When setting failover mode to StopNodeService for Windows, SMB2 servers on two nodes can still be accessed by the client. // So the client needs to get the new node to access it after failover by comparing host name. if (string.Compare(currentAccessNode, Dns.GetHostEntry(ipAddress).HostName, true) == 0) { continue; } } Smb2FunctionalClient pingClient = new Smb2FunctionalClient(TestConfig.FailoverTimeout, TestConfig, BaseTestSite); try { pingClient.ConnectToServerOverTCP(ipAddress); pingClient.Disconnect(); pingClient = null; currentAccessIpAddr = ipAddress; break; } catch { } } } } else if (witnessType == WitnessType.SwnWitness) { // Verifying for notification RESP_ASYNC_NOTIFY respNotify; do { // Wait the notification ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify); BaseTestSite.Assert.AreEqual<SwnErrorCode>( SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "ExpectWitnessrAsyncNotify returns with result code = 0x{0:x8}", ret); SWNTestUtility.PrintNotification(respNotify); RESOURCE_CHANGE[] resourceChangeList; SwnUtility.ParseResourceChange(respNotify, out resourceChangeList); BaseTestSite.Assert.AreEqual<uint>(0x00000001, respNotify.NumberOfMessages, "Expect NumberOfMessages is set to 1."); if (resourceChangeList[0].ChangeType == (uint)SwnResourceChangeType.RESOURCE_STATE_AVAILABLE) { // Verify RESP_ASYNC_NOTIFY, the resource is available SWNTestUtility.VerifyResourceChange(respNotify, SwnResourceChangeType.RESOURCE_STATE_AVAILABLE); break; } // Verify RESP_ASYNC_NOTIFY, the resource is unavailable SWNTestUtility.VerifyResourceChange(respNotify, SwnResourceChangeType.RESOURCE_STATE_UNAVAILABLE); callId = swnClientForWitness.WitnessrAsyncNotify(pContext); BaseTestSite.Assert.AreNotEqual<uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId); } while (true); ret = swnClientForWitness.WitnessrUnRegister(pContext); BaseTestSite.Assert.AreEqual<SwnErrorCode>( SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret); pContext = IntPtr.Zero; swnClientForWitness.SwnUnbind(TestConfig.Timeout); if (fsType == FileServerType.ScaleOutFileServer) { // For scale-out file server case, retrieve and use another access IP for connection currentAccessIpAddr = (registerInterface.Flags & (uint)SwnNodeFlagsValue.IPv4) != 0 ? new IPAddress(registerInterface.IPV4) : SWNTestUtility.ConvertIPV6(registerInterface.IPV6); } } #endregion #region Read content and close the file DoUntilSucceed(() => ReadContentAfterFailover(server, currentAccessIpAddr, uncSharePath, file, content, clientGuid, createGuid), TestConfig.FailoverTimeout, "After failover, retry Read content until succeed within timeout span."); #endregion }
/// <summary> /// Get the witness server to be used to register. /// </summary> /// <param name="interfaceList">The interface list from server.</param> /// <param name="registerInterface">Interface to register.</param> public static void GetRegisterInterface(WITNESS_INTERFACE_LIST interfaceList, out WITNESS_INTERFACE_INFO registerInterface) { registerInterface = new WITNESS_INTERFACE_INFO(); foreach (var info in interfaceList.InterfaceInfo) { if (info.NodeState == SwnNodeState.AVAILABLE && (info.Flags & (uint)SwnNodeFlagsValue.INTERFACE_WITNESS) != 0) { registerInterface = info; BaseTestSite.Log.Add(LogEntryKind.Debug, "Register to interface:"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tInterface group name: {0}", registerInterface.InterfaceGroupName); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tInterface IPV4 address: {0}", new IPAddress(registerInterface.IPV4).ToString()); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tInterface IPV6 address: {0}", SWNTestUtility.ConvertIPV6(registerInterface.IPV6).ToString()); return; } } BaseTestSite.Assert.Fail("Cannot get register interface."); }
/// <summary> /// SWN client invoke WitnessrGetInterfaceList method to retrieve information about the interfaces to which witness client connections can be made. /// </summary> /// <param name="InterfaceList">A pointer to a PWITNESS_INTERFACE_LIST, as specified in section 2.2.1.9.</param> /// <returns>Return zero if success, otherwise return nonzero.</returns> public int WitnessrGetInterfaceList(out WITNESS_INTERFACE_LIST InterfaceList) { Int3264[] paramList; int retVal = 0; paramList = new Int3264[] { IntPtr.Zero, //out param IntPtr.Zero //return value }; using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrGetInterfaceList)) { WITNESS_INTERFACE_LIST_RPC rpcList = TypeMarshal.ToStruct<WITNESS_INTERFACE_LIST_RPC>(Marshal.ReadIntPtr(outParamList[0])); WITNESS_INTERFACE_INFO[] infoList = new WITNESS_INTERFACE_INFO[rpcList.NumberOfInterfaces]; int sizeInByte = Marshal.SizeOf(typeof(WITNESS_INTERFACE_INFO)); for (int i = 0; i < rpcList.NumberOfInterfaces; i++) { IntPtr pInfo = IntPtrUtility.Add(rpcList.InterfaceInfo, i * sizeInByte); infoList[i] = (WITNESS_INTERFACE_INFO)Marshal.PtrToStructure(pInfo, typeof(WITNESS_INTERFACE_INFO)); } InterfaceList = new WITNESS_INTERFACE_LIST(); InterfaceList.NumberOfInterfaces = rpcList.NumberOfInterfaces; InterfaceList.InterfaceInfo = infoList; retVal = outParamList[paramList.Length - 1].ToInt32(); } return retVal; }