public async Task ValidateVMInExistingArmSubnetId() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3")); AsmToArmGenerator 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"); }
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>()); }
public async Task ValidateVMInVnetButNotInTargetVNet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM3")); AsmToArmGenerator 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"); }
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"); }
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"); }
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>()); }
private async Task <JObject> GenerateSingleVMTemplate() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM1")); AsmToArmGenerator 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()); }
public async Task ValidateSingleStorageAccount() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\Storage1")); AsmToArmGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial); var artifacts = new ExportArtifacts(); 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>()); }
public async Task ValidateSingleVMWithDataDisksNotInVnet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VM2")); AsmToArmGenerator 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>()); }