protected override bool CheckExistence() { if (Parameters.Properties.ResourceGroupExists) { using (var client = new TrafficManagerManagementClient(GetCredentials())) { var listResult = client.Profiles.ListAllAsync().Result; return listResult.Profiles.Any(database => database.Name.Equals(Parameters.Tenant.SiteName)); } } return false; }
public static Endpoint CreateOrUpdateDefaultEndpoint( TrafficManagerManagementClient trafficManagerClient, string resourceGroupName, string profileName, string target = "foobar.contoso.com") { string endpointName = "My external endpoint"; return(trafficManagerClient.Endpoints.CreateOrUpdate( resourceGroupName, profileName, "ExternalEndpoints", endpointName, GenerateDefaultEndpoint(endpointName, target))); }
public static Profile CreateOrUpdateProfileWithCustomHeadersAndStatusCodeRanges( TrafficManagerManagementClient trafficManagerClient, string resourceGroupName, string profileName) { Profile expectedProfile = GenerateDefaultEmptyProfile(profileName); expectedProfile.MonitorConfig.CustomHeaders = new List <MonitorConfigCustomHeadersItem> { new MonitorConfigCustomHeadersItem("host", "www.contoso.com"), new MonitorConfigCustomHeadersItem("custom-name", "custom-value") }; expectedProfile.MonitorConfig.ExpectedStatusCodeRanges = new List <MonitorConfigExpectedStatusCodeRangesItem> { new MonitorConfigExpectedStatusCodeRangesItem(200, 499) }; trafficManagerClient.Profiles.CreateOrUpdate( resourceGroupName, profileName, expectedProfile); expectedProfile.Endpoints = new List <Endpoint>(); for (int ndx = 0; ndx < 3; ndx++) { Endpoint endpoint = TrafficManagerHelper.GenerateDefaultEndpoint( $"My external endpoint {ndx}", $"foobar.Contoso{ndx}.com"); endpoint.CustomHeaders = new List <EndpointPropertiesCustomHeadersItem> { new EndpointPropertiesCustomHeadersItem("custom-name", "custom-value-overriden") }; trafficManagerClient.Endpoints.CreateOrUpdate( resourceGroupName, profileName, "ExternalEndpoints", endpoint.Name, endpoint); expectedProfile.Endpoints.Add(endpoint); } return(expectedProfile); }
public EndpointScenarioTests() { // Cleanup using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll(); foreach (Profile profile in listResponse.Profiles) { string resourceGroup = TrafficManagerHelper.ExtractResourceGroupFromId(profile.Id); trafficManagerClient.Profiles.Delete(resourceGroup, profile.Name); } } }
protected override bool CreateOrUpdate() { var created = true; try { using (var client = new TrafficManagerManagementClient(GetCredentials())) { // Skip if exists if (!CheckExistence()) { var createResult = client.Profiles.CreateOrUpdateAsync( Parameters.Tenant.SiteName, Parameters.Tenant.SiteName, new ProfileCreateOrUpdateParameters() { Profile = new Profile() { Location = "Global", Properties = new ProfileProperties() { DnsConfig = new DnsConfig() { RelativeName = Parameters.Tenant.SiteName, Fqdn = string.Format("{0}.trafficmanager.net", Parameters.Tenant.SiteName), Ttl = 30 }, MonitorConfig = new MonitorConfig("Http", 80, "/"), TrafficRoutingMethod = "Priority", Endpoints = Parameters.Properties.EndPoints } } }).Result; } } } catch (Exception ex) { created = false; Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return created; }
protected override bool CreateOrUpdate() { var created = true; try { using (var client = new TrafficManagerManagementClient(GetCredentials())) { // Skip if exists if (!CheckExistence()) { var createResult = client.Profiles.CreateOrUpdateAsync( Parameters.Tenant.SiteName, Parameters.Tenant.SiteName, new ProfileCreateOrUpdateParameters() { Profile = new Profile() { Location = "Global", Properties = new ProfileProperties() { DnsConfig = new DnsConfig() { RelativeName = Parameters.Tenant.SiteName, Fqdn = string.Format("{0}.trafficmanager.net", Parameters.Tenant.SiteName), Ttl = 30 }, MonitorConfig = new MonitorConfig("Http", 80, "/"), TrafficRoutingMethod = "Priority", Endpoints = Parameters.Properties.EndPoints } } }).Result; } } } catch (Exception ex) { created = false; Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return(created); }
public void CrudProfileWithoutEndpoints_ThenUpdate() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context); string resourceGroupName = TestUtilities.GenerateName("resourcegroup"); string profileName = TestUtilities.GenerateName("atmprofile"); ResourceGroup resourceGroup = this.CreateResourceGroup(context, resourceGroupName); Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName); profile.Endpoints = null; // Create the profile trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup.Name, profileName, profile); profile.Endpoints = new[] { new Endpoint { Id = null, Name = "My external endpoint", Type = "Microsoft.network/TrafficManagerProfiles/ExternalEndpoints", TargetResourceId = null, Target = "foobar.contoso.com", EndpointLocation = "North Europe", EndpointStatus = "Enabled" } }; // Create the profile trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup.Name, profileName, profile); this.DeleteResourceGroup(context, resourceGroupName); } }
public void ListAllProfiles() { using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); // This tests the list operation at subscription level therefore // we can't use any granularity (e.g. resource groups) to isolate test runs int numberOfProfilesBeforeTest = trafficManagerClient.Profiles.ListAll().Profiles.Count; ResourceGroupExtended resourceGroup1 = TrafficManagerHelper.CreateResourceGroup(); ResourceGroupExtended resourceGroup2 = TrafficManagerHelper.CreateResourceGroup(); // Create 2 resource groups with two profiles each for (int i = 0; i < 2; ++i) { string profileName = TestUtilities.GenerateName("hydratestwatmv2profile"); trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup1.Name, profileName, new ProfileCreateOrUpdateParameters { Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName) }); trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup2.Name, profileName, new ProfileCreateOrUpdateParameters { Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName) }); } ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll(); // At the end of the test we should have 4 profiles more than when we started Assert.Equal(numberOfProfilesBeforeTest + 4, listResponse.Profiles.Count); } }
public void NameAvailabilityTest_NameAvailable() { using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); string relativeName = TestUtilities.GenerateName("hydratestrelativename"); var parameters = new CheckTrafficManagerRelativeDnsNameAvailabilityParameters { Name = relativeName, Type = "microsoft.network/trafficmanagerprofiles" }; CheckTrafficManagerRelativeDnsNameAvailabilityResponse response = trafficManagerClient.Profiles.CheckTrafficManagerRelativeDnsNameAvailability(parameters); Assert.True(response.NameAvailable); } }
public static Profile CreateOrUpdateProfileWithMultiValue( TrafficManagerManagementClient trafficManagerClient, string resourceGroupName, string profileName, long?maxReturn = 2, long?minChildEndpointsSeed = null, long?minChildEndpointsIPv4Seed = null, long?minChildEndpointsIPv6Seed = null) { Profile expectedProfile = CreateOrUpdateDefaultEmptyProfile(trafficManagerClient, resourceGroupName, profileName, "MultiValue", "Disabled", maxReturn); expectedProfile.Endpoints = new List <Endpoint>(); for (int ndx = 0; ndx < 5; ndx++) { Endpoint endpoint = TrafficManagerHelper.GenerateDefaultEndpoint( $"My external endpoint {ndx}", $"1.2.3.{ndx}"); endpoint.MinChildEndpoints = minChildEndpointsSeed.HasValue ? minChildEndpointsSeed + ndx : null; endpoint.MinChildEndpointsIPv4 = minChildEndpointsIPv4Seed.HasValue ? minChildEndpointsIPv4Seed + ndx : null; endpoint.MinChildEndpointsIPv6 = minChildEndpointsIPv6Seed.HasValue ? minChildEndpointsIPv6Seed + ndx : null; EndpointPropertiesSubnetsItem range = new EndpointPropertiesSubnetsItem($"1.2.{ndx}.0", $"1.2.{ndx}.250"); EndpointPropertiesSubnetsItem subnet = new EndpointPropertiesSubnetsItem($"3.4.{ndx}.0", null, 24); endpoint.Subnets = new List <EndpointPropertiesSubnetsItem> { range, subnet }; trafficManagerClient.Endpoints.CreateOrUpdate( resourceGroupName, profileName, "ExternalEndpoints", endpoint.Name, endpoint); expectedProfile.Endpoints.Add(endpoint); } return(expectedProfile); }
public ProfileScenarioTests() { // Cleanup using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); try { ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll(); foreach (Profile profile in listResponse.Profiles) { string resourceGroup = TrafficManagerHelper.ExtractResourceGroupFromId(profile.Id); trafficManagerClient.Profiles.Delete(resourceGroup, profile.Name); } } catch (Exception) { // TODO: (alguerra) Remove after we fix bug on list operation } } }
public void CrudProfileWithCustomSubnets() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context); string resourceGroupName = TrafficManagerHelper.GenerateName(); string profileName = TrafficManagerHelper.GenerateName(); ResourceGroup resourceGroup = this.CreateResourceGroup(context, resourceGroupName); // Create the profile var expectedProfile = TrafficManagerHelper.CreateOrUpdateProfileWithSubnets( trafficManagerClient, resourceGroupName, profileName); // Get the profile var actualProfile = trafficManagerClient.Profiles.Get( resourceGroup.Name, profileName); for (var i = 0; i < expectedProfile.Endpoints.Count; ++i) { Assert.Equal(2, expectedProfile.Endpoints[i].Subnets.Count); Assert.Equal($"1.2.{i}.0", expectedProfile.Endpoints[i].Subnets[0].First); Assert.Equal($"1.2.{i}.250", expectedProfile.Endpoints[i].Subnets[0].Last); Assert.Equal($"3.4.{i}.0", expectedProfile.Endpoints[i].Subnets[1].First); Assert.Equal(24, expectedProfile.Endpoints[i].Subnets[1].Scope); } // Delete the profile trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName); this.DeleteResourceGroup(context, resourceGroupName); } }
public static Profile CreateOrUpdateDefaultProfileWithExternalEndpoint( TrafficManagerManagementClient trafficManagerClient, string resourceGroupName, string profileName, string trafficRoutingMethod = "Performance", string trafficViewEnrollmentStatus = "Disabled", string target = "foobar.contoso.com") { Profile profile = TrafficManagerHelper.CreateOrUpdateDefaultEmptyProfile( trafficManagerClient, resourceGroupName, profileName, trafficRoutingMethod, trafficViewEnrollmentStatus); // Create the endpoint and associate it with the resource group and profile. TrafficManagerHelper.CreateOrUpdateDefaultEndpoint( trafficManagerClient, resourceGroupName, profileName, target); return(trafficManagerClient.Profiles.Get(resourceGroupName, profileName)); }
public void CrudEndpointsFullCycle() { using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); string profileName = TestUtilities.GenerateName("hydratestwatmv2profile"); string endpointName = TestUtilities.GenerateName("hydratestwatmv2endpoint"); ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup(); Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName); profile.Properties.Endpoints = null; // Create profile without endpoints trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup.Name, profileName, new ProfileCreateOrUpdateParameters { Profile = profile }); // Create the endpoint EndpointCreateOrUpdateResponse createEndpoint = trafficManagerClient.Endpoints.CreateOrUpdate( resourceGroup.Name, profileName, "ExternalEndpoints", endpointName, new EndpointCreateOrUpdateParameters { Endpoint = TrafficManagerHelper.GenerateDefaultEndpoint(endpointName) }); Assert.Equal(HttpStatusCode.Created, createEndpoint.StatusCode); EndpointGetResponse getEndpoint = trafficManagerClient.Endpoints.Get( resourceGroup.Name, profileName, "ExternalEndpoints", endpointName); Assert.Equal(HttpStatusCode.OK, getEndpoint.StatusCode); Endpoint endpointToUpdate = getEndpoint.Endpoint; string oldTarget = endpointToUpdate.Properties.Target; string newTarget = "another." + oldTarget; endpointToUpdate.Properties.Target = newTarget; // Create the endpoint EndpointUpdateResponse updateEndpoint = trafficManagerClient.Endpoints.Update( resourceGroup.Name, profileName, "ExternalEndpoints", endpointName, new EndpointUpdateParameters { Endpoint = endpointToUpdate }); Assert.Equal(HttpStatusCode.Created, updateEndpoint.StatusCode); Assert.Equal(newTarget, updateEndpoint.Endpoint.Properties.Target); AzureOperationResponse deleteResponse = trafficManagerClient.Endpoints.Delete( resourceGroup.Name, profileName, "ExternalEndpoints", endpointName); Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode); } }
public void CrudEndpointGeographicProfile() { using (UndoContext context = UndoContext.Current) { context.Start(); TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient(); string profileName = TestUtilities.GenerateName("hydratestwatmv2profile"); ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup(); Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName); profile.Properties.TrafficRoutingMethod = "Geographic"; profile.Properties.Endpoints = null; // Create the profile ProfileCreateOrUpdateResponse createResponse = trafficManagerClient.Profiles.CreateOrUpdate( resourceGroup.Name, profileName, new ProfileCreateOrUpdateParameters { Profile = profile }); Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode); Assert.Equal("Geographic", createResponse.Profile.Properties.TrafficRoutingMethod); Endpoint endpoint = new Endpoint { Id = null, Name = "My external endpoint", Type = "Microsoft.network/TrafficManagerProfiles/ExternalEndpoints", Properties = new EndpointProperties { TargetResourceId = null, Target = "foobar.contoso.com", EndpointStatus = "Enabled", GeoMapping = new[] { "GEO-AS", "GEO-AF" }, } }; // Create the endpoint EndpointCreateOrUpdateResponse createEndpointResponse = trafficManagerClient.Endpoints.CreateOrUpdate( resourceGroup.Name, profileName, "ExternalEndpoints", endpoint.Name, new EndpointCreateOrUpdateParameters { Endpoint = endpoint }); Assert.Equal(HttpStatusCode.Created, createEndpointResponse.StatusCode); Assert.Equal("GEO-AS", createEndpointResponse.Endpoint.Properties.GeoMapping[0]); Assert.Equal("GEO-AF", createEndpointResponse.Endpoint.Properties.GeoMapping[1]); // Get the endpoint EndpointGetResponse endpointGetResponse = trafficManagerClient.Endpoints.Get( resourceGroup.Name, profileName, "ExternalEndpoints", endpoint.Name); Assert.Equal("GEO-AS", endpointGetResponse.Endpoint.Properties.GeoMapping[0]); Assert.Equal("GEO-AF", endpointGetResponse.Endpoint.Properties.GeoMapping[1]); } }
public TrafficManagerClient(WindowsAzureSubscription subscription) { this.Client = subscription.CreateClient <TrafficManagerManagementClient>(); }
public TrafficManagerClient(AzureSubscription subscription) { this.Client = AzureSession.ClientFactory.CreateClient <TrafficManagerManagementClient>(subscription, AzureEnvironment.Endpoint.ServiceManagement); }
public void TrafficViewEnableDisableQuerySizeScope() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context); string resourceGroupName = TrafficManagerHelper.GetPersistentResourceGroupName(); string profileName = TrafficManagerHelper.GetPersistentTrafficViewProfile(); ResourceGroup resourceGroup = this.CreateResourceGroup(context, resourceGroupName); Profile profile = TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint( trafficManagerClient, resourceGroup.Name, profileName); bool authorized = true; bool found = true; try { trafficManagerClient.HeatMap.Get(resourceGroupName, profileName); } catch (Microsoft.Rest.Azure.CloudException e) { authorized = !e.Body.Code.Contains("NotAuthorized"); // 'NotFound' can happen if there were no queries to the endpoint since it was provisioned. found = !(authorized && e.Body.Code.Contains("NotFound")); // Let's hope you were paying attention in that math logic class. } if (!found) { // Pause, then retry once. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(120)); try { trafficManagerClient.HeatMap.Get(resourceGroupName, profileName); } catch (Microsoft.Rest.Azure.CloudException e) { authorized = !e.Body.Code.Contains("NotAuthorized"); } } Assert.False(authorized); // Change the enrollment status and update the profile. // Clear the endpoints first; those are not serializable as child objects because they have their own resource info. profile.TrafficViewEnrollmentStatus = "Enabled"; profile.Endpoints = null; trafficManagerClient.Profiles.CreateOrUpdate( resourceGroupName, profileName, profile); HeatMapModel heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName); Assert.True(heatMapModel.StartTime.Value.CompareTo(System.DateTime.MinValue) > 0, "Invalid start time"); Assert.True(heatMapModel.StartTime.Value.CompareTo(heatMapModel.EndTime.Value) <= 0, "Start time smaller than end time"); Assert.True(heatMapModel.Endpoints.Count > 0, "Endpoint list empty, Not really an error but can not run test with no heatmap data."); foreach (HeatMapEndpoint ep in heatMapModel.Endpoints) { Assert.True((ep.EndpointId ?? -1) >= 0, "Endpoint id null or out of range"); Assert.False(string.IsNullOrWhiteSpace(ep.ResourceId), "Resource Id undefined"); } foreach (TrafficFlow tf in heatMapModel.TrafficFlows) { Assert.False(string.IsNullOrWhiteSpace(tf.SourceIp), "SourceIp is undefined"); foreach (QueryExperience qe in tf.QueryExperiences) { Assert.True(heatMapModel.Endpoints.Where(ep => ep.EndpointId == qe.EndpointId).Count() > 0, "Query Experience does not match an existing endpoint"); } } IList <TrafficFlow> trafficFlowList = heatMapModel.TrafficFlows; foreach (TrafficFlow tf in trafficFlowList) { if ((tf.Latitude - .1 >= -90.0) && (tf.Latitude + .1 <= 90.0) && (tf.Longitude - .1 >= -180.0) && (tf.Longitude + .1 <= 180.0)) { heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>() { (tf.Latitude + .10), (tf.Longitude - .10) }, new List <double?>() { (tf.Latitude - 0.10), (tf.Longitude + 0.10) }); Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() > 0, "Subset of coordinates not found"); heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>() { (tf.Latitude + .10), (tf.Longitude - .10) }, new List <double?>() { (tf.Latitude + 0.05), (tf.Longitude - 0.05) }); Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() == 0, "Subset of coordinates not expected"); } } } }
public TrafficManagerClient(TrafficManagerManagementClient client) { this.Client = client; }
public TrafficManagerClient(AzureSMProfile profile, IAzureSubscription subscription) { this.Client = AzureSession.Instance.ClientFactory.CreateClient <TrafficManagerManagementClient>(profile, subscription, AzureEnvironment.Endpoint.ServiceManagement); }