Example #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>());
        }
Example #2
0
        private ExportArtifacts GetAsmArtifacts()
        {
            ExportArtifacts artifacts = new ExportArtifacts();

            foreach (TreeNode selectedNode in _SelectedNodes)
            {
                Type tagType = selectedNode.Tag.GetType();
                if (tagType == typeof(Azure.Asm.NetworkSecurityGroup) || tagType == typeof(Azure.Arm.NetworkSecurityGroup))
                {
                    artifacts.NetworkSecurityGroups.Add((INetworkSecurityGroup)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.Asm.VirtualNetwork) || tagType == typeof(Azure.Arm.VirtualNetwork))
                {
                    artifacts.VirtualNetworks.Add((IVirtualNetwork)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.Asm.StorageAccount) || tagType == typeof(Azure.Arm.StorageAccount))
                {
                    artifacts.StorageAccounts.Add((IStorageAccount)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.Asm.VirtualMachine) || tagType == typeof(Azure.Arm.VirtualMachine))
                {
                    artifacts.VirtualMachines.Add((IVirtualMachine)selectedNode.Tag);
                }
            }

            return(artifacts);
        }
Example #3
0
        public async Task ValidateVMInExistingArmSubnetId()
        {
            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]);
            TestHelper.SetTargetSubnets(artifacts);

            templateGenerator.UpdateArtifacts(artifacts);
            JObject templateJson = templateGenerator.GetTemplate();

            // 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");
        }
Example #4
0
        private void GetExportArtifactsRecursive(TreeNode parentTreeNode, ref ExportArtifacts exportArtifacts)
        {
            foreach (TreeNode selectedNode in parentTreeNode.Nodes)
            {
                Type tagType = selectedNode.Tag.GetType();

                if (tagType == typeof(Azure.MigrationTarget.VirtualNetwork))
                {
                    exportArtifacts.VirtualNetworks.Add((Azure.MigrationTarget.VirtualNetwork)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.StorageAccount))
                {
                    exportArtifacts.StorageAccounts.Add((Azure.MigrationTarget.StorageAccount)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.NetworkSecurityGroup))
                {
                    exportArtifacts.NetworkSecurityGroups.Add((Azure.MigrationTarget.NetworkSecurityGroup)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.VirtualMachine))
                {
                    exportArtifacts.VirtualMachines.Add((Azure.MigrationTarget.VirtualMachine)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.LoadBalancer))
                {
                    exportArtifacts.LoadBalancers.Add((Azure.MigrationTarget.LoadBalancer)selectedNode.Tag);
                }
            }

            foreach (TreeNode treeNode in parentTreeNode.Nodes)
            {
                GetExportArtifactsRecursive(treeNode, ref exportArtifacts);
            }
        }
Example #5
0
        public async Task LoadARMObjectsFromSampleOfflineFile()
        {
            string       restResponseFile         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\NewTest1\\ArmObjectsOffline.json");
            AzureContext azureContextUSCommercial = await TestHelper.SetupAzureContext(restResponseFile);

            await azureContextUSCommercial.AzureSubscription.BindArmResources();

            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.ResourceGroup = await TestHelper.GetTargetResourceGroup(azureContextUSCommercial);

            //foreach (Azure.MigrationTarget.StorageAccount s in azureContextUSCommercial.AzureRetriever.ArmTargetStorageAccounts)
            //{
            //    artifacts.StorageAccounts.Add(s);
            //}

            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsFalse(templateGenerator.HasErrors, "Template Generation cannot occur as the are error(s).");

            await templateGenerator.GenerateStreams();

            JObject templateJson = JObject.Parse(await templateGenerator.GetTemplateString());

            Assert.AreEqual(0, templateJson["resources"].Children().Count());

            //var resource = templateJson["resources"].First();
            //Assert.AreEqual("Microsoft.Storage/storageAccounts", resource["type"].Value<string>());
            //Assert.AreEqual("manageddiskdiag857v2", resource["name"].Value<string>());
            //Assert.AreEqual("[resourceGroup().location]", resource["location"].Value<string>());
            //Assert.AreEqual("Standard_LRS", resource["properties"]["accountType"].Value<string>());
        }
Example #6
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");
        }
Example #7
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");
        }
Example #8
0
        private void GetExportArtifactsRecursive(TreeNode parentTreeNode, ref ExportArtifacts exportArtifacts)
        {
            foreach (TreeNode selectedNode in parentTreeNode.Nodes)
            {
                Type tagType = selectedNode.Tag.GetType();

                if (tagType == typeof(Azure.MigrationTarget.VirtualNetwork))
                {
                    exportArtifacts.VirtualNetworks.Add((Azure.MigrationTarget.VirtualNetwork)selectedNode.Tag);
                }
                //else if (tagType == typeof(Azure.MigrationTarget.StorageAccount))
                //{
                //    exportArtifacts.StorageAccounts.Add((Azure.MigrationTarget.StorageAccount)selectedNode.Tag);
                //}
                else if (tagType == typeof(Azure.MigrationTarget.NetworkSecurityGroup))
                {
                    exportArtifacts.NetworkSecurityGroups.Add((Azure.MigrationTarget.NetworkSecurityGroup)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.AvailabilitySet))
                {
                    exportArtifacts.AvailablitySets.Add((Azure.MigrationTarget.AvailabilitySet)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.VirtualMachine))
                {
                    exportArtifacts.VirtualMachines.Add((Azure.MigrationTarget.VirtualMachine)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.LoadBalancer))
                {
                    exportArtifacts.LoadBalancers.Add((Azure.MigrationTarget.LoadBalancer)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.PublicIp))
                {
                    exportArtifacts.PublicIPs.Add((Azure.MigrationTarget.PublicIp)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.Disk))
                {
                    Azure.MigrationTarget.Disk targetDisk = (Azure.MigrationTarget.Disk)selectedNode.Tag;
                    if (targetDisk.TargetStorage != null && targetDisk.TargetStorage.GetType() == typeof(Azure.MigrationTarget.ManagedDiskStorage))
                    {
                        // We are only adding the Target Disk into the Export Artifacts as a Disk object if the Target Disk is targeted as a Managed Disk.
                        // Otherwise, it is a Classic Disk and will be generated as part of the Virtual Machine JSON (does not have a stand alone Disk object).
                        exportArtifacts.Disks.Add((Azure.MigrationTarget.Disk)selectedNode.Tag);
                    }
                }
                else if (tagType == typeof(Azure.MigrationTarget.NetworkInterface))
                {
                    exportArtifacts.NetworkInterfaces.Add((Azure.MigrationTarget.NetworkInterface)selectedNode.Tag);
                }
                else if (tagType == typeof(Azure.MigrationTarget.RouteTable))
                {
                    exportArtifacts.RouteTables.Add((Azure.MigrationTarget.RouteTable)selectedNode.Tag);
                }
            }

            foreach (TreeNode treeNode in parentTreeNode.Nodes)
            {
                GetExportArtifactsRecursive(treeNode, ref exportArtifacts);
            }
        }
Example #9
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");
        }
Example #10
0
        public async Task OfflineUITargetTreeViewTest()
        {
            string       restResponseFile         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\NewTest1\\temp.json");
            AzureContext azureContextUSCommercial = await TestHelper.SetupAzureContext(Core.Interface.AzureEnvironment.AzureCloud, restResponseFile);

            await azureContextUSCommercial.AzureSubscription.BindArmResources();

            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.ResourceGroup = await TestHelper.GetTargetResourceGroup(azureContextUSCommercial);

            TargetTreeView targetTreeView = new TargetTreeView();

            await targetTreeView.AddMigrationTargetToTargetTree(azureContextUSCommercial.AzureSubscription.ArmTargetRouteTables[0]);

            targetTreeView.SeekAlertSource(azureContextUSCommercial.AzureSubscription.ArmTargetRouteTables[0]);
            Assert.IsTrue(targetTreeView.SelectedNode != null, "Selected Node is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag != null, "Selected Node Tag is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag.GetType() == azureContextUSCommercial.AzureSubscription.ArmTargetRouteTables[0].GetType(), "Object type mismatch");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag == azureContextUSCommercial.AzureSubscription.ArmTargetRouteTables[0], "Not the correct object");

            await targetTreeView.AddMigrationTargetToTargetTree(azureContextUSCommercial.AzureSubscription.ArmTargetVirtualNetworks[0]);

            targetTreeView.SeekAlertSource(azureContextUSCommercial.AzureSubscription.ArmTargetVirtualNetworks[0]);
            Assert.IsTrue(targetTreeView.SelectedNode != null, "Selected Node is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag != null, "Selected Node Tag is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag.GetType() == azureContextUSCommercial.AzureSubscription.ArmTargetVirtualNetworks[0].GetType(), "Object type mismatch");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag == azureContextUSCommercial.AzureSubscription.ArmTargetVirtualNetworks[0], "Not the correct object");

            await targetTreeView.AddMigrationTargetToTargetTree(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkInterfaces[0]);

            targetTreeView.SeekAlertSource(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkInterfaces[0]);
            Assert.IsTrue(targetTreeView.SelectedNode != null, "Selected Node is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag != null, "Selected Node Tag is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag.GetType() == azureContextUSCommercial.AzureSubscription.ArmTargetNetworkInterfaces[0].GetType(), "Object type mismatch");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag == azureContextUSCommercial.AzureSubscription.ArmTargetNetworkInterfaces[0], "Not the correct object");

            await targetTreeView.AddMigrationTargetToTargetTree(azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[0]);

            targetTreeView.SeekAlertSource(azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[0]);
            Assert.IsTrue(targetTreeView.SelectedNode != null, "Selected Node is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag != null, "Selected Node Tag is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag.GetType() == azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[0].GetType(), "Object type mismatch");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag == azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[0], "Not the correct object");

            await targetTreeView.AddMigrationTargetToTargetTree(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkSecurityGroups[0]);

            targetTreeView.SeekAlertSource(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkSecurityGroups[0]);
            Assert.IsTrue(targetTreeView.SelectedNode != null, "Selected Node is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag != null, "Selected Node Tag is null");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag.GetType() == azureContextUSCommercial.AzureSubscription.ArmTargetNetworkSecurityGroups[0].GetType(), "Object type mismatch");
            Assert.IsTrue(targetTreeView.SelectedNode.Tag == azureContextUSCommercial.AzureSubscription.ArmTargetNetworkSecurityGroups[0], "Not the correct object");
        }
Example #11
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>());
        }
Example #12
0
        public ExportArtifacts GetExportArtifacts()
        {
            ExportArtifacts exportArtifacts = new ExportArtifacts();

            if (this.Nodes.Count == 1 && this.Nodes[0].Tag != null)
            {
                exportArtifacts.ResourceGroup = (MigrationTarget.ResourceGroup) this.Nodes[0].Tag;
            }

            foreach (TreeNode treeNode in treeTargetARM.Nodes)
            {
                GetExportArtifactsRecursive(treeNode, ref exportArtifacts);
            }

            return(exportArtifacts);
        }
Example #13
0
        internal static void SetTargetSubnets(ExportArtifacts artifacts)
        {
            string  x = "{\r\n  \"name\": \"DummyVNet\",\r\n  \"id\": \"/subscriptions/" + SubscriptionId + "/resourceGroups/dummygroup-rg/providers/Microsoft.Network/virtualNetworks/DummyVNet\",\r\n  \"etag\": \"W/\\\"1fa3c5bd-1cf4-4bb9-9839-96ece3b3776d\\\"\",\r\n  \"type\": \"Microsoft.Network/virtualNetworks\",\r\n  \"location\": \"westus\",\r\n  \"properties\": {\r\n    \"provisioningState\": \"Succeeded\",\r\n    \"resourceGuid\": \"b8b6b69d-2480-436a-886b-ac3ef4061253\",\r\n    \"addressSpace\": {\r\n      \"addressPrefixes\": [\r\n        \"10.0.0.0/16\"\r\n      ]\r\n    },\r\n    \"subnets\": [\r\n      {\r\n        \"name\": \"subnet01\",\r\n        \"id\": \"/subscriptions/" + SubscriptionId + "/resourceGroups/dummygroup-rg/providers/Microsoft.Network/virtualNetworks/DummyVNet/subnets/subnet01\",\r\n        \"etag\": \"W/\\\"1f53c5be-1cf4-4bb9-9839-96ece3b3776d\\\"\",\r\n        \"properties\": {\r\n          \"provisioningState\": \"Succeeded\",\r\n          \"addressPrefix\": \"10.0.0.0/24\",\r\n\"applicationGatewayIPConfigurations\": [\r\n            {\r\n              \"id\": \"/subscriptions/" + SubscriptionId + "/resourceGroups/dummygroup-rg/providers/Microsoft.Network/applicationGateways/appgwtest/gatewayIPConfigurations/gatewayIP01\"\r\n            }\r\n          ]\r\n        }\r\n      }\r\n    ]\r\n  }\r\n}";
            JObject webRequestResultJson = JObject.Parse(x);

            // Azure.Arm.VirtualNetwork armVirtualNetwork = new Azure.Arm.VirtualNetwork(webRequestResultJson);

            // todo??
            //foreach (Azure.Asm.VirtualMachine asmVirtualMachine in artifacts.VirtualMachines)
            //{
            //    if (asmVirtualMachine.TargetVirtualNetwork == null)
            //        asmVirtualMachine.TargetVirtualNetwork = armVirtualNetwork;

            //    if (asmVirtualMachine.TargetSubnet == null)
            //        asmVirtualMachine.TargetSubnet = armVirtualNetwork.Subnets[0];
            //}
        }
Example #14
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());
        }
Example #15
0
        public async Task LoadASMObjectsFromSampleOfflineFile()
        {
            string           restResponseFile         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\NewTest1\\AsmObjectsOffline.json");
            TargetSettings   targetSettings           = new FakeSettingsProvider().GetTargetSettings();
            AzureEnvironment azureEnvironment         = AzureEnvironment.GetAzureEnvironments()[0];
            AzureContext     azureContextUSCommercial = await TestHelper.SetupAzureContext(azureEnvironment, restResponseFile);

            await azureContextUSCommercial.AzureSubscription.InitializeChildrenAsync(true);

            await azureContextUSCommercial.AzureSubscription.BindAsmResources(targetSettings);

            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts(azureContextUSCommercial.AzureSubscription);

            artifacts.ResourceGroup = await TestHelper.GetTargetResourceGroup(azureContextUSCommercial);

            //foreach (Azure.MigrationTarget.StorageAccount s in azureContextUSCommercial.AzureRetriever.AsmTargetStorageAccounts)
            //{
            //    artifacts.StorageAccounts.Add(s);
            //}
            await artifacts.ValidateAzureResources();

            Assert.IsFalse(artifacts.HasErrors, "Template Generation cannot occur as the are error(s).");

            templateGenerator.ExportArtifacts = artifacts;
            await templateGenerator.GenerateStreams();

            JObject templateJson = JObject.Parse(await templateGenerator.GetTemplateString());

            Assert.AreEqual(0, templateJson["resources"].Children().Count());

            //var resource = templateJson["resources"].Single();
            //Assert.AreEqual("Microsoft.Storage/storageAccounts", resource["type"].Value<string>());
            //Assert.AreEqual("asmtest8155v2", resource["name"].Value<string>());
            //Assert.AreEqual("[resourceGroup().location]", resource["location"].Value<string>());
            //Assert.AreEqual("Standard_LRS", resource["properties"]["accountType"].Value<string>());
        }
Example #16
0
        public async Task ValidateDiskNamescapeChangeAcrossAzureEnvironments()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            AzureContext       azureContextUSGovernment          = TestHelper.SetupAzureContext(AzureEnvironment.AzureUSGovernment);
            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"));
            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            Azure.Asm.VirtualMachine asmVirtualMachine = (Azure.Asm.VirtualMachine)(await azureContextUSCommercialRetriever.GetAzureAsmCloudServices())[0].VirtualMachines[0];

            // todo asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount = await azureContextUSGovernmentRetriever.GetAzureAsmStorageAccount("targetstorage");

            //artifacts.VirtualMachines.Add(asmVirtualMachine);

            Assert.AreEqual(asmVirtualMachine.OSVirtualHardDisk.MediaLink, "https://mystorage.blob.core.windows.net/vhds/mydisk.vhd");
            //Assert.AreEqual(asmVirtualMachine.OSVirtualHardDisk.TargetMediaLink, "https://targetstoragev2.blob.core.usgovcloudapi.net/vhds/mydisk.vhd");
        }
Example #17
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>());
        }
Example #18
0
        public async Task ValidateSingleVMWithDataDisksNotInVnet()
        {
            AzureContext       azureContextUSCommercial          = TestHelper.SetupAzureContext();
            FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever;

            azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM2"));
            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);

            JObject templateJson = templateGenerator.GetTemplate();

            // 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>());
        }
Example #19
0
        public async Task LoadARMObjectsFromSampleOfflineFile2()
        {
            string       restResponseFile         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\NewTest1\\temp.json");
            AzureContext azureContextUSCommercial = await TestHelper.SetupAzureContext(Core.Interface.AzureEnvironment.AzureCloud, restResponseFile);

            await azureContextUSCommercial.AzureSubscription.BindArmResources();

            AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial);

            var artifacts = new ExportArtifacts();

            artifacts.ResourceGroup = await TestHelper.GetTargetResourceGroup(azureContextUSCommercial);


            artifacts.VirtualMachines.Add(azureContextUSCommercial.AzureSubscription.ArmTargetVirtualMachines[0]);
            artifacts.VirtualMachines[0].OSVirtualHardDisk.DiskSizeInGB = 128;

            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNotNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' utilizes Network Security Group (NSG) 'ManagedDisk01-nsg-nsg', but the NSG resource is not added into the migration template."));
            artifacts.NetworkSecurityGroups.Add(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkSecurityGroups[0]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' utilizes Network Security Group (NSG) 'ManagedDisk01-nsg-nsg', but the NSG resource is not added into the migration template."));

            Assert.IsNotNull(templateGenerator.SeekAlert("Target Virtual Network 'ManagedDiskvnet-vnet' for Virtual Machine 'ManagedDisk01-vm' Network Interface 'manageddisk01549-nic' is invalid, as it is not included in the migration / template."));
            artifacts.VirtualNetworks.Add(azureContextUSCommercial.AzureSubscription.ArmTargetVirtualNetworks[0]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Target Virtual Network 'ManagedDiskvnet-vnet' for Virtual Machine 'ManagedDisk01-vm' Network Interface 'manageddisk01549-nic' is invalid, as it is not included in the migration / template."));

            Assert.IsNotNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' IP Configuration 'ipconfig1' utilizes Public IP 'ManagedDisk01-ip', but the Public IP resource is not added into the migration template."));
            artifacts.PublicIPs.Add(azureContextUSCommercial.AzureSubscription.ArmTargetPublicIPs[0]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' IP Configuration 'ipconfig1' utilizes Public IP 'ManagedDisk01-ip', but the Public IP resource is not added into the migration template."));

            Assert.IsNotNull(templateGenerator.SeekAlert("Virtual Machine 'ManagedDisk01' references Managed Disk 'ManagedDisk01_OsDisk_1_e901d155e5404b6a912afb22e7a804a6' which has not been added as an export resource."));
            artifacts.Disks.Add(azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[1]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Virtual Machine 'ManagedDisk01' references Managed Disk 'ManagedDisk01_OsDisk_1_e901d155e5404b6a912afb22e7a804a6' which has not been added as an export resource."));

            Assert.IsNotNull(templateGenerator.SeekAlert("Virtual Machine 'ManagedDisk01' references Managed Disk 'ManagedDataDisk01' which has not been added as an export resource."));
            artifacts.Disks.Add(azureContextUSCommercial.AzureSubscription.ArmTargetManagedDisks[0]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Virtual Machine 'ManagedDisk01' references Managed Disk 'ManagedDataDisk01' which has not been added as an export resource."));

            Assert.IsNotNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' is used by Virtual Machine 'ManagedDisk01-vm', but is not included in the exported resources."));
            artifacts.NetworkInterfaces.Add(azureContextUSCommercial.AzureSubscription.ArmTargetNetworkInterfaces[0]);
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Network Interface Card (NIC) 'manageddisk01549-nic' is used by Virtual Machine 'ManagedDisk01-vm', but is not included in the exported resources."));

            Assert.IsTrue(artifacts.VirtualMachines[0].TargetSize.ToString() == "Standard_A1");
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsFalse(templateGenerator.HasErrors, "Template Generation cannot occur as the are error(s).");

            ManagedDiskStorage managedDiskStorage = new ManagedDiskStorage(artifacts.VirtualMachines[0].OSVirtualHardDisk.SourceDisk);

            managedDiskStorage.StorageAccountType = Core.Interface.StorageAccountType.Premium_LRS;
            artifacts.VirtualMachines[0].OSVirtualHardDisk.TargetStorage = managedDiskStorage;
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNotNull(templateGenerator.SeekAlert("Premium Disk based Virtual Machines must be of VM Series 'DS', 'DS v2', 'GS', 'GS v2', 'Ls' or 'Fs'."));

            artifacts.VirtualMachines[0].TargetSize = artifacts.ResourceGroup.TargetLocation.VMSizes.Where(a => a.Name == "Standard_DS2_v2").FirstOrDefault();
            await templateGenerator.UpdateArtifacts(artifacts);

            Assert.IsNull(templateGenerator.SeekAlert("Premium Disk based Virtual Machines must be of VM Series 'DS', 'DS v2', 'GS', 'GS v2', 'Ls' or 'Fs'."));

            Assert.IsFalse(templateGenerator.HasErrors, "Template Generation cannot occur as the are error(s).");

            await templateGenerator.GenerateStreams();

            JObject templateJson = JObject.Parse(await templateGenerator.GetTemplateString());

            Assert.AreEqual(7, templateJson["resources"].Children().Count());

            var resource = templateJson["resources"].First();

            Assert.AreEqual("Microsoft.Network/networkSecurityGroups", resource["type"].Value <string>());
            Assert.AreEqual("ManagedDisk01-nsg-nsg", resource["name"].Value <string>());
            Assert.AreEqual("[resourceGroup().location]", resource["location"].Value <string>());
        }