public void AddRouteTableToSubnetWithNonExistantSubnetName() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.EnsureWideVNetNetworkConfigurationExists(); networkTestClient.Routes.EnsureRouteTableExists("MockRouteTableName"); AddRouteTableToSubnetParameters parameters = new AddRouteTableToSubnetParameters() { RouteTableName = "MockRouteTableName" }; try { networkTestClient.Routes.AddRouteTableToSubnet(NetworkTestConstants.VirtualNetworkSiteName, "NonExistantSubnetName", parameters); Assert.True(false, "AddRouteTableToSubnet should have thrown a CloudException when the subnetName did not exist in the current vnet."); } catch (Hyak.Common.CloudException e) { Assert.Equal("ResourceNotFound", e.Error.Code); Assert.Equal("Subnet name NonExistantSubnetName was not found in Virtual Network virtualNetworkSiteName.", e.Error.Message); Assert.Null(e.Response); } } }
public void AddRouteTableToSubnetWithNonExistantVNetName() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.EnsureNoNetworkConfigurationExists(); networkTestClient.Routes.EnsureRouteTableExists("MockRouteTableName"); AddRouteTableToSubnetParameters parameters = new AddRouteTableToSubnetParameters() { RouteTableName = "MockRouteTableName" }; try { networkTestClient.Routes.AddRouteTableToSubnet(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.WideVNetSubnetName, parameters); Assert.True(false, "AddRouteTableToSubnet should have thrown a CloudException when the parameters object's route table name was empty."); } catch (Hyak.Common.CloudException e) { Assert.Equal("ResourceNotFound", e.Error.Code); Assert.Equal("The virtual network virtualNetworkSiteName does not exist.", e.Error.Message); Assert.Null(e.Response); } } }
/// <summary> /// Set the specified route table for the provided subnet in the /// provided virtual network in this subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Network.IRouteOperations. /// </param> /// <param name='vnetName'> /// Required. The name of the virtual network that contains the /// provided subnet. /// </param> /// <param name='subnetName'> /// Required. The name of the subnet that the route table will be added /// to. /// </param> /// <param name='parameters'> /// Required. The parameters necessary to add a route table to the /// provided subnet. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static OperationStatusResponse AddRouteTableToSubnet(this IRouteOperations operations, string vnetName, string subnetName, AddRouteTableToSubnetParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IRouteOperations)s).AddRouteTableToSubnetAsync(vnetName, subnetName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
public AddRouteTableToSubnet(IRouteOperations routeOperations, string vnetName, string subnetName, AddRouteTableToSubnetParameters parameters) { this.routeOperations = routeOperations; this.vnetName = vnetName; this.subnetName = subnetName; this.parameters = parameters; if (parameters == null || string.IsNullOrEmpty(parameters.RouteTableName)) { routeTableAssignedPreviously = false; } else { string assignedRouteTable = RouteTestClient.GetRouteTableAssignedToSubnet(routeOperations, vnetName, subnetName); routeTableAssignedPreviously = string.Equals(parameters.RouteTableName, assignedRouteTable, StringComparison.InvariantCultureIgnoreCase); } }
/// <summary> /// Set the specified route table for the provided subnet in the /// provided virtual network in this subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Network.IRouteOperations. /// </param> /// <param name='vnetName'> /// Required. The name of the virtual network that contains the /// provided subnet. /// </param> /// <param name='subnetName'> /// Required. The name of the subnet that the route table will be added /// to. /// </param> /// <param name='parameters'> /// Required. The parameters necessary to add a route table to the /// provided subnet. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task<OperationResponse> BeginAddRouteTableToSubnetAsync(this IRouteOperations operations, string vnetName, string subnetName, AddRouteTableToSubnetParameters parameters) { return operations.BeginAddRouteTableToSubnetAsync(vnetName, subnetName, parameters, CancellationToken.None); }
public void AddRouteTableToSubnetWithNullRouteTableName() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { AddRouteTableToSubnetParameters parameters = new AddRouteTableToSubnetParameters() { RouteTableName = null }; try { networkTestClient.Routes.AddRouteTableToSubnet(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.WideVNetSubnetName, parameters); Assert.True(false, "AddRouteTableToSubnet should have thrown a CloudException when the parameters object's route table name was null."); } catch (Hyak.Common.CloudException e) { Assert.Equal("BadRequest", e.Error.Code); Assert.Equal("Route Table name is null or empty.", e.Error.Message); Assert.NotNull(e.Response); Assert.Equal("Bad Request", e.Response.ReasonPhrase); Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode); } } }
public void AddRouteTableToSubnet() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.EnsureWideVNetNetworkConfigurationExists(); networkTestClient.Routes.EnsureRouteTableExists("MockRouteTableName"); AddRouteTableToSubnetParameters parameters = new AddRouteTableToSubnetParameters() { RouteTableName = "MockRouteTableName" }; networkTestClient.Routes.AddRouteTableToSubnet(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.WideVNetSubnetName, parameters); GetRouteTableForSubnetResponse response = networkTestClient.Routes.GetRouteTableForSubnet(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.WideVNetSubnetName); Assert.NotNull(response); Assert.Equal("MockRouteTableName", response.RouteTableName); } }
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 AddRouteTableToSubnet(string vnetName, string subnetName, AddRouteTableToSubnetParameters parameters) { AddRouteTableToSubnet operation = new AddRouteTableToSubnet(routeOperations, vnetName, subnetName, parameters); testClient.InvokeTestOperation(operation); return operation.InvokeResponse; }