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);
                    }
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        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);
        }
 /// <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>
 /// 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 Task<OperationStatusResponse> SetRouteAsync(this IRouteOperations operations, string routeTableName, string routeName, SetRouteParameters parameters)
 {
     return operations.SetRouteAsync(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>
 /// 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 SetRoute(this IRouteOperations operations, string routeTableName, string routeName, SetRouteParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRouteOperations)s).SetRouteAsync(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);
                        }
                    }
                }
            }
        }
Пример #7
0
        public AzureOperationResponse SetRoute(string routeTableName, string routeName, SetRouteParameters parameters)
        {
            SetRoute operation = new SetRoute(routeOperations, routeTableName, routeName, parameters);

            testClient.InvokeTestOperation(operation);

            return operation.InvokeResponse;
        }
Пример #8
0
        public void EnsureRouteExists(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;
                    }
                }
            }

            if (routeExists == false)
            {
                SetRouteParameters parameters = new SetRouteParameters()
                {
                    Name = routeName,
                    AddressPrefix = "0.0.0.0/0",
                    NextHop = new NextHop()
                    {
                        Type = "VPNGateway",
                    },
                };
                SetRoute(routeTableName, routeName, parameters);
            }
        }