Ejemplo n.º 1
0
        public void TestVMScaleSetRollingUpgradeHistory()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

                // Create resource group
                var    rgName             = TestUtilities.GenerateName(TestPrefix);
                var    vmssName           = TestUtilities.GenerateName("vmss");
                string storageAccountName = TestUtilities.GenerateName(TestPrefix);
                VirtualMachineScaleSet inputVMScaleSet;

                try
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "southcentralus");
                    EnsureClientsInitialized(context);

                    ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
                    imageRef.Version = "latest";

                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                    var getResponse = CreateVMScaleSet_NoAsyncTracking(
                        rgName,
                        vmssName,
                        storageAccountOutput,
                        imageRef,
                        out inputVMScaleSet,
                        null,
                        (vmScaleSet) =>
                    {
                        vmScaleSet.Overprovision      = false;
                        vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Rolling;
                    },
                        createWithManagedDisks: true,
                        createWithPublicIpAddress: false,
                        createWithHealthProbe: true);

                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);
                    ComputeManagementTestUtilities.WaitSeconds(600);
                    var vmssStatus = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);

                    m_CrpClient.VirtualMachineScaleSetRollingUpgrades.StartOSUpgrade(rgName, vmssName);
                    var rollingUpgradeHistory = m_CrpClient.VirtualMachineScaleSets.GetOSUpgradeHistory(rgName, vmssName);
                    Assert.NotNull(rollingUpgradeHistory);
                    Assert.True(rollingUpgradeHistory.Count() == 1);
                    Assert.Equal(inputVMScaleSet.Sku.Capacity, rollingUpgradeHistory.First().Properties.Progress.SuccessfulInstanceCount);
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                    //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                    //of the test to cover deletion. CSM does persistent retrying over all RG resources.
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Ejemplo n.º 2
0
        public void Gallery_CRUD_Tests()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                EnsureClientsInitialized(context);
                string rgName  = ComputeManagementTestUtilities.GenerateName(ResourceGroupPrefix);
                string rgName2 = rgName + "New";

                m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup {
                    Location = galleryHomeLocation
                });
                Trace.TraceInformation("Created the resource group: " + rgName);

                string  galleryName = ComputeManagementTestUtilities.GenerateName(GalleryNamePrefix);
                Gallery galleryIn   = GetTestInputGallery();
                m_CrpClient.Galleries.CreateOrUpdate(rgName, galleryName, galleryIn);
                Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName, rgName));

                Gallery galleryOut = m_CrpClient.Galleries.Get(rgName, galleryName);
                Trace.TraceInformation("Got the gallery.");
                Assert.NotNull(galleryOut);
                ValidateGallery(galleryIn, galleryOut);

                galleryIn.Description = "This is an updated description";
                m_CrpClient.Galleries.CreateOrUpdate(rgName, galleryName, galleryIn);
                Trace.TraceInformation("Updated the gallery.");
                galleryOut = m_CrpClient.Galleries.Get(rgName, galleryName);
                ValidateGallery(galleryIn, galleryOut);

                Trace.TraceInformation("Listing galleries.");
                string galleryName2 = galleryName + "New";
                m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName2, new ResourceGroup {
                    Location = galleryHomeLocation
                });
                Trace.TraceInformation("Created the resource group: " + rgName2);
                ComputeManagementTestUtilities.WaitSeconds(10);
                m_CrpClient.Galleries.CreateOrUpdate(rgName2, galleryName2, galleryIn);
                Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName2, rgName2));
                IPage <Gallery> listGalleriesInRgResult = m_CrpClient.Galleries.ListByResourceGroup(rgName);
                Assert.Single(listGalleriesInRgResult);
                Assert.Null(listGalleriesInRgResult.NextPageLink);
                IPage <Gallery> listGalleriesInSubIdResult = m_CrpClient.Galleries.List();
                // Below, >= instead of == is used because this subscription is shared in the group so other developers
                // might have created galleries in this subscription.
                Assert.True(listGalleriesInSubIdResult.Count() >= 2);

                Trace.TraceInformation("Deleting 2 galleries.");
                m_CrpClient.Galleries.Delete(rgName, galleryName);
                m_CrpClient.Galleries.Delete(rgName2, galleryName2);
                listGalleriesInRgResult = m_CrpClient.Galleries.ListByResourceGroup(rgName);
                Assert.Empty(listGalleriesInRgResult);
                // resource groups cleanup is taken cared by MockContext.Dispose() method.
            }
        }
Ejemplo n.º 3
0
        protected StorageAccount CreateStorageAccount(string rgName, string storageAccountName)
        {
            try
            {
                // Create the resource Group.
                var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate(
                    rgName,
                    new ResourceGroup
                {
                    Location = m_location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { rgName, DateTime.UtcNow.ToString("u") }
                    }
                });

                var stoInput = new StorageAccountCreateParameters
                {
                    Location    = m_location,
                    AccountType = AccountType.StandardGRS
                };

                StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName,
                                                                                         storageAccountName, stoInput);
                bool created = false;
                while (!created)
                {
                    ComputeManagementTestUtilities.WaitSeconds(10);
                    var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName);
                    created =
                        stos.Any(
                            t =>
                            StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName));
                }

                return(m_SrpClient.StorageAccounts.GetProperties(rgName, storageAccountName));
            }
            catch
            {
                m_ResourcesClient.ResourceGroups.Delete(rgName);
                throw;
            }
        }
Ejemplo n.º 4
0
        protected StorageAccount CreateStorageAccount(string rgName, string storageAccountName)
        {
            try
            {
                // Create the resource Group.
                var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate(
                    rgName,
                    new ResourceGroup
                {
                    Location = m_location
                });

                var stoInput = new StorageAccountCreateParameters
                {
                    Location    = m_location,
                    AccountType = AccountType.StandardGRS
                };

                StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName,
                                                                                         storageAccountName, stoInput).StorageAccount;
                bool created = false;
                while (!created)
                {
                    ComputeManagementTestUtilities.WaitSeconds(10);
                    var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName);
                    created =
                        stos.StorageAccounts.Any(
                            t =>
                            StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName));
                }

                storageAccountOutput.Name = storageAccountName; // TODO: try to remove this in a future recording

                return(storageAccountOutput);
            }
            catch
            {
                var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName);
                Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK);
                throw;
            }
        }
Ejemplo n.º 5
0
        public void TestVMScaleSetRollingUpgrade()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

                // Create resource group
                var    rgName             = TestUtilities.GenerateName(TestPrefix);
                var    vmssName           = TestUtilities.GenerateName("vmss");
                string storageAccountName = TestUtilities.GenerateName(TestPrefix);
                VirtualMachineScaleSet inputVMScaleSet;
                try
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "southcentralus");
                    EnsureClientsInitialized(context);
                    ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

                    VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile()
                    {
                        Extensions = new List <VirtualMachineScaleSetExtension>()
                        {
                            GetTestVMSSVMExtension(autoUpdateMinorVersion: false),
                        }
                    };

                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                    var getResponse = CreateVMScaleSet_NoAsyncTracking(
                        rgName,
                        vmssName,
                        storageAccountOutput,
                        imageRef,
                        out inputVMScaleSet,
                        null,
                        (vmScaleSet) =>
                    {
                        vmScaleSet.Overprovision      = false;
                        vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Rolling;
                    },
                        createWithManagedDisks: true,
                        createWithPublicIpAddress: false,
                        createWithHealthProbe: true);

                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    var getInstanceViewResponse = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);
                    Assert.NotNull(getInstanceViewResponse);
                    ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

                    var getVMInstanceViewResponse = m_CrpClient.VirtualMachineScaleSetVMs.GetInstanceView(rgName, vmssName, "0");
                    Assert.NotNull(getVMInstanceViewResponse);
                    Assert.NotNull(getVMInstanceViewResponse.VmHealth);
                    Assert.Equal("HealthState/healthy", getVMInstanceViewResponse.VmHealth.Status.Code);

                    // Update the VMSS by adding an extension
                    ComputeManagementTestUtilities.WaitSeconds(600);
                    var vmssStatus = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);

                    inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;
                    UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet);

                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    getInstanceViewResponse = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);
                    Assert.NotNull(getInstanceViewResponse);
                    ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmssName);
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                    //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                    //of the test to cover deletion. CSM does persistent retrying over all RG resources.
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Ejemplo n.º 6
0
        public void GalleryApplicationVersion_CRUD_Tests()
        {
            string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string location = galleryHomeLocation;
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", location);
                EnsureClientsInitialized(context);
                string rgName                        = ComputeManagementTestUtilities.GenerateName(ResourceGroupPrefix);
                string applicationName               = ComputeManagementTestUtilities.GenerateName("psTestSourceApplication");
                string galleryName                   = ComputeManagementTestUtilities.GenerateName(GalleryNamePrefix);
                string galleryApplicationName        = ComputeManagementTestUtilities.GenerateName(GalleryApplicationNamePrefix);
                string galleryApplicationVersionName = "1.0.0";

                try
                {
                    string applicationMediaLink = CreateApplicationMediaLink(rgName, "test.txt");

                    Assert.False(string.IsNullOrEmpty(applicationMediaLink));
                    Trace.TraceInformation(string.Format("Created the source application media link: {0}", applicationMediaLink));

                    Gallery gallery = GetTestInputGallery();
                    gallery.Location = location;
                    m_CrpClient.Galleries.CreateOrUpdate(rgName, galleryName, gallery);
                    Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName,
                                                         rgName));
                    GalleryApplication inputGalleryApplication = GetTestInputGalleryApplication();
                    m_CrpClient.GalleryApplications.CreateOrUpdate(rgName, galleryName, galleryApplicationName, inputGalleryApplication);
                    Trace.TraceInformation(string.Format("Created the gallery application: {0} in gallery: {1}", galleryApplicationName,
                                                         galleryName));

                    GalleryApplicationVersion inputApplicationVersion = GetTestInputGalleryApplicationVersion(applicationMediaLink);
                    m_CrpClient.GalleryApplicationVersions.CreateOrUpdate(rgName, galleryName, galleryApplicationName,
                                                                          galleryApplicationVersionName, inputApplicationVersion);
                    Trace.TraceInformation(string.Format("Created the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));

                    GalleryApplicationVersion applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName,
                                                                                                                     galleryName, galleryApplicationName, galleryApplicationVersionName);
                    Assert.NotNull(applicationVersionFromGet);
                    ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);
                    applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName, galleryName, galleryApplicationName,
                                                                                           galleryApplicationVersionName, ReplicationStatusTypes.ReplicationStatus);
                    Assert.Equal(StorageAccountType.StandardLRS, applicationVersionFromGet.PublishingProfile.StorageAccountType);
                    Assert.Equal(StorageAccountType.StandardLRS,
                                 applicationVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType);
                    Assert.NotNull(applicationVersionFromGet.ReplicationStatus);
                    Assert.NotNull(applicationVersionFromGet.ReplicationStatus.Summary);

                    inputApplicationVersion.PublishingProfile.EndOfLifeDate = DateTime.Now.AddDays(100).Date;
                    m_CrpClient.GalleryApplicationVersions.CreateOrUpdate(rgName, galleryName, galleryApplicationName,
                                                                          galleryApplicationVersionName, inputApplicationVersion);
                    Trace.TraceInformation(string.Format("Updated the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));
                    applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName, galleryName,
                                                                                           galleryApplicationName, galleryApplicationVersionName);
                    Assert.NotNull(applicationVersionFromGet);
                    ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);

                    m_CrpClient.GalleryApplicationVersions.Delete(rgName, galleryName, galleryApplicationName, galleryApplicationVersionName);
                    Trace.TraceInformation(string.Format("Deleted the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));
                    ComputeManagementTestUtilities.WaitSeconds(300);

                    m_CrpClient.GalleryApplications.Delete(rgName, galleryName, galleryApplicationName);
                    Trace.TraceInformation("Deleted the gallery application.");
                    m_CrpClient.Galleries.Delete(rgName, galleryName);
                    Trace.TraceInformation("Deleted the gallery.");
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                }
            }
        }