public void CreateAndVerifyListOfWebHostingPlan()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var webSitesClient  = ResourceGroupHelper.GetWebSitesClient(handler);
                var resourcesClient = ResourceGroupHelper.GetResourcesClient(handler);

                string whpName1          = TestUtilities.GenerateName("csmwhp");
                string whpName2          = TestUtilities.GenerateName("csmwhp");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name       = whpName1,
                        Location   = location,
                        Properties = new WebHostingPlanProperties
                        {
                            Sku = SkuOptions.Shared
                        }
                    }
                });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name       = whpName2,
                        Location   = location,
                        Properties = new WebHostingPlanProperties
                        {
                            Sku             = SkuOptions.Basic,
                            NumberOfWorkers = 1,
                            WorkerSize      = WorkerSizeOptions.Small
                        }
                    }
                });

                var webHostingPlanResponse = webSitesClient.WebHostingPlans.List(resourceGroupName);

                var whp1 = webHostingPlanResponse.WebHostingPlans.First(f => f.Name == whpName1);
                var whp2 = webHostingPlanResponse.WebHostingPlans.First(f => f.Name == whpName2);
                Assert.Equal(whp1.Properties.Sku, SkuOptions.Shared);
                Assert.Equal(whp2.Properties.Sku, SkuOptions.Basic);
            }
        }
Esempio n. 2
0
        public void TestUpdateSourceControlUpdates()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var webSitesClient = ResourceGroupHelper.GetWebSitesClient(handler);

                webSitesClient.SourceControls.Update(GitHubSourceControl.Name, new SourceControlUpdateParameters()
                {
                    Properties = GitHubSourceControl.Properties
                });

                var sourceControlGetResponse = webSitesClient.SourceControls.Get("GitHub");

                AssertSourceControl(GitHubSourceControl, sourceControlGetResponse.SourceControl);

                var sourceControlListResponse = webSitesClient.SourceControls.List();

                Assert.True(sourceControlListResponse.SourceControls.Count >= 4, "Invalid source controls count at " + sourceControlListResponse.SourceControls.Count);
                var github = sourceControlListResponse.SourceControls.FirstOrDefault(s => s.Name == "GitHub");
                AssertSourceControl(GitHubSourceControl, github);

                var bitbucket = sourceControlListResponse.SourceControls.FirstOrDefault(s => s.Name == "Bitbucket");
                AssertSourceControl(BitbucketSourceControl, bitbucket);
            }
        }
        public void CreateAndDeleteWebSiteSlot()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string       webSiteName       = TestUtilities.GenerateName("csmws");
                string       resourceGroupName = TestUtilities.GenerateName("csmrg");
                string       whpName           = TestUtilities.GenerateName("csmwhp");
                var          serverFarmId      = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, whpName);
                const string slotName          = "staging";
                string       siteWithSlotName  = string.Format("{0}({1})", webSiteName, slotName);

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, whpName,
                                                                    new ServerFarmWithRichSku
                {
                    ServerFarmWithRichSkuName = whpName,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name     = "S1",
                        Tier     = "Standard",
                        Capacity = 1
                    }
                });

                webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, webSiteName, new Site
                {
                    SiteName     = webSiteName,
                    Location     = location,
                    ServerFarmId = serverFarmId
                });

                webSitesClient.Sites.CreateOrUpdateSiteSlot(resourceGroupName, webSiteName, slot: slotName, siteEnvelope:
                                                            new Site
                {
                    Location     = location,
                    ServerFarmId = serverFarmId
                });

                webSitesClient.Sites.DeleteSiteSlot(resourceGroupName, webSiteName, slotName, deleteAllSlots: true.ToString());

                var webSites = webSitesClient.Sites.GetSiteSlots(resourceGroupName, webSiteName);

                Assert.Equal(0, webSites.Value.Count);
            }
        }
        public void CreateAndVerifyGetOnAWebsiteSlot()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string       webSiteName       = TestUtilities.GenerateName("csmws");
                string       resourceGroupName = TestUtilities.GenerateName("csmrg");
                string       whpName           = TestUtilities.GenerateName("cswhp");
                var          serverFarmId      = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, whpName);
                const string slotName          = "staging";
                string       siteWithSlotName  = string.Format("{0}({1})", webSiteName, slotName);

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, whpName, new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = whpName,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name = "S1",
                        Tier = "Standard"
                    }
                });

                webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, webSiteName, new Site
                {
                    SiteName = webSiteName,
                    Location = location,
                    Tags     = new Dictionary <string, string> {
                        { "tag1", "value1" }, { "tag2", "" }
                    },
                    ServerFarmId = serverFarmId
                });

                webSitesClient.Sites.CreateOrUpdateSiteSlot(resourceGroupName, webSiteName, new Site()
                {
                    Location     = location,
                    ServerFarmId = serverFarmId
                }, slotName);

                // TODO: Replace with GetSite with slotName API once its CSM related issue is resolved.
                var webSiteSlotCollection = webSitesClient.Sites.GetSiteSlots(resourceGroupName, webSiteName);
                Assert.Equal(1, webSiteSlotCollection.Value.Count);
                Assert.Equal(siteWithSlotName, webSiteSlotCollection.Value[0].SiteName);
            }
        }
        public void CreateAndVerifyListOfSlots()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string       webSiteName       = TestUtilities.GenerateName("csmws");
                string       resourceGroupName = TestUtilities.GenerateName("csmrg");
                string       whpName           = TestUtilities.GenerateName("csmwhp");
                var          serverFarmId      = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, whpName);
                const string slotName          = "staging";
                string       siteWithSlotName  = string.Format("{0}({1})", webSiteName, slotName);

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.AppServicePlans.CreateOrUpdate(resourceGroupName, whpName, new AppServicePlan()
                {
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name     = "S1",
                        Tier     = "Standard",
                        Capacity = 1
                    }
                });

                webSitesClient.WebApps.CreateOrUpdate(resourceGroupName, webSiteName, new Site
                {
                    Location     = location,
                    ServerFarmId = serverFarmId
                });

                string siteSlotResourceName = webSiteName + "/" + slotName;
                webSitesClient.WebApps.CreateOrUpdateSlot(resourceGroupName, webSiteName, slot: slotName, siteEnvelope:
                                                          new Site
                {
                    Location     = location,
                    ServerFarmId = serverFarmId
                });

                var webSiteSlots = webSitesClient.WebApps.ListSlots(resourceGroupName, webSiteName);

                Assert.Equal(1, webSiteSlots.Count());
                Assert.Equal(siteSlotResourceName, webSiteSlots.ToList()[0].Name);
                Assert.Equal(serverFarmId, webSiteSlots.ToList()[0].ServerFarmId, StringComparer.OrdinalIgnoreCase);
            }
        }
        public void GetResourceHealthMetadata()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string farmName          = TestUtilities.GenerateName("csmsf");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                string locationName = "West US";
                string siteName     = TestUtilities.GenerateName("csmws");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = locationName
                });

                webSitesClient.AppServicePlans.CreateOrUpdate(resourceGroupName, farmName, new AppServicePlan
                {
                    Location = locationName,
                    Sku      = new SkuDescription
                    {
                        Name     = "S1",
                        Tier     = "Standard",
                        Capacity = 1
                    }
                });

                var serverfarmId = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, farmName);
                webSitesClient.WebApps.CreateOrUpdate(resourceGroupName, siteName, new Site
                {
                    Location     = locationName,
                    ServerFarmId = serverfarmId
                });

                var resourceHealthMetadataResponse = webSitesClient.ResourceHealthMetadata.GetBySite(resourceGroupName, siteName);

                if (resourceHealthMetadataResponse != null)
                {
                    Assert.Equal("default", resourceHealthMetadataResponse.Name);
                    Assert.Equal("Microsoft.Web/sites/resourceHealthMetadata", resourceHealthMetadataResponse.Type);
                }

                webSitesClient.WebApps.Delete(resourceGroupName, siteName, deleteMetrics: true);

                webSitesClient.AppServicePlans.Delete(resourceGroupName, farmName);

                var serverFarmResponse = webSitesClient.AppServicePlans.ListByResourceGroup(resourceGroupName);

                Assert.Empty(serverFarmResponse);
            }
        }
        public void GetAndSetAdminSiteWebHostingPlan()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string webSiteName        = TestUtilities.GenerateName("csmws");
                string webHostingPlanName = TestUtilities.GenerateName("csmsf");
                string resourceGroupName  = TestUtilities.GenerateName("csmrg");
                var    serverFarmId       = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName,
                                                                                webHostingPlanName);
                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                var serverFarm = webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, webHostingPlanName, new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = webHostingPlanName,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name     = "S1",
                        Capacity = 1,
                        Tier     = "Standard"
                    }
                });

                webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, webSiteName, new Site()
                {
                    SiteName = webSiteName,
                    Location = location,
                    Tags     = new Dictionary <string, string> {
                        { "tag1", "value1" }, { "tag2", "" }
                    },
                    ServerFarmId = serverFarmId
                });

                serverFarm.AdminSiteName = webSiteName;
                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, webHostingPlanName, serverFarm);

                var webHostingPlanResponse = webSitesClient.ServerFarms.GetServerFarm(resourceGroupName, webHostingPlanName);

                Assert.Equal(webHostingPlanName, webHostingPlanResponse.Name);
                Assert.Equal(1, webHostingPlanResponse.Sku.Capacity);
                Assert.Equal("S1", webHostingPlanResponse.Sku.Name);
                Assert.Equal("Standard", webHostingPlanResponse.Sku.Tier);
                Assert.Equal(webSiteName, webHostingPlanResponse.AdminSiteName);
            }
        }
        public static async Task Run([TimerTrigger("%CrawlerFrequency%")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"timercrawlerforvirtualmachinescaleset executed at: {DateTime.UtcNow}");
            var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription();

            if (resourceGroupList == null)
            {
                log.Info($"timercrawlerforvirtualmachinescaleset: no resource groups to crawl");
                return;
            }

            await GetScaleSetsForResourceGroupsAsync(resourceGroupList, log);
        }
        public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");
            var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription();

            if (resourceGroupList == null)
            {
                log.Info($"timercrawlerforvirtualmachinescaleset: no resource groups to crawl");
                return;
            }

            await GetScaleSetsForResourceGroupsAsync(resourceGroupList, log);
        }
Esempio n. 10
0
        public AutomationTestBase(MockContext context, string resourceGroup)
        {
            ResourceGroup = resourceGroup;
            var handler = new RecordedDelegatingHandler();

            AutomationClient = ResourceGroupHelper.GetAutomationClient(context, handler);
            var resourcesClient = ResourceGroupHelper.GetResourcesClient(context, handler);

            try
            {
                resourcesClient.ResourceGroups.CreateOrUpdate(ResourceGroup,
                                                              new ResourceGroup
                {
                    Location = Location
                });
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.Conflict)
                {
                    throw;
                }
            }

            try
            {
                AutomationClient.AutomationAccount.CreateOrUpdate(ResourceGroup, AutomationAccount,
                                                                  new AutomationAccountCreateOrUpdateParameters
                {
                    Name     = AutomationAccount,
                    Location = Location,
                    Sku      = new Sku {
                        Name = "Free", Family = "Test", Capacity = 1
                    }
                });
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.Conflict)
                {
                    throw;
                }
            }

            // Clean up the automation account, delete runbooks, schedules, variables, etc.
            CleanUpCredentials();
            CleanUpRunbooks();
            CleanUpSchedules();
            CleanUpVariables();
            CleanUpWebhooks();
        }
Esempio n. 11
0
        public void CreateAndVerifyListOfWebsites()
        {
            RunWebsiteTestScenario(
                (webSiteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) =>
            {
                var webSites = webSitesClient.WebApps.ListByResourceGroup(resourceGroupName, null);

                Assert.Equal(1, webSites.Count());
                Assert.Equal(webSiteName, webSites.ToList()[0].Name);
                var serverfarmId = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId,
                                                                       resourceGroupName, whpName);
                Assert.Equal(serverfarmId, webSites.ToList()[0].ServerFarmId, StringComparer.OrdinalIgnoreCase);
            });
        }
        public void CreateAndVerifyListOfWebHostingPlan()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string whpName1          = TestUtilities.GenerateName("csmwhp");
                string whpName2          = TestUtilities.GenerateName("csmwhp");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, whpName1, serverFarmEnvelope: new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = whpName1,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name = "D1",
                        Tier = "Shared"
                    }
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, whpName2, serverFarmEnvelope: new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = whpName2,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name     = "B1",
                        Capacity = 1,
                        Tier     = "Basic"
                    }
                });

                var webHostingPlanResponse = webSitesClient.ServerFarms.GetServerFarms(resourceGroupName);

                var whp1 = webHostingPlanResponse.Value.First(f => f.Name == whpName1);
                var whp2 = webHostingPlanResponse.Value.First(f => f.Name == whpName2);
                Assert.Equal(whp1.Sku.Tier, "Shared");
                Assert.Equal(whp2.Sku.Tier, "Basic");
            }
        }
Esempio n. 13
0
 public static async Task Run([TimerTrigger("%CrawlerFrequency%")] TimerInfo myTimer, TraceWriter log)
 {
     log.Info($"timercrawlerresourcegroups executed at: {DateTime.UtcNow}");
     try
     {
         var resourceGroups = ResourceGroupHelper.GetResourceGroupsInSubscription();
         //Todo make it as Sync
         await InsertOrReplaceResourceGroupsAsync(resourceGroups, log); //Can we make it as task.run ??
     }
     catch (Exception ex)
     {
         log.Error($"timercrawlerresourcegroups threw exception ", ex, "timercrawlerresourcegroups");
     }
 }
Esempio n. 14
0
        private void RunWebsiteTestScenario(WebsiteTestDelegate testAction, string skuTier = "Shared", string skuName = "D1",
                                            [System.Runtime.CompilerServices.CallerMemberName]
                                            string methodName = "testframework_failed")
        {
            using (var context = MockContext.Start(this.GetType().FullName, methodName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                var webSiteName        = TestUtilities.GenerateName("csmws");
                var resourceGroupName  = TestUtilities.GenerateName("csmrg");
                var webHostingPlanName = TestUtilities.GenerateName("csmwhp");
                var location           = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                var serverFarm = webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, webHostingPlanName,
                                                                                     new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = webHostingPlanName,
                    Location = location,
                    Sku      = new SkuDescription()
                    {
                        Name = skuName,
                        Tier = skuTier
                    }
                });

                var webSite = webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, webSiteName, new Site
                {
                    SiteName = webSiteName,
                    Location = location,
                    Tags     = new Dictionary <string, string> {
                        { "tag1", "value1" }, { "tag2", "" }
                    },
                    ServerFarmId = serverFarm.Id
                });

                Assert.Equal(webSiteName, webSite.Name);
                Assert.Equal(serverFarm.Id, webSite.ServerFarmId, StringComparer.OrdinalIgnoreCase);
                Assert.Equal("value1", webSite.Tags["tag1"]);
                Assert.Equal("", webSite.Tags["tag2"]);

                testAction(webSiteName, resourceGroupName, webHostingPlanName, location, webSitesClient, resourcesClient);
            }
        }
Esempio n. 15
0
        public static async Task Run([TimerTrigger("%CrawlerFrequency%")] TimerInfo myTimer, TraceWriter log)
        {
            //log.Info($"timercrawlerforavailabilitysets executed at: {DateTime.UtcNow}"); -- not required as it is already available in logs meta data
            var sw = Stopwatch.StartNew();//Recording
            var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription();

            if (resourceGroupList == null)
            {
                log.Info($"timercrawlerforavailabilitysets: no resource groups to crawler");
                return;
            }

            await InsertAvailabilitySets(resourceGroupList, log);

            log.Info($"timercrawlerforavailabilitysets function processed a request. time elapsed : {sw.ElapsedMilliseconds}");
        }
Esempio n. 16
0
        public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("%CrawlerFrequency%")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info("timercrawlerforloadbalancers function processed a request.");
            var sw = Stopwatch.StartNew();//Recording
            var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription(log);

            if (resourceGroupList == null)
            {
                log.Info($"timercrawlerforloadbalancers: no resource groups to crawler");
                return;
            }

            await GetLoadBalancersForResourceGroupsAsync(resourceGroupList, log);

            log.Info($"timercrawlerforloadbalancers function processed a request. time elapsed : {sw.ElapsedMilliseconds}");
        }
        public void CreateAndVerifyWebHostingPlan()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();
                var webSitesClient  = ResourceGroupHelper.GetWebSitesClient(handler);
                var resourcesClient = ResourceGroupHelper.GetResourcesClient(handler);

                string webHostingPlanName = TestUtilities.GenerateName("csmsf");
                string resourceGroupName  = TestUtilities.GenerateName("csmrg");

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name       = webHostingPlanName,
                        Location   = location,
                        Properties = new WebHostingPlanProperties
                        {
                            NumberOfWorkers = 1,
                            WorkerSize      = WorkerSizeOptions.Small,
                            Sku             = SkuOptions.Basic
                        }
                    }
                });

                var webHostingPlanResponse = webSitesClient.WebHostingPlans.Get(resourceGroupName, webHostingPlanName);

                Assert.Equal(webHostingPlanName, webHostingPlanResponse.WebHostingPlan.Name);
                Assert.Equal(1, webHostingPlanResponse.WebHostingPlan.Properties.NumberOfWorkers);
                Assert.Equal(WorkerSizeOptions.Small, webHostingPlanResponse.WebHostingPlan.Properties.WorkerSize);
                Assert.Equal(SkuOptions.Basic, webHostingPlanResponse.WebHostingPlan.Properties.Sku);
            }
        }
Esempio n. 18
0
        public void CreateAndVerifyGetOnAWebsite()
        {
            RunWebsiteTestScenario(
                (webSiteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) =>
            {
                var webSite = webSitesClient.WebApps.Get(resourceGroupName, webSiteName);

                Assert.Equal(webSiteName, webSite.Name);
                var serverfarmId = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId,
                                                                       resourceGroupName, whpName);
                Assert.Equal(serverfarmId, webSite.ServerFarmId, StringComparer.OrdinalIgnoreCase);
                Assert.Equal("value1", webSite.Tags["tag1"]);
                Assert.Equal("", webSite.Tags["tag2"]);
                Assert.NotNull(webSite.HostNameSslStates);
                Assert.NotEmpty(webSite.HostNameSslStates);
            });
        }
Esempio n. 19
0
        public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
                                     HttpRequestMessage req, TraceWriter log)
        {
            log.Info("timercrawlerforloadbalancers function processed a request.");
            var sw = Stopwatch.StartNew();//Recording
            var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription(log);

            if (resourceGroupList == null)
            {
                log.Info($"timercrawlerforloadbalancers: no resource groups to crawler");
                return;
            }

            await GetLoadBalancersForResourceGroupsAsync(resourceGroupList, log);

            log.Info($"timercrawlerforloadbalancers function processed a request. time elapsed : {sw.ElapsedMilliseconds}");
        }
        public void CloneSite()
        {
            RunWebsiteTestScenario(
                (webSiteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) =>
            {
                string targetSiteName             = TestUtilities.GenerateName("csmws");
                string location                   = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");
                WebSiteCloneParameters parameters = new WebSiteCloneParameters()
                {
                    WebSiteClone = new WebSiteCloneBase()
                    {
                        Location   = location,
                        Properties = new WebSiteCloneBaseProperties()
                        {
                            CloningInfo = new CloningInfo()
                            {
                                Source = new SourceWebSite()
                                {
                                    Location          = location,
                                    Name              = webSiteName,
                                    ResourceGroupName = resourceGroupName,
                                    SubscriptionId    = resourcesClient.Credentials.SubscriptionId
                                }
                            }
                        }
                    }
                };

                var operationResponse = webSitesClient.WebSites.Clone(resourceGroupName, targetSiteName, null,
                                                                      parameters);
                Assert.NotNull(operationResponse);
                Assert.NotNull(operationResponse.Location);

                Guid operationId = ParseOperationIdFromLocation(operationResponse.Location);

                WaitForOperationCompletion(360, 1000, "WebSites.GetOperation", () =>
                {
                    operationResponse = webSitesClient.WebSites.GetOperation(resourceGroupName, targetSiteName, null, operationId);
                    return(operationResponse.StatusCode);
                });
            }, SkuOptions.Standard);
        }
        public static async Task Run([TimerTrigger("%CrawlerFrequency%")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"timercrawlerforvirtualmachines executed at: {DateTime.UtcNow}");
            try
            {
                var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription();
                if (resourceGroupList == null)
                {
                    log.Info($"timercrawlerforvirtualmachines: no resource groups to crawl");
                    return;
                }

                await GetVirtualMachinesByResourceGroups(resourceGroupList, log);

                log.Info($"timercrawlerforvirtualmachines end  at: {DateTime.UtcNow}");
            }
            catch (Exception ex)
            {
                log.Error($"timercrawlerforvirtualmachines threw the exception ", ex, "timercrawlerforvirtualmachines");
            }
        }
Esempio n. 22
0
        public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
                                     HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");
            try
            {
                var resourceGroupList = ResourceGroupHelper.GetResourceGroupsInSubscription();
                if (resourceGroupList == null)
                {
                    log.Info($"timercrawlerforvirtualmachines: no resource groups to crawl");
                    return;
                }

                await GetVirtualMachinesByResourceGroups(resourceGroupList, log);
            }
            catch (Exception ex)
            {
                log.Error($"timercrawlerforvirtualmachines threw the exception ", ex, "timercrawlerforvirtualmachines");
            }

            log.Info($"timercrawlerforvirtualmachines end  at: {DateTime.UtcNow}");
        }
        public void CreateAndDeleteWebHostingPlan()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string whpName           = TestUtilities.GenerateName("csmsf");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.Sites.GetSites(resourceGroupName);

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, whpName, new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = whpName,
                    Location = location,
                    Sku      = new SkuDescription
                    {
                        Name     = "D1",
                        Capacity = 1,
                        Tier     = "Shared"
                    }
                });

                webSitesClient.ServerFarms.DeleteServerFarm(resourceGroupName, whpName);

                var webHostingPlanResponse = webSitesClient.ServerFarms.GetServerFarms(resourceGroupName);

                Assert.Equal(0, webHostingPlanResponse.Value.Count);
            }
        }
Esempio n. 24
0
        public void CloneSite()
        {
            RunWebsiteTestScenario(
                (webSiteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) =>
            {
                string targetSiteName = TestUtilities.GenerateName("csmws");
                string location       = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");
                var webAppIdFormat    = "/subscriptions/{0}/resourcegroups/{1}/providers/Microsoft.Web/sites/{2}";
                var site = new Site()
                {
                    Location    = "West US",
                    CloningInfo = new CloningInfo()
                    {
                        SourceWebAppId = string.Format(webAppIdFormat, webSitesClient.SubscriptionId, resourceGroupName, webSiteName)
                    }
                };

                ServiceClientTracing.IsEnabled = true;
                var operationResponse          = webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, targetSiteName, site);
                ServiceClientTracing.IsEnabled = false;
            }, "Premium", "P1");
        }
        public void CreateAndVerifyWebHostingPlan()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string webHostingPlanName = TestUtilities.GenerateName("csmsf");
                string resourceGroupName  = TestUtilities.GenerateName("csmrg");

                var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, webHostingPlanName, new ServerFarmWithRichSku()
                {
                    ServerFarmWithRichSkuName = webHostingPlanName,
                    Location = location,
                    Sku      = new SkuDescription()
                    {
                        Name     = "B1",
                        Tier     = "Basic",
                        Capacity = 1
                    }
                });

                var webHostingPlanResponse = webSitesClient.ServerFarms.GetServerFarm(resourceGroupName, webHostingPlanName);

                Assert.Equal(webHostingPlanName, webHostingPlanResponse.Name);
                Assert.Equal(1, webHostingPlanResponse.Sku.Capacity);
                Assert.Equal("B1", webHostingPlanResponse.Sku.Name);
                Assert.Equal("Basic", webHostingPlanResponse.Sku.Tier);
            }
        }
        public static async Task RunSample(DefaultAzureCredential credential)
        {
            string subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            string appConfigName  = Utilities.RandomResourceName("appcnfg", 20);
            string rgName         = Utilities.RandomResourceName("rgNEMV", 24);
            string region         = "eastus";

            var appConfigManagementClient = new AppConfigurationManagementClient(subscriptionId, credential);
            var configurationStores       = appConfigManagementClient.ConfigurationStores;

            await ResourceGroupHelper.CreateOrUpdateResourceGroup(rgName, region);

            // Create an App Configuration
            Utilities.Log("Creating an App Configuration...");

            var configurationStore = new ConfigurationStore(region, new Sku("free"));

            var rawResult = await configurationStores.StartCreateAsync(rgName, appConfigName, configurationStore);

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

            Utilities.Log("Created App Configuration");
            Utilities.PrintAppConfiguration(appConfiguration);
        }
Esempio n. 27
0
        public static async Task RunSample(DefaultAzureCredential credential)
        {
            string subscriptionId     = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            string storageAccountName = Utilities.RandomResourceName("strg", 20);
            string rgName             = Utilities.RandomResourceName("rgNEMV", 24);
            string region             = "eastus";

            var storageManagementClient = new StorageManagementClient(subscriptionId, credential);
            var storageAccounts         = storageManagementClient.StorageAccounts;

            await ResourceGroupHelper.CreateOrUpdateResourceGroup(rgName, region);

            // Create a storage account
            Utilities.Log("Creating a Storage Account...");

            var StorageAccountCreateParameters = new StorageAccountCreateParameters(new Sku(SkuName.StandardLRS), Kind.StorageV2, region);

            var rawResult = await storageAccounts.StartCreateAsync(rgName, storageAccountName, StorageAccountCreateParameters);

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

            Utilities.Log("Created Storage Account");
            Utilities.PrintStorageAccount(storageAccount);
        }
        public static async Task RunSample(DefaultAzureCredential credential)
        {
            String resourceGroupName = Utilities.RandomResourceName("rg-manage-comm-", 24);
            String resourceName      = Utilities.RandomResourceName("manage-comm-", 24);
            String region            = "westus";

            CommunicationManagementClient acsClient = CreateCommunicationManagementClient(credential);
            await ResourceGroupHelper.CreateOrUpdateResourceGroup(resourceGroupName, region);

            await CreateCommunicationServiceAsync(acsClient, resourceGroupName, resourceName);
            await GetCommunicationServiceAsync(acsClient, resourceGroupName, resourceName);
            await UpdateCommunicationServiceAsync(acsClient, resourceGroupName, resourceName);

            ListCommunicationServiceBySubscription(acsClient);
            ListCommunicationServiceByResourceGroup(acsClient, resourceGroupName);

            await ListKeysAsync(acsClient, resourceGroupName, resourceName);
            await RegenerateKeyAsync(acsClient, resourceGroupName, resourceName, KeyType.Primary);
            await RegenerateKeyAsync(acsClient, resourceGroupName, resourceName, KeyType.Secondary);

            await LinkNotificationHubAsync(acsClient, resourceGroupName, resourceName);

            await DeleteCommunicationServiceAsync(acsClient, resourceGroupName, resourceName);
        }
        public void ListRecommendationsRoundTrip()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string farmName          = TestUtilities.GenerateName("csmsf");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                string locationName = "West US";
                string siteName     = TestUtilities.GenerateName("csmws");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = locationName
                });

                webSitesClient.AppServicePlans.CreateOrUpdate(resourceGroupName, farmName, new AppServicePlan
                {
                    Location = locationName,
                    Sku      = new SkuDescription
                    {
                        Name     = "S1",
                        Tier     = "Standard",
                        Capacity = 1
                    }
                });

                var serverfarmId = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, farmName);
                webSitesClient.WebApps.CreateOrUpdate(resourceGroupName, siteName, new Site
                {
                    Location     = locationName,
                    ServerFarmId = serverfarmId
                });

                var recommendationResponse = webSitesClient.Recommendations.ListRecommendedRulesForWebApp(resourceGroupName, siteName);

                Assert.Equal("0", recommendationResponse.AsEnumerable().Count().ToString());
                Assert.Null(recommendationResponse.NextPageLink);

                var rec = recommendationResponse.FirstOrDefault();

                if (rec != null)
                {
                    Assert.Equal("PaidSiteSlots", rec.RuleName);
                    Assert.False(rec.IsDynamic);
                    Assert.True(rec.NextNotificationTime.HasValue);
                    Assert.True(rec.NotificationExpirationTime.HasValue);
                    Assert.True(rec.RecommendationId.HasValue);
                    Assert.Equal("WebSite", rec.ResourceScope);
                    Assert.Equal(1000, rec.Score);
                }

                webSitesClient.WebApps.Delete(resourceGroupName, siteName, deleteMetrics: true);

                webSitesClient.AppServicePlans.Delete(resourceGroupName, farmName);

                var serverFarmResponse = webSitesClient.AppServicePlans.ListByResourceGroup(resourceGroupName);

                Assert.Equal("0", serverFarmResponse.AsEnumerable().Count().ToString());
                Assert.Null(serverFarmResponse.NextPageLink);
            }
        }
Esempio n. 30
0
        public void ListBackupsAndScheduledBackupRoundTrip()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var webSitesClient  = this.GetWebSiteManagementClient(context);
                var resourcesClient = this.GetResourceManagementClient(context);

                string farmName          = TestUtilities.GenerateName("csmsf");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                string locationName = "West US";
                string siteName     = TestUtilities.GenerateName("csmws");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = locationName
                });

                webSitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, farmName, new ServerFarmWithRichSku
                {
                    ServerFarmWithRichSkuName = farmName,
                    Location = locationName,
                    Sku      = new SkuDescription
                    {
                        Name     = "F1",
                        Tier     = "Free",
                        Capacity = 1
                    }
                });

                var serverfarmId = ResourceGroupHelper.GetServerFarmId(webSitesClient.SubscriptionId, resourceGroupName, farmName);
                webSitesClient.Sites.CreateOrUpdateSite(resourceGroupName, siteName, new Site
                {
                    SiteName     = siteName,
                    Location     = locationName,
                    ServerFarmId = serverfarmId
                });

                var backupResponse = webSitesClient.Sites.ListSiteBackups(resourceGroupName, siteName);
                Assert.Equal(0, backupResponse.Value.Count); // , "Backup list should be empty"

                // the following URL just have a proper format, but it is not valid - for an API test it is not needed to be valid,
                // since we are just testing a roundtrip here
                // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
                string storageUrl = "https://nonexistingusername3567.blob.core.windows.net/backup/?sv=2012-02-12&st=2013-12-05T19%3A30%3A45Z&se=2017-12-04T19%3A30%3A45Z&sr=c&sp=rwdl&sig=3BY5sbzQ2NeKvdaelzxc8inxJgE1mGq2a%2BaqUeFGJYo%3D";

                var sr = new BackupRequest()
                {
                    Enabled        = false,
                    BackupSchedule = new BackupSchedule()
                    {
                        FrequencyInterval     = 17,
                        FrequencyUnit         = FrequencyUnit.Day,
                        KeepAtLeastOneBackup  = true,
                        RetentionPeriodInDays = 26,
                        StartTime             = DateTime.Now.AddDays(5)
                    },
                    BackupRequestName = "abc",
                    StorageAccountUrl = storageUrl
                };

                webSitesClient.Sites.UpdateSiteBackupConfiguration(resourceGroupName, siteName, sr);

                var backupConfiguration = webSitesClient.Sites.GetSiteBackupConfiguration(resourceGroupName, siteName);

                Assert.Equal(sr.Enabled, backupConfiguration.Enabled);
                Assert.Equal(sr.BackupSchedule.FrequencyInterval, backupConfiguration.BackupSchedule.FrequencyInterval);
                Assert.Equal(sr.BackupSchedule.FrequencyUnit, backupConfiguration.BackupSchedule.FrequencyUnit);
                Assert.Equal(sr.BackupSchedule.KeepAtLeastOneBackup, backupConfiguration.BackupSchedule.KeepAtLeastOneBackup);
                Assert.Equal(sr.Name, backupConfiguration.BackupRequestName);

                webSitesClient.Sites.DeleteSite(resourceGroupName, siteName, deleteAllSlots: true.ToString(), deleteMetrics: true.ToString());

                webSitesClient.ServerFarms.DeleteServerFarm(resourceGroupName, farmName);

                var serverFarmResponse = webSitesClient.ServerFarms.GetServerFarms(resourceGroupName);

                Assert.Equal(0, serverFarmResponse.Value.Count);
            }
        }