Пример #1
0
        public async Task Setup()
        {
            resourceGroupName = Guid.NewGuid().ToString();

            clientId       = ExternalVariables.Get(ExternalVariable.AzureSubscriptionClientId);
            clientSecret   = ExternalVariables.Get(ExternalVariable.AzureSubscriptionPassword);
            tenantId       = ExternalVariables.Get(ExternalVariable.AzureSubscriptionTenantId);
            subscriptionId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionId);

            var resourceGroupLocation = Environment.GetEnvironmentVariable("AZURE_NEW_RESOURCE_REGION") ?? "eastus";

            authToken = await GetAuthToken(tenantId, clientId, clientSecret);

            var resourcesClient = new ResourcesManagementClient(subscriptionId,
                                                                new ClientSecretCredential(tenantId, clientId, clientSecret));

            resourceGroupClient = resourcesClient.ResourceGroups;

            var resourceGroup = new ResourceGroup(resourceGroupLocation);

            resourceGroup = await resourceGroupClient.CreateOrUpdateAsync(resourceGroupName, resourceGroup);

            webMgmtClient = new WebSiteManagementClient(new TokenCredentials(authToken))
            {
                SubscriptionId = subscriptionId,
                HttpClient     = { BaseAddress = new Uri(DefaultVariables.ResourceManagementEndpoint) },
            };

            var svcPlan = await webMgmtClient.AppServicePlans.BeginCreateOrUpdateAsync(resourceGroup.Name,
                                                                                       resourceGroup.Name, new AppServicePlan(resourceGroup.Location)
            {
                Kind     = "linux",
                Reserved = true,
                Sku      = new SkuDescription
                {
                    Name = "S1",
                    Tier = "Standard"
                }
            });

            site = await webMgmtClient.WebApps.BeginCreateOrUpdateAsync(resourceGroup.Name, resourceGroup.Name,
                                                                        new Site(resourceGroup.Location)
            {
                ServerFarmId = svcPlan.Id,
                SiteConfig   = new SiteConfig
                {
                    LinuxFxVersion = @"DOCKER|mcr.microsoft.com/azuredocs/aci-helloworld",
                    AppSettings    = new List <NameValuePair>
                    {
                        new NameValuePair("DOCKER_REGISTRY_SERVER_URL", "https://index.docker.io"),
                        new NameValuePair("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false")
                    },
                    AlwaysOn = true
                }
            });

            webappName = site.Name;

            await AssertSetupSuccessAsync();
        }
Пример #2
0
        public async Task CreateLargeWebDeploymentTemplateWorks()
        {
            string resourceName   = Recording.GenerateAssetName("csmr");
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   = ("{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             );

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationSouthCentralUS));

            await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            // Wait until deployment completes
            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(30 * 1000);
            }
            var operations = await DeploymentOperations.ListAsync(groupName, deploymentName, null).ToEnumerableAsync();

            Assert.True(operations.Any());
        }
        public async Task CreatedAndDeleteResourceById()
        {
            string subscriptionId = "b9f138a1-1d64-4108-8413-9ea3be1c1b2d";
            string groupName      = Recording.GenerateAssetName("csmrg");
            string resourceName   = Recording.GenerateAssetName("csmr");

            string location = this.GetWebsiteLocation();

            string resourceId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Web/serverFarms/{2}", subscriptionId, groupName, resourceName);
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(location));

            var createOrUpdateResult = await ResourcesOperations.StartCreateOrUpdateByIdAsync(
                resourceId,
                WebResourceProviderVersion,
                new GenericResource
            {
                Location = location,
                Sku      = new Sku
                {
                    Name = "S1"
                },
                Properties = new Dictionary <string, object> {
                }
            }
                );

            var listResult = await ResourcesOperations.ListByResourceGroupAsync(groupName).ToEnumerableAsync();

            Assert.AreEqual(resourceName, listResult.First().Name);

            await ResourcesOperations.StartDeleteByIdAsync(
                resourceId, WebResourceProviderVersion);
        }
Пример #4
0
        protected async Task DiskEncryptionSet_CreateDisk_Execute(string methodName, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            var  desName  = "longlivedSwaggerDES";
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.Location = location;

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(location));

            // Get DiskEncryptionSet
            DiskEncryptionSet desOut = await DiskEncryptionSetsOperations.GetAsync("longrunningrg-southeastasia", desName);

            Assert.NotNull(desOut);
            disk.Encryption = new Encryption
            {
                Type = EncryptionType.EncryptionAtRestWithCustomerKey.ToString(),
                DiskEncryptionSetId = desOut.Id
            };
            //Put Disk
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(desOut.Id.ToLower(), diskOut.Encryption.DiskEncryptionSetId.ToLower());
            Assert.AreEqual(EncryptionType.EncryptionAtRestWithCustomerKey, diskOut.Encryption.Type);

            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
        private async Task <(ContainerService, ContainerService)> CreateContainerServiceAndGetOperationResponse(
            string rgName,
            string csName,
            string masterDnsPrefix,
            string agentPoolDnsPrefix,
            //out ContainerService inputContainerService,
            Action <ContainerService> containerServiceCustomizer = null)
        {
            var resourceGroup = await ResourceGroupsOperations.CreateOrUpdateAsync(
                rgName,
                new ResourceGroup(m_location));

            var inputContainerService = CreateDefaultContainerServiceInput(rgName, masterDnsPrefix, agentPoolDnsPrefix);

            if (containerServiceCustomizer != null)
            {
                containerServiceCustomizer(inputContainerService);
            }
            var createOrUpdateResponse = await WaitForCompletionAsync(await ContainerServicesOperations.StartCreateOrUpdateAsync(rgName, csName, inputContainerService));

            Assert.AreEqual(csName, createOrUpdateResponse.Value.Name);
            Assert.AreEqual(inputContainerService.Location.ToLower().Replace(" ", ""), createOrUpdateResponse.Value.Location.ToLower());
            Assert.AreEqual(ContainerServiceType, createOrUpdateResponse.Value.Type);

            ValidateContainerService(inputContainerService, createOrUpdateResponse.Value);

            return(createOrUpdateResponse, inputContainerService);

            ;
        }
Пример #6
0
        public async Task DnsListZonesInSubscription()
        {
            string zoneNameOne = "dns.zoneonename.io";
            string zoneNameTwo = "dns.zonetwoname.io";
            var    aZone       = new Zone("Global");
            await ZonesOperations.CreateOrUpdateAsync(resourceGroup, zoneNameOne, aZone);

            aZone = new Zone("Global");
            await ZonesOperations.CreateOrUpdateAsync(resourceGroup, zoneNameTwo, aZone);

            await Helper.TryRegisterResourceGroupAsync(ResourceGroupsOperations, this.location, this.resourceGroup + "-Two");

            var response     = ZonesOperations.ListAsync();
            var totalList    = response.ToEnumerableAsync().Result;
            var zoneOneFound = false;
            var zoneTwoFound = false;

            foreach (var zone in totalList)
            {
                if (zone.Name == zoneNameOne)
                {
                    zoneOneFound = true;
                }
                else if (zone.Name == zoneNameTwo)
                {
                    zoneTwoFound = true;
                }
            }
            Assert.IsTrue(zoneOneFound && zoneTwoFound);
            await(await ResourceGroupsOperations.GetAsync(this.resourceGroup + "-Two")).Value.DeleteAsync(WaitUntil.Completed);
            await this.WaitForCompletionAsync(await ZonesOperations.StartDeleteAsync(resourceGroup, zoneNameOne));
        }
        public async Task WhatIfAtSubscriptionScope_ModifyResources_ReturnsModifyChanges()
        {
            // Arrange.
            var deployment = new Deployment(
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template   = SubscriptionTemplate,
                Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\"")
            })
            {
                Location = "westus2"
            };

            var deploymentWhatIf = new DeploymentWhatIf(
                new DeploymentWhatIfProperties(DeploymentMode.Incremental)
            {
                Template       = SubscriptionTemplateWestEurope,
                Parameters     = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\""),
                WhatIfSettings = new DeploymentWhatIfSettings()
                {
                    ResultFormat = WhatIfResultFormat.FullResourcePayloads
                }
            }
                )
            {
                Location = "westus2"
            };

            var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync("SDK-test", ResourceGroup)).Value;
            var deploy        = await DeploymentsOperations.StartCreateOrUpdateAtSubscriptionScopeAsync(NewDeploymentName(), deployment);

            await WaitForCompletionAsync(deploy);

            // Act.
            var rawResult = await DeploymentsOperations.StartWhatIfAtSubscriptionScopeAsync(NewDeploymentName(), deploymentWhatIf);

            var result = (await WaitForCompletionAsync(rawResult)).Value;

            // Assert.
            Assert.AreEqual("Succeeded", result.Status);
            Assert.NotNull(result.Changes);
            Assert.IsNotEmpty(result.Changes);

            WhatIfChange policyChange = result.Changes.FirstOrDefault(change =>
                                                                      change.ResourceId.EndsWith("Microsoft.Authorization/policyDefinitions/policy2"));

            Assert.NotNull(policyChange);
            Assert.True(policyChange.ChangeType == ChangeType.Deploy ||
                        policyChange.ChangeType == ChangeType.Modify);
            Assert.NotNull(policyChange.Delta);
            Assert.IsNotEmpty(policyChange.Delta);

            WhatIfPropertyChange policyRuleChange = policyChange.Delta
                                                    .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.policyRule.if.equals"));

            Assert.NotNull(policyRuleChange);
            Assert.AreEqual(PropertyChangeType.Modify, policyRuleChange.PropertyChangeType);
            Assert.AreEqual("northeurope", policyRuleChange.Before);
            Assert.AreEqual("westeurope", policyRuleChange.After);
        }
Пример #8
0
        public async Task ValidateBadDeployment()
        {
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            var    parameters     = new Deployment
                                    (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(BadTemplateUri),
                Parameters   = @"{ 'siteName': {'value': 'mctest0101'},'hostingPlanName': {'value': 'mctest0101'},'siteMode': {'value': 'Limited'},'computeMode': {'value': 'Shared'},'siteLocation': {'value': 'North Europe'},'sku': {'value': 'Free'},'workerSize': {'value': '0'}}".Replace("'", "\"")
            }
                                    );

            // TODO
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            try
            {
                var rawResult = await DeploymentsOperations.StartValidateAsync(groupName, deploymentName, parameters);

                var result = (await WaitForCompletionAsync(rawResult)).Value;
                Assert.NotNull(result);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("InvalidTemplate"));
            }
        }
        public async Task CanCreateResourceGroup()
        {
            string groupName = Recording.GenerateAssetName("csmrg");
            var    result    = await ResourceGroupsOperations.CreateOrUpdateAsync(groupName,
                                                                                  new ResourceGroup(DefaultLocation)
            {
                Tags = { { "department", "finance" }, { "tagname", "tagvalue" } },
            });

            var listResult = await ResourceGroupsOperations.ListAsync().ToEnumerableAsync();

            var listedGroup = listResult.FirstOrDefault((g) => string.Equals(g.Name, groupName, StringComparison.Ordinal));

            Assert.NotNull(listedGroup);
            Assert.AreEqual("finance", listedGroup.Tags["department"]);
            Assert.AreEqual("tagvalue", listedGroup.Tags["tagname"]);
            Assert.True(Utilities.LocationsAreEqual(DefaultLocation, listedGroup.Location),
                        string.Format("Expected location '{0}' did not match actual location '{1}'", DefaultLocation, listedGroup.Location));
            var gottenGroup = (await ResourceGroupsOperations.GetAsync(groupName)).Value;

            Assert.NotNull(gottenGroup);
            Assert.AreEqual(groupName, gottenGroup.Name);
            Assert.True(Utilities.LocationsAreEqual(DefaultLocation, gottenGroup.Location),
                        string.Format("Expected location '{0}' did not match actual location '{1}'", DefaultLocation, gottenGroup.Location));
        }
        public async Task CheckConnectivityVmToInternetTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = "westus2";
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";

            //Deploy VM with a template
            await CreateVm(
                resourcesClient : ResourceManagementClient,
                resourceGroupName : resourceGroupName,
                location : location,
                virtualMachineName : virtualMachineName,
                storageAccountName : Recording.GenerateAssetName("azsmnet"),
                networkInterfaceName : networkInterfaceName,
                networkSecurityGroupName : networkSecurityGroupName,
                diagnosticsStorageAccountName : Recording.GenerateAssetName("azsmnet"),
                deploymentName : Recording.GenerateAssetName("azsmnet"),
                adminPassword : Recording.GenerateAlphaNumericId("AzureSDKNetworkTest#")
                );

            Response <VirtualMachine> getVm = await ComputeManagementClient.VirtualMachines.GetAsync(resourceGroupName, virtualMachineName);

            //Deploy networkWatcherAgent on VM
            VirtualMachineExtension parameters = new VirtualMachineExtension(location)
            {
                Publisher          = "Microsoft.Azure.NetworkWatcher",
                TypeHandlerVersion = "1.4",
                TypePropertiesType = "NetworkWatcherAgentWindows"
            };

            VirtualMachineExtensionsCreateOrUpdateOperation createOrUpdateOperation = await ComputeManagementClient.VirtualMachineExtensions.StartCreateOrUpdateAsync(resourceGroupName, getVm.Value.Name, "NetworkWatcherAgent", parameters);

            await WaitForCompletionAsync(createOrUpdateOperation);

            //TODO:There is no need to perform a separate create NetworkWatchers operation
            //Create network Watcher
            //string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            //NetworkWatcher properties = new NetworkWatcher { Location = location };
            //await NetworkManagementClient.NetworkWatchers.CreateOrUpdateAsync("NetworkWatcherRG", "NetworkWatcher_westus2", properties);

            ConnectivityParameters connectivityParameters =
                new ConnectivityParameters(new ConnectivitySource(getVm.Value.Id), new ConnectivityDestination {
                Address = "bing.com", Port = 80
            });

            Operation <ConnectivityInformation> connectivityCheckOperation = await NetworkManagementClient.NetworkWatchers.StartCheckConnectivityAsync("NetworkWatcherRG", "NetworkWatcher_westus2", connectivityParameters);

            Response <ConnectivityInformation> connectivityCheck = await WaitForCompletionAsync(connectivityCheckOperation);

            //Validation
            Assert.AreEqual("Reachable", connectivityCheck.Value.ConnectionStatus.ToString());
            Assert.AreEqual(0, connectivityCheck.Value.ProbesFailed);
            Assert.AreEqual("Source", connectivityCheck.Value.Hops.FirstOrDefault().Type);
            Assert.AreEqual("Internet", connectivityCheck.Value.Hops.LastOrDefault().Type);
        }
Пример #11
0
        public async Task ValidateGoodDeployment()
        {
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            string resourceName   = Recording.GenerateAssetName("csres");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   = (@"{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             );

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            //Action
            var rawValidationResult = await DeploymentsOperations.StartValidateAsync(groupName, deploymentName, parameters);

            var validationResult = (await WaitForCompletionAsync(rawValidationResult)).Value;

            //Assert
            Assert.Null(validationResult.Error);
            Assert.NotNull(validationResult.Properties);
            Assert.NotNull(validationResult.Properties.Providers);
            Assert.AreEqual(1, validationResult.Properties.Providers.Count);
            Assert.AreEqual("Microsoft.Web", validationResult.Properties.Providers[0].Namespace);
        }
        public async Task PublicIpAddressApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/publicIPAddresses");

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            // Create the parameter for PUT PublicIPAddress
            string publicIpName    = Recording.GenerateAssetName("ipname");
            string domainNameLabel = Recording.GenerateAssetName("domain");

            PublicIPAddress publicIp = new PublicIPAddress()
            {
                Location = location,
                Tags     = { { "key", "value" } },
                PublicIPAllocationMethod = IPAllocationMethod.Dynamic,
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                }
            };

            // Put PublicIPAddress
            PublicIPAddressesCreateOrUpdateOperation putPublicIpAddressResponseOperation = await NetworkManagementClient.PublicIPAddresses.StartCreateOrUpdateAsync(resourceGroupName, publicIpName, publicIp);

            Response <PublicIPAddress> putPublicIpAddressResponse = await WaitForCompletionAsync(putPublicIpAddressResponseOperation);

            Assert.AreEqual("Succeeded", putPublicIpAddressResponse.Value.ProvisioningState.ToString());

            // Get PublicIPAddress
            Response <PublicIPAddress> getPublicIpAddressResponse = await NetworkManagementClient.PublicIPAddresses.GetAsync(resourceGroupName, publicIpName);

            Assert.AreEqual(4, getPublicIpAddressResponse.Value.IdleTimeoutInMinutes);
            Assert.NotNull(getPublicIpAddressResponse.Value.ResourceGuid);

            // Get List of PublicIPAddress
            AsyncPageable <PublicIPAddress> getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName);
            List <PublicIPAddress>          getPublicIpAddressListResponse   = await getPublicIpAddressListResponseAP.ToEnumerableAsync();

            Has.One.EqualTo(getPublicIpAddressListResponse);
            ArePublicIpAddressesEqual(getPublicIpAddressResponse, getPublicIpAddressListResponse.First());

            // Get List of PublicIPAddress in a subscription
            AsyncPageable <PublicIPAddress> getPublicIpAddressListSubscriptionResponseAP = NetworkManagementClient.PublicIPAddresses.ListAllAsync();
            List <PublicIPAddress>          getPublicIpAddressListSubscriptionResponse   = await getPublicIpAddressListSubscriptionResponseAP.ToEnumerableAsync();

            Assert.IsNotEmpty(getPublicIpAddressListSubscriptionResponse);

            // Delete PublicIPAddress
            PublicIPAddressesDeleteOperation deleteOperation = await NetworkManagementClient.PublicIPAddresses.StartDeleteAsync(resourceGroupName, publicIpName);

            await WaitForCompletionAsync(deleteOperation);

            // Get PublicIPAddress
            getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName);
            getPublicIpAddressListResponse   = await getPublicIpAddressListResponseAP.ToEnumerableAsync();

            Assert.IsEmpty(getPublicIpAddressListResponse);
        }
        public async Task DiskEncryptionPositiveTest()
        {
            EnsureClientsInitialized(DefaultLocation);
            string testVaultId               = @"/subscriptions/" + TestEnvironment.SubscriptionId + "/resourceGroups/24/providers/Microsoft.KeyVault/vaults/swaggervault2";
            string encryptionKeyUri          = @"https://swaggervault2.vault.azure.net/keys/swaggerkey/6108e4eb47c14bdf863f1465229f8e66";
            string secretUri                 = @"https://swaggervault2.vault.azure.net/secrets/swaggersecret/c464e5083aab4f73968700e8b077c54d";
            string encryptionSettingsVersion = "1.0";

            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.EncryptionSettingsCollection = GetDiskEncryptionSettings(testVaultId, encryptionKeyUri, secretUri, encryptionSettingsVersion: encryptionSettingsVersion);
            disk.Location = DiskRPLocation;
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            //put disk
            await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk)));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(encryptionSettingsVersion, diskOut.EncryptionSettingsCollection.EncryptionSettingsVersion);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id);
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
        public async Task WhatIf_BlankTemplate_ReturnsNoChange()
        {
            // Arrange.
            var deploymentWhatIf = new DeploymentWhatIf(
                new DeploymentWhatIfProperties(DeploymentMode.Incremental)
            {
                Template       = BlankTemplate,
                WhatIfSettings = new DeploymentWhatIfSettings()
                {
                    ResultFormat = WhatIfResultFormat.FullResourcePayloads
                }
            }
                );

            string resourceGroupName = NewResourceGroupName();
            string deploymentName    = NewDeploymentName();

            var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, ResourceGroup)).Value;

            // Act.
            var rawResult = await DeploymentsOperations.StartWhatIfAsync(resourceGroupName, deploymentName, deploymentWhatIf);

            var result = (await WaitForCompletionAsync(rawResult)).Value;

            // Assert.
            Assert.AreEqual("Succeeded", result.Status);
            Assert.NotNull(result.Changes);
            Assert.IsEmpty(result.Changes);
        }
Пример #15
0
        public async Task CreateDeploymentWithStringTemplateAndParameters()
        {
            var templateString  = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "simple-storage-account.json"));
            var parameterString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "simple-storage-account-parameters.json"));

            JsonElement jsonParameter = JsonSerializer.Deserialize <JsonElement>(parameterString);

            if (!jsonParameter.TryGetProperty("parameters", out JsonElement parameter))
            {
                parameter = jsonParameter;
            }

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template       = templateString,
                ParametersJson = parameter
            }
                             );

            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            var rawResult = await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            await WaitForCompletionAsync(rawResult);

            var deployment = (await DeploymentsOperations.GetAsync(groupName, deploymentName)).Value;

            Assert.AreEqual("Succeeded", deployment.Properties.ProvisioningState);
        }
Пример #16
0
        public async Task CreateResourceWithPlan()
        {
            string groupName                 = Recording.GenerateAssetName("csmrg");
            string resourceName              = Recording.GenerateAssetName("csmr");
            string password                  = Recording.GenerateAssetName("p@ss");
            string mySqlLocation             = "centralus";
            string resourceProviderNamespace = "Sendgrid.Email";
            string resourceType              = "accounts";

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup("centralus"));

            var rawCreateOrUpdateResult = await ResourcesOperations.StartCreateOrUpdateAsync(
                groupName,
                resourceProviderNamespace,
                "",
                resourceType,
                resourceName,
                SendGridResourceProviderVersion,
                new GenericResource
            {
                Location = mySqlLocation,
                Plan     = new Plan {
                    Name = "free", Publisher = "Sendgrid", Product = "sendgrid_azure", PromotionCode = ""
                },
                Tags = new Dictionary <string, string> {
                    { "provision_source", "RMS" }
                },
                Properties = new Dictionary <string, object>
                {
                    {
                        "password", password
                    },
                    {
                        "acceptMarketingEmails", false
                    },
                    {
                        "email", "*****@*****.**"
                    }
                }
            }
                );

            var createOrUpdateResult = (await WaitForCompletionAsync(rawCreateOrUpdateResult)).Value;

            Assert.True(Utilities.LocationsAreEqual(mySqlLocation, createOrUpdateResult.Location),
                        string.Format("Resource location for resource '{0}' does not match expected location '{1}'", createOrUpdateResult.Location, mySqlLocation));
            Assert.NotNull(createOrUpdateResult.Plan);
            Assert.AreEqual("free", createOrUpdateResult.Plan.Name);

            var getResult = await ResourcesOperations.GetAsync(groupName, resourceProviderNamespace,
                                                               "", resourceType, resourceName, SendGridResourceProviderVersion);

            Assert.AreEqual(resourceName, getResult.Value.Name);
            Assert.True(Utilities.LocationsAreEqual(mySqlLocation, getResult.Value.Location),
                        string.Format("Resource location for resource '{0}' does not match expected location '{1}'", getResult.Value.Location, mySqlLocation));
            Assert.NotNull(getResult.Value.Plan);
            Assert.AreEqual("free", getResult.Value.Plan.Name);
        }
Пример #17
0
        protected async Task DiskEncryptionSet_List_Execute(string methodName, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var rgName1            = Recording.GenerateAssetName(TestPrefix);
            var rgName2            = Recording.GenerateAssetName(TestPrefix);
            var desName1           = Recording.GenerateAssetName(DiskNamePrefix);
            var desName2           = Recording.GenerateAssetName(DiskNamePrefix);
            DiskEncryptionSet des1 = GenerateDefaultDiskEncryptionSet(DiskRPLocation);
            DiskEncryptionSet des2 = GenerateDefaultDiskEncryptionSet(DiskRPLocation);

            // **********
            // SETUP
            // **********
            // Create resource groups
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName1, new ResourceGroup(DiskRPLocation));

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(DiskRPLocation));

            // Put 4 diskEncryptionSets, 2 in each resource group
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName1, desName1, des1));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName1, desName2, des2));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName2, desName1, des1));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName2, desName2, des2));

            // **********
            // TEST
            // **********
            // List diskEncryptionSets under resource group
            //IPage<DiskEncryptionSet> dessOut = await DiskEncryptionSetsClient.ListByResourceGroupAsync(rgName1).ToEnumerableAsync();
            var dessOut = await DiskEncryptionSetsOperations.ListByResourceGroupAsync(rgName1).ToEnumerableAsync();

            Assert.AreEqual(2, dessOut.Count());
            //Assert.Null(dessOut.NextPageLink);

            dessOut = await DiskEncryptionSetsOperations.ListByResourceGroupAsync(rgName2).ToEnumerableAsync();

            Assert.AreEqual(2, dessOut.Count());
            //Assert.Null(dessOut.NextPageLink);

            // List diskEncryptionSets under subscription
            dessOut = await DiskEncryptionSetsOperations.ListAsync().ToEnumerableAsync();

            Assert.True(dessOut.Count() >= 4);
            //if (dessOut.NextPageLink != null)
            //{
            //    dessOut = await DiskEncryptionSetsClient.ListNext(dessOut.NextPageLink);
            //    Assert.True(dessOut.Any());
            //}

            // Delete diskEncryptionSets
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName1, desName1));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName1, desName2));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName2, desName1));
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName2, desName2));
        }
        public async Task Gallery_CRUD_Tests()
        {
            EnsureClientsInitialized(LocationEastUs2);
            string rgName  = Recording.GenerateAssetName(ResourceGroupPrefix);
            string rgName2 = rgName + "New";

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(LocationEastUs2));

            Trace.TraceInformation("Created the resource group: " + rgName);

            string  galleryName = Recording.GenerateAssetName(GalleryNamePrefix);
            Gallery galleryIn   = GetTestInputGallery();

            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryIn));

            Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName, rgName));

            Gallery galleryOut = await GalleriesOperations.GetAsync(rgName, galleryName);

            Trace.TraceInformation("Got the gallery.");
            Assert.NotNull(galleryOut);
            ValidateGallery(galleryIn, galleryOut);

            galleryIn.Description = "This is an updated description";
            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryIn));

            Trace.TraceInformation("Updated the gallery.");
            galleryOut = await GalleriesOperations.GetAsync(rgName, galleryName);

            ValidateGallery(galleryIn, galleryOut);

            Trace.TraceInformation("Listing galleries.");
            string galleryName2 = galleryName + "New";
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(LocationEastUs2));

            Trace.TraceInformation("Created the resource group: " + rgName2);
            WaitSeconds(10);
            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName2, galleryName2, galleryIn));

            Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName2, rgName2));
            List <Gallery> listGalleriesInRgResult = await(GalleriesOperations.ListByResourceGroupAsync(rgName)).ToEnumerableAsync();

            Assert.True(listGalleriesInRgResult.Count() == 1);
            //Assert.Null(listGalleriesInRgResult.NextPageLink);
            List <Gallery> listGalleriesInSubIdResult = await(GalleriesOperations.ListAsync()).ToEnumerableAsync();

            // 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.");
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName));
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName2, galleryName2));

            listGalleriesInRgResult = await(GalleriesOperations.ListByResourceGroupAsync(rgName)).ToEnumerableAsync();
            Assert.IsEmpty(listGalleriesInRgResult);
            // resource groups cleanup is taken cared by MockContext.Dispose() method.
        }
Пример #19
0
        public async Task NextHopApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = "westus2";
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");

            //Deploy VM wih VNet,Subnet and Route Table from template
            await CreateVm(
                resourcesClient : ResourceManagementClient,
                resourceGroupName : resourceGroupName,
                location : location,
                virtualMachineName : virtualMachineName,
                storageAccountName : Recording.GenerateAssetName("azsmnet"),
                networkInterfaceName : networkInterfaceName,
                networkSecurityGroupName : networkSecurityGroupName,
                diagnosticsStorageAccountName : Recording.GenerateAssetName("azsmnet"),
                deploymentName : Recording.GenerateAssetName("azsmnet"),
                adminPassword : Recording.GenerateAlphaNumericId("AzureSDKNetworkTest#")
                );

            //TODO:There is no need to perform a separate create NetworkWatchers operation
            //Create Network Watcher
            //string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            //NetworkWatcher properties = new NetworkWatcher { Location = location };
            //await NetworkManagementClient.NetworkWatchers.CreateOrUpdateAsync(resourceGroupName, networkWatcherName, properties);

            string sourceIPAddress = NetworkManagementClient.NetworkInterfaces
                                     .GetAsync(resourceGroupName, networkInterfaceName).Result.Value.IpConfigurations
                                     .FirstOrDefault().PrivateIPAddress;

            Response <VirtualMachine> getVm = await ComputeManagementClient.VirtualMachines.GetAsync(resourceGroupName, virtualMachineName);

            //Use DestinationIPAddress from Route Table
            NextHopParameters nhProperties1 = new NextHopParameters(getVm.Value.Id, sourceIPAddress, "10.1.3.6");

            NextHopParameters nhProperties2 = new NextHopParameters(getVm.Value.Id, sourceIPAddress, "12.11.12.14");

            NetworkWatchersGetNextHopOperation getNextHop1Operation = await NetworkManagementClient.NetworkWatchers.StartGetNextHopAsync("NetworkWatcherRG", "NetworkWatcher_westus2", nhProperties1);

            Response <NextHopResult> getNextHop1 = await WaitForCompletionAsync(getNextHop1Operation);

            NetworkWatchersGetNextHopOperation getNextHop2Operation = await NetworkManagementClient.NetworkWatchers.StartGetNextHopAsync("NetworkWatcherRG", "NetworkWatcher_westus2", nhProperties2);

            Response <NextHopResult> getNextHop2 = await WaitForCompletionAsync(getNextHop2Operation);

            Response <RouteTable> routeTable = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, resourceGroupName + "RT");

            //Validation
            Assert.AreEqual("10.0.1.2", getNextHop1.Value.NextHopIpAddress);
            Assert.AreEqual(routeTable.Value.Id, getNextHop1.Value.RouteTableId);
            Assert.AreEqual("Internet", getNextHop2.Value.NextHopType.ToString());
            Assert.AreEqual("System Route", getNextHop2.Value.RouteTableId);
        }
Пример #20
0
        public async Task TopologyApiTest()
        {
            string resourceGroupName1 = Recording.GenerateAssetName("azsmnet");
            string resourceGroupName2 = Recording.GenerateAssetName("azsmnet");

            string location = "westus2";
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName1, new ResourceGroup(location));

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");

            //Deploy Vm from template
            await CreateVm(
                resourcesClient : ResourceManagementClient,
                resourceGroupName : resourceGroupName1,
                location : location,
                virtualMachineName : virtualMachineName,
                storageAccountName : Recording.GenerateAssetName("azsmnet"),
                networkInterfaceName : networkInterfaceName,
                networkSecurityGroupName : networkSecurityGroupName,
                diagnosticsStorageAccountName : Recording.GenerateAssetName("azsmnet"),
                deploymentName : Recording.GenerateAssetName("azsmnet"),
                adminPassword : Recording.GenerateAlphaNumericId("AzureSDKNetworkTest#")
                );

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName2, new ResourceGroup(location));

            //TODO:There is no need to perform a separate create NetworkWatchers operation
            //Create NetworkWatcher
            //string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            //NetworkWatcher properties = new NetworkWatcher { Location = location };
            //await NetworkManagementClient.NetworkWatchers.CreateOrUpdateAsync(resourceGroupName2, networkWatcherName, properties);

            TopologyParameters tpProperties = new TopologyParameters()
            {
                TargetResourceGroupName = resourceGroupName1
            };

            Response <VirtualMachine> getVm = await ComputeManagementClient.VirtualMachines.GetAsync(resourceGroupName1, virtualMachineName);

            //Get the current network topology of the resourceGroupName1
            Response <Topology> getTopology = await NetworkManagementClient.NetworkWatchers.GetTopologyAsync("NetworkWatcherRG", "NetworkWatcher_westus2", tpProperties);

            //Getting infromation about VM from topology
            TopologyResource vmResource = getTopology.Value.Resources[0];

            //Verify that topology contain right number of resources (9 resources from template)
            Assert.AreEqual(9, getTopology.Value.Resources.Count);

            //Verify that topology contain information about acreated VM
            Assert.AreEqual(virtualMachineName, vmResource.Name);
            Assert.AreEqual(getVm.Value.Id, vmResource.Id);
            Assert.AreEqual(networkInterfaceName, vmResource.Associations.FirstOrDefault().Name);
            Assert.AreEqual(getVm.Value.NetworkProfile.NetworkInterfaces.FirstOrDefault().Id, vmResource.Associations.FirstOrDefault().ResourceId);
            Assert.AreEqual("Contains", vmResource.Associations.FirstOrDefault().AssociationType.ToString());
        }
Пример #21
0
        protected async Task Disk_List_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var  rgName1   = Recording.GenerateAssetName(TestPrefix);
            var  rgName2   = Recording.GenerateAssetName(TestPrefix);
            var  diskName1 = Recording.GenerateAssetName(DiskNamePrefix);
            var  diskName2 = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk1     = await GenerateDefaultDisk(diskCreateOption, rgName1, diskSizeGB, location : location);

            Disk disk2 = await GenerateDefaultDisk(diskCreateOption, rgName2, diskSizeGB, location : location);

            // **********
            // SETUP
            // **********
            // Create resource groups, unless create option is import in which case resource group will be created with vm
            if (diskCreateOption != DiskCreateOption.Import)
            {
                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName1, new ResourceGroup(DiskRPLocation));

                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(DiskRPLocation));
            }

            // Put 4 disks, 2 in each resource group
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName1, disk1));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName2, disk2));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName1, disk1));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName2, disk2));

            // **********
            // TEST
            // **********
            // List disks under resource group
            var disksOut = await DisksOperations.ListByResourceGroupAsync(rgName1).ToEnumerableAsync();

            //Page<Disk> disksOut = (await DisksClient.ListByResourceGroupAsync(rgName1)).ToEnumerableAsync;
            Assert.AreEqual(2, disksOut.Count());
            //Assert.Null(disksOut.NextPageLink);

            disksOut = await DisksOperations.ListByResourceGroupAsync(rgName2).ToEnumerableAsync();

            Assert.AreEqual(2, disksOut.Count());
            //Assert.Null(disksOut.NextPageLink);

            // List disks under subscription
            disksOut = await DisksOperations.ListAsync().ToEnumerableAsync();

            Assert.True(disksOut.Count() >= 4);
            //if (disksOut.NextPageLink != null)
            //{
            //    disksOut = await DisksClient.ListNext(disksOut.NextPageLink);
            //    Assert.True(disksOut.Any());
            //}
        }
        public static async Task <string> CreateResourceGroup(ResourceGroupsOperations resourceGroupsOperations, TestRecording recording)
        {
            string name = recording.GenerateAssetName("res");

            if (!IsTestTenant)
            {
                await resourceGroupsOperations.CreateOrUpdateAsync(name, new ResourceGroup(DefaultRGLocation));
            }
            return(name);
        }
        public async Task VmssNetworkInterfaceApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Compute/virtualMachineScaleSets");

            string deploymentName = Recording.GenerateAssetName("vmss");
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            await CreateVmss(ResourceManagementClient, resourceGroupName, deploymentName);

            string virtualMachineScaleSetName = "vmssip";
            AsyncPageable <PublicIPAddress> vmssListAllPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddressesAsync(resourceGroupName, virtualMachineScaleSetName);
            List <PublicIPAddress>          vmssListAllPageResult   = await vmssListAllPageResultAP.ToEnumerableAsync();

            List <PublicIPAddress> vmssListAllResult = vmssListAllPageResult.ToList();
            PublicIPAddress        firstResult       = vmssListAllResult.First();

            Assert.NotNull(vmssListAllResult);
            Assert.AreEqual("Succeeded", firstResult.ProvisioningState.ToString());
            Assert.NotNull(firstResult.ResourceGuid);

            string idItem  = firstResult.Id;
            string vmIndex = GetNameById(idItem, "virtualMachines");
            string nicName = GetNameById(idItem, "networkInterfaces");

            // Verify that NICs contain refernce to publicip, nsg and dns settings
            AsyncPageable <NetworkInterface> listNicPerVmssAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName);
            List <NetworkInterface>          listNicPerVmss   = await listNicPerVmssAP.ToEnumerableAsync();

            Assert.NotNull(listNicPerVmss);

            foreach (NetworkInterface nic in listNicPerVmss)
            {
                VerifyVmssNicProperties(nic);
            }

            // Verify nics on a vm level
            AsyncPageable <NetworkInterface> listNicPerVmAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetVMNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex);
            List <NetworkInterface>          listNicPerVm   = await listNicPerVmAP.ToEnumerableAsync();

            Assert.NotNull(listNicPerVm);
            Has.One.EqualTo(listNicPerVm);

            foreach (NetworkInterface nic in listNicPerVm)
            {
                VerifyVmssNicProperties(nic);
            }

            // Verify getting individual nic
            Response <NetworkInterface> getNic = await NetworkManagementClient.NetworkInterfaces.GetVirtualMachineScaleSetNetworkInterfaceAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName);

            Assert.NotNull(getNic);
            VerifyVmssNicProperties(getNic);
        }
        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);
        }
        public async Task GalleryImage_CRUD_Tests()
        {
            EnsureClientsInitialized(LocationEastUs2);
            string rgName = Recording.GenerateAssetName(ResourceGroupPrefix);

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(LocationEastUs2));

            Trace.TraceInformation("Created the resource group: " + rgName);
            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));

            GalleryImage galleryImageFromGet = await GalleryImagesOperations.GetAsync(rgName, galleryName, galleryImageName);

            Assert.NotNull(galleryImageFromGet);
            ValidateGalleryImage(inputGalleryImage, galleryImageFromGet);

            inputGalleryImage.Description = "Updated description.";
            await WaitForCompletionAsync(await GalleryImagesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, inputGalleryImage));

            Trace.TraceInformation(string.Format("Updated the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));
            galleryImageFromGet = await GalleryImagesOperations.GetAsync(rgName, galleryName, galleryImageName);

            Assert.NotNull(galleryImageFromGet);
            ValidateGalleryImage(inputGalleryImage, galleryImageFromGet);

            List <GalleryImage> listGalleryImagesResult = await(GalleryImagesOperations.ListByGalleryAsync(rgName, galleryName)).ToEnumerableAsync();

            Assert.IsTrue(listGalleryImagesResult.Count() == 1);
            //Assert.Single(listGalleryImagesResult);
            //Assert.Null(listGalleryImagesResult.NextPageLink);

            await WaitForCompletionAsync(await GalleryImagesOperations.StartDeleteAsync(rgName, galleryName, galleryImageName));

            listGalleryImagesResult = await(GalleryImagesOperations.ListByGalleryAsync(rgName, galleryName)).ToEnumerableAsync();
            Assert.IsEmpty(listGalleryImagesResult);
            Trace.TraceInformation(string.Format("Deleted the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));
            WaitSeconds(30);
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName));
        }
        private async void Initialize()
        {
            m_baseResourceGroupName = Recording.GenerateAssetName(TestPrefix);
            m_resourceGroup1Name    = m_baseResourceGroupName + "_1";

            m_resourceGroup1 = await ResourceGroupsOperations.CreateOrUpdateAsync(
                m_resourceGroup1Name,
                new ResourceGroup(m_location)
            {
                Tags = { { m_resourceGroup1Name, Recording.UtcNow.ToString("u") } }
            });
        }
Пример #27
0
        protected async Task DiskEncryptionSet_CRUD_Execute(string methodName, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var rgName            = Recording.GenerateAssetName(TestPrefix);
            var desName           = Recording.GenerateAssetName(DiskNamePrefix);
            DiskEncryptionSet des = GenerateDefaultDiskEncryptionSet(DiskRPLocation);
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            // Put DiskEncryptionSet
            DiskEncryptionSet desOut = await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartCreateOrUpdateAsync(rgName, desName, des));

            Validate(des, desOut, desName);

            // Get DiskEncryptionSet
            desOut = await DiskEncryptionSetsOperations.GetAsync(rgName, desName);

            Validate(des, desOut, desName);

            // Patch DiskEncryptionSet
            const string tagKey    = "tageKey";
            var          updateDes = new DiskEncryptionSetUpdate();

            updateDes.Tags = new Dictionary <string, string>()
            {
                { tagKey, "tagvalue" }
            };
            desOut = await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartUpdateAsync(rgName, desName, updateDes));

            Validate(des, desOut, desName);
            Assert.AreEqual(1, desOut.Tags.Count);

            // Delete DiskEncryptionSet
            await WaitForCompletionAsync(await DiskEncryptionSetsOperations.StartDeleteAsync(rgName, desName));

            try
            {
                // Ensure it was really deleted
                await DiskEncryptionSetsOperations.GetAsync(rgName, desName);

                Assert.False(true);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
                //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }
Пример #28
0
        public async Task DeploymentWithScope_AtSubscription()
        {
            string groupName      = "SDK-test";
            string deploymentName = Recording.GenerateAssetName("csmd");
            var    templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "subscription_level_template.json"));

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template   = templateString,
                Parameters = "{'storageAccountName': {'value': 'armbuilddemo1803'}}".Replace("'", "\"")
            }
                             )
            {
                Location = "WestUS",
                Tags     = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" }
                }
            };

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup("WestUS"));

            var subscriptionScope = $"//subscriptions/{TestEnvironment.SubscriptionId}";

            //Validate
            var rawValidationResult = await DeploymentsOperations.StartValidateAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName, parameters : parameters);

            var validationResult = (await WaitForCompletionAsync(rawValidationResult)).Value;

            //Assert
            Assert.Null(validationResult.Error);
            Assert.NotNull(validationResult.Properties);
            Assert.NotNull(validationResult.Properties.Providers);

            //Put deployment
            var deploymentResult = await DeploymentsOperations.StartCreateOrUpdateAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName, parameters : parameters);

            await WaitForCompletionAsync(deploymentResult);

            var deployment = (await DeploymentsOperations.GetAtScopeAsync(scope: subscriptionScope, deploymentName: deploymentName)).Value;

            Assert.AreEqual("Succeeded", deployment.Properties.ProvisioningState);
            Assert.NotNull(deployment.Tags);
            Assert.True(deployment.Tags.ContainsKey("tagKey1"));

            var deploymentOperations = await DeploymentOperations.ListAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName).ToEnumerableAsync();

            Assert.AreEqual(4, deploymentOperations.Count());
        }
Пример #29
0
        public async Task CreateDeploymentAndValidateProperties()
        {
            string resourceName = Recording.GenerateAssetName("csmr");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   =
                    (@"{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             )
            {
                Tags = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" }
                }
            };
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            var rawResult = await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            var deploymentCreateResult = (await WaitForCompletionAsync(rawResult)).Value;

            Assert.NotNull(deploymentCreateResult.Id);
            Assert.AreEqual(deploymentName, deploymentCreateResult.Name);

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(1 * 1000);
            }

            var deploymentListResult = await DeploymentsOperations.ListByResourceGroupAsync(groupName, null).ToEnumerableAsync();

            var deploymentGetResult = (await DeploymentsOperations.GetAsync(groupName, deploymentName)).Value;

            Assert.IsNotEmpty(deploymentListResult);
            Assert.AreEqual(deploymentName, deploymentGetResult.Name);
            Assert.AreEqual(deploymentName, deploymentListResult.First().Name);
            Assert.AreEqual(GoodWebsiteTemplateUri, deploymentGetResult.Properties.TemplateLink.Uri);
            Assert.AreEqual(GoodWebsiteTemplateUri, deploymentListResult.First().Properties.TemplateLink.Uri);
            Assert.NotNull(deploymentGetResult.Properties.ProvisioningState);
            Assert.NotNull(deploymentListResult.First().Properties.ProvisioningState);
            Assert.NotNull(deploymentGetResult.Properties.CorrelationId);
            Assert.NotNull(deploymentListResult.First().Properties.CorrelationId);
            Assert.NotNull(deploymentListResult.First().Tags);
            Assert.True(deploymentListResult.First().Tags.ContainsKey("tagKey1"));
        }
        public async Task CheckExistenceReturnsCorrectValue()
        {
            string groupName = Recording.GenerateAssetName("csmrg");;

            var checkExistenceFirst = await ResourceGroupsOperations.CheckExistenceAsync(groupName);

            Assert.AreEqual(404, checkExistenceFirst.Status);

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(DefaultLocation));

            var checkExistenceSecond = await ResourceGroupsOperations.CheckExistenceAsync(groupName);

            Assert.AreEqual(204, checkExistenceSecond.Status);
        }