public void TestVMScaleSetApplicationProfile()
        {
            string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
                EnsureClientsInitialized(context);

                // Create resource group
                string rgName               = TestUtilities.GenerateName(TestPrefix);
                var    vmssName             = TestUtilities.GenerateName("vmss");
                string storageAccountName   = TestUtilities.GenerateName(TestPrefix);
                var    storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);
                IList <VMGalleryApplication> galleryApplications = new List <VMGalleryApplication>()
                {
                    // for recording the test ensure that a real galley application version exists at the location
                    // creating a gallery application version is beyond the sope of this test
                    new VMGalleryApplication("/subscriptions/5393f919-a68a-43d0-9063-4b2bda6bffdf/resourceGroups/bhbrahma/providers/Microsoft.Compute/galleries/bhbrahmaGallery/applications/go/versions/1.15.8", treatFailureAsDeploymentFailure: true, enableAutomaticUpgrade: true)
                };

                VirtualMachineScaleSet          inputVMScaleSet;
                Action <VirtualMachineScaleSet> vmProfileCustomizer = vmss =>
                {
                    vmss.VirtualMachineProfile.ApplicationProfile = new ApplicationProfile(galleryApplications);
                };

                try
                {
                    VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(
                        rgName: rgName,
                        vmssName: vmssName,
                        storageAccount: storageAccountOutput,
                        imageRef: GetPlatformVMImage(true),
                        inputVMScaleSet: out inputVMScaleSet,
                        createWithManagedDisks: true,
                        vmScaleSetCustomizer: vmProfileCustomizer
                        );

                    var response = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName);
                    Assert.NotNull(response.VirtualMachineProfile.ApplicationProfile);
                    Assert.NotNull(response.VirtualMachineProfile.ApplicationProfile.GalleryApplications);
                    Assert.Equal(1, response.VirtualMachineProfile.ApplicationProfile.GalleryApplications.Count);
                    VMGalleryApplication vmGalleryApplication = response.VirtualMachineProfile.ApplicationProfile.GalleryApplications[0];
                    Assert.True(vmGalleryApplication.TreatFailureAsDeploymentFailure);
                    Assert.True(vmGalleryApplication.EnableAutomaticUpgrade);
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                    m_ResourcesClient.ResourceGroups.DeleteIfExists(rgName);
                }
            }
        }
Ejemplo n.º 2
0
        public void VMApplicationProfile_Tests()
        {
            string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "centraluseuap");
                EnsureClientsInitialized(context);

                ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
                var            image    = m_CrpClient.VirtualMachineImages.Get(
                    this.m_location, imageRef.Publisher, imageRef.Offer, imageRef.Sku, imageRef.Version);
                Assert.True(image != null);

                // Create resource group
                var            rgName             = ComputeManagementTestUtilities.GenerateName(TestPrefix);
                string         storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
                string         asName             = ComputeManagementTestUtilities.GenerateName("as");
                VirtualMachine inputVM;

                try
                {
                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);
                    IList <VMGalleryApplication> galleryApplications = new List <VMGalleryApplication>()
                    {
                        // when re-recording the test ensure that you use a valid packageReferenceId
                        // refer to https://microsoft.sharepoint.com/:w:/t/ComputeVM/EcYeD-HHrLZHpYyxo3iRCtkB-VeO8BuWE4dq4hoX9tlzEg?e=nOTgTu
                        // for how to create a valid VMApplication
                        new VMGalleryApplication("/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/bhbrahma/providers/Microsoft.Compute/galleries/bhbrahmaGallery/applications/go/versions/1.15.8", treatFailureAsDeploymentFailure: true, enableAutomaticUpgrade: true)
                    };

                    var vm1 = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM, (vm) =>
                    {
                        vm.StorageProfile.OsDisk.DiskSizeGB = 150;
                        vm.ApplicationProfile = new ApplicationProfile(galleryApplications);
                    });

                    var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name);
                    ValidateVM(inputVM, getVMResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name));
                    Assert.NotNull(getVMResponse.ApplicationProfile);
                    Assert.NotNull(getVMResponse.ApplicationProfile.GalleryApplications);
                    Assert.Equal(1, getVMResponse.ApplicationProfile.GalleryApplications.Count);
                    VMGalleryApplication vmGalleryApplication = getVMResponse.ApplicationProfile.GalleryApplications[0];
                    Assert.True(vmGalleryApplication.TreatFailureAsDeploymentFailure);
                    Assert.True(vmGalleryApplication.EnableAutomaticUpgrade);
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }