private bool VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp)
 {
     try
     {
         Assert.AreEqual(role, resultContext.Role.RoleType.ToString());
         Assert.AreEqual("RDP", resultContext.Extension);
         Assert.AreEqual(extID, resultContext.Id);
         Assert.AreEqual(userName, resultContext.UserName);
         Assert.IsTrue(Utilities.CompareDateTime(exp, resultContext.Expiration));
         return true;
     }
     catch
     {
         return false;
     }
 }
        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;
            }
        }
Exemple #3
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;
            }
        }
        private void VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp, string version  = null)
        {
            Utilities.PrintContextAndItsBase(resultContext);

            try
            {
                Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
                Assert.AreEqual("RDP", resultContext.Extension, "extension is not RDP");
                Assert.AreEqual(extID, resultContext.Id, "extension id is not same");
                Assert.AreEqual(userName, resultContext.UserName, "storage account name is not same");
                Assert.IsTrue(Utilities.CompareDateTime(exp, resultContext.Expiration), "expiration is not same");
                if (! string.IsNullOrEmpty(version))
                {
                    Assert.AreEqual(version, resultContext.Version, "version numbers are not same");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error happens: {0}", e.ToString());
                throw;
            }
        }
 private bool VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp)
 {
     try
     {
         Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
         Assert.AreEqual("RDP", resultContext.Extension, "extension is not RDP");
         Assert.AreEqual(extID, resultContext.Id, "extension id is not same");
         Assert.AreEqual(userName, resultContext.UserName, "storage account name is not same");
         Assert.IsTrue(Utilities.CompareDateTime(exp, resultContext.Expiration), "expiration is not same");
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine("Error happens: {0}", e.ToString());
         return false;
     }
 }