Exemple #1
0
        public void DeploymentManagerTest_GetDevMachinesIsLocalhost()
        {
            string manifestPath = Path.Combine(BaseDir, XmlManifestFilename);

            Assert.IsTrue(File.Exists(manifestPath), string.Format("Manifest file {0} did not exist.", manifestPath));
            List <string> machines = StandaloneUtility.GetMachineNamesFromClusterManifest(manifestPath);

            Assert.IsNotNull(machines);
            Assert.AreEqual(machines.Count, 1);
            Assert.IsTrue("localhost".CompareTo(machines[0]) == 0,
                          "Expected to find the machine localhost, but found {0} instead", machines[0]);
        }
        internal static bool ValidateClusterRemoval(
            string configPath,
            bool usingClusterManifest = false)
        {
            SFDeployerTrace.WriteInfo(StringResources.Info_BPAStart);
            var summary = new AnalysisSummary();

            // Check user has local admin privilege
            summary.LocalAdminPrivilege = CheckLocalAdminPrivilege();
            StandAloneInstallerJsonModelBase standAloneModel = null;

            if (!usingClusterManifest)
            {
                standAloneModel     = StandAloneInstallerJsonModelBase.GetJsonConfigFromFile(configPath);
                summary.IsJsonValid = IsJsonConfigModelValid(standAloneModel, null, validateDownNodes: false, throwIfError: false);
            }

            // Below depends on JSON being valid
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(false);
            }

            // Get machine names from JSON config
            IEnumerable <string> machineNames = usingClusterManifest
                                        ? StandaloneUtility.GetMachineNamesFromClusterManifest(configPath)
                                        : standAloneModel.GetClusterTopology().Machines;

            MachineHealthContainer machineHealthContainer = new MachineHealthContainer(machineNames);

            // Log validations but don't fail
            StandaloneUtility.CheckRequiredPorts(machineHealthContainer);
            CheckRPCAccess(machineHealthContainer);

            // At least one machine should be removable
            bool anyMachinesRemovable = CheckAnyMachinesRemovable(machineNames);

            LogResult(summary, anyMachinesRemovable);

            return(summary.Passed);
        }
Exemple #3
0
        public void DeploymentManagerTest_ConvertJsonToXml()
        {
            Console.WriteLine("Current directory: {0}", Environment.CurrentDirectory);
            string clusterConfigPath = Path.Combine(BaseDir, JsonConfigUnsecureJan2017Filename);

            Directory.SetCurrentDirectory(BaseDir);
            Console.WriteLine("New current directory changed to: {0}", Environment.CurrentDirectory);
            Assert.IsTrue(File.Exists(clusterConfigPath), string.Format("Config file {0} did not exist.", clusterConfigPath));
            string clusterManifestPath = Path.Combine(Path.GetTempPath(), "cmtest.xml");
            var    clusterResource     = DeploymentManagerInternal.GetClusterResource(clusterConfigPath, System.Guid.NewGuid().ToString());
            var    cm = clusterResource.Current.ExternalState.ClusterManifest;

            Assert.IsNotNull(cm, "Cluster manifest was null.");
            XMLHelper.WriteXmlExclusive <ClusterManifestType>(clusterManifestPath, cm);
            Assert.IsTrue(File.Exists(clusterManifestPath), "Cluster manifest was not written.");
            List <string> machines = StandaloneUtility.GetMachineNamesFromClusterManifest(clusterManifestPath);

            Assert.IsNotNull(machines);
            Assert.IsTrue(machines.Count > 0, "Cluster manifest was not written correctly. Machines missing.");
        }
        internal static AnalysisSummary AnalyzeClusterSetup(
            string configPath,
            string oldConfigPath,
            string cabPath,
            bool usingClusterManifest           = false,
            FabricPackageType fabricPackageType = FabricPackageType.XCopyPackage,
            bool isForcedRun          = false,
            int maxPercentFailedNodes = 0)
        {
            SFDeployerTrace.WriteInfo(StringResources.Info_BPAStart);
            var summary = new AnalysisSummary();

            // Check user has local admin privilege
            summary.LocalAdminPrivilege = CheckLocalAdminPrivilege();

            // Validate JSON config
            StandAloneInstallerJsonModelBase standAloneModel    = null;
            StandAloneInstallerJsonModelBase oldStandAloneModel = null;

            if (!usingClusterManifest)
            {
                standAloneModel = StandAloneInstallerJsonModelBase.GetJsonConfigFromFile(configPath);

                if (!string.IsNullOrEmpty(oldConfigPath))
                {
                    oldStandAloneModel = StandAloneInstallerJsonModelBase.GetJsonConfigFromFile(oldConfigPath);
                }

                summary.IsJsonValid = IsJsonConfigModelValid(standAloneModel, oldStandAloneModel, validateDownNodes: true, throwIfError: false) && ValidateCodeVersionExists(standAloneModel);
            }

            // Deliberately not checking empty. Some invocations aren't intended to test cabPath.
            if (cabPath != null)
            {
                summary.IsCabValid = CheckIsCabFile(cabPath);
            }

            // Below depends on JSON being valid
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            // Get machine names from JSON config
            IEnumerable <string> healthyMachineNames = usingClusterManifest
                                        ? StandaloneUtility.GetMachineNamesFromClusterManifest(configPath)
                                        : standAloneModel.GetClusterTopology().Machines;

            MachineHealthContainer machineHealthContainer = new MachineHealthContainer(healthyMachineNames, maxPercentFailedNodes);

            // Validate machine FQDNs, Check SMB ports opened
            summary.RequiredPortsOpen = StandaloneUtility.CheckRequiredPorts(machineHealthContainer);

            // Below depends on machines being reachable
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            // Validate Remote Registry Service is not disabled on all machines
            summary.RemoteRegistryAvailable = CheckRemoteRegistryEnabled(machineHealthContainer);

            // Below depends on remote registry service
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            summary.FirewallAvailable = CheckFirewallEnabled(machineHealthContainer);

            // Below depends on firewall service
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            // Run RPC check to validate end-to-end registry access to all machines
            summary.RpcCheckPassed = CheckRPCAccess(machineHealthContainer);

            // Below depend on remote registry access
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            summary.NoDomainController = CheckNoMachineIsDomainController(machineHealthContainer);

            // Below depends on machines not being domain controller
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            if (fabricPackageType == FabricPackageType.XCopyPackage)
            {
                // Validate that Fabric runtime MSI is not installed since this will be conflicting with Standalone
                summary.NoConflictingInstallations = !StandaloneUtility.IsMsiInstalled(machineHealthContainer);
            }

            string fabricDataRoot = null;
            string fabricLogRoot  = null;

            if (!usingClusterManifest)
            {
                if (string.IsNullOrEmpty(oldConfigPath))
                {
                    summary.FabricInstallable = CheckForCleanInstall(standAloneModel, machineHealthContainer, isForcedRun); // Fabric is not installed on target machines
                }

                var importantSettings = standAloneModel.GetFabricSystemSettings();
                fabricDataRoot = importantSettings.ContainsKey(DMConstants.FabricDataRootString) ?
                                 importantSettings[DMConstants.FabricDataRootString] :
                                 null;
                fabricLogRoot = importantSettings.ContainsKey(DMConstants.FabricLogRootString) ?
                                importantSettings[DMConstants.FabricLogRootString] :
                                null;

                summary.DataDrivesAvailable = CheckDataSystemDrives(machineHealthContainer, fabricDataRoot, fabricLogRoot); // System drives for path-based settings, exist on target machines

                // Below depend on data system drives
                if (!summary.Passed)
                {
                    SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                    return(summary);
                }
            }

            summary.DrivesEnoughAvailableSpace = CheckDrivesAvailableSpace(machineHealthContainer, fabricDataRoot, fabricLogRoot);

            // Below depend on root drives having enough space available
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            summary.IsAllOrNoneIOTDevice = CheckAllIOTDevices(machineHealthContainer);

            // Below depend on all or none machines being IOT Devices
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            // Check dotnet.exe exists in %Path%
            // Currently we only need to check for IOTCore environment.
            summary.DotNetExeInPath = IsDotNetExeInPath(machineHealthContainer);

            // Below depend on IOT Devices having dotnet.exe in path
            if (!summary.Passed)
            {
                SFDeployerTrace.WriteError(StringResources.Error_BPABailing);
                return(summary);
            }

            summary.MachineHealthContainer = machineHealthContainer;
            LogResult(summary);

            return(summary);
        }
        internal void ConvertDevJsonToXml_Utility(int expectedReplicaSize, string inputFile, string outputFile, string sectionToChangeWin7, bool isSecure = false, bool testOverride = false)
        {
            Console.WriteLine("Current directory: {0}", Environment.CurrentDirectory);
            string clusterConfigPath = Path.Combine(DevJsonModelTest.BaseDir, inputFile);

            Directory.SetCurrentDirectory(DevJsonModelTest.BaseDir);
            Console.WriteLine("New current directory changed to: {0}", Environment.CurrentDirectory);
            string clusterManifestPath = Path.Combine(Path.GetTempPath(), outputFile);
            var    clusterResource     = DeploymentManagerInternal.GetClusterResource(clusterConfigPath, System.Guid.NewGuid().ToString());
            var    cm = clusterResource.Current.ExternalState.ClusterManifest;

            Assert.IsNotNull(cm, "Cluster manifest was null.");

            File.Delete(clusterManifestPath);
            XMLHelper.WriteXmlExclusive <ClusterManifestType>(clusterManifestPath, cm);
            List <string> machines = StandaloneUtility.GetMachineNamesFromClusterManifest(clusterManifestPath);

            Assert.IsNotNull(machines);

            Assert.AreEqual(expectedReplicaSize, ((WindowsInfrastructureType)cm.Infrastructure.Item).NodeList.ToList().Where(node => node.IsSeedNode).Count());

            if (isSecure)
            {
                Assert.AreEqual(InputEndpointTypeProtocol.https, cm.NodeTypes[0].Endpoints.HttpGatewayEndpoint.Protocol);
                Assert.IsNotNull(cm.NodeTypes[0].Certificates.ClientCertificate, "Client certificate was null.");
            }

            foreach (SettingsOverridesTypeSection setting in cm.FabricSettings)
            {
                Assert.IsTrue(IsSectionAllowed(cm.NodeTypes.Count(), setting.Name));
                if (setting.Name == StringConstants.SectionName.Setup)
                {
                    foreach (SettingsOverridesTypeSectionParameter param in setting.Parameter)
                    {
                        Assert.AreNotEqual(StringConstants.ParameterName.IsDevCluster, param.Name);
                        if (param.Name == StringConstants.ParameterName.FabricDataRoot)
                        {
                            Assert.AreEqual(Environment.ExpandEnvironmentVariables("%systemdrive%\\SfDevCluster\\Data"), param.Value);
                        }
                    }
                }
                if (setting.Name == StringConstants.SectionName.ClusterManager)
                {
                    SettingsOverridesTypeSectionParameter TargetReplicaSetSizeParam = setting.Parameter.FirstOrDefault(x => x.Name == StringConstants.ParameterName.TargetReplicaSetSize);
                    Assert.IsNotNull(TargetReplicaSetSizeParam, "Cannot find TargetReplicaSetSize for Cluster Manager");
                    Assert.AreEqual(expectedReplicaSize.ToString(), TargetReplicaSetSizeParam.Value);
                }
                if (DevJsonModel.IsWin7() && setting.Name == sectionToChangeWin7)
                {
                    SettingsOverridesTypeSectionParameter isEnabledParam = setting.Parameter.FirstOrDefault(x => x.Name == StringConstants.ParameterName.IsEnabled);
                    Assert.IsNotNull(isEnabledParam, "Cannot find isEnabled for " + sectionToChangeWin7);
                    Assert.AreEqual("false", isEnabledParam.Value);
                }
                if (setting.Name == StringConstants.SectionName.Diagnostics && testOverride)
                {
                    SettingsOverridesTypeSectionParameter isEnabledTraceSessionParam = setting.Parameter.FirstOrDefault(x => x.Name == StringConstants.ParameterName.EnableCircularTraceSession);
                    Assert.IsNotNull(isEnabledTraceSessionParam, "Cannot find isEnabled for EnableCircularTraceSession");
                    Assert.AreEqual("false", isEnabledTraceSessionParam.Value);
                }
                if (setting.Name == StringConstants.SectionName.FailoverManager && expectedReplicaSize == 1)
                {
                    SettingsOverridesTypeSectionParameter IsSingletonReplicaMoveAllowedDuringUpgradeParam = setting.Parameter.FirstOrDefault(x => x.Name == StringConstants.ParameterName.IsSingletonReplicaMoveAllowedDuringUpgrade);
                    Assert.IsNotNull(IsSingletonReplicaMoveAllowedDuringUpgradeParam, "Cannot find isEnabled for EnableCircularTraceSession");
                    Assert.AreEqual("false", IsSingletonReplicaMoveAllowedDuringUpgradeParam.Value);
                }
            }

            //DevCluster should have one distinct IPaddress, i.e. localhost
            Assert.AreEqual(1, machines.Count);
        }