コード例 #1
0
        public static Uri GetDeploymentAndWaitForReady(string serviceName, string slot, int waitTime, int maxWaitTime)
        {
            DateTime startTime = DateTime.Now;

            while (true)
            {
                bool allReady = true;
                DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(serviceName, slot);
                int    instanceNum           = result.RoleInstanceList.Count;
                bool[] isReady = new bool[instanceNum];

                for (int j = 0; j < instanceNum; j++)
                {
                    var instance = result.RoleInstanceList[j];
                    Console.WriteLine("Instance: {0}, Status: {1}", instance.InstanceName, instance.InstanceStatus);
                    isReady[j] = (instance.InstanceStatus == "ReadyRole");
                    allReady  &= isReady[j];
                }

                if (!allReady && (DateTime.Now - startTime).TotalSeconds < maxWaitTime)
                {
                    Console.WriteLine("Some roles are not ready, waiting for {0} seconds.", waitTime);
                    Thread.Sleep(waitTime * 1000);
                }
                else if (!allReady) // some roles are not ready, and time-out.
                {
                    Assert.Fail("Deployment is not ready within {0} seconds!", maxWaitTime);
                }
                else // all roles are ready
                {
                    Console.WriteLine("Result of the deployment: {0}", result.Status);
                    return(result.Url);
                }
            }
        }
コード例 #2
0
        public static bool PrintAndCompareDeployment
            (DeploymentInfoContext deployment, string serviceName, string deploymentName, string deploymentLabel, string slot, string status, int instanceCount)
        {
            Console.WriteLine("ServiceName:{0}, DeploymentID: {1}, Uri: {2}", deployment.ServiceName, deployment.DeploymentId, deployment.Url.AbsoluteUri);
            Console.WriteLine("Name - {0}, Label - {1}, Slot - {2}, Status - {3}",
                              deployment.DeploymentName, deployment.Label, deployment.Slot, deployment.Status);
            Console.WriteLine("RoleInstance: {0}", deployment.RoleInstanceList.Count);
            foreach (var instance in deployment.RoleInstanceList)
            {
                Console.WriteLine("InstanceName - {0}, InstanceStatus - {1}", instance.InstanceName, instance.InstanceStatus);
            }

            Assert.AreEqual(deployment.ServiceName, serviceName);
            Assert.AreEqual(deployment.DeploymentName, deploymentName);
            Assert.AreEqual(deployment.Label, deploymentLabel);
            Assert.AreEqual(deployment.Slot, slot);
            if (status != null)
            {
                Assert.AreEqual(deployment.Status, status);
            }

            Assert.AreEqual(deployment.RoleInstanceList.Count, instanceCount);

            return(true);
        }
コード例 #3
0
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         Operation  operation         = null;
         Deployment deploymentProcess = this.GetDeploymentProcess(out operation);
         if (deploymentProcess != null)
         {
             if (string.IsNullOrEmpty(deploymentProcess.DeploymentSlot))
             {
                 deploymentProcess.DeploymentSlot = this.Slot;
             }
             DeploymentInfoContext deploymentInfoContext = new DeploymentInfoContext(deploymentProcess);
             deploymentInfoContext.ServiceName = this.ServiceName;
             deploymentInfoContext.set_OperationId(operation.OperationTrackingId);
             deploymentInfoContext.set_OperationDescription(base.CommandRuntime.ToString());
             deploymentInfoContext.set_OperationStatus(operation.Status);
             DeploymentInfoContext deploymentInfoContext1 = deploymentInfoContext;
             base.WriteObject(deploymentInfoContext1, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
コード例 #4
0
        public void GetDeployment_ValidDeployment_DeploymentContext()
        {
            // Arrange
            var target = new GetDeployment
            {
                Slot                    = "Production",
                ServiceName             = string.Empty,
                SubscriptionId          = string.Empty,
                CertificateThumbprintId = string.Empty
            };

            // Act
            IDictionary <string, object> results = WorkflowInvoker.Invoke(target, new Dictionary <string, object>());
            DeploymentInfoContext        ctx     = results["DeploymentContext"] as DeploymentInfoContext;

            // Assert
            Assert.IsNotNull(ctx);
        }
コード例 #5
0
        /// <summary>
        /// Connect to an Azure subscription and obtain deployment information.
        /// </summary>
        protected override void AzureExecute()
        {
            try
            {
                Deployment deployment = this.RetryCall(s => this.Channel.GetDeploymentBySlot(s, this.ServiceName.Get(this.ActivityContext), this.Slot.Get(this.ActivityContext)));

                if (string.IsNullOrEmpty(deployment.DeploymentSlot))
                {
                    deployment.DeploymentSlot = this.Slot.Get(this.ActivityContext);
                }

                var ctx = new DeploymentInfoContext(deployment);
                ctx.SubscriptionId = this.SubscriptionId.Get(this.ActivityContext);
                ctx.ServiceName    = this.ServiceName.Get(this.ActivityContext);
                ctx.Certificate    = this.ManagementCertificate;

                this.DeploymentContext.Set(this.ActivityContext, ctx);
            }
            catch (EndpointNotFoundException ex)
            {
                this.LogBuildMessage(ex.Message);
                this.DeploymentContext.Set(this.ActivityContext, null);
            }
        }
コード例 #6
0
        public void AzureServiceExtensionTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            const string rdpPath = @".\WebRole2.rdp";

            try
            {
                Collection <ExtensionImageContext> resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension();

                foreach (var extension in resultExtensions)
                {
                    if (extension.ExtensionName == "RDP")
                    {
                        _extensionName     = extension.ExtensionName;
                        _providerNamespace = extension.ProviderNameSpace;
                        _version           = extension.Version;
                        break;
                    }
                }

                vmPowershellCmdlets.NewAzureService(_serviceName, _serviceName, locationName);
                Console.WriteLine("service, {0}, is created.", _serviceName);

                vmPowershellCmdlets.NewAzureDeployment(_serviceName, _packagePath.FullName, _configPath.FullName,
                                                       DeploymentSlotType.Production, DeploymentLabel, DeploymentName, false, false);

                DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(_serviceName, DeploymentSlotType.Production);
                pass = Utilities.PrintAndCompareDeployment(result, _serviceName, DeploymentName, DeploymentLabel, DeploymentSlotType.Production, null, 2);
                Console.WriteLine("successfully deployed the package");

                vmPowershellCmdlets.SetAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    publicConfig: PublicConfig,
                    privateConfig: PrivateConfig,
                    version: _version
                    );

                ExtensionContext resultExtensionContext = vmPowershellCmdlets.GetAzureServiceExtension(_serviceName)[0];

                Utilities.PrintContext(resultExtensionContext);

                VerifyExtensionContext(resultExtensionContext, "AllRoles", _extensionName, _providerNamespace, _version);

                RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(_serviceName)[0];

                Utilities.PrintContext(resultContext);

                VerifyRDP(_serviceName, rdpPath);

                vmPowershellCmdlets.RemoveAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    uninstall: true);

                try
                {
                    vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);
                    Assert.Fail("Succeeded, but extected to fail!");
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    Console.WriteLine("Failed to get RDP file as expected");
                }

                vmPowershellCmdlets.RemoveAzureDeployment(_serviceName, DeploymentSlotType.Production, true);

                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, _serviceName, DeploymentSlotType.Production);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: {0}", e);
                throw;
            }
        }
コード例 #7
0
        public void AzureServiceExtensionConfigScenarioTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            const string rdpPath = @".\WebRole1.rdp";

            try
            {
                Collection <ExtensionImageContext> resultExtensions = vmPowershellCmdlets.GetAzureServiceAvailableExtension();

                foreach (var extension in resultExtensions)
                {
                    if (extension.ExtensionName == "RDP")
                    {
                        _extensionName     = extension.ExtensionName;
                        _providerNamespace = extension.ProviderNameSpace;
                        break;
                    }
                }

                vmPowershellCmdlets.NewAzureService(_serviceName, _serviceName, locationName);
                Console.WriteLine("service, {0}, is created.", _serviceName);

                ExtensionConfigurationInput config = vmPowershellCmdlets.NewAzureServiceExtensionConfig(
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace,
                    publicConfig: PublicConfig,
                    privateConfig: PrivateConfig
                    );

                vmPowershellCmdlets.NewAzureDeployment(_serviceName, _packagePath.FullName, _configPath.FullName,
                                                       DeploymentSlotType.Production, DeploymentLabel, DeploymentName, false, false, config);

                DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(_serviceName, DeploymentSlotType.Production);
                pass = Utilities.PrintAndCompareDeployment(result, _serviceName, DeploymentName, DeploymentLabel, DeploymentSlotType.Production, null, 2);
                Console.WriteLine("successfully deployed the package");

                ExtensionContext resultExtensionContext = vmPowershellCmdlets.GetAzureServiceExtension(_serviceName)[0];

                Utilities.PrintContext(resultExtensionContext);

                VerifyExtensionContext(resultExtensionContext, "AllRoles", _extensionName, _providerNamespace);

                RemoteDesktopExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceRemoteDesktopExtension(_serviceName)[0];

                Utilities.PrintContext(resultContext);

                Utilities.GetDeploymentAndWaitForReady(_serviceName, DeploymentSlotType.Production, 10, 600);

                vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);

                string dns;

                using (var stream = new StreamReader(rdpPath))
                {
                    string firstLine = stream.ReadLine();
                    dns = Utilities.FindSubstring(firstLine, ':', 2);
                }

                Assert.IsTrue((Utilities.RDPtestPaaS(dns, "WebRole1", 0, username, password, true)), "Cannot RDP to the instance!!");

                vmPowershellCmdlets.RemoveAzureServiceExtension(
                    serviceName: _serviceName,
                    extensionName: _extensionName,
                    providerNamespace: _providerNamespace);

                try
                {
                    vmPowershellCmdlets.GetAzureRemoteDesktopFile("WebRole1_IN_0", _serviceName, rdpPath, false);
                    Assert.Fail("Succeeded, but extected to fail!");
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    Console.WriteLine("Failed to get RDP file as expected");
                }

                vmPowershellCmdlets.RemoveAzureDeployment(_serviceName, DeploymentSlotType.Production, true);

                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, _serviceName, DeploymentSlotType.Production);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: {0}", e);
                throw;
            }
        }