public void SetIPForwardingOnRoleSucceeds()
        {
            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 storageAccountName = _testFixture.GenerateRandomName().ToLower();

                    _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);
                    _testFixture.SetSimpleVirtualNetwork();
                    _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);
                    var deployment = _testFixture.CreatePaaSDeployment(
                        storageAccountName,
                        serviceName,
                        deploymentName,
                        NetworkTestConstants.OneWebOneWorkerPkgFilePath,
                        NetworkTestConstants.VnetOneWebOneWorkerCscfgFilePath,
                        startDeployment: true);

                    try
                    {
                        // action
                        var ipForwardingState = "Enabled";
                        var ipForwarding      = new IPForwardingSetParameters(ipForwardingState);

                        _testFixture.NetworkClient.IPForwarding.SetOnRole(serviceName, deploymentName, roleName,
                                                                          ipForwarding);

                        // assert
                        IPForwardingGetResponse response =
                            _testFixture.NetworkClient.IPForwarding.GetForRole(serviceName, deploymentName, roleName);
                        Assert.Equal(ipForwardingState, response.State);
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
        public void SetIPForwardingOnRoleSucceeds()
        {
            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 storageAccountName = _testFixture.GenerateRandomName().ToLower();

                    _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);
                    _testFixture.SetSimpleVirtualNetwork();
                    _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);
                    var deployment = _testFixture.CreatePaaSDeployment(
                        storageAccountName,
                        serviceName,
                        deploymentName,
                        NetworkTestConstants.OneWebOneWorkerPkgFilePath,
                        NetworkTestConstants.VnetOneWebOneWorkerCscfgFilePath);

                    try
                    {
                        // action
                        var ipForwardingState = "Enabled";
                        var ipForwarding = new IPForwardingSetParameters(ipForwardingState);

                        _testFixture.NetworkClient.IPForwarding.SetOnRole(serviceName, deploymentName, roleName,
                            ipForwarding);

                        // assert
                        IPForwardingGetResponse response =
                            _testFixture.NetworkClient.IPForwarding.GetForRole(serviceName, deploymentName, roleName);
                        Assert.Equal(ipForwardingState, response.State);
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
        public void TestReservingExistingDeploymentIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    var managementClient = _testFixture.ManagementClient;
                    bool storageAccountCreated = false;
                    bool hostedServiceCreated = false;
                    string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName = string.Format("{0}Prd", serviceName);
                    string reserveIpName = HttpMockServer.GetAssetName("res", "testres").ToLower();
                    string location = managementClient.GetDefaultLocation("Storage", "Compute");
                    bool reservedIpCreated = false;
                    try
                    {
                        _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

                        _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);

                        var deployment = _testFixture.CreatePaaSDeployment(storageAccountName, serviceName, deploymentName, NetworkTestConstants.OneWebOneWorkerPkgFilePath, "OneWebOneWorker.cscfg");

                        NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                        {
                            Name = reserveIpName,
                            Label = "TestLabel",
                            DeploymentName = deploymentName,
                            ServiceName = serviceName,
                            Location = "uswest"
                        };

                        OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);
                        Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK);

                        reservedIpCreated = true;
                        NetworkReservedIPGetResponse reserveIpCreationResponse =
                            _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);


                        Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);

                        Assert.True(reserveIpCreationResponse.ServiceName == serviceName);
                        Assert.True(reserveIpCreationResponse.DeploymentName == deploymentName);
                        Assert.True(reserveIpCreationResponse.InUse == true);
                        Assert.True(reserveIpCreationResponse.Address == deployment.VirtualIPAddresses[0].Address);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
        public void AddAndRemoveNetworkSecurityGroupToRole()
        {
            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 storageAccountName = _testFixture.GenerateRandomName().ToLower();

                    // create Network Security Group
                    string securityGroupName = _testFixture.GenerateRandomNetworkSecurityGroupName();
                    string securityGroupLabel = _testFixture.GenerateRandomName();
                    string securityGroupLocation = "North Central US";
                    _testFixture.CreateNetworkSecurityGroup(securityGroupName, securityGroupLabel, securityGroupLocation);

                    _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);
                    _testFixture.SetSimpleVirtualNetwork();
                    _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);
                    var deployment = _testFixture.CreatePaaSDeployment(
                        storageAccountName,
                        serviceName,
                        deploymentName,
                        NetworkTestConstants.OneWebOneWorkerPkgFilePath,
                        NetworkTestConstants.VnetOneWebOneWorkerCscfgFilePath);

                    try
                    {
                        // action 1
                        var associationParams = new NetworkSecurityGroupAddAssociationParameters(securityGroupName);
                        _testFixture.NetworkClient.NetworkSecurityGroups.AddToRole(serviceName, deploymentName, roleName,
                            associationParams);

                        // assert 1
                        NetworkSecurityGroupGetAssociationResponse response =
                            _testFixture.NetworkClient.NetworkSecurityGroups.GetForRole(serviceName, deploymentName, roleName);
                        Assert.Equal(associationParams.Name, response.Name);

                        // action 2
                        _testFixture.NetworkClient.NetworkSecurityGroups.RemoveFromRole(
                            serviceName,
                            deploymentName,
                            roleName,
                            securityGroupName);

                        // assert 2
                        Assert.Throws<CloudException>(() =>
                            _testFixture.NetworkClient.NetworkSecurityGroups.GetForRole(serviceName, deploymentName, roleName));
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
Example #5
0
        public void AddAndRemoveNetworkSecurityGroupToRole()
        {
            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 storageAccountName = _testFixture.GenerateRandomName().ToLower();

                    // create Network Security Group
                    string securityGroupName     = _testFixture.GenerateRandomNetworkSecurityGroupName();
                    string securityGroupLabel    = _testFixture.GenerateRandomName();
                    string securityGroupLocation = "North Central US";
                    _testFixture.CreateNetworkSecurityGroup(securityGroupName, securityGroupLabel, securityGroupLocation);

                    _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);
                    _testFixture.SetSimpleVirtualNetwork();
                    _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);
                    var deployment = _testFixture.CreatePaaSDeployment(
                        storageAccountName,
                        serviceName,
                        deploymentName,
                        NetworkTestConstants.OneWebOneWorkerPkgFilePath,
                        NetworkTestConstants.VnetOneWebOneWorkerCscfgFilePath,
                        startDeployment: true);

                    try
                    {
                        // action 1
                        var associationParams = new NetworkSecurityGroupAddAssociationParameters(securityGroupName);
                        _testFixture.NetworkClient.NetworkSecurityGroups.AddToRole(serviceName, deploymentName, roleName,
                                                                                   associationParams);

                        // assert 1
                        NetworkSecurityGroupGetAssociationResponse response =
                            _testFixture.NetworkClient.NetworkSecurityGroups.GetForRole(serviceName, deploymentName, roleName);
                        Assert.Equal(associationParams.Name, response.Name);

                        // action 2
                        _testFixture.NetworkClient.NetworkSecurityGroups.RemoveFromRole(
                            serviceName,
                            deploymentName,
                            roleName,
                            securityGroupName);

                        // assert 2
                        Assert.Throws <CloudException>(() =>
                                                       _testFixture.NetworkClient.NetworkSecurityGroups.GetForRole(serviceName, deploymentName, roleName));
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
Example #6
0
        public void TestReservingExistingDeploymentIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    var    managementClient      = _testFixture.ManagementClient;
                    bool   storageAccountCreated = false;
                    bool   hostedServiceCreated  = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName        = string.Format("{0}Prd", serviceName);
                    string reserveIpName         = HttpMockServer.GetAssetName("res", "testres").ToLower();
                    string location          = managementClient.GetDefaultLocation("Storage", "Compute");
                    bool   reservedIpCreated = false;
                    try
                    {
                        _testFixture.CreateStorageAccount(location, storageAccountName, out storageAccountCreated);

                        _testFixture.CreateHostedService(location, serviceName, out hostedServiceCreated);

                        var deployment = _testFixture.CreatePaaSDeployment(storageAccountName, serviceName, deploymentName, NetworkTestConstants.OneWebOneWorkerPkgFilePath, "OneWebOneWorker.cscfg", startDeployment: true);

                        NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                        {
                            Name           = reserveIpName,
                            Label          = "TestLabel",
                            DeploymentName = deploymentName,
                            ServiceName    = serviceName,
                            Location       = location
                        };

                        OperationStatusResponse reserveIpCreate = _testFixture.NetworkClient.ReservedIPs.Create(reservedIpCreatePars);
                        Assert.True(reserveIpCreate.StatusCode == HttpStatusCode.OK);

                        reservedIpCreated = true;
                        NetworkReservedIPGetResponse reserveIpCreationResponse =
                            _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);


                        Assert.True(reserveIpCreationResponse.StatusCode == HttpStatusCode.OK);

                        Assert.True(reserveIpCreationResponse.ServiceName == serviceName);
                        Assert.True(reserveIpCreationResponse.DeploymentName == deploymentName);
                        Assert.True(reserveIpCreationResponse.InUse == true);
                        Assert.True(reserveIpCreationResponse.Address == deployment.VirtualIPAddresses[0].Address);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            _testFixture.StorageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            _testFixture.ComputeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }