// Ensure VMs for the LB public IEnumerable <IVirtualMachine> EnsureVMs( INetworks networks, IComputeManager computeManager, int count) { // Create a network for the VMs INetwork network = networks.Define("net" + TestId) .WithRegion(Region) .WithNewResourceGroup(GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); // Define an availability set for the VMs var availabilitySetDefinition = computeManager.AvailabilitySets.Define("as" + TestId) .WithRegion(Region) .WithExistingResourceGroup(GroupName) .WithSku(AvailabilitySetSkuTypes.Managed); // Create the requested number of VM definitions string userName = "******" + TestId; List <ICreatable <IVirtualMachine> > vmDefinitions = new List <ICreatable <IVirtualMachine> >(); for (int i = 0; i < count; i++) { string vmName = TestUtilities.GenerateName("vm"); var vm = computeManager.VirtualMachines.Define(vmName) .WithRegion(Region) .WithExistingResourceGroup(GroupName) .WithExistingPrimaryNetwork(network) .WithSubnet(network.Subnets.Values.First().Name) .WithPrimaryPrivateIPAddressDynamic() .WithoutPrimaryPublicIPAddress() .WithPopularLinuxImage(KnownLinuxVirtualMachineImage.UbuntuServer14_04_Lts) .WithRootUsername(userName) .WithRootPassword("Abcdef.123456") .WithNewAvailabilitySet(availabilitySetDefinition) .WithSize(VirtualMachineSizeTypes.StandardA1); vmDefinitions.Add(vm); } var createdVMs = computeManager.VirtualMachines.Create(vmDefinitions.ToArray()); return(createdVMs); }
public override IApplicationGateway CreateResource(IApplicationGateways resources) { testPips = new List <IPublicIPAddress>(applicationGatewayHelper.EnsurePIPs(resources.Manager.PublicIPAddresses)); networks = resources.Manager.Networks; INetwork vnet = networks.Define("net" + applicationGatewayHelper.TestId) .WithRegion(applicationGatewayHelper.Region) .WithNewResourceGroup(applicationGatewayHelper.GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); Thread creationThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; // Create an application gateway resources.Define(applicationGatewayHelper.AppGatewayName) .WithRegion(applicationGatewayHelper.Region) .WithExistingResourceGroup(applicationGatewayHelper.GroupName) // Request routing rules .DefineRequestRoutingRule("rule80") .FromPrivateFrontend() .FromFrontendHttpPort(80) .ToBackendHttpPort(8080) .ToBackendIPAddress("11.1.1.1") .ToBackendIPAddress("11.1.1.2") .WithCookieBasedAffinity() .Attach() .DefineRequestRoutingRule("rule443") .FromPrivateFrontend() .FromFrontendHttpsPort(443) .WithSslCertificateFromPfxFile(new FileInfo(Path.Combine("Assets", "myTest._pfx"))) .WithSslCertificatePassword("Abc123") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("rule9000") .FromListener("listener1") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("ruleRedirect") .FromPrivateFrontend() .FromFrontendHttpsPort(444) .WithSslCertificate("cert1") .WithRedirectConfiguration("redirect1") .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .Attach() .DefineBackendHttpConfiguration("config2") .Attach() // Additional/explicit backends .DefineBackend("backend1") .WithIPAddress("11.1.1.3") .WithIPAddress("11.1.1.4") .Attach() .DefineBackend("backend2") .Attach() // Additional/explicit frontend listeners .DefineListener("listener1") .WithPrivateFrontend() .WithFrontendPort(9000) .WithHttp() .Attach() // Additional/explicit certificates .DefineSslCertificate("cert1") .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest2._pfx"))) .WithPfxPassword("Abc123") .Attach() // Authentication certificates .DefineAuthenticationCertificate("auth2") .FromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer"))) .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .WithHttps() .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest.cer"))) .Attach() .DefineBackendHttpConfiguration("config2") .WithPort(8082) .WithHttps() .WithAuthenticationCertificate("auth2") // Add the same cert, so only one should be added .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer"))) .Attach() // Redirect configurations .DefineRedirectConfiguration("redirect1") .WithType(ApplicationGatewayRedirectType.Permanent) .WithTargetListener("listener1") .WithPathIncluded() .Attach() .DefineRedirectConfiguration("redirect2") .WithType(ApplicationGatewayRedirectType.Temporary) .WithTargetUrl("http://www.microsoft.com") .WithQueryStringIncluded() .Attach() .WithExistingSubnet(vnet, "subnet1") .WithSize(ApplicationGatewaySkuName.StandardMedium) .WithInstanceCount(2) .Create(); }); // Start creating in a separate thread... creationThread.Start(); // ...But don't wait till the end - not needed for the test, 30 sec should be enough TestHelper.Delay(30 * 1000); // Get the resource as created so far string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId); IApplicationGateway appGateway = resources.GetById(resourceId); Assert.NotNull(appGateway); Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier); Assert.Equal(ApplicationGatewaySkuName.StandardMedium, appGateway.Size); Assert.Equal(2, appGateway.InstanceCount); Assert.False(appGateway.IsPublic); Assert.True(appGateway.IsPrivate); Assert.Single(appGateway.IPConfigurations); // Verify redirect configurations Assert.Equal(2, appGateway.RedirectConfigurations.Count); IApplicationGatewayRedirectConfiguration redirect = null; Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect1", out redirect)); Assert.NotNull(redirect); Assert.Equal(ApplicationGatewayRedirectType.Permanent, redirect.Type); Assert.NotNull(redirect.TargetListener); Assert.Equal("listener1", redirect.TargetListener.Name, true); Assert.Null(redirect.TargetUrl); Assert.True(redirect.IsPathIncluded); Assert.False(redirect.IsQueryStringIncluded); Assert.Single(redirect.RequestRoutingRules); Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect2", out redirect)); Assert.NotNull(redirect); Assert.Equal(ApplicationGatewayRedirectType.Temporary, redirect.Type); Assert.Null(redirect.TargetListener); Assert.NotNull(redirect.TargetUrl); Assert.Equal("http://www.microsoft.com", redirect.TargetUrl, true); Assert.True(redirect.IsQueryStringIncluded); Assert.False(redirect.IsPathIncluded); // Verify frontend ports Assert.Equal(4, appGateway.FrontendPorts.Count); Assert.NotNull(appGateway.FrontendPortNameFromNumber(80)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(443)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(9000)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(444)); // Verify frontends Assert.Single(appGateway.Frontends); Assert.Empty(appGateway.PublicFrontends); Assert.Single(appGateway.PrivateFrontends); IApplicationGatewayFrontend frontend = appGateway.PrivateFrontends.Values.FirstOrDefault(); Assert.False(frontend.IsPublic); Assert.True(frontend.IsPrivate); // Verify listeners Assert.Equal(4, appGateway.Listeners.Count); IApplicationGatewayListener listener = appGateway.Listeners["listener1"]; Assert.NotNull(listener); Assert.Equal(9000, listener.FrontendPortNumber); Assert.Equal(ApplicationGatewayProtocol.Http, listener.Protocol); Assert.NotNull(listener.Frontend); Assert.True(listener.Frontend.IsPrivate); Assert.False(listener.Frontend.IsPublic); Assert.NotNull(appGateway.ListenerByPortNumber(80)); Assert.NotNull(appGateway.ListenerByPortNumber(443)); Assert.NotNull(appGateway.ListenerByPortNumber(444)); // Verify SSL certificates Assert.Equal(2, appGateway.SslCertificates.Count); Assert.Contains("cert1", appGateway.SslCertificates.Keys); // Verify backend HTTP settings configs Assert.Equal(3, appGateway.BackendHttpConfigurations.Count); IApplicationGatewayBackendHttpConfiguration config = appGateway.BackendHttpConfigurations["config1"]; Assert.NotNull(config); Assert.Equal(8081, config.Port); Assert.Equal(45, config.RequestTimeout); Assert.Single(config.AuthenticationCertificates); var config2 = appGateway.BackendHttpConfigurations["config2"]; Assert.NotNull(config2); // Verify authentication certificates Assert.Equal(2, appGateway.AuthenticationCertificates.Count); var authCert2 = appGateway.AuthenticationCertificates["auth2"]; Assert.NotNull(authCert2); Assert.NotNull(authCert2.Data); var authCert = config.AuthenticationCertificates.Values.FirstOrDefault(); Assert.NotNull(authCert); Assert.Single(config2.AuthenticationCertificates); Assert.Equal(authCert2.Name, config2.AuthenticationCertificates.Values.FirstOrDefault().Name, true); // Verify backends Assert.Equal(3, appGateway.Backends.Count); IApplicationGatewayBackend backend = appGateway.Backends["backend1"]; Assert.NotNull(backend); Assert.Equal(2, backend.Addresses.Count); Assert.True(backend.ContainsIPAddress("11.1.1.3")); Assert.True(backend.ContainsIPAddress("11.1.1.4")); Assert.True(appGateway.Backends.ContainsKey("backend2")); // Verify request routing rules Assert.Equal(4, appGateway.RequestRoutingRules.Count); IApplicationGatewayRequestRoutingRule rule; rule = appGateway.RequestRoutingRules["rule80"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(80, rule.FrontendPort); Assert.Equal(8080, rule.BackendPort); Assert.True(rule.CookieBasedAffinity); Assert.Equal(2, rule.BackendAddresses.Count); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1")); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2")); rule = appGateway.RequestRoutingRules["rule443"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(443, rule.FrontendPort); Assert.Equal(ApplicationGatewayProtocol.Https, rule.FrontendProtocol); Assert.NotNull(rule.SslCertificate); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true); Assert.NotNull(rule.Backend); Assert.Equal("backend1", rule.Backend.Name, true); rule = appGateway.RequestRoutingRules["rule9000"]; Assert.NotNull(rule); Assert.NotNull(rule.Listener); Assert.Equal("listener1", rule.Listener.Name); Assert.NotNull(rule.Listener.SubnetName); Assert.NotNull(rule.Listener.NetworkId); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true); Assert.NotNull(rule.Backend); Assert.Equal("backend1", rule.Backend.Name, true); rule = appGateway.RequestRoutingRules["ruleRedirect"]; Assert.NotNull(rule); Assert.NotNull(rule.RedirectConfiguration); Assert.Equal("redirect1", rule.RedirectConfiguration.Name, true); creationThread.Join(); return(appGateway); }
public override IApplicationGateway CreateResource(IApplicationGateways resources) { testPips = new List <IPublicIPAddress>(applicationGatewayHelper.EnsurePIPs(resources.Manager.PublicIPAddresses)); networks = resources.Manager.Networks; INetwork vnet = networks.Define("net" + applicationGatewayHelper.TestId) .WithRegion(applicationGatewayHelper.Region) .WithNewResourceGroup(applicationGatewayHelper.GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); Thread creationThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; // Create an application gateway resources.Define(applicationGatewayHelper.AppGatewayName) .WithRegion(applicationGatewayHelper.Region) .WithExistingResourceGroup(applicationGatewayHelper.GroupName) // Request routing rules .DefineRequestRoutingRule("rule80") .FromPrivateFrontend() .FromFrontendHttpPort(80) .ToBackendHttpPort(8080) .ToBackendIPAddress("11.1.1.1") .ToBackendIPAddress("11.1.1.2") .WithCookieBasedAffinity() .Attach() .DefineRequestRoutingRule("rule443") .FromPrivateFrontend() .FromFrontendHttpsPort(443) .WithSslCertificateFromPfxFile(new FileInfo(Path.Combine("Assets", "myTest._pfx"))) .WithSslCertificatePassword("Abc123") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("rule9000") .FromListener("listener1") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .Attach() .DefineBackendHttpConfiguration("config2") .Attach() // Additional/explicit backends .DefineBackend("backend1") .WithIPAddress("11.1.1.3") .WithIPAddress("11.1.1.4") .Attach() .DefineBackend("backend2") .Attach() // Additional/explicit frontend listeners .DefineListener("listener1") .WithPrivateFrontend() .WithFrontendPort(9000) .WithHttp() .Attach() // Additional/explicit certificates .DefineSslCertificate("cert1") .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest2._pfx"))) .WithPfxPassword("Abc123") .Attach() .WithExistingSubnet(vnet, "subnet1") .WithSize(ApplicationGatewaySkuName.StandardMedium) .WithInstanceCount(2) .Create(); }); // Start creating in a separate thread... creationThread.Start(); // ...But don't wait till the end - not needed for the test, 30 sec should be enough TestHelper.Delay(30 * 1000); // Get the resource as created so far string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId); IApplicationGateway appGateway = resources.GetById(resourceId); Assert.NotNull(appGateway); Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier); Assert.Equal(ApplicationGatewaySkuName.StandardMedium, appGateway.Size); Assert.Equal(appGateway.InstanceCount, 2); Assert.False(appGateway.IsPublic); Assert.True(appGateway.IsPrivate); Assert.Equal(appGateway.IPConfigurations.Count, 1); // Verify frontend ports Assert.Equal(appGateway.FrontendPorts.Count, 3); Assert.NotNull(appGateway.FrontendPortNameFromNumber(80)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(443)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(9000)); // Verify frontends Assert.Equal(appGateway.Frontends.Count, 1); Assert.Equal(appGateway.PublicFrontends.Count, 0); Assert.Equal(appGateway.PrivateFrontends.Count, 1); IApplicationGatewayFrontend frontend = appGateway.PrivateFrontends.Values.First(); Assert.False(frontend.IsPublic); Assert.True(frontend.IsPrivate); // Verify listeners Assert.Equal(appGateway.Listeners.Count, 3); IApplicationGatewayListener listener = appGateway.Listeners["listener1"]; Assert.NotNull(listener); Assert.Equal(listener.FrontendPortNumber, 9000); Assert.Equal(ApplicationGatewayProtocol.Http, listener.Protocol); Assert.NotNull(listener.Frontend); Assert.True(listener.Frontend.IsPrivate); Assert.False(listener.Frontend.IsPublic); Assert.NotNull(appGateway.ListenerByPortNumber(80)); Assert.NotNull(appGateway.ListenerByPortNumber(443)); // Verify certificates Assert.Equal(appGateway.SslCertificates.Count, 2); Assert.True(appGateway.SslCertificates.ContainsKey("cert1")); // Verify backend HTTP settings configs Assert.Equal(appGateway.BackendHttpConfigurations.Count, 3); IApplicationGatewayBackendHttpConfiguration config = appGateway.BackendHttpConfigurations["config1"]; Assert.NotNull(config); Assert.Equal(config.Port, 8081); Assert.Equal(config.RequestTimeout, 45); Assert.True(appGateway.BackendHttpConfigurations.ContainsKey("config2")); // Verify backends Assert.Equal(appGateway.Backends.Count, 3); IApplicationGatewayBackend backend = appGateway.Backends["backend1"]; Assert.NotNull(backend); Assert.Equal(backend.Addresses.Count, 2); Assert.True(backend.ContainsIPAddress("11.1.1.3")); Assert.True(backend.ContainsIPAddress("11.1.1.4")); Assert.True(appGateway.Backends.ContainsKey("backend2")); // Verify request routing rules Assert.Equal(appGateway.RequestRoutingRules.Count, 3); IApplicationGatewayRequestRoutingRule rule; rule = appGateway.RequestRoutingRules["rule80"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(rule.FrontendPort, 80); Assert.Equal(rule.BackendPort, 8080); Assert.True(rule.CookieBasedAffinity); Assert.Equal(rule.BackendAddresses.Count, 2); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1")); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2")); rule = appGateway.RequestRoutingRules["rule443"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(rule.FrontendPort, 443); Assert.Equal(ApplicationGatewayProtocol.Https, rule.FrontendProtocol); Assert.NotNull(rule.SslCertificate); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal(rule.BackendHttpConfiguration.Name, "config1"); Assert.NotNull(rule.Backend); Assert.Equal(rule.Backend.Name, "backend1"); rule = appGateway.RequestRoutingRules["rule9000"]; Assert.NotNull(rule); Assert.NotNull(rule.Listener); Assert.Equal(rule.Listener.Name, "listener1"); Assert.NotNull(rule.Listener.SubnetName); Assert.NotNull(rule.Listener.NetworkId); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal(rule.BackendHttpConfiguration.Name, "config1"); Assert.NotNull(rule.Backend); Assert.Equal(rule.Backend.Name, "backend1"); creationThread.Join(); return(appGateway); }