Exemple #1
0
        private HostedServiceGetDetailedResponse ProvisionHostedService(string newServiceName)
        {
            ComputeManagementClient computeClient = TestBase.GetServiceClient <ComputeManagementClient>();
            StorageManagementClient storageClient = TestBase.GetServiceClient <StorageManagementClient>();

            string computeLocation = GetLocation("Compute");

            var createHostedServiceResp = computeClient.HostedServices.Create(new HostedServiceCreateParameters()
            {
                ServiceName = newServiceName,
                Location    = computeLocation
            });

            Assert.Equal(HttpStatusCode.Created, createHostedServiceResp.StatusCode);

            string newStorageAccountName = TestUtilities.GenerateName("storage");
            string storageLocation       = GetLocation("Storage");

            var createStorageResp = storageClient.StorageAccounts.Create(new StorageAccountCreateParameters
            {
                Location    = storageLocation,
                Name        = newStorageAccountName,
                AccountType = "Standard_GRS"
            });

            Assert.Equal(HttpStatusCode.OK, createStorageResp.StatusCode);

            var blobUri = StorageTestUtilities.UploadFileToBlobStorage(newStorageAccountName, "deployments",
                                                                       @"SampleService\SMNetTestAppProject.cspkg");
            var configXml = File.ReadAllText(@"SampleService\ServiceConfiguration.Cloud.cscfg");

            string deploymentName = TestUtilities.GenerateName("deployment");

            // create the hosted service deployment
            var deploymentResult = computeClient.Deployments.Create(newServiceName,
                                                                    DeploymentSlot.Production,
                                                                    new DeploymentCreateParameters
            {
                Configuration          = configXml,
                Name                   = deploymentName,
                Label                  = "label1",
                StartDeployment        = true,
                ExtensionConfiguration = null,
                PackageUri             = blobUri
            });

            Assert.Equal(HttpStatusCode.OK, deploymentResult.StatusCode);

            var detailedStatus = computeClient.HostedServices.GetDetailedAsync(newServiceName).Result;

            return(detailedStatus);
        }
        private void CreateDeployment(string storageAccountName, string serviceName, string deploymentName)
        {
            using (var computeMgmtClient = fixture.GetComputeManagementClient())
            {
                _blobUri = StorageTestUtilities.UploadFileToBlobStorage(storageAccountName,
                                                                        TestDeploymentsBlobStorageContainerName, @"SampleService\SMNetTestAppProject.cspkg");
                // upload the compute service package file
                // persist the XML of the configuration file to a variable
                var configXml = File.ReadAllText(@"SampleService\ServiceConfiguration.Cloud.cscfg");

                // Get an extension for our deployment
                computeMgmtClient.HostedServices.AddExtension(
                    serviceName,
                    new HostedServiceAddExtensionParameters
                {
                    Id   = "RDPExtensionTest",
                    Type = "RDP",
                    ProviderNamespace   = "Microsoft.Windows.Azure.Extensions",
                    PublicConfiguration =
                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PublicConfig><UserName>WilliamGatesIII</UserName><Expiration>2020-11-20</Expiration></PublicConfig>",
                    PrivateConfiguration =
                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PrivateConfig><Password>WindowsAzure1277!</Password></PrivateConfig>",
                    Version = "*"
                });
                ExtensionConfiguration extensionConfig = new ExtensionConfiguration();
                extensionConfig.AllRoles.Add(new ExtensionConfiguration.Extension()
                {
                    Id = "RDPExtensionTest"
                });

                // create the hosted service deployment
                var deploymentResult = computeMgmtClient.Deployments.Create(serviceName,
                                                                            DeploymentSlot.Production,
                                                                            new DeploymentCreateParameters
                {
                    Configuration          = configXml,
                    Name                   = deploymentName,
                    Label                  = deploymentName,
                    StartDeployment        = true,
                    ExtensionConfiguration = extensionConfig,
                    PackageUri             = _blobUri
                });

                // assert that nothing went wrong
                var error = deploymentResult.Error;
                Assert.True(error == null, "Unexpected error: " + (error == null ? "" : error.Message));
            }
        }
        public void DeploymentUpgradeWithUninstallExtension()
        {
            TestUtilities.StartTest();
            var newStorageAccountName = TestUtilities.GenerateName();
            var newServiceName        = TestUtilities.GenerateName();
            var newDeploymentName     = TestUtilities.GenerateName();

            CreateStorageAccount(newStorageAccountName);
            CreateHostedService(newServiceName);
            CreateDeployment(newStorageAccountName, newServiceName, newDeploymentName);

            var computeMgmtClient = fixture.GetComputeManagementClient();
            var deploymentResult  = computeMgmtClient.Deployments.GetByName(newServiceName, newDeploymentName);

            Assert.NotNull(deploymentResult.ExtensionConfiguration);
            Assert.Equal(deploymentResult.ExtensionConfiguration.AllRoles.Count, 1);
            Assert.Equal(deploymentResult.ExtensionConfiguration.AllRoles[0].Id, "RDPExtensionTest");

            var extension = new ExtensionConfiguration.Extension
            {
                Id    = "RDPExtensionTest",
                State = "Uninstall"
            };

            var extensionList = new List <ExtensionConfiguration.Extension>();

            extensionList.Add(extension);
            var _blobUri = StorageTestUtilities.UploadFileToBlobStorage(newStorageAccountName,
                                                                        "deployments", @"SampleService\SMNetTestAppProject.cspkg");

            computeMgmtClient.Deployments.UpgradeBySlot(newServiceName, DeploymentSlot.Production,
                                                        new DeploymentUpgradeParameters
            {
                Configuration          = File.ReadAllText(@"SampleService\ServiceConfiguration.Cloud.cscfg"),
                PackageUri             = _blobUri,
                Label                  = "UpgradeBySlot",
                Force                  = true,
                Mode                   = DeploymentUpgradeMode.Auto,
                ExtensionConfiguration = new ExtensionConfiguration
                {
                    AllRoles = extensionList
                }
            });
            deploymentResult = computeMgmtClient.Deployments.GetBySlot(newServiceName, DeploymentSlot.Production);
            TestUtilities.EndTest();
        }
Exemple #4
0
        public DeploymentGetResponse CreatePaaSDeployment(
            string storageAccountName,
            string serviceName,
            string deploymentName,
            string pkgFileName,
            string cscfgFilePath,
            bool startDeployment = false)
        {
            var containerStr = AZT.TestUtilities.GenerateName("cspkg");
            var pkgFilePath  = ".\\" + pkgFileName;

            var blobUri = StorageTestUtilities.UploadFileToBlobStorage(
                storageAccountName,
                containerStr,
                pkgFilePath);
            var blobUriStr      = blobUri.ToString();
            var containerUriStr = blobUriStr.Substring(0, blobUriStr.IndexOf("/" + pkgFileName));

            containerUriStr = containerUriStr.Replace("https", "http");
            var containerUri = new Uri(containerUriStr);

            var deploymentCreate = this.ComputeClient.Deployments.Create(
                serviceName,
                DeploymentSlot.Production,
                new DeploymentCreateParameters
            {
                Configuration          = File.ReadAllText(cscfgFilePath),
                PackageUri             = blobUri,
                Name                   = deploymentName,
                Label                  = serviceName,
                ExtendedProperties     = null,
                StartDeployment        = startDeployment,
                TreatWarningsAsError   = false,
                ExtensionConfiguration = null
            });

            Assert.True(deploymentCreate.StatusCode == HttpStatusCode.OK);

            var deploymentReceived = this.ComputeClient.Deployments.GetByName(serviceName, deploymentName);

            return(deploymentReceived);
        }
        public void Instantiate(string className)
        {
            try
            {
                using (UndoContext context = UndoContext.Current)
                {
                    context.Start(className, "FixtureSetup");

                    this.managementClient  = this.GetManagementClient();
                    this.computeMgmtClient = this.GetComputeManagementClient();
                    this.storageMgmtClient = this.GetStorageManagementClient();

                    NewStorageAccountName  = TestUtilities.GenerateName();
                    NewServiceName         = TestUtilities.GenerateName();
                    DeploymentNameTemplate = TestUtilities.GenerateName();
                    this.DefaultLocation   = managementClient.GetDefaultLocation("Compute", "Storage");
                    // create a storage account
                    var storageAccountResult = storageMgmtClient.StorageAccounts.Create(
                        new StorageAccountCreateParameters
                    {
                        Location    = this.DefaultLocation,
                        Name        = NewStorageAccountName,
                        AccountType = "Standard_LRS"
                    });

                    // get the storage account
                    var keyResult = storageMgmtClient.StorageAccounts.GetKeys(NewStorageAccountName);

                    // build the connection string
                    _storageAccountConnectionString = string.Format(_storageConnectionStringTemplate,
                                                                    NewStorageAccountName, keyResult.PrimaryKey);

                    _blobUri = StorageTestUtilities.UploadFileToBlobStorage(NewStorageAccountName,
                                                                            _testDeploymentsBlobStorageContainerName, @"SampleService\SMNetTestAppProject.cspkg");
                    // upload the compute service package file
                    // persist the XML of the configuration file to a variable
                    var configXml = File.ReadAllText(@"SampleService\ServiceConfiguration.Cloud.cscfg");

                    // create a hosted service for the tests to use
                    var result = computeMgmtClient.HostedServices.Create(new HostedServiceCreateParameters
                    {
                        Location    = this.DefaultLocation,
                        Label       = NewServiceName,
                        ServiceName = NewServiceName
                    });

                    // assert that the call worked
                    Assert.Equal(result.StatusCode, HttpStatusCode.Created);

                    // Get an extension for our deployment
                    computeMgmtClient.HostedServices.AddExtension(
                        NewServiceName,
                        new HostedServiceAddExtensionParameters
                    {
                        Id   = "RDPExtensionTest",
                        Type = "RDP",
                        ProviderNamespace   = "Microsoft.Windows.Azure.Extensions",
                        PublicConfiguration =
                            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PublicConfig><UserName>WilliamGatesIII</UserName><Expiration>2020-11-20</Expiration></PublicConfig>",
                        PrivateConfiguration =
                            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PrivateConfig><Password>WindowsAzure1277!</Password></PrivateConfig>",
                        Version = "*"
                    });
                    ExtensionConfiguration extensionConfig = new ExtensionConfiguration();
                    extensionConfig.AllRoles.Add(new ExtensionConfiguration.Extension()
                    {
                        Id = "RDPExtensionTest"
                    });
                    _serviceDeploymentName = string.Format(DeploymentNameTemplate, NewServiceName);

                    // create the hosted service deployment
                    var deploymentResult = computeMgmtClient.Deployments.Create(NewServiceName,
                                                                                DeploymentSlot.Production,
                                                                                new DeploymentCreateParameters
                    {
                        Configuration          = configXml,
                        Name                   = _serviceDeploymentName,
                        Label                  = _serviceDeploymentName,
                        StartDeployment        = true,
                        ExtensionConfiguration = extensionConfig,
                        PackageUri             = _blobUri
                    });

                    // assert that nothing went wrong
                    var error = deploymentResult.Error;
                    Assert.True(error == null, "Unexpected error: " + (error == null ? "" : error.Message));
                }
            }
            catch (Exception)
            {
                Cleanup();
                throw;
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }
        public void CanCreateServiceDeployments()
        {
            TestLogTracingInterceptor.Current.Start();

            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt    = fixture.GetManagementClient();
                var compute = fixture.GetComputeManagementClient();
                var storage = fixture.GetStorageManagementClient();

                try
                {
                    var    storageAccountName = HttpMockServer.GetAssetName("teststorage1234", "teststorage").ToLower();
                    string serviceName        = TestUtilities.GenerateName("testsvc");
                    string deploymentName     = string.Format("{0}Prod", serviceName);
                    string location           = mgmt.GetDefaultLocation("Storage", "Compute");

                    const string usWestLocStr = "West US";
                    if (mgmt.Locations.List().Any(
                            c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase)))
                    {
                        location = usWestLocStr;
                    }

                    var st1 = storage.StorageAccounts.Create(
                        new StorageAccountCreateParameters
                    {
                        Location    = location,
                        Label       = storageAccountName,
                        Name        = storageAccountName,
                        AccountType = "Standard_LRS"
                    });

                    var st2 = compute.HostedServices.Create(
                        new HostedServiceCreateParameters
                    {
                        Location    = location,
                        Label       = serviceName,
                        ServiceName = serviceName
                    });

                    var cfgFilePath  = "OneWebOneWorker.cscfg";
                    var containerStr = TestUtilities.GenerateName("cspkg");
                    var pkgFileName  = "OneWebOneWorker.cspkg";
                    var pkgFilePath  = ".\\" + pkgFileName;
                    var blobUri      = StorageTestUtilities.UploadFileToBlobStorage(
                        storageAccountName,
                        containerStr,
                        pkgFilePath);
                    var blobUriStr      = blobUri.ToString();
                    var containerUriStr = blobUriStr.Substring(0, blobUriStr.IndexOf("/" + pkgFileName));
                    containerUriStr = containerUriStr.Replace("https", "http");
                    var containerUri = new Uri(containerUriStr);

                    var st3 = compute.Deployments.Create(
                        serviceName,
                        DeploymentSlot.Production,
                        new DeploymentCreateParameters
                    {
                        Configuration          = File.ReadAllText(cfgFilePath),
                        PackageUri             = blobUri,
                        Name                   = deploymentName,
                        Label                  = serviceName,
                        ExtendedProperties     = null,
                        StartDeployment        = true,
                        TreatWarningsAsError   = false,
                        ExtensionConfiguration = null
                    });

                    Assert.True(st3.StatusCode == HttpStatusCode.OK);

                    var st4 = compute.Deployments.GetPackageByName(
                        serviceName,
                        deploymentName,
                        new DeploymentGetPackageParameters
                    {
                        OverwriteExisting = true,
                        ContainerUri      = containerUri
                    });

                    Assert.True(st4.StatusCode == HttpStatusCode.OK);

                    var roles = compute.Deployments
                                .GetBySlot(serviceName, DeploymentSlot.Production)
                                .Roles.ToList();

                    Assert.True(roles.TrueForAll(r => !string.IsNullOrEmpty(r.OSVersion)));

                    var roleInstanceNames = compute.Deployments
                                            .GetBySlot(serviceName, DeploymentSlot.Production)
                                            .RoleInstances.Select(r => r.InstanceName).ToList();

                    Assert.True(roleInstanceNames.Any(r => r.StartsWith("WebRole1")) &&
                                roleInstanceNames.Any(r => r.StartsWith("WorkerRole1")));

                    // Check Rebuild Role Instance APIs
                    var instName1 = roleInstanceNames.First(r => r.StartsWith("WebRole1"));
                    var instName2 = roleInstanceNames.First(r => r.StartsWith("WorkerRole1"));

                    WaitForReadyRoleInstance(compute, serviceName, deploymentName, instName1);
                    var modifiedTimeBefore = compute.Deployments.GetByName(serviceName, deploymentName)
                                             .LastModifiedTime;
                    compute.Deployments.RebuildRoleInstanceByDeploymentName(
                        serviceName,
                        deploymentName,
                        instName1,
                        RoleInstanceRebuildResourceTypes.AllLocalDrives);
                    var inStatus = compute.Deployments.GetByName(serviceName, deploymentName)
                                   .RoleInstances.First(r => r.InstanceName == instName1)
                                   .InstanceStatus;
                    Assert.True(inStatus != RoleInstanceStatus.ReadyRole);
                    WaitForReadyRoleInstance(compute, serviceName, deploymentName, instName1);
                    var modifiedTimeAfter = compute.Deployments.GetByName(serviceName, deploymentName)
                                            .LastModifiedTime;
                    Assert.True(!modifiedTimeAfter.Equals(modifiedTimeBefore));

                    WaitForReadyRoleInstance(compute, serviceName, deploymentName, instName2);
                    modifiedTimeBefore = compute.Deployments.GetByName(serviceName, deploymentName)
                                         .LastModifiedTime;
                    compute.Deployments.RebuildRoleInstanceByDeploymentSlot(
                        serviceName,
                        DeploymentSlot.Production.ToString(),
                        instName2,
                        RoleInstanceRebuildResourceTypes.AllLocalDrives);
                    inStatus = compute.Deployments.GetByName(serviceName, deploymentName)
                               .RoleInstances.First(r => r.InstanceName == instName2)
                               .InstanceStatus;
                    Assert.True(inStatus != RoleInstanceStatus.ReadyRole);
                    WaitForReadyRoleInstance(compute, serviceName, deploymentName, instName2);
                    modifiedTimeAfter = compute.Deployments.GetByName(serviceName, deploymentName)
                                        .LastModifiedTime;
                    Assert.True(!modifiedTimeAfter.Equals(modifiedTimeBefore));

                    // Check Upgrade Deployment API
                    compute.Deployments.UpgradeByName(
                        serviceName,
                        deploymentName,
                        new DeploymentUpgradeParameters
                    {
                        Configuration          = File.ReadAllText(cfgFilePath),
                        PackageUri             = blobUri,
                        Force                  = true,
                        Label                  = "UpgradeByName",
                        Mode                   = DeploymentUpgradeMode.Auto,
                        RoleToUpgrade          = null,
                        ExtendedProperties     = null,
                        ExtensionConfiguration = null
                    });
                    Assert.True(compute.Deployments.GetByName(serviceName, deploymentName).Label == "UpgradeByName");

                    compute.Deployments.UpgradeBySlot(
                        serviceName,
                        DeploymentSlot.Production,
                        new DeploymentUpgradeParameters
                    {
                        Configuration          = File.ReadAllText(cfgFilePath),
                        PackageUri             = blobUri,
                        Force                  = true,
                        Label                  = "UpgradeBySlot",
                        Mode                   = DeploymentUpgradeMode.Auto,
                        RoleToUpgrade          = null,
                        ExtendedProperties     = null,
                        ExtensionConfiguration = null
                    });
                    Assert.True(compute.Deployments.GetByName(serviceName, deploymentName).Label == "UpgradeBySlot");

                    // Check Delete Role Instance APIs
                    compute.Deployments.DeleteRoleInstanceByDeploymentName(
                        serviceName,
                        deploymentName,
                        new DeploymentDeleteRoleInstanceParameters
                    {
                        Name = new List <string> {
                            instName1
                        }
                    });

                    compute.Deployments.DeleteRoleInstanceByDeploymentSlot(
                        serviceName,
                        DeploymentSlot.Production.ToString(),
                        new DeploymentDeleteRoleInstanceParameters
                    {
                        Name = new List <string> {
                            instName2
                        }
                    });

                    roleInstanceNames = compute.Deployments
                                        .GetBySlot(serviceName, DeploymentSlot.Production)
                                        .RoleInstances.Select(r => r.InstanceName).ToList();

                    Assert.True(!roleInstanceNames.Any(r => r == instName1 || r == instName2));
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    compute.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }
Exemple #7
0
        public void CanRegisterUpdateAndUnregisterExtensionImage()
        {
            TestLogTracingInterceptor.Current.Start();
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt    = fixture.GetManagementClient();
                var compute = fixture.GetComputeManagementClient();
                var storage = fixture.GetStorageManagementClient();

                string versionStr = "74.59.0.0";
                string verUpdtStr = "74.60.0.0";

                const string publicSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>"
                                               + @"<xs:schema attributeFormDefault=""unqualified"""
                                               + @"  elementFormDefault=""qualified"""
                                               + @"  xmlns:xs=""http://www.w3.org/2001/XMLSchema"">"
                                               + @"  <xs:element name=""PublicConfig"">"
                                               + @"    <xs:complexType>"
                                               + @"      <xs:sequence>"
                                               + @"        <xs:element name=""UserName"" type=""xs:string"" />"
                                               + @"      </xs:sequence>"
                                               + @"    </xs:complexType>"
                                               + @"  </xs:element>"
                                               + @"</xs:schema>";

                const string privateSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>"
                                                + @"<xs:schema attributeFormDefault=""unqualified"""
                                                + @"  elementFormDefault=""qualified"""
                                                + @"  xmlns:xs=""http://www.w3.org/2001/XMLSchema"">"
                                                + @"  <xs:element name=""PrivateConfig"">"
                                                + @"    <xs:complexType>"
                                                + @"      <xs:sequence>"
                                                + @"        <xs:element name=""Password"" type=""xs:string"" />"
                                                + @"      </xs:sequence>"
                                                + @"    </xs:complexType>"
                                                + @"  </xs:element>"
                                                + @"</xs:schema>";

                const string sampleConfigStr = "TestSampleConfig";

                try
                {
                    string storageName   = TestUtilities.GenerateName("teststorage");
                    string providerName  = TestUtilities.GenerateName("testprovider");
                    string extensionName = TestUtilities.GenerateName("testextension");
                    string location      = mgmt.GetDefaultLocation("Storage", "Compute");

                    const string usWestLocStr = "West US";
                    if (mgmt.Locations.List().Any(
                            c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase)))
                    {
                        location = usWestLocStr;
                    }

                    // create a storage account
                    var storageAccountResult = storage.StorageAccounts.Create(
                        new StorageAccountCreateParameters
                    {
                        Location    = location,
                        Name        = storageName,
                        AccountType = "Standard_LRS"
                    });

                    // get the storage account
                    var keyResult = storage.StorageAccounts.GetKeys(storageName);

                    // build the connection string
                    const string containerStr = "ext";
                    Uri          blobUri      = StorageTestUtilities.UploadFileToBlobStorage(storageName, containerStr, @".\RemoteAccessPlugin.zip");
                    bool         isPublisher  = false;
                    const string errorCodeStr = "ForbiddenError";

                    try
                    {
                        var parameters = new ExtensionImageRegisterParameters
                        {
                            ProviderNameSpace = providerName,
                            Type                 = extensionName,
                            Version              = versionStr,
                            HostingResources     = "VmRole",
                            MediaLink            = blobUri,
                            Label                = providerName,
                            Description          = providerName,
                            BlockRoleUponFailure = false,
                            Certificate          = new ExtensionCertificateConfiguration
                            {
                                StoreLocation       = "LocalMachine",
                                StoreName           = "My",
                                ThumbprintAlgorithm = "sha1",
                                ThumbprintRequired  = true
                            },
                            LocalResources = new List <ExtensionLocalResourceConfiguration>
                            {
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test1",
                                    SizeInMB = 100
                                },
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test2",
                                    SizeInMB = 200
                                }
                            },
                            DisallowMajorVersionUpgrade = true,
                            SampleConfig               = sampleConfigStr,
                            PublishedDate              = DateTime.Now,
                            Eula                       = new Uri("http://test.com"),
                            PrivacyUri                 = new Uri("http://test.com"),
                            HomepageUri                = new Uri("http://test.com"),
                            IsInternalExtension        = true,
                            PrivateConfigurationSchema = privateSchemaStr,
                            PublicConfigurationSchema  = publicSchemaStr,
                            ExtensionEndpoints         = new ExtensionEndpointConfiguration
                            {
                                InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test1",
                                        Port      = 1111,
                                        LocalPort = "*",
                                        Protocol  = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test2",
                                        Port      = 2222,
                                        LocalPort = "22222",
                                        Protocol  = "tcp"
                                    }
                                },
                                InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test1",
                                        Port     = 1111,
                                        Protocol = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test2",
                                        Port     = 2222,
                                        Protocol = "tcp"
                                    },
                                },
                                InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test1",
                                        Protocol     = "tcp",
                                        LocalPort    = "111",
                                        FixedPortMin = 100,
                                        FixedPortMax = 1000
                                    },
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test2",
                                        Protocol     = "tcp",
                                        LocalPort    = "22",
                                        FixedPortMin = 2000,
                                        FixedPortMax = 10000
                                    }
                                }
                            },
                            IsJsonExtension = false,
                            CompanyName     = providerName,
                            SupportedOS     = ExtensionImageSupportedOperatingSystemType.Windows,
                            Regions         = usWestLocStr,
                        };

                        compute.ExtensionImages.Register(parameters);

                        isPublisher = true;

                        bool      found         = false;
                        const int maxRetryTimes = 60;
                        int       retryTime     = 0;
                        VirtualMachineExtensionListResponse.ResourceExtension ext = null;
                        while (!found && retryTime < maxRetryTimes)
                        {
                            Thread.Sleep(TimeSpan.FromMinutes(1.0));

                            ext = compute.VirtualMachineExtensions
                                  .ListVersions(providerName, extensionName)
                                  .FirstOrDefault(e => string.Equals(e.Version, versionStr));

                            if (ext != null)
                            {
                                found = true;
                            }

                            retryTime++;
                        }

                        if (found)
                        {
                            Assert.True(ext != null);

                            Assert.Equal <string>(ext.Name, parameters.Type);
                            Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace);
                            Assert.Equal <string>(ext.Description, parameters.Description);
                            Assert.Equal <string>(ext.SampleConfig, parameters.SampleConfig);
                            Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema);
                            Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema);
                            Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString());
                            Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString());
                            Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString());
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade);
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <string>(ext.CompanyName, parameters.CompanyName);
                            Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS);

                            Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value &&
                                        (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value));
                        }
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    try
                    {
                        var parameters = new ExtensionImageUpdateParameters
                        {
                            ProviderNameSpace = providerName,
                            Type                 = extensionName,
                            Version              = verUpdtStr,
                            HostingResources     = "VmRole",
                            MediaLink            = blobUri,
                            Label                = providerName,
                            Description          = providerName,
                            BlockRoleUponFailure = false,
                            Certificate          = new ExtensionCertificateConfiguration
                            {
                                StoreLocation       = "LocalMachine",
                                StoreName           = "My",
                                ThumbprintAlgorithm = "sha1",
                                ThumbprintRequired  = true
                            },
                            LocalResources = new List <ExtensionLocalResourceConfiguration>
                            {
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test1",
                                    SizeInMB = 100
                                },
                                new ExtensionLocalResourceConfiguration
                                {
                                    Name     = "Test2",
                                    SizeInMB = 200
                                }
                            },
                            DisallowMajorVersionUpgrade = true,
                            SampleConfig               = sampleConfigStr,
                            PublishedDate              = DateTime.Now,
                            Eula                       = new Uri("http://test.com"),
                            PrivacyUri                 = new Uri("http://test.com"),
                            HomepageUri                = new Uri("http://test.com"),
                            IsInternalExtension        = true,
                            PrivateConfigurationSchema = privateSchemaStr,
                            PublicConfigurationSchema  = publicSchemaStr,
                            ExtensionEndpoints         = new ExtensionEndpointConfiguration
                            {
                                InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test1",
                                        Port      = 1111,
                                        LocalPort = "11111",
                                        Protocol  = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InputEndpoint
                                    {
                                        Name      = "Test2",
                                        Port      = 2222,
                                        LocalPort = "*",
                                        Protocol  = "tcp"
                                    }
                                },
                                InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test1",
                                        Port     = 1111,
                                        Protocol = "tcp"
                                    },
                                    new ExtensionEndpointConfiguration.InternalEndpoint
                                    {
                                        Name     = "Test2",
                                        Port     = 2222,
                                        Protocol = "tcp"
                                    }
                                },
                                InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint>
                                {
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test1",
                                        Protocol     = "tcp",
                                        LocalPort    = "11",
                                        FixedPortMin = 100,
                                        FixedPortMax = 1000
                                    },
                                    new ExtensionEndpointConfiguration.InstanceInputEndpoint
                                    {
                                        Name         = "Test2",
                                        Protocol     = "tcp",
                                        LocalPort    = "22",
                                        FixedPortMin = 2000,
                                        FixedPortMax = 10000
                                    }
                                }
                            },
                            IsJsonExtension = false,
                            CompanyName     = providerName,
                            SupportedOS     = ExtensionImageSupportedOperatingSystemType.Windows,
                            Regions         = usWestLocStr,
                        };

                        compute.ExtensionImages.Update(parameters);

                        bool      found         = false;
                        const int maxRetryTimes = 60;
                        int       retryTime     = 0;
                        VirtualMachineExtensionListResponse.ResourceExtension ext = null;
                        while (!found && retryTime < maxRetryTimes)
                        {
                            Thread.Sleep(TimeSpan.FromMinutes(1.0));

                            ext = compute.VirtualMachineExtensions
                                  .ListVersions(providerName, extensionName)
                                  .FirstOrDefault(e => string.Equals(e.Version, verUpdtStr));

                            if (ext != null)
                            {
                                found = true;
                            }

                            retryTime++;
                        }

                        if (found)
                        {
                            Assert.True(ext != null);

                            Assert.Equal <string>(ext.Name, parameters.Type);
                            Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace);
                            Assert.Equal <string>(ext.Description, parameters.Description);
                            Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema);
                            Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema);
                            Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString());
                            Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString());
                            Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString());
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade);
                            Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension);
                            Assert.Equal <string>(ext.CompanyName, parameters.CompanyName);
                            Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS);

                            Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value &&
                                        (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value));
                        }
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    try
                    {
                        compute.ExtensionImages.Unregister(
                            providerName,
                            extensionName,
                            versionStr);

                        compute.ExtensionImages.Unregister(
                            providerName,
                            extensionName,
                            verUpdtStr);
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }

                    // List Publisher Extensions
                    try
                    {
                        compute.HostedServices.ListPublisherExtensions();
                    }
                    catch (CloudException e)
                    {
                        Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr));
                    }
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    compute.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }