public void Undo() { if (oldRouteTable != null) { Route oldRoute = null; if (oldRouteTable.RouteList != null) { foreach (Route route in oldRouteTable.RouteList) { if (string.Equals(route.Name, routeName, StringComparison.InvariantCultureIgnoreCase)) { oldRoute = route; break; } } } if (oldRoute != null) { SetRouteParameters undoParameters = new SetRouteParameters() { Name = oldRoute.Name, AddressPrefix = oldRoute.AddressPrefix, NextHop = oldRoute.NextHop, }; routeOperations.SetRoute(routeTableName, routeName, undoParameters); } } }
public void Undo() { if (oldRouteTable != null) { CreateRouteTableParameters createParameters = new CreateRouteTableParameters() { Name = oldRouteTable.Name, Label = oldRouteTable.Label, Location = oldRouteTable.Location, }; routeOperations.CreateRouteTable(createParameters); if (oldRouteTable.RouteList != null) { foreach (Route route in oldRouteTable.RouteList) { SetRouteParameters setParameters = new SetRouteParameters() { Name = route.Name, AddressPrefix = route.AddressPrefix, NextHop = route.NextHop, }; routeOperations.SetRoute(routeTableName, route.Name, setParameters); } } } }
public SetRoute(IRouteOperations routeOperations, string routeTableName, string routeName, SetRouteParameters parameters) { this.routeOperations = routeOperations; this.routeTableName = routeTableName; this.routeName = routeName; this.parameters = parameters; oldRouteTable = RouteTestClient.GetRouteTableSafe(routeOperations, routeTableName); }
public AzureOperationResponse SetRoute(string routeTableName, string routeName, string addressPrefix, string nextHopType) { NextHop nextHop = new NextHop() { Type = nextHopType, }; SetRouteParameters parameters = new SetRouteParameters() { Name = routeName, AddressPrefix = addressPrefix, NextHop = nextHop, }; return(client.Routes.SetRoute(routeTableName, routeName, parameters)); }
public void SetRoute() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.Routes.EnsureRouteTableIsEmpty("MockRouteTableName"); SetRouteParameters parameters = CreateParameters("MockRouteName", "0.0.0.0/0", "VPNGateway"); AzureOperationResponse setResponse = networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.NotNull(setResponse); Assert.Equal(HttpStatusCode.OK, setResponse.StatusCode); Assert.NotNull(setResponse.RequestId); Assert.NotEqual(0, setResponse.RequestId.Length); } }
public void EnsureRouteIsOnlyRouteInRouteTable(string routeTableName, string routeName) { if (string.IsNullOrEmpty(routeTableName)) { throw new ArgumentException("routeTableName cannot be null or empty.", "routeTableName"); } if (string.IsNullOrEmpty(routeName)) { throw new ArgumentException("routeName cannot be null or empty.", "routeName"); } EnsureRouteTableExists(routeTableName); RouteTable routeTable = GetRouteTableSafe(routeOperations, routeTableName); bool routeExists = false; if (routeTable != null && routeTable.RouteList != null) { foreach (Route route in routeTable.RouteList) { if (string.Equals(route.Name, routeName, StringComparison.InvariantCultureIgnoreCase)) { routeExists = true; break; } else { DeleteRoute(routeTable.Name, route.Name); } } } if (routeExists == false) { SetRouteParameters parameters = new SetRouteParameters() { Name = routeName, AddressPrefix = "0.0.0.0/0", NextHop = new NextHop() { Type = "VPNGateway", }, }; SetRoute(routeTableName, routeName, parameters); } }
public void SetRouteWithEmptyAddressPrefixInParameters() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { SetRouteParameters parameters = CreateParameters("MockRouteName", "", "VPNGateway"); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the parameters object's address prefix was empty."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("The address prefix is a mandatory parameter, but it is not specified.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
public void SetRouteWhenRouteAlreadyExistsInRouteTable() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.Routes.EnsureRouteExists("MockRouteTableName", "MockRouteName"); SetRouteParameters parameters = CreateParameters("MockRouteName", "0.0.0.0/0", "VPNGateway"); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the route already exists in the provided route table."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("The Route MockRouteTableName cannot be added to Route Table MockRouteName. A Route with the specified name already exists.", e.Error.Message); Assert.Null(e.Response); } } }
public void SetRouteWithNullNextHopTypeInParameters() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { SetRouteParameters parameters = CreateParameters("MockRouteName", "0.0.0.0/0", (string)null); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the parameters object's next hop type was null."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("The next hop type is not supported yet. Please use next hop type VPNGateway.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
public void SetRouteWhenRouteTableDoesntExist() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.Routes.EnsureRouteTableDoesntExist("MockRouteTableName"); SetRouteParameters parameters = CreateParameters("MockRouteTable", "0.0.0.0/0", "VPNGateway"); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteTable", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the route table doesn't exist."); } catch (Hyak.Common.CloudException e) { Assert.Equal("ResourceNotFound", e.Error.Code); Assert.Equal("The Route Table MockRouteTableName does not exist.", e.Error.Message); Assert.Null(e.Response); } } }
public void SetRouteWhenRouteNamesDontMatch() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { SetRouteParameters parameters = CreateParameters("MockRouteNameB", "MockAddressPrefix", "MockNextHopType"); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteNameA", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the route name does not match the parameters object's route name."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("Route name MockRouteNameB is invalid.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
public void SetRouteWithEmptyNextHopTypeInParameters() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { SetRouteParameters parameters = CreateParameters("MockRouteName", "0.0.0.0/0", ""); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the parameters object's next hop type was empty."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("The next hop type is invalid. Please use next hop types VPNGateway, VirtualAppliance, Internet, VNETLocal, Null.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
public void SetRouteWithNullNextHopInParameters() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { SetRouteParameters parameters = CreateParameters("MockRouteName", "0.0.0.0/0", (NextHop)null); try { networkTestClient.Routes.SetRoute("MockRouteTableName", "MockRouteName", parameters); Assert.True(false, "SetRoute should have thrown a CloudException when the parameters object's next hop object was null."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("The next hop is a mandatory parameter, but it is not specified.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
/// <summary> /// Set the specified route for the provided table in this subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Network.IRouteOperations. /// </param> /// <param name='routeTableName'> /// Required. The name of the route table where the provided route will /// be set. /// </param> /// <param name='routeName'> /// Required. The name of the route that will be set on the provided /// route table. /// </param> /// <param name='parameters'> /// Required. The parameters necessary to create a new route table. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> BeginSetRouteAsync(this IRouteOperations operations, string routeTableName, string routeName, SetRouteParameters parameters) { return(operations.BeginSetRouteAsync(routeTableName, routeName, parameters, CancellationToken.None)); }
/// <summary> /// Set the specified route for the provided table in this subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Network.IRouteOperations. /// </param> /// <param name='routeTableName'> /// Required. The name of the route table where the provided route will /// be set. /// </param> /// <param name='routeName'> /// Required. The name of the route that will be set on the provided /// route table. /// </param> /// <param name='parameters'> /// Required. The parameters necessary to create a new route table. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse BeginSetRoute(this IRouteOperations operations, string routeTableName, string routeName, SetRouteParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IRouteOperations)s).BeginSetRouteAsync(routeTableName, routeName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public void GetEffectiveRouteTableOnRoleSucceeds() { using (var undoContext = UndoContext.Current) { undoContext.Start(); using (NetworkTestBase _testFixture = new NetworkTestBase()) { // setup bool storageAccountCreated = false; bool hostedServiceCreated = false; string serviceName = _testFixture.GenerateRandomName(); string deploymentName = _testFixture.GenerateRandomName(); string roleName = "WebRole1"; string location = _testFixture.ManagementClient.GetDefaultLocation("Storage", "Compute", "PersistentVMRole"); string routeTableName = _testFixture.GenerateRandomName(); string routeName = "routename"; string vnetName = "virtualNetworkSiteName"; string subnetName = "FrontEndSubnet5"; string storageAccountName = _testFixture.GenerateRandomName().ToLower(); _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated); _testFixture.SetSimpleVirtualNetwork(); _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated); CreateRouteTableParameters parameters = new CreateRouteTableParameters() { Name = routeTableName, Label = _testFixture.GenerateRandomName(), Location = location, }; AzureOperationResponse createResponse = _testFixture.NetworkClient.Routes.CreateRouteTable(parameters); var createRouteParameters = new SetRouteParameters() { Name = routeName, AddressPrefix = "0.0.0.0/0", NextHop = new NextHop() { IpAddress = "192.168.100.4", Type = "VirtualAppliance" }, }; _testFixture.NetworkClient.Routes.SetRoute(routeTableName, routeName, createRouteParameters); AddRouteTableToSubnetParameters addRouteTableToSubnetParameters = new AddRouteTableToSubnetParameters() { RouteTableName = routeTableName }; _testFixture.NetworkClient.Routes.AddRouteTableToSubnet(vnetName, subnetName, addRouteTableToSubnetParameters); var deployment = _testFixture.CreatePaaSDeployment( storageAccountName, serviceName, deploymentName, NetworkTestConstants.OneWebOneWorkerPkgFilePath, NetworkTestConstants.VnetOneWebOneWorkerCscfgFilePath); try { // action _testFixture.ComputeClient.Deployments.UpdateStatusByDeploymentName(serviceName, deploymentName, new DeploymentUpdateStatusParameters() { Status = UpdatedDeploymentStatus.Running }); RoleInstancePowerState roleStatus = RoleInstancePowerState.Unknown; Action getRole = () => { var vmStatus = _testFixture.ComputeClient.Deployments.GetByName(serviceName, deploymentName); roleStatus = vmStatus.RoleInstances.Single( r => string.Equals(r.RoleName, roleName, StringComparison.OrdinalIgnoreCase)) .PowerState; }; Func <bool> retryUntil = () => { return(roleStatus == RoleInstancePowerState.Started); }; TestUtilities.RetryActionWithTimeout( getRole, retryUntil, TimeSpan.FromMinutes(15), (code => { Thread.Sleep(5000); return(true); })); // assert var response = _testFixture.NetworkClient.Routes.GetEffectiveRouteTableForRoleInstance(serviceName, deploymentName, roleName + "_IN_0"); Assert.NotNull(response); Assert.NotNull(response.EffectiveRouteTable); Assert.NotEmpty(response.EffectiveRouteTable.EffectiveRoutes); var userDefinedRoute = response.EffectiveRouteTable.EffectiveRoutes.Single(r => r.Source == "User"); Assert.Equal(1, userDefinedRoute.AddressPrefixes.Count); Assert.Equal(createRouteParameters.AddressPrefix, userDefinedRoute.AddressPrefixes[0]); Assert.Equal(createRouteParameters.Name, userDefinedRoute.Name); Assert.Equal(createRouteParameters.NextHop.Type, userDefinedRoute.EffectiveNextHop.Type); Assert.Equal(1, userDefinedRoute.EffectiveNextHop.IpAddresses.Count); Assert.Equal(createRouteParameters.NextHop.IpAddress, userDefinedRoute.EffectiveNextHop.IpAddresses[0]); Assert.Equal("Active", userDefinedRoute.Status); } finally { _testFixture.NetworkClient.Routes.BeginRemoveRouteTableFromSubnet(vnetName, subnetName); if (storageAccountCreated) { _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName); } if (hostedServiceCreated) { _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName); } } } } }
public AzureOperationResponse SetRoute(string routeTableName, string routeName, SetRouteParameters parameters) { SetRoute operation = new SetRoute(routeOperations, routeTableName, routeName, parameters); testClient.InvokeTestOperation(operation); return(operation.InvokeResponse); }