public void TestDisassociateReserveIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();
                    var  managementClient      = _testFixture.ManagementClient;
                    bool storageAccountCreated = false;
                    bool hostedServiceCreated  = false;
                    bool reserveIpCreated      = false;

                    string       storageAccountName = HttpMockServer.GetAssetName("teststorage1234", "teststorage").ToLower();
                    string       serviceName        = AZT.TestUtilities.GenerateName("testsvc");
                    string       deploymentName     = string.Format("{0}Prod", serviceName);
                    string       reserveIpName      = HttpMockServer.GetAssetName("rip", "testrip").ToLower();
                    string       location           = managementClient.GetDefaultLocation("Storage", "Compute");
                    const string usWestLocStr       = "West US";
                    try
                    {
                        _testFixture.AssociateReservedIP(
                            usWestLocStr,
                            location,
                            storageAccountName,
                            ref storageAccountCreated,
                            serviceName,
                            deploymentName,
                            reserveIpName,
                            ref hostedServiceCreated,
                            ref reserveIpCreated);

                        Assert.True(storageAccountCreated);
                        Assert.True(hostedServiceCreated);
                        Assert.True(reserveIpCreated);
                        DisassociateReservedIP(_testFixture, reserveIpName, serviceName, deploymentName);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            storageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reserveIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
        public void TestDisassociateReserveIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();
                    var managementClient = _testFixture.ManagementClient;
                    bool storageAccountCreated = false;
                    bool hostedServiceCreated = false;
                    bool reserveIpCreated = false;

                    string storageAccountName = HttpMockServer.GetAssetName("teststorage1234", "teststorage").ToLower();
                    string serviceName = AZT.TestUtilities.GenerateName("testsvc");
                    string deploymentName = string.Format("{0}Prod", serviceName);
                    string reserveIpName = HttpMockServer.GetAssetName("rip", "testrip").ToLower();
                    string location = managementClient.GetDefaultLocation("Storage", "Compute");
                    const string usWestLocStr = "West US";
                    try
                    {
                        _testFixture.AssociateReservedIP(
                            usWestLocStr,
                            location,
                            storageAccountName,
                            ref storageAccountCreated,
                            serviceName,
                            deploymentName,
                            reserveIpName,
                            ref hostedServiceCreated,
                            ref reserveIpCreated);

                        Assert.True(storageAccountCreated);
                        Assert.True(hostedServiceCreated);
                        Assert.True(reserveIpCreated);
                        DisassociateReservedIP(_testFixture, reserveIpName, serviceName, deploymentName);

                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (storageAccountCreated)
                        {
                            storageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reserveIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
        public void TestAddAndRemoveVip()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool hostedServiceCreated = false;
                    bool storageAccountCreated = false;
                    string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName = AZT.TestUtilities.GenerateName("testser");
                    string virtualIPName1 = AZT.TestUtilities.GenerateName("vip1");
                    string virtualIPName2 = AZT.TestUtilities.GenerateName("vip2");
                    string virtualIPName3 = AZT.TestUtilities.GenerateName("vip2");
                    string deploymentName = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    ManagementClient managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                            out storageAccountCreated);
                        Assert.True(storageAccountCreated);

                        // Create a new VM
                        Utilities.CreateAzureVirtualMachine(computeClient, serviceName, deploymentName, storageAccountName,
                            "blob.core.windows.net");

                        // Add and assert vip status
                        OperationStatusResponse virtualIPCreate1 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                            present: true);

                        OperationStatusResponse virtualIPCreate2 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName2);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName2, expectedVipCount: 3,
                            present: true);

                        OperationStatusResponse virtualIPCreate3 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName3);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName3, expectedVipCount: 4,
                            present: true);

                        // Remove and assert vip status
                        OperationStatusResponse virtualIPRemove1 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 3,
                            present: false);

                        OperationStatusResponse virtualIPRemove3 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName3);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName3, expectedVipCount: 2,
                            present: false);

                        OperationStatusResponse virtualIPRemove2 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName2);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName2, expectedVipCount: 1,
                            present: false);
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
        public void TestAdditionalVipLifeCycle()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool hostedServiceCreated = false;
                    bool storageAccountCreated = false;
                    string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName = AZT.TestUtilities.GenerateName("testser");
                    string virtualIPName1 = AZT.TestUtilities.GenerateName("vip1");
                    string deploymentName = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    ManagementClient managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                            out storageAccountCreated);
                        Assert.True(storageAccountCreated);

                        // Create a new VM
                        Utilities.CreateAzureVirtualMachine(computeClient, serviceName, deploymentName,
                            storageAccountName, "blob.core.windows.net");

                        DeploymentGetResponse depRetrieved =
                            computeClient.Deployments.GetByName(serviceName: serviceName, deploymentName: deploymentName);

                        IEnumerable<ConfigurationSet> endpointCfgSets = new List<ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints =
                                    new List<InputEndpoint>
                                    {
                                        new InputEndpoint()
                                        {
                                            LocalPort = 3387,
                                            Name = "RDP2",
                                            Port = 52777,
                                            Protocol = InputEndpointTransportProtocol.Tcp,
                                            EnableDirectServerReturn = false
                                        },
                                    }
                            }
                        };

                        // Update with single endpoint

                        var updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                            storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);

                        computeClient.VirtualMachines.Update(
                        serviceName,
                        deploymentName,
                        depRetrieved.Roles.First().RoleName,
                        updateParams);

                        // Add and assert vip status
                        OperationStatusResponse virtualIPCreate1 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        depRetrieved = Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                            present: true);

                        endpointCfgSets = new List<ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints =
                                    new List<InputEndpoint>
                                    {
                                        new InputEndpoint()
                                        {
                                            LocalPort = 3387,
                                            Name = "RDP2",
                                            Port = 52777,
                                            Protocol = InputEndpointTransportProtocol.Tcp,
                                            EnableDirectServerReturn = false,
                                        },
                                        new InputEndpoint()
                                        {
                                            LocalPort = 3379,
                                            Name = "RDP",
                                            Port = 52728,
                                            Protocol = InputEndpointTransportProtocol.Tcp,
                                            EnableDirectServerReturn = false,
                                            VirtualIPName = virtualIPName1,
                                        }
                                    
                                    }
                            }
                        };

                        updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                            storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);

                        computeClient.VirtualMachines.Update(
                        serviceName,
                        deploymentName,
                        depRetrieved.Roles.First().RoleName,
                        updateParams);

                        var depRetrievedAfterUpdate = Utilities.AssertLogicalVipWithIPPresent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2);

                        endpointCfgSets = new List<ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints =
                                    new List<InputEndpoint>
                                    {
                                        new InputEndpoint()
                                        {
                                            LocalPort = 3387,
                                            Name = "RDP2",
                                            Port = 52777,
                                            Protocol = InputEndpointTransportProtocol.Tcp,
                                            EnableDirectServerReturn = false,
                                        },
                                    }
                            }
                        };

                        updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                            storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);
                        computeClient.VirtualMachines.Update(
                        serviceName,
                        deploymentName,
                        depRetrieved.Roles.First().RoleName,
                        updateParams);

                        depRetrieved = Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient,
                            serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                            present: true);

                        // Remove and assert vip status
                        OperationStatusResponse virtualIPRemove1 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                            deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 3,
                            present: false);
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
        public void TestAssociateDisassociateOnMultivipIaaSDeployment()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool hostedServiceCreated = false;
                    bool storageAccountCreated = false;
                    string storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    ManagementClient managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();
                    List<string> createdRips = new List<string>();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                            out storageAccountCreated);
                        Assert.True(storageAccountCreated);


                        List<string> vipNames = new List<string>()
                        {
                            AZT.TestUtilities.GenerateName("VipA"),
                            AZT.TestUtilities.GenerateName("VipB"),
                            AZT.TestUtilities.GenerateName("VipC"),
                            AZT.TestUtilities.GenerateName("VipD"),
                            AZT.TestUtilities.GenerateName("VipE")
                        };

                        List<string> reservedIPNames = new List<string>()
                        {
                            AZT.TestUtilities.GenerateName("RipA"),
                            AZT.TestUtilities.GenerateName("RipB"),
                            AZT.TestUtilities.GenerateName("RipC"),
                            AZT.TestUtilities.GenerateName("RipD"),
                            AZT.TestUtilities.GenerateName("RipE")
                        };

                        CreateMultivipDeploymentAndAssertSuccess(_testFixture.NetworkClient, computeClient,
                            vipNames, serviceName, deploymentName, storageAccountName, location);

                        // Associate 5 reserved IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName = vipNames[i];
                            NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                            {
                                Name = reserveIpName,
                                Location = location,
                                Label = "SampleReserveIPLabel"
                            };

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

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

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

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName = vipName
                            };
                            OperationStatusResponse responseAssociateRip = _testFixture.NetworkClient.ReservedIPs.Associate(reserveIpName, pars);
                            Assert.True(responseAssociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

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

                            Assert.True(serviceName == receivedReservedIpFromRdfe.ServiceName);
                            Assert.True(receivedReservedIpFromRdfe.InUse == true);
                            Assert.True(deploymentName == receivedReservedIpFromRdfe.DeploymentName);
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(vipName == receivedReservedIpFromRdfe.VirtualIPName);
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(vipAssociated.ReservedIPName == reserveIpName);
                        }

                        // Disassociate the associated IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName = vipNames[i];

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName = vipName
                            };

                            OperationStatusResponse responseDisassociateRip = _testFixture.NetworkClient.ReservedIPs.Disassociate(reserveIpName, pars);
                            Assert.True(responseDisassociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

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

                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.ServiceName));
                            Assert.True(receivedReservedIpFromRdfe.InUse == false);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.DeploymentName));
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.VirtualIPName));
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(string.IsNullOrEmpty(vipAssociated.ReservedIPName));
                        }
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (createdRips.Any())
                        {
                            foreach (var rip in createdRips)
                            {
                                // Clean up created Reserved IPs
                                _testFixture.NetworkClient.ReservedIPs.Delete(rip);
                            }
                        }
                    }
                }
            }
        }
        public void TestReservingExistingDeploymentIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();
                    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
                    {
                        CreateStorageAccount(location, storageClient, storageAccountName, out storageAccountCreated);

                        CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);

                        var deployment = CreatePaaSDeployment(storageAccountName, computeClient, serviceName, deploymentName);

                        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)
                        {
                            storageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public void TestAddAndRemoveVip()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool   hostedServiceCreated  = false;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string virtualIPName1        = AZT.TestUtilities.GenerateName("vip1");
                    string virtualIPName2        = AZT.TestUtilities.GenerateName("vip2");
                    string virtualIPName3        = AZT.TestUtilities.GenerateName("vip2");
                    string deploymentName        = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient    = _testFixture.GetComputeManagementClient();
                    ManagementClient        managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient    = _testFixture.GetStorageManagementClient();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                                                       out storageAccountCreated);
                        Assert.True(storageAccountCreated);

                        // Create a new VM
                        Utilities.CreateAzureVirtualMachine(computeClient, serviceName, deploymentName, storageAccountName,
                                                            "blob.core.windows.net");

                        // Add and assert vip status
                        OperationStatusResponse virtualIPCreate1 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                                                      deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                                                                           present: true);

                        OperationStatusResponse virtualIPCreate2 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                                                      deploymentName: deploymentName, virtualIPName: virtualIPName2);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName2, expectedVipCount: 3,
                                                                           present: true);

                        OperationStatusResponse virtualIPCreate3 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                                                      deploymentName: deploymentName, virtualIPName: virtualIPName3);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName3, expectedVipCount: 4,
                                                                           present: true);

                        // Remove and assert vip status
                        OperationStatusResponse virtualIPRemove1 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                                                         deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 3,
                                                                           present: false);

                        OperationStatusResponse virtualIPRemove3 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                                                         deploymentName: deploymentName, virtualIPName: virtualIPName3);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName3, expectedVipCount: 2,
                                                                           present: false);

                        OperationStatusResponse virtualIPRemove2 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                                                         deploymentName: deploymentName, virtualIPName: virtualIPName2);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName2, expectedVipCount: 1,
                                                                           present: false);
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public void TestAdditionalVipLifeCycle()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool   hostedServiceCreated  = false;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string virtualIPName1        = AZT.TestUtilities.GenerateName("vip1");
                    string deploymentName        = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient    = _testFixture.GetComputeManagementClient();
                    ManagementClient        managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient    = _testFixture.GetStorageManagementClient();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                                                       out storageAccountCreated);
                        Assert.True(storageAccountCreated);

                        // Create a new VM
                        Utilities.CreateAzureVirtualMachine(computeClient, serviceName, deploymentName,
                                                            storageAccountName, "blob.core.windows.net");

                        DeploymentGetResponse depRetrieved =
                            computeClient.Deployments.GetByName(serviceName: serviceName, deploymentName: deploymentName);

                        IEnumerable <ConfigurationSet> endpointCfgSets = new List <ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints       =
                                    new List <InputEndpoint>
                                {
                                    new InputEndpoint()
                                    {
                                        LocalPort = 3387,
                                        Name      = "RDP2",
                                        Port      = 52777,
                                        Protocol  = InputEndpointTransportProtocol.Tcp,
                                        EnableDirectServerReturn = false
                                    },
                                }
                            }
                        };

                        // Update with single endpoint

                        var updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                                                                           storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);

                        computeClient.VirtualMachines.Update(
                            serviceName,
                            deploymentName,
                            depRetrieved.Roles.First().RoleName,
                            updateParams);

                        // Add and assert vip status
                        OperationStatusResponse virtualIPCreate1 =
                            _testFixture.NetworkClient.VirtualIPs.Add(serviceName: serviceName,
                                                                      deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        depRetrieved = Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                                          deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                                                                                          present: true);

                        endpointCfgSets = new List <ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints       =
                                    new List <InputEndpoint>
                                {
                                    new InputEndpoint()
                                    {
                                        LocalPort = 3387,
                                        Name      = "RDP2",
                                        Port      = 52777,
                                        Protocol  = InputEndpointTransportProtocol.Tcp,
                                        EnableDirectServerReturn = false,
                                    },
                                    new InputEndpoint()
                                    {
                                        LocalPort = 3379,
                                        Name      = "RDP",
                                        Port      = 52728,
                                        Protocol  = InputEndpointTransportProtocol.Tcp,
                                        EnableDirectServerReturn = false,
                                        VirtualIPName            = virtualIPName1,
                                    }
                                }
                            }
                        };

                        updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                                                                       storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);

                        computeClient.VirtualMachines.Update(
                            serviceName,
                            deploymentName,
                            depRetrieved.Roles.First().RoleName,
                            updateParams);

                        var depRetrievedAfterUpdate = Utilities.AssertLogicalVipWithIPPresent(computeClient, serviceName: serviceName,
                                                                                              deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2);

                        endpointCfgSets = new List <ConfigurationSet>
                        {
                            new ConfigurationSet
                            {
                                ConfigurationSetType = "NetworkConfiguration",
                                InputEndpoints       =
                                    new List <InputEndpoint>
                                {
                                    new InputEndpoint()
                                    {
                                        LocalPort = 3387,
                                        Name      = "RDP2",
                                        Port      = 52777,
                                        Protocol  = InputEndpointTransportProtocol.Tcp,
                                        EnableDirectServerReturn = false,
                                    },
                                }
                            }
                        };

                        updateParams = Utilities.GetVMUpdateParameters(depRetrieved.Roles.First(),
                                                                       storageAccountName, endpointCfgSets, preserveOriginalConfigSets: false);
                        computeClient.VirtualMachines.Update(
                            serviceName,
                            deploymentName,
                            depRetrieved.Roles.First().RoleName,
                            updateParams);

                        depRetrieved = Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient,
                                                                                          serviceName: serviceName,
                                                                                          deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 2,
                                                                                          present: true);

                        // Remove and assert vip status
                        OperationStatusResponse virtualIPRemove1 =
                            _testFixture.NetworkClient.VirtualIPs.Remove(serviceName: serviceName,
                                                                         deploymentName: deploymentName, virtualIPName: virtualIPName1);

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

                        Utilities.AssertLogicalVipWithoutIPPresentOrAbsent(computeClient, serviceName: serviceName,
                                                                           deploymentName: deploymentName, virtualIPName: virtualIPName1, expectedVipCount: 3,
                                                                           present: false);
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public void TestAssociateDisassociateOnMultivipIaaSDeployment()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    bool   hostedServiceCreated  = false;
                    bool   storageAccountCreated = false;
                    string storageAccountName    = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                    string serviceName           = AZT.TestUtilities.GenerateName("testser");
                    string deploymentName        = AZT.TestUtilities.GenerateName("dep");

                    ComputeManagementClient computeClient    = _testFixture.GetComputeManagementClient();
                    ManagementClient        managementClient = _testFixture.ManagementClient;
                    StorageManagementClient storageClient    = _testFixture.GetStorageManagementClient();
                    List <string>           createdRips      = new List <string>();

                    try
                    {
                        string location = Utilities.GetTestLocation(managementClient);
                        Assert.True(!string.IsNullOrEmpty(location));

                        // Create hosted service
                        Utilities.CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);
                        Assert.True(hostedServiceCreated);

                        // Create storage account
                        storageAccountName = HttpMockServer.GetAssetName("tststr1234", "tststr").ToLower();
                        Utilities.CreateStorageAccount(location, storageClient, storageAccountName,
                                                       out storageAccountCreated);
                        Assert.True(storageAccountCreated);


                        List <string> vipNames = new List <string>()
                        {
                            AZT.TestUtilities.GenerateName("VipA"),
                            AZT.TestUtilities.GenerateName("VipB"),
                            AZT.TestUtilities.GenerateName("VipC"),
                            AZT.TestUtilities.GenerateName("VipD"),
                            AZT.TestUtilities.GenerateName("VipE")
                        };

                        List <string> reservedIPNames = new List <string>()
                        {
                            AZT.TestUtilities.GenerateName("RipA"),
                            AZT.TestUtilities.GenerateName("RipB"),
                            AZT.TestUtilities.GenerateName("RipC"),
                            AZT.TestUtilities.GenerateName("RipD"),
                            AZT.TestUtilities.GenerateName("RipE")
                        };

                        CreateMultivipDeploymentAndAssertSuccess(_testFixture.NetworkClient, computeClient,
                                                                 vipNames, serviceName, deploymentName, storageAccountName, location);

                        // Associate 5 reserved IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName       = vipNames[i];
                            NetworkReservedIPCreateParameters reservedIpCreatePars = new NetworkReservedIPCreateParameters
                            {
                                Name     = reserveIpName,
                                Location = location,
                                Label    = "SampleReserveIPLabel"
                            };

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

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

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

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName    = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName  = vipName
                            };
                            OperationStatusResponse responseAssociateRip = _testFixture.NetworkClient.ReservedIPs.Associate(reserveIpName, pars);
                            Assert.True(responseAssociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

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

                            Assert.True(serviceName == receivedReservedIpFromRdfe.ServiceName);
                            Assert.True(receivedReservedIpFromRdfe.InUse == true);
                            Assert.True(deploymentName == receivedReservedIpFromRdfe.DeploymentName);
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(vipName == receivedReservedIpFromRdfe.VirtualIPName);
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(vipAssociated.ReservedIPName == reserveIpName);
                        }

                        // Disassociate the associated IPs
                        for (int i = 0; i < 5; i++)
                        {
                            string reserveIpName = reservedIPNames[i];
                            string vipName       = vipNames[i];

                            NetworkReservedIPMobilityParameters pars = new NetworkReservedIPMobilityParameters
                            {
                                ServiceName    = serviceName,
                                DeploymentName = deploymentName,
                                VirtualIPName  = vipName
                            };

                            OperationStatusResponse responseDisassociateRip = _testFixture.NetworkClient.ReservedIPs.Disassociate(reserveIpName, pars);
                            Assert.True(responseDisassociateRip.StatusCode == HttpStatusCode.OK);
                            DeploymentGetResponse deploymentResponse =
                                computeClient.Deployments.GetByName(serviceName: serviceName,
                                                                    deploymentName: deploymentName);

                            NetworkReservedIPGetResponse receivedReservedIpFromRdfe =
                                _testFixture.NetworkClient.ReservedIPs.Get(reserveIpName);

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

                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.ServiceName));
                            Assert.True(receivedReservedIpFromRdfe.InUse == false);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.DeploymentName));
                            Assert.True(reserveIpName == receivedReservedIpFromRdfe.Name);
                            Assert.True(string.IsNullOrEmpty(receivedReservedIpFromRdfe.VirtualIPName));
                            var vipAssociated = deploymentResponse.VirtualIPAddresses.FirstOrDefault(vip => vip.Name == vipName);
                            Assert.NotNull(vipAssociated);
                            Assert.True(string.IsNullOrEmpty(vipAssociated.ReservedIPName));
                        }
                    }
                    finally
                    {
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (createdRips.Any())
                        {
                            foreach (var rip in createdRips)
                            {
                                // Clean up created Reserved IPs
                                _testFixture.NetworkClient.ReservedIPs.Delete(rip);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public void TestReservingExistingDeploymentIP()
        {
            using (var undoContext = AZT.UndoContext.Current)
            {
                undoContext.Start();
                using (NetworkTestBase _testFixture = new NetworkTestBase())
                {
                    ComputeManagementClient computeClient = _testFixture.GetComputeManagementClient();
                    StorageManagementClient storageClient = _testFixture.GetStorageManagementClient();
                    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
                    {
                        CreateStorageAccount(location, storageClient, storageAccountName, out storageAccountCreated);

                        CreateHostedService(location, computeClient, serviceName, out hostedServiceCreated);

                        var deployment = CreatePaaSDeployment(storageAccountName, computeClient, serviceName, deploymentName);

                        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)
                        {
                            storageClient.StorageAccounts.Delete(storageAccountName);
                        }
                        if (hostedServiceCreated)
                        {
                            computeClient.HostedServices.DeleteAll(serviceName);
                        }
                        if (reservedIpCreated)
                        {
                            _testFixture.NetworkClient.ReservedIPs.Delete(reserveIpName);
                        }
                    }
                }
            }
        }