Пример #1
0
        public async Task ValidateSingleVnetWithNoSubnetsGetsNewDefaultSubet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET4"));
            AsmToArmGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmnet"));

            templateGenerator.UpdateArtifacts(artifacts);

            JObject templateJson = templateGenerator.GetTemplate();

            // Validate VNETs
            var vnets = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworks");

            Assert.AreEqual(1, vnets.Count());
            Assert.AreEqual("asmnet-vnet", vnets.First()["name"].Value <string>());
            Assert.AreEqual("10.0.0.0/20", vnets.First()["properties"]["addressSpace"]["addressPrefixes"][0].Value <string>());

            // Validate subnets
            var subnets = vnets.First()["properties"]["subnets"];

            Assert.AreEqual(1, subnets.Count());
            Assert.AreEqual("Subnet1", subnets[0]["name"].Value <string>());
            Assert.AreEqual("10.0.0.0/20", subnets[0]["properties"]["addressPrefix"].Value <string>());
        }
Пример #2
0
        public async Task ValidateVMInExistingArmSubnetId()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            TemplateGenerator  templateGenerator                 = TestHelper.SetupTemplateGenerator(azureContextUSCommercial);
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3"));

            var artifacts = new AsmArtifacts();

            artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);
            TestHelper.SetTargetSubnets(artifacts);

            TemplateResult templateReault = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory);

            JObject templateJson = templateReault.GenerateTemplate();

            // Validate VM
            var vmResource = templateJson["resources"].Where(
                j => j["type"].Value <string>() == "Microsoft.Compute/virtualMachines").Single();

            Assert.AreEqual("VM3-vm", vmResource["name"].Value <string>());
            StringAssert.Contains(vmResource["properties"]["networkProfile"]["networkInterfaces"][0]["id"].Value <string>(),
                                  "'" + ArmConst.ProviderNetworkInterfaces + "VM3-nic'");

            // Validate NIC
            var nicResource = templateJson["resources"].Where(
                j => j["type"].Value <string>() == "Microsoft.Network/networkInterfaces").Single();

            Assert.AreEqual("VM3-nic", nicResource["name"].Value <string>());
            StringAssert.Contains(nicResource["properties"]["ipConfigurations"][0]["properties"]["subnet"]["id"].Value <string>(),
                                  "/subscriptions/22222222-2222-2222-2222-222222222222/resourceGroups/dummygroup-rg/providers/Microsoft.Network/virtualNetworks/DummyVNet/subnets/subnet01");
        }
Пример #3
0
        public async Task ValidateVMInVnetButNotInTargetVNet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            TemplateGenerator  templateGenerator                 = TestHelper.SetupTemplateGenerator(azureContextUSCommercial);
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3"));

            var artifacts = new AsmArtifacts();

            artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);

            bool exceptionThrown = false;

            try
            {
                TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory);
            }
            catch (Exception exc)
            {
                if (exc.GetType() == typeof(ArgumentException) && exc.Message == "Target Virtual Network for ASM Virtual Machine 'VM3' must be specified.")
                {
                    exceptionThrown = true;
                }
            }

            Assert.IsFalse(!exceptionThrown, "Did not receive Null Target Virtual Network Argument Exception");
        }
Пример #4
0
        public async Task ValidateVMInVnetButNotInTargetVNet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3"));
            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            //artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);

            templateGenerator.UpdateArtifacts(artifacts);

            bool messageExists = false;

            foreach (MigAzGeneratorAlert alert in templateGenerator.Alerts)
            {
                if (alert.Message.Contains("Target Virtual Network for ASM Virtual Machine 'VM3' must be specified."))
                {
                    messageExists = true;
                    break;
                }
            }

            Assert.IsFalse(!messageExists, "Did not receive Null Target Virtual Network Argument Exception");
        }
Пример #5
0
        public async Task ValidateSingleVnetWithNsgAndRT()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET2"));
            AsmToArmGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmtest"));
            artifacts.NetworkSecurityGroups.Add(await azureContextUSCommercialRetriever.GetAzureAsmNetworkSecurityGroup("asmnsg"));

            templateGenerator.UpdateArtifacts(artifacts);

            JObject templateJson = templateGenerator.GetTemplate();

            // Validate NSG
            var nsgs = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/networkSecurityGroups");

            Assert.AreEqual(1, nsgs.Count());
            Assert.AreEqual("asmnsg-nsg", nsgs.First()["name"].Value <string>());

            // Validate NSG rules
            JArray rules = (JArray)nsgs.First()["properties"]["securityRules"];

            Assert.AreEqual(2, rules.Count());
            Assert.AreEqual("Enable-Internal-DNS", rules[0]["name"].Value <string>());
            Assert.AreEqual("Port-7777-rule", rules[1]["name"].Value <string>());

            // Validate RouteTable
            var rt = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/routeTables");

            Assert.AreEqual(1, rt.Count());
            Assert.AreEqual("asmrt", rt.First()["name"].Value <string>());

            // Validate Routes
            JArray routes = (JArray)rt.First()["properties"]["routes"];

            Assert.AreEqual(1, routes.Count());
            Assert.AreEqual("all-traffic-to-fw", routes[0]["name"].Value <string>());

            // Validate VNETs
            var vnets = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworks");

            Assert.AreEqual(1, vnets.Count());
            Assert.AreEqual("asmtest-vnet", vnets.First()["name"].Value <string>());

            // Validate subnets
            var subnets = vnets.First()["properties"]["subnets"];

            Assert.AreEqual(1, subnets.Count());
            Assert.AreEqual("Subnet-1", subnets.First()["name"].Value <string>());
            StringAssert.Contains(subnets.First()["properties"]["networkSecurityGroup"]["id"].Value <string>(), "networkSecurityGroups/asmnsg");
            StringAssert.Contains(subnets.First()["properties"]["routeTable"]["id"].Value <string>(), "routeTables/asmrt");
        }
Пример #6
0
        public async Task ValidateSingleVnetWithExpressRouteGateway()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET3"));
            AsmToArmGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("vnet3"));

            templateGenerator.UpdateArtifacts(artifacts);

            JObject templateJson = templateGenerator.GetTemplate();

            // Validate VNETs
            var vnets = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworks");

            Assert.AreEqual(1, vnets.Count());
            Assert.AreEqual("vnet3-vnet", vnets.First()["name"].Value <string>());

            // Validate subnets
            var subnets = vnets.First()["properties"]["subnets"];

            Assert.AreEqual(2, subnets.Count());

            // Validate gateway
            var gw = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworkGateways");

            Assert.AreEqual(1, gw.Count());
            Assert.AreEqual("vnet3-gw", gw.First()["name"].Value <string>());
            Assert.AreEqual("ExpressRoute", gw.First()["properties"]["gatewayType"].Value <string>());

            // Validate no local network
            var localGw = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/localNetworkGateways");

            Assert.AreEqual(0, localGw.Count());

            // Validate connection
            var conn = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/connections");

            Assert.AreEqual(1, conn.Count());
            Assert.AreEqual("vnet3-gw-localsite-connection", conn.First()["name"].Value <string>());
            Assert.AreEqual("ExpressRoute", conn.First()["properties"]["connectionType"].Value <string>());
            Assert.IsNotNull(conn.First()["properties"]["peer"]["id"].Value <string>());

            // Validate message
            Assert.AreEqual(1, templateGenerator.Alerts.Count);
            StringAssert.Contains(templateGenerator.Alerts[0].Message, "ExpressRoute");
        }
Пример #7
0
        public async Task ValidateComplexSingleVnet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET1"));
            AsmToArmGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("10.2.0.0"));

            templateGenerator.UpdateArtifacts(artifacts);

            JObject templateJson = templateGenerator.GetTemplate();

            // Validate VNETs
            var vnets = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworks");

            Assert.AreEqual(1, vnets.Count());
            Assert.AreEqual("10.2.0.0-vnet", vnets.First()["name"].Value <string>());

            // Validate subnets
            var subnets = vnets.First()["properties"]["subnets"];

            Assert.AreEqual(8, subnets.Count());

            // Validate gateway
            var gw = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworkGateways");

            Assert.AreEqual(1, gw.Count());
            Assert.AreEqual("10.2.0.0-gw", gw.First()["name"].Value <string>());

            var localGw = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/localNetworkGateways");

            Assert.AreEqual(2, localGw.Count());
            Assert.AreEqual("MOBILEDATACENTER-LocalGateway", localGw.First()["name"].Value <string>());
            Assert.AreEqual("EastUSNet-LocalGateway", localGw.Last()["name"].Value <string>());

            var pips = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/publicIPAddresses");

            Assert.AreEqual(1, pips.Count());
            Assert.AreEqual("10.2.0.0-gw-pip", pips.First()["name"].Value <string>());
            Assert.AreEqual("Dynamic", pips.First()["properties"]["publicIPAllocationMethod"].Value <string>());
        }
Пример #8
0
        private async Task <JObject> GenerateSingleVMTemplate()

        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            TemplateGenerator  templateGenerator                 = TestHelper.SetupTemplateGenerator(azureContextUSCommercial);
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM1"));

            var artifacts = new AsmArtifacts();

            artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);
            TestHelper.SetTargetSubnets(artifacts);

            TemplateResult tempalteResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory);

            return(tempalteResult.GenerateTemplate());
        }
Пример #9
0
        private async Task <JObject> GenerateSingleVMTemplate()

        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM1"));
            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            //artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);
            TestHelper.SetTargetSubnets(artifacts);

            templateGenerator.UpdateArtifacts(artifacts);

            return(templateGenerator.GetTemplate());
        }
Пример #10
0
        public async Task ValidateDiskNamescapeChangeAcrossAzureEnvironments()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            AzureContext       azureContextUSGovernment          = TestHelper.SetupAzureContext(AzureEnvironment.AzureUSGovernment);
            TemplateGenerator  templateGenerator                 = TestHelper.SetupTemplateGenerator(azureContextUSCommercial);
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3"));
            FakeAzureRetriever azureContextUSGovernmentRetriever = (FakeAzureRetriever)azureContextUSGovernment.AzureRetriever;

            azureContextUSGovernmentRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\i"));

            var artifacts = new AsmArtifacts();

            artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);

            artifacts.VirtualMachines[0].OSVirtualHardDisk.TargetStorageAccount = await azureContextUSGovernmentRetriever.GetAzureAsmStorageAccount("targetstorage");

            Assert.AreEqual(artifacts.VirtualMachines[0].OSVirtualHardDisk.MediaLink, "https://mystorage.blob.core.windows.net/vhds/mydisk.vhd");
            Assert.AreEqual(artifacts.VirtualMachines[0].OSVirtualHardDisk.TargetMediaLink, "https://targetstoragev2.blob.core.usgovcloudapi.net/vhds/mydisk.vhd");
        }
Пример #11
0
        public async Task ValidateSingleStorageAccount()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\Storage1"));
            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            // todo artifacts.StorageAccounts.Add(await azureContextUSCommercialRetriever.GetAzureAsmStorageAccount("mystorage"));
            templateGenerator.UpdateArtifacts(artifacts);

            JObject templateJson = templateGenerator.GetTemplate();

            Assert.AreEqual(1, templateJson["resources"].Children().Count());
            var resource = templateJson["resources"].Single();

            Assert.AreEqual("Microsoft.Storage/storageAccounts", resource["type"].Value <string>());
            Assert.AreEqual("mystoragev2", resource["name"].Value <string>());
            Assert.AreEqual((await azureContextUSCommercialRetriever.GetAzureASMLocations())[0].Name, resource["location"].Value <string>());
            Assert.AreEqual("Standard_LRS", resource["properties"]["accountType"].Value <string>());
        }
Пример #12
0
        public async Task ValidateSingleVMWithDataDisksNotInVnet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            TemplateGenerator  templateGenerator                 = TestHelper.SetupTemplateGenerator(azureContextUSCommercial);
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM2"));

            var artifacts = new AsmArtifacts();

            artifacts.VirtualMachines.Add((await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0]);
            TestHelper.SetTargetSubnets(artifacts);

            TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory);

            JObject templateJson = templateResult.GenerateTemplate();

            // Validate VNET
            var vnets = templateJson["resources"].Children().Where(
                r => r["type"].Value <string>() == "Microsoft.Network/virtualNetworks");

            Assert.AreEqual(0, vnets.Count());

            // Validate VM
            var vmResource = templateJson["resources"].Where(
                j => j["type"].Value <string>() == "Microsoft.Compute/virtualMachines").Single();

            Assert.AreEqual("myasmvm-vm", vmResource["name"].Value <string>());

            // Validate disks
            var dataDisks = (JArray)vmResource["properties"]["storageProfile"]["dataDisks"];

            Assert.AreEqual(2, dataDisks.Count);
            Assert.AreEqual("Disk1", dataDisks[0]["name"].Value <string>());
            Assert.AreEqual("Disk2", dataDisks[1]["name"].Value <string>());
        }