public async Task TestVMMarketplace() { EnsureClientsInitialized(DefaultLocation); ImageReference dummyImageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var img = await GetMarketplaceImage(); Action <VirtualMachine> useVMMImage = vm => { vm.StorageProfile.DataDisks.Clear(); vm.StorageProfile.ImageReference = new ImageReference { Publisher = vmmPublisherName, Offer = vmmOfferName, Sku = vmmSku, Version = img.Name }; vm.Plan = new Plan() { Name = img.Plan.Name, Product = img.Plan.Product, PromotionCode = null, Publisher = img.Plan.Publisher }; }; VirtualMachine vm1 = null; inputVM = null; try { var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, dummyImageRef, useVMMImage); vm1 = returnTwoVM.Response; inputVM = returnTwoVM.Input; } catch (Exception ex) { if (ex.Message.Contains("User failed validation to purchase resources.")) { return; } throw; } // Validate the VMM Plan field ValidateMarketplaceVMPlanField(vm1, img); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM.Name)); }
public async Task TestVMOperations_Reapply() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1; bool passed = false; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, asName, storageAccountOutput, imageRef); VirtualMachine vm1 = returnTwovm.Item1; inputVM1 = returnTwovm.Item2; var reapplyperationResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartReapplyAsync(rg1Name, vm1.Name)); var lroResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartReapplyAsync(rg1Name, vm1.Name)); //var lroResponse = await VirtualMachinesClient.StartReapplyAsync(rg1Name, // vm1.Name).GetAwaiter().GetResult(); passed = true; Assert.True(passed); }
public async Task TestVMOperations_Redeploy() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1; bool passed = false; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, asName, storageAccountOutput, imageRef); VirtualMachine vm1 = returnTwovm.Response; inputVM1 = returnTwovm.Input; var redeployOperationResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartRedeployAsync(rg1Name, vm1.Name)); //.BeginRedeployWithHttpMessagesAsync //Assert.Equal(HttpStatusCode.Accepted, redeployOperationResponse.Result.Response.StatusCode); var lroResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartRedeployAsync(rg1Name, vm1.Name)); //var lroResponse = await VirtualMachinesClient.StartRedeployAsync(rg1Name, // vm1.Name).GetAwaiter().GetResult(); //Assert.Equal(ComputeOperationStatus.Succeeded, lroResponse.Status); passed = true; Assert.True(passed); }
public async Task TestVMOperations_PowerOffWithSkipShutdown() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1; bool passed = false; // Create Storage Account for this VM var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, asName, storageAccountOutput, imageRef); VirtualMachine vm1 = returnTwovm.Item1; inputVM1 = returnTwovm.Item2; await WaitForCompletionAsync(await VirtualMachinesOperations.StartStartAsync(rg1Name, vm1.Name)); // Shutdown VM with SkipShutdown = true await WaitForCompletionAsync(await VirtualMachinesOperations.StartPowerOffAsync(rg1Name, vm1.Name, true)); passed = true; Assert.True(passed); }
public async Task DiskManagedByTest() { EnsureClientsInitialized(DefaultLocation); var rgName = Recording.GenerateAssetName(TestPrefix); var diskName = Recording.GenerateAssetName(DiskNamePrefix); // Create a VM, so we can use its OS disk for testing managedby string storageAccountName = Recording.GenerateAssetName(DiskNamePrefix); string avSet = Recording.GenerateAssetName("avSet"); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); VirtualMachine inputVM = null; // Create Storage Account for creating vm var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); // Create the VM, whose OS disk will be used in creating the image var returnTwovm = await CreateVM(rgName, avSet, storageAccountOutput, imageRef, hasManagedDisks : true); var createdVM = returnTwovm.Item1; inputVM = returnTwovm.Item2; var listResponse = (await VirtualMachinesOperations.ListAllAsync().ToEnumerableAsync()); Assert.True(listResponse.Count() >= 1); var vmName = createdVM.Name; var vmDiskName = createdVM.StorageProfile.OsDisk.Name; //get disk from VM Disk diskFromVM = await DisksOperations.GetAsync(rgName, vmDiskName); //managedby should have format: "/subscriptions/{subId}/resourceGroups/{rg}/Microsoft.Compute/virtualMachines/vm1" //Assert.Contains(vmName, diskFromVM.ManagedBy); Assert.True(diskFromVM.ManagedBy.Contains(vmName)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM.Name)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, createdVM.Name)); await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName)); }
public async Task TestListUsages() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imageRef); var vm1 = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; string inputVMName = returnTwoVM.Item3; // List Usages, and do weak validation to assure that some usages were returned. var luResponse = await(UsageClient.ListAsync(vm1.Location)).ToEnumerableAsync(); ValidateListUsageResponse(luResponse); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVMName)); } catch (Exception e) { Assert.Null(e); } }
public async Task TestVMDiskSizeScenario() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); var image = await VirtualMachineImagesOperations.GetAsync( this.m_location, imageRef.Publisher, imageRef.Offer, imageRef.Sku, imageRef.Version); Assert.True(image != null); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imageRef, (vm) => { vm.StorageProfile.OsDisk.DiskSizeGB = 150; }); var vm1 = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; var getVMResponse = await VirtualMachinesOperations.GetAsync(rgName, inputVM.Name); ValidateVM(inputVM, getVMResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); }
private async Task TestVMWithOSProfile( string rgName, bool useWindowsProfile, Action <VirtualMachine> vmCustomizer = null, Action <VirtualMachine> vmValidator = null) { string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); ImageReference imageRef = await GetPlatformVMImage(useWindowsProfile); VirtualMachine inputVM; StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imageRef, vmCustomizer); VirtualMachine vm = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; string inputVMName = returnTwoVM.Item3; //var getVMWithInstanceViewResponse = await VirtualMachinesClient.GetAsync(rgName, inputVM.Name, InstanceViewTypes.InstanceView); var getVMWithInstanceViewResponse = await VirtualMachinesOperations.GetAsync(rgName, inputVMName); ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse); var lroResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartCreateOrUpdateAsync(rgName, vm.Name, vm)); Assert.True(lroResponse.Value.ProvisioningState == "Succeeded"); if (vmValidator != null) { vmValidator(vm); } await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, vm.Name)); }
public static async Task <VirtualMachine> CreateVM(VirtualMachinesOperations virtualMachines, string vmName, VirtualMachine vmParameter) { var result = await(await virtualMachines .StartCreateOrUpdateAsync(rgName, vmName, vmParameter)).WaitForCompletionAsync(); Utilities.Log("VM created for: " + result.Value.Id); return(result.Value); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { Labs = new LabsOperations(this); GlobalSchedules = new GlobalSchedulesOperations(this); ArtifactSources = new ArtifactSourcesOperations(this); ArmTemplates = new ArmTemplatesOperations(this); Artifacts = new ArtifactsOperations(this); Costs = new CostsOperations(this); CustomImages = new CustomImagesOperations(this); Formulas = new FormulasOperations(this); GalleryImages = new GalleryImagesOperations(this); NotificationChannels = new NotificationChannelsOperations(this); PolicySets = new PolicySetsOperations(this); Policies = new PoliciesOperations(this); Schedules = new SchedulesOperations(this); ServiceRunners = new ServiceRunnersOperations(this); Users = new UsersOperations(this); Disks = new DisksOperations(this); Environments = new EnvironmentsOperations(this); Secrets = new SecretsOperations(this); VirtualMachines = new VirtualMachinesOperations(this); VirtualMachineSchedules = new VirtualMachineSchedulesOperations(this); VirtualNetworks = new VirtualNetworksOperations(this); BaseUri = new System.Uri("https://management.azure.com"); ApiVersion = "2016-05-15"; AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; SerializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); DeserializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }
public async Task TestVMIdentitySystemAssignedUserAssigned() { EnsureClientsInitialized(DefaultLocation); // Prerequisite: in order to record this test, first create a user identity in resource group 'identitytest' and set the value of identity here. const string rgName = "identitytest"; const string identity = "/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourcegroups/identitytest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userid"; ImageReference imgageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; bool passed = false; try { var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); Action <VirtualMachine> addUserIdentity = vm => { vm.Identity = new VirtualMachineIdentity(); vm.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned; vm.Identity.UserAssignedIdentities.Add(identity, new Components1H8M3EpSchemasVirtualmachineidentityPropertiesUserassignedidentitiesAdditionalproperties()); }; var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imgageRef, addUserIdentity); VirtualMachine vmResult = returnTwoVM.Response; inputVM = returnTwoVM.Input; Assert.AreEqual(ResourceIdentityType.SystemAssignedUserAssigned, vmResult.Identity.Type); Assert.NotNull(vmResult.Identity.PrincipalId); Assert.NotNull(vmResult.Identity.TenantId); Assert.True(vmResult.Identity.UserAssignedIdentities.Keys.Contains(identity)); Assert.NotNull(vmResult.Identity.UserAssignedIdentities[identity].PrincipalId); Assert.NotNull(vmResult.Identity.UserAssignedIdentities[identity].ClientId); var getVM = (await VirtualMachinesOperations.GetAsync(rgName, inputVM.Name)).Value; Assert.AreEqual(ResourceIdentityType.SystemAssignedUserAssigned, getVM.Identity.Type); Assert.NotNull(getVM.Identity.PrincipalId); Assert.NotNull(getVM.Identity.TenantId); Assert.True(getVM.Identity.UserAssignedIdentities.Keys.Contains(identity)); Assert.NotNull(getVM.Identity.UserAssignedIdentities[identity].PrincipalId); Assert.NotNull(getVM.Identity.UserAssignedIdentities[identity].ClientId); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM.Name)); passed = true; } catch (Exception) { throw; } finally { Assert.True(passed); } }
/// <summary> /// Initializes client properties. /// </summary> protected override void Initialize() { Operations = new Operations(this); AvailabilitySets = new AvailabilitySetsOperations(this); VirtualMachineExtensionImages = new VirtualMachineExtensionImagesOperations(this); VirtualMachineExtensions = new VirtualMachineExtensionsOperations(this); VirtualMachineImages = new VirtualMachineImagesOperations(this); Usage = new UsageOperations(this); VirtualMachines = new VirtualMachinesOperations(this); VirtualMachineSizes = new VirtualMachineSizesOperations(this); Images = new ImagesOperations(this); VirtualMachineScaleSets = new VirtualMachineScaleSetsOperations(this); VirtualMachineScaleSetExtensions = new VirtualMachineScaleSetExtensionsOperations(this); VirtualMachineScaleSetRollingUpgrades = new VirtualMachineScaleSetRollingUpgradesOperations(this); VirtualMachineScaleSetVMs = new VirtualMachineScaleSetVMsOperations(this); LogAnalytics = new LogAnalyticsOperations(this); VirtualMachineRunCommands = new VirtualMachineRunCommandsOperations(this); ResourceSkus = new ResourceSkusOperations(this); Disks = new DisksOperations(this); Snapshots = new SnapshotsOperations(this); Galleries = new GalleriesOperations(this); GalleryImages = new GalleryImagesOperations(this); GalleryImageVersions = new GalleryImageVersionsOperations(this); ContainerServices = new ContainerServicesOperations(this); BaseUri = new System.Uri("https://management.azure.com"); AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; SerializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; DeserializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }
public async Task TestVMBYOL() { EnsureClientsInitialized(DefaultLocation); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; string inputVMName; string storageAccountName = Recording.GenerateAssetName(TestPrefix); ImageReference dummyImageRef = null; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); Action <VirtualMachine> useVMMImage = async vm => { vm.StorageProfile.ImageReference = await GetPlatformVMImage(true); vm.LicenseType = "Windows_Server"; }; VirtualMachine vm1 = null; try { var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, dummyImageRef, useVMMImage); vm1 = returnTwoVM.Response; inputVM = returnTwoVM.Input; inputVMName = returnTwoVM.Name; } catch (Exception ex) { if (ex.Message.Contains("License type cannot be specified when creating a virtual machine from platform image. Please use an image from on-premises instead.")) { return; } else if (ex.Message.Equals("Long running operation failed with status 'Failed'.")) { return; } throw; } var getResponse = await VirtualMachinesOperations.GetAsync(rgName, vm1.Name); //var getResponse = await VirtualMachinesClient.GetAsync(rgName, vm1.Name).GetAwaiter().GetResult(); //Assert.True(getResponse.Status == HttpStatusCode.OK); ValidateVM(inputVM, getResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVMName)); var lroResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVMName)); //var lroResponse = await VirtualMachinesClient.DeleteWithHttpMessagesAsync(rgName, inputVM.Name).GetAwaiter().GetResult(); /////TODO //Assert.True(lroResponse .StatusCode == HttpStatusCode.OK); }
public async Task TestNicVirtualMachineReference() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); string rgName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM; // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = await ResourceGroupsOperations.CreateOrUpdateAsync( rgName, new ResourceGroup(m_location) { Tags = new Dictionary <string, string>() { { rgName, Recording.UtcNow.ToString("u") } } }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); Subnet subnetResponse = await CreateVNET(rgName); NetworkInterface nicResponse = await CreateNIC(rgName, subnetResponse, null); string asetId = await CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse.Id); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartCreateOrUpdateAsync( rgName, inputVM.Name, inputVM)); Assert.NotNull(createOrUpdateResponse); var getVMResponse = await VirtualMachinesOperations.GetAsync(rgName, inputVM.Name); //Assert.True( // getVMResponse.Value.AvailabilitySet.Id // .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, getVMResponse, expectedVMReferenceId); var getNicResponse = (await NetworkInterfacesOperations.GetAsync(rgName, nicResponse.Name)).Value; // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse.MacAddress); Assert.NotNull(getNicResponse.Primary); Assert.True(getNicResponse.Primary != null && getNicResponse.Primary.Value); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { AvailabilitySets = new AvailabilitySetsOperations(this); VirtualMachineExtensionImages = new VirtualMachineExtensionImagesOperations(this); VirtualMachineExtensions = new VirtualMachineExtensionsOperations(this); VirtualMachineImages = new VirtualMachineImagesOperations(this); Usage = new UsageOperations(this); VirtualMachineSizes = new VirtualMachineSizesOperations(this); Images = new ImagesOperations(this); VirtualMachines = new VirtualMachinesOperations(this); VirtualMachineScaleSets = new VirtualMachineScaleSetsOperations(this); VirtualMachineScaleSetVMs = new VirtualMachineScaleSetVMsOperations(this); Disks = new DisksOperations(this); Snapshots = new SnapshotsOperations(this); BaseUri = new System.Uri("https://management.azure.com"); ApiVersion = "2016-04-30-preview"; AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; SerializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); DeserializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { Images = new ImagesOperations(this); LabPlans = new LabPlansOperations(this); Operations = new Operations(this); Labs = new LabsOperations(this); OperationResults = new OperationResultsOperations(this); Schedules = new SchedulesOperations(this); Users = new UsersOperations(this); VirtualMachines = new VirtualMachinesOperations(this); Usages = new UsagesOperations(this); Skus = new SkusOperations(this); BaseUri = new System.Uri("https://management.azure.com"); ApiVersion = "2021-11-15-preview"; AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; SerializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); DeserializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }
public async Task TestListVMInSubscription() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); string baseRGName = Recording.GenerateAssetName(TestPrefix); string rg1Name = baseRGName + "a"; string rg2Name = baseRGName + "b"; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1, inputVM2; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, asName, storageAccountOutput, imageRef); var vm1 = returnTwovm.Response; inputVM1 = returnTwovm.Input; returnTwovm = await CreateVM(rg2Name, asName, storageAccountOutput, imageRef); var vm2 = returnTwovm.Response; inputVM2 = returnTwovm.Input; var listResponse = await(VirtualMachinesOperations.ListAllAsync()).ToEnumerableAsync(); Assert.True(listResponse.Count() >= 2); //Assert.Null(listResponse.NextPageLink); int vmsValidatedCount = 0; foreach (var vm in listResponse) { if (vm.Name == vm1.Name) { ValidateVM(vm, vm1, Helpers.GetVMReferenceId(m_subId, rg1Name, vm1.Name)); vmsValidatedCount++; } else if (vm.Name == vm2.Name) { ValidateVM(vm, vm2, Helpers.GetVMReferenceId(m_subId, rg2Name, vm2.Name)); vmsValidatedCount++; } } Assert.True(vmsValidatedCount == 2); }
public async Task TestListVMsInSubscriptionByLocation() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); string baseResourceGroupName = Recording.GenerateAssetName(TestPrefix); string resourceGroup1Name = baseResourceGroupName + "a"; string resourceGroup2Name = baseResourceGroupName + "b"; string availabilitySetName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1, inputVM2; // Create Storage Account, so that both VMs can share it StorageAccount storageAccountOutput = await CreateStorageAccount(resourceGroup1Name, storageAccountName); var returnTwovm = await CreateVM(resourceGroup1Name, availabilitySetName, storageAccountOutput, imageRef); var vm1 = returnTwovm.Item1; inputVM1 = returnTwovm.Item2; returnTwovm = await CreateVM(resourceGroup2Name, availabilitySetName, storageAccountOutput, imageRef); var vm2 = returnTwovm.Item1; inputVM2 = returnTwovm.Item2; var listResponse = await(VirtualMachinesOperations.ListByLocationAsync(DefaultLocation)).ToEnumerableAsync(); Assert.True(listResponse.Count() >= 2); //Assert.Null(listResponse.NextPageLink); int vmsValidatedCount = 0; foreach (VirtualMachine vm in listResponse) { if (vm.Name.Equals(vm1.Name)) { ValidateVM(vm, vm1, Helpers.GetVMReferenceId(m_subId, resourceGroup1Name, vm1.Name)); vmsValidatedCount++; } else if (vm.Name.Equals(vm2.Name)) { ValidateVM(vm, vm2, Helpers.GetVMReferenceId(m_subId, resourceGroup2Name, vm2.Name)); vmsValidatedCount++; } } Assert.AreEqual(2, vmsValidatedCount); }
//[Trait("Name", "TestVMBootDiagnostics")] public async Task TestVMBootDiagnostics() { EnsureClientsInitialized(DefaultLocation); ImageReference imageReference = await GetPlatformVMImage(useWindowsImage : true); string resourceGroupName = Recording.GenerateAssetName(TestPrefix); string storageAccountForDisksName = Recording.GenerateAssetName(TestPrefix); string storageAccountForBootDiagnosticsName = Recording.GenerateAssetName(TestPrefix); string availabilitySetName = Recording.GenerateAssetName(TestPrefix); StorageAccount storageAccountForDisks = await CreateStorageAccount(resourceGroupName, storageAccountForDisksName); StorageAccount storageAccountForBootDiagnostics = await CreateStorageAccount(resourceGroupName, storageAccountForBootDiagnosticsName); VirtualMachine inputVM; var returnTwoVm = await CreateVM(resourceGroupName, availabilitySetName, storageAccountForDisks, imageReference, (vm) => { vm.DiagnosticsProfile = GetDiagnosticsProfile(storageAccountForBootDiagnosticsName); }); inputVM = returnTwoVm.Item2; string inputVMName = returnTwoVm.Item3; VirtualMachine getVMWithInstanceViewResponse = await VirtualMachinesOperations.GetAsync(resourceGroupName, inputVMName); ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse); ValidateBootDiagnosticsInstanceView(getVMWithInstanceViewResponse.InstanceView.BootDiagnostics, hasError: false); // Make boot diagnostics encounter an error due to a missing boot diagnostics storage account await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeallocateAsync(resourceGroupName, inputVMName)); await StorageAccountsOperations.DeleteAsync(resourceGroupName, storageAccountForBootDiagnosticsName); //await StorageAccountsClient.DeleteWithHttpMessagesAsync(resourceGroupName, storageAccountForBootDiagnosticsName).GetAwaiter().GetResult(); await WaitForCompletionAsync(await VirtualMachinesOperations.StartStartAsync(resourceGroupName, inputVMName)); getVMWithInstanceViewResponse = await VirtualMachinesOperations.GetAsync(resourceGroupName, inputVMName); ValidateBootDiagnosticsInstanceView(getVMWithInstanceViewResponse.InstanceView.BootDiagnostics, hasError: true); }
public async Task TestVMOperations_SimulateEviction() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1; bool passed = false; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwoVM = await CreateVM(rg1Name, asName, storageAccountOutput.Name, imageRef, (virtualMachine) => { virtualMachine.Priority = VirtualMachinePriorityTypes.Spot; virtualMachine.AvailabilitySet = null; virtualMachine.BillingProfile = new BillingProfile { MaxPrice = -1 }; }, vmSize : VirtualMachineSizeTypes.StandardA1.ToString()); VirtualMachine vm1 = returnTwoVM.Item1; inputVM1 = returnTwoVM.Item2; await VirtualMachinesOperations.SimulateEvictionAsync(rg1Name, vm1.Name); passed = true; Assert.True(passed); }
public async Task TestVMCertificatesOperations() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; Action <VirtualMachine> AddCertificateInfo = SetCertificateInfo; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imageRef, AddCertificateInfo); VirtualMachine vm1 = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM.Name)); }
//[Trait("Name", "TestDiskEncryption")] public async Task TestVMDiskEncryption() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); //Create VM with encryptionKey VirtualMachine inputVM1; var returnTwoVm = await CreateVM(rgName, asName, storageAccountOutput, imageRef, (vm) => { vm.StorageProfile.OsDisk.EncryptionSettings = GetEncryptionSettings(); vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardD1; }, waitForCompletion : false); inputVM1 = returnTwoVm.Item2; //Create VM with encryptionKey and KEK VirtualMachine inputVM2; returnTwoVm = await CreateVM(rgName, asName, storageAccountOutput, imageRef, (vm) => { vm.StorageProfile.OsDisk.EncryptionSettings = GetEncryptionSettings(addKek: true); vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardD1; }, waitForCompletion : false); inputVM2 = returnTwoVm.Item2; await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM1.Name)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVM2.Name)); }
public async Task TestVMOperations_PerformMaintenance() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1 = null; string inputVM1Name = null; bool passed = false; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, asName, storageAccountOutput, imageRef); VirtualMachine vm1 = returnTwovm.Item1; inputVM1 = returnTwovm.Item2; inputVM1Name = returnTwovm.Item3; await WaitForCompletionAsync(await VirtualMachinesOperations.StartPerformMaintenanceAsync(rg1Name, vm1.Name)); passed = true; } catch (Exception cex) { passed = true; string expectedMessage = $"Operation 'performMaintenance' is not allowed on VM '{inputVM1Name}' since the Subscription of this VM" + " is not eligible."; Assert.IsTrue(cex.Message.Contains(expectedMessage)); } Assert.True(passed); }
/// <summary> /// Generates a disk used when the DiskCreateOption is Import /// </summary> /// <returns></returns> private async Task <Disk> GenerateImportDisk(string diskCreateOption, string rgName, string location) { // Create a VM, so we can use its OS disk for creating the image string storageAccountName = Recording.GenerateAssetName(DiskNamePrefix); string asName = Recording.GenerateAssetName("as"); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); VirtualMachine inputVM = null; m_location = location; // Create Storage Account var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); // Create the VM, whose OS disk will be used in creating the image var returnTwovm = await CreateVM(rgName, asName, storageAccountOutput, imageRef); var createdVM = returnTwovm.Response; inputVM = returnTwovm.Input; string inputVMName = returnTwovm.Name; var listResponse = await VirtualMachinesOperations.ListAllAsync().ToEnumerableAsync(); Assert.True(listResponse.Count() >= 1); string[] id = createdVM.Id.Split('/'); string subscription = id[2]; var uri = createdVM.StorageProfile.OsDisk.Vhd.Uri; await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVMName)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, createdVM.Name)); Disk disk = GenerateBaseDisk(diskCreateOption); disk.CreationData.SourceUri = uri; disk.CreationData.StorageAccountId = "/subscriptions/" + subscription + "/resourceGroups/" + rgName + "/providers/Microsoft.Storage/storageAccounts/" + storageAccountName; return(disk); }
public async Task GalleryImageVersion_CRUD_Tests() { EnsureClientsInitialized(LocationEastUs2); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); VirtualMachine vm = null; string imageName = Recording.GenerateAssetName("psTestSourceImage"); vm = await CreateCRPImage(rgName, imageName); Assert.False(string.IsNullOrEmpty(sourceImageId)); Trace.TraceInformation(string.Format("Created the source image id: {0}", sourceImageId)); string galleryName = Recording.GenerateAssetName(GalleryNamePrefix); Gallery gallery = GetTestInputGallery(); await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, gallery)); Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName, rgName)); string galleryImageName = Recording.GenerateAssetName(GalleryImageNamePrefix); GalleryImage inputGalleryImage = GetTestInputGalleryImage(); await WaitForCompletionAsync((await GalleryImagesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, inputGalleryImage))); Trace.TraceInformation(string.Format("Created the gallery image: {0} in gallery: {1}", galleryImageName, galleryName)); string galleryImageVersionName = "1.0.0"; GalleryImageVersion inputImageVersion = GetTestInputGalleryImageVersion(sourceImageId); await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, galleryImageVersionName, inputImageVersion)); Trace.TraceInformation(string.Format("Created the gallery image version: {0} in gallery image: {1}", galleryImageVersionName, galleryImageName)); GalleryImageVersion imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName, galleryName, galleryImageName, galleryImageVersionName); Assert.NotNull(imageVersionFromGet); ValidateGalleryImageVersion(inputImageVersion, imageVersionFromGet); imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName, galleryName, galleryImageName, galleryImageVersionName, ReplicationStatusTypes.ReplicationStatus); Assert.AreEqual(StorageAccountType.StandardLRS, imageVersionFromGet.PublishingProfile.StorageAccountType); Assert.AreEqual(StorageAccountType.StandardLRS, imageVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType); Assert.NotNull(imageVersionFromGet.ReplicationStatus); Assert.NotNull(imageVersionFromGet.ReplicationStatus.Summary); inputImageVersion.PublishingProfile.EndOfLifeDate = Recording.UtcNow.AddDays(100); await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, galleryImageVersionName, inputImageVersion)); Trace.TraceInformation(string.Format("Updated the gallery image version: {0} in gallery image: {1}", galleryImageVersionName, galleryImageName)); imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName, galleryName, galleryImageName, galleryImageVersionName); Assert.NotNull(imageVersionFromGet); ValidateGalleryImageVersion(inputImageVersion, imageVersionFromGet); Trace.TraceInformation("Listing the gallery image versions"); List <GalleryImageVersion> listGalleryImageVersionsResult = await(GalleryImageVersionsOperations. ListByGalleryImageAsync(rgName, galleryName, galleryImageName)).ToEnumerableAsync(); Assert.IsTrue(listGalleryImageVersionsResult.Count() == 1); //Assert.Single(listGalleryImageVersionsResult); //Assert.Null(listGalleryImageVersionsResult.NextPageLink); await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartDeleteAsync(rgName, galleryName, galleryImageName, galleryImageVersionName)); listGalleryImageVersionsResult = await(GalleryImageVersionsOperations. ListByGalleryImageAsync(rgName, galleryName, galleryImageName)).ToEnumerableAsync(); //Assert.Null(listGalleryImageVersionsResult.NextPageLink); Trace.TraceInformation(string.Format("Deleted the gallery image version: {0} in gallery image: {1}", galleryImageVersionName, galleryImageName)); this.WaitMinutes(5); await WaitForCompletionAsync(await ImagesOperations.StartDeleteAsync(rgName, imageName)); Trace.TraceInformation("Deleted the CRP image."); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, vm.Name)); Trace.TraceInformation("Deleted the virtual machine."); await WaitForCompletionAsync(await GalleryImagesOperations.StartDeleteAsync(rgName, galleryName, galleryImageName)); Trace.TraceInformation("Deleted the gallery image."); WaitSeconds(100); await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName)); WaitSeconds(100); Trace.TraceInformation("Deleted the gallery."); }
private async Task TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList <string> zones = null, string vmSize = "Standard_A0", string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool?writeAcceleratorEnabled = null, bool hasDiffDisks = false, bool callUpdateVM = false, bool isPpgScenario = false, string diskEncryptionSetId = null) { var imageRef = await GetPlatformVMImage(useWindowsImage : true); const string expectedOSName = "Windows Server 2012 R2 Datacenter", expectedOSVersion = "Microsoft Windows NT 6.3.9600.0", expectedComputerName = ComputerName; // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); string ppgName = null; string expectedPpgReferenceId = null; if (isPpgScenario) { ppgName = Recording.GenerateAssetName("ppgtest"); expectedPpgReferenceId = Helpers.GetProximityPlacementGroupRef(m_subId, rgName, ppgName); } VirtualMachine inputVM; if (!hasManagedDisks) { await CreateStorageAccount(rgName, storageAccountName); } var returnTwoVM = await CreateVM(rgName, asName, storageAccountName, imageRef, hasManagedDisks : hasManagedDisks, hasDiffDisks : hasDiffDisks, vmSize : vmSize, osDiskStorageAccountType : osDiskStorageAccountType, dataDiskStorageAccountType : dataDiskStorageAccountType, writeAcceleratorEnabled : writeAcceleratorEnabled, zones : zones, ppgName : ppgName, diskEncryptionSetId : diskEncryptionSetId); //VirtualMachine outVM = returnTwoVM.Item1; inputVM = returnTwoVM.Input; string inputVMName = returnTwoVM.Name; // Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to // allow GA blob to populate. WaitMinutes(5); var getVMWithInstanceViewResponse = (await VirtualMachinesOperations.GetAsync(rgName, inputVMName)).Value; Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); if (diskEncryptionSetId != null) { Assert.True(getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet != null, "OsDisk.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "OsDisk.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); Assert.AreEqual(1, getVMWithInstanceViewResponse.StorageProfile.DataDisks.Count); Assert.True(getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet != null, ".DataDisks.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "DataDisks.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); } ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); var getVMInstanceViewResponse = await VirtualMachinesOperations.InstanceViewAsync(rgName, inputVMName); Assert.True(getVMInstanceViewResponse != null, "VM in InstanceView"); ValidateVMInstanceView(inputVM, getVMInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); bool hasUserDefinedAS = zones == null; string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVMName); var listResponse = await(VirtualMachinesOperations.ListAsync(rgName)).ToEnumerableAsync(); ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVMName), expectedVMReferenceId, hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks, expectedPpgReferenceId: expectedPpgReferenceId); var listVMSizesResponse = await(VirtualMachinesOperations.ListAvailableSizesAsync(rgName, inputVMName)).ToEnumerableAsync(); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); listVMSizesResponse = await(AvailabilitySetsOperations.ListAvailableSizesAsync(rgName, asName)).ToEnumerableAsync(); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); if (isPpgScenario) { ProximityPlacementGroup outProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(rgName, ppgName); string expectedAvSetReferenceId = Helpers.GetAvailabilitySetRef(m_subId, rgName, asName); Assert.AreEqual(1, outProximityPlacementGroup.VirtualMachines.Count); Assert.AreEqual(1, outProximityPlacementGroup.AvailabilitySets.Count); Assert.AreEqual(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id); Assert.AreEqual(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id); //Assert.Equal(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id, StringComparer.OrdinalIgnoreCase); //Assert.Equal(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id, StringComparer.OrdinalIgnoreCase); } if (callUpdateVM) { VirtualMachineUpdate updateParams = new VirtualMachineUpdate(); updateParams.Tags.InitializeFrom(inputVM.Tags); string updateKey = "UpdateTag"; updateParams.Tags.Add(updateKey, "UpdateTagValue"); VirtualMachine updateResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartUpdateAsync(rgName, inputVMName, updateParams)); Assert.True(updateResponse.Tags.ContainsKey(updateKey)); } }
public async Task TestVMExtensionOperations() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var returnTwovm = await CreateVM(rgName, asName, storageAccountOutput, imageRef); var vm = returnTwovm.Response; inputVM = returnTwovm.Input; // Delete an extension that does not exist in the VM. A http status code of NoContent should be returned which translates to operation success. var xx = await WaitForCompletionAsync(await VirtualMachineExtensionsOperations.StartDeleteAsync(rgName, vm.Name, "VMExtensionDoesNotExist")); // Add an extension to the VM var vmExtension = GetTestVMExtension(); var resp = await VirtualMachineExtensionsOperations.StartCreateOrUpdateAsync(rgName, vm.Name, vmExtension.Name, vmExtension); var response = await WaitForCompletionAsync(resp); ValidateVMExtension(vmExtension, response); // Perform a Get operation on the extension var getVMExtResponse = await VirtualMachineExtensionsOperations.GetAsync(rgName, vm.Name, vmExtension.Name); ValidateVMExtension(vmExtension, getVMExtResponse); // Perform a GetExtensions on the VM var getVMExtsResponse = (await VirtualMachineExtensionsOperations.ListAsync(rgName, vm.Name)).Value; Assert.True(getVMExtsResponse.Value.Count > 0); var vme = getVMExtsResponse.Value.Where(c => c.Name == "vmext01"); Assert.AreEqual(vme.Count(), 1); //Assert.Single(vme); ValidateVMExtension(vmExtension, vme.First()); // Validate Get InstanceView for the extension var getVMExtInstanceViewResponse = (await VirtualMachineExtensionsOperations.GetAsync(rgName, vm.Name, vmExtension.Name, "instanceView")).Value; ValidateVMExtensionInstanceView(getVMExtInstanceViewResponse.InstanceView); // Update extension on the VM var vmExtensionUpdate = GetTestVMUpdateExtension(); await WaitForCompletionAsync(await VirtualMachineExtensionsOperations.StartUpdateAsync(rgName, vm.Name, vmExtension.Name, vmExtensionUpdate)); vmExtension.Tags["extensionTag3"] = "3"; getVMExtResponse = await VirtualMachineExtensionsOperations.GetAsync(rgName, vm.Name, vmExtension.Name); ValidateVMExtension(vmExtension, getVMExtResponse); // Validate the extension in the VM info var getVMResponse = (await VirtualMachinesOperations.GetAsync(rgName, vm.Name)).Value; // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode ValidateVMExtension(vmExtension, getVMResponse.Resources.FirstOrDefault(c => c.Name == vmExtension.Name)); // Validate the extension instance view in the VM instance-view var getVMWithInstanceViewResponse = (await VirtualMachinesOperations.GetAsync(rgName, vm.Name)).Value; ValidateVMExtensionInstanceView(getVMWithInstanceViewResponse.InstanceView.Extensions.FirstOrDefault()); // Validate the extension delete API await WaitForCompletionAsync(await VirtualMachineExtensionsOperations.StartDeleteAsync(rgName, vm.Name, vmExtension.Name)); }
public async Task TestEffectiveRouteAndAcls() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); string rgName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM; // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = await ResourceGroupsOperations.CreateOrUpdateAsync( rgName, new ResourceGroup(m_location) { Tags = new Dictionary <string, string>() { { rgName, Recording.UtcNow.ToString("u") } } }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); Subnet subnetResponse = await CreateVNET(rgName); NetworkSecurityGroup nsgResponse = await CreateNsg(rgName); NetworkInterface nicResponse = await CreateNIC(rgName, subnetResponse, null, null, nsgResponse); string asetId = await CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse.Id); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartCreateOrUpdateAsync( rgName, inputVM.Name, inputVM)); Assert.NotNull(createOrUpdateResponse); var getVMResponse = (await VirtualMachinesOperations.GetAsync(rgName, inputVM.Name)).Value; //Assert.True( // getVMResponse.AvailabilitySet.Id // .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, getVMResponse, expectedVMReferenceId); var getNicResponse = (await NetworkInterfacesOperations.GetAsync(rgName, nicResponse.Name)).Value; // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse.MacAddress); Assert.NotNull(getNicResponse.Primary); Assert.True(getNicResponse.Primary != null && getNicResponse.Primary.Value); // Get Effective RouteTable var getEffectiveRouteTable = (await WaitForCompletionAsync(await NetworkInterfacesOperations.StartGetEffectiveRouteTableAsync(rgName, nicResponse.Name))).Value; Assert.NotNull(getEffectiveRouteTable); //Assert.AreNotEqual(0, getEffectiveRouteTable.Value.Count); Assert.AreEqual(getEffectiveRouteTable.Value[0].Source, EffectiveRouteSource.Default); Assert.AreEqual(getEffectiveRouteTable.Value[0].State, EffectiveRouteState.Active); // Get Effecting NSG var getEffectiveNSGresponse = (await WaitForCompletionAsync(await NetworkInterfacesOperations.StartListEffectiveNetworkSecurityGroupsAsync(rgName, nicResponse.Name.ToString()))).Value; Assert.NotNull(getEffectiveNSGresponse); Assert.AreNotEqual(0, getEffectiveNSGresponse.Value.Count); Assert.NotNull(getEffectiveNSGresponse.Value[0].Association); Assert.NotNull(getEffectiveNSGresponse.Value[0].Association.NetworkInterface); Assert.Null(getEffectiveNSGresponse.Value[0].Association.Subnet); Assert.AreEqual(getEffectiveNSGresponse.Value[0].Association.NetworkInterface.Id, nicResponse.Id); Assert.NotNull(getEffectiveNSGresponse.Value[0].NetworkSecurityGroup); Assert.AreEqual(getEffectiveNSGresponse.Value[0].NetworkSecurityGroup.Id, nsgResponse.Id); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules); Assert.AreNotEqual(0, getEffectiveNSGresponse.Value[0].EffectiveSecurityRules.Count); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Access); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].DestinationAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].DestinationPortRange); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].SourceAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].SourcePortRange); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Priority); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Name); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].ExpandedDestinationAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].ExpandedSourceAddressPrefix); }
public async Task TestVMDataDiskScenario() { EnsureClientsInitialized(DefaultLocation); ImageReference imgageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); VirtualMachine inputVM; bool passed = false; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); Action <VirtualMachine> addDataDiskToVM = vm => { string containerName = Recording.GenerateAssetName("testvmdatadiskscenario", TestPrefix); var vhdContainer = "https://" + storageAccountName + ".blob.core.windows.net/" + containerName; var vhduri = vhdContainer + string.Format("/{0}.vhd", Recording.GenerateAssetName("testvmdatadiskscenario", TestPrefix)); vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardA4; foreach (int index in new int[] { 1, 2 }) { var diskName = "dataDisk" + index; var ddUri = vhdContainer + string.Format("/{0}{1}.vhd", diskName, Recording.GenerateAssetName("testvmdatadiskscenario", TestPrefix)); var dd = new DataDisk(1 + index, DiskCreateOptionTypes.Empty) { Caching = CachingTypes.None, Image = null, DiskSizeGB = 10, Name = diskName, Vhd = new VirtualHardDisk { Uri = ddUri } }; vm.StorageProfile.DataDisks.Add(dd); } var testStatus = new InstanceViewStatus { Code = "test", Message = "test" }; var testStatusList = new List <InstanceViewStatus> { testStatus }; // Negative tests for a bug in 5.0.0 that read-only fields have side-effect on the request body /* vm.InstanceView = new VirtualMachineInstanceView * { * Statuses = testStatusList, * VmAgent = new VirtualMachineAgentInstanceView * { * Statuses = testStatusList, * ExtensionHandlers = { * new VirtualMachineExtensionHandlerInstanceView * { * Status = testStatus, * Type = "test", * TypeHandlerVersion = "test" * } * }, * VmAgentVersion = "test" * }, * Disks = { * new DiskInstanceView * { * Statuses = testStatusList, * Name = "test" * } * }, * Extensions = { * new VirtualMachineExtensionInstanceView * { * Statuses = testStatusList * } * } * }; */ }; var returnTwoVM = await CreateVM(rgName, asName, storageAccountOutput, imgageRef, addDataDiskToVM); VirtualMachine vm1 = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; string inputVMName = returnTwoVM.Item3; var getVMWithInstanceViewResponse = await VirtualMachinesOperations.GetAsync(rgName, inputVMName); Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse); var vm2 = getVMWithInstanceViewResponse; var vmReCreateResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartCreateOrUpdateAsync(rgName, getVMWithInstanceViewResponse.Value.Name, getVMWithInstanceViewResponse)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, inputVMName)); passed = true; Assert.True(passed); } catch (Exception e) { throw e; } }
public async Task TestVMOperations() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rg1Name = Recording.GenerateAssetName(TestPrefix) + 1; string as1Name = Recording.GenerateAssetName("as"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachine inputVM1; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = await CreateStorageAccount(rg1Name, storageAccountName); var returnTwovm = await CreateVM(rg1Name, as1Name, storageAccountOutput, imageRef); var vm1 = returnTwovm.Item1; inputVM1 = returnTwovm.Item2; await WaitForCompletionAsync(await VirtualMachinesOperations.StartStartAsync(rg1Name, vm1.Name)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartRedeployAsync(rg1Name, vm1.Name)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartRestartAsync(rg1Name, vm1.Name)); var runCommandImput = new RunCommandInput("RunPowerShellScript") { Script = { "param(", " [string]$arg1,", " [string]$arg2", ")", "echo This is a sample script with parameters $arg1 $arg2" }, Parameters = { new RunCommandInputParameter("arg1", "value1"), new RunCommandInputParameter("arg2", "value2"), } }; RunCommandResult result = (await WaitForCompletionAsync(await VirtualMachinesOperations.StartRunCommandAsync(rg1Name, vm1.Name, runCommandImput))).Value; Assert.NotNull(result); Assert.NotNull(result.Value); Assert.True(result.Value.Count > 0); await WaitForCompletionAsync(await VirtualMachinesOperations.StartPowerOffAsync(rg1Name, vm1.Name)); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeallocateAsync(rg1Name, vm1.Name)); await VirtualMachinesOperations.GeneralizeAsync(rg1Name, vm1.Name); VirtualMachine ephemeralVM; string as2Name = as1Name + "_ephemeral"; var returnTwoVM = await CreateVM(rg1Name, as2Name, storageAccountName, imageRef, hasManagedDisks : true, hasDiffDisks : true, vmSize : VirtualMachineSizeTypes.StandardDS5V2.ToString(), osDiskStorageAccountType : StorageAccountTypes.StandardLRS.ToString(), dataDiskStorageAccountType : StorageAccountTypes.StandardLRS.ToString()); ephemeralVM = returnTwoVM.Item2; await WaitForCompletionAsync(await VirtualMachinesOperations.StartReimageAsync(rg1Name, ephemeralVM.Name)); var captureParams = new VirtualMachineCaptureParameters(Recording.GenerateAssetName(TestPrefix), Recording.GenerateAssetName(TestPrefix), true); var captureResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartCaptureAsync(rg1Name, vm1.Name, captureParams)); Assert.NotNull(captureResponse); Assert.True(captureResponse.Value.Resources.Count > 0); string resource = captureResponse.Value.Resources[0].ToString(); Assert.IsTrue(resource.ToLowerInvariant().Contains(captureParams.DestinationContainerName.ToLowerInvariant())); Assert.IsTrue(resource.ToLowerInvariant().Contains(captureParams.VhdPrefix.ToLowerInvariant())); Resource template = JsonSerializer.Deserialize <Resource>(resource); string imageUri = template.Properties.StorageProfile.OSDisk.Image.Uri; Assert.False(string.IsNullOrEmpty(imageUri)); // Create 3rd VM from the captured image // TODO : Provisioning Time-out Issues VirtualMachine inputVM2; string as3Name = as1Name + "b"; returnTwovm = await CreateVM(rg1Name, as3Name, storageAccountOutput, imageRef, vm => { vm.StorageProfile.ImageReference = null; vm.StorageProfile.OsDisk.Image = new VirtualHardDisk { Uri = imageUri }; vm.StorageProfile.OsDisk.Vhd.Uri = vm.StorageProfile.OsDisk.Vhd.Uri.Replace(".vhd", "copy.vhd"); vm.StorageProfile.OsDisk.OsType = OperatingSystemTypes.Windows; }, false, false); var vm3 = returnTwovm.Item1; inputVM2 = returnTwovm.Item2; Assert.True(vm3.StorageProfile.OsDisk.Image.Uri == imageUri); }