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"); }
public async Task ValidateSingleVnetWithNoSubnetsGetsNewDefaultSubet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); TemplateGenerator templateGenerator = TestHelper.SetupTemplateGenerator(azureContextUSCommercial); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET4")); var artifacts = new AsmArtifacts(); artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmnet")); TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory); JObject templateJson = templateResult.GenerateTemplate(); // 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>()); }
private async void PreExportForm_Load(object sender, EventArgs e) { parentForm = (AsmToArmForm)this.Owner; txtDestinationFolder.Text = AppDomain.CurrentDomain.BaseDirectory; List <TreeNode> selectedNodes = parentForm.SelectedNodes; btnExport.Text = btnExport.Text.Replace("0", selectedNodes.Count().ToString()); artifacts = new AsmArtifacts(); foreach (TreeNode selectedNode in selectedNodes) { Type tagType = selectedNode.Tag.GetType(); if (tagType == typeof(AsmNetworkSecurityGroup)) { artifacts.NetworkSecurityGroups.Add((AsmNetworkSecurityGroup)selectedNode.Tag); } else if (tagType == typeof(AsmVirtualNetwork)) { artifacts.VirtualNetworks.Add((AsmVirtualNetwork)selectedNode.Tag); } else if (tagType == typeof(AsmStorageAccount)) { artifacts.StorageAccounts.Add((AsmStorageAccount)selectedNode.Tag); } else if (tagType == typeof(AsmVirtualMachine)) { artifacts.VirtualMachines.Add((AsmVirtualMachine)selectedNode.Tag); } } }
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"); }
public async Task ValidateSingleVnetWithNsgAndRT() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); TemplateGenerator templateGenerator = TestHelper.SetupTemplateGenerator(azureContextUSCommercial); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET2")); var artifacts = new AsmArtifacts(); artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmtest")); artifacts.NetworkSecurityGroups.Add(await azureContextUSCommercialRetriever.GetAzureAsmNetworkSecurityGroup("asmnsg")); TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory); JObject templateJson = templateResult.GenerateTemplate(); // 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(); TemplateGenerator templateGenerator = TestHelper.SetupTemplateGenerator(azureContextUSCommercial); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET3")); var artifacts = new AsmArtifacts(); artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("vnet3")); TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory); JObject templateJson = templateResult.GenerateTemplate(); // 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, templateResult.Messages.Count); StringAssert.Contains(templateResult.Messages[0], "ExpressRoute"); }
public async Task ValidateComplexSingleVnet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); TemplateGenerator templateGenerator = TestHelper.SetupTemplateGenerator(azureContextUSCommercial); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET1")); var artifacts = new AsmArtifacts(); artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("10.2.0.0")); TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory); JObject templateJson = templateResult.GenerateTemplate(); // 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(); 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()); }
internal static void SetTargetSubnets(AsmArtifacts 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); ArmVirtualNetwork armVirtualNetwork = new ArmVirtualNetwork(webRequestResultJson); foreach (AsmVirtualMachine asmVirtualMachine in artifacts.VirtualMachines) { if (asmVirtualMachine.TargetVirtualNetwork == null) { asmVirtualMachine.TargetVirtualNetwork = armVirtualNetwork; } if (asmVirtualMachine.TargetSubnet == null) { asmVirtualMachine.TargetSubnet = armVirtualNetwork.Subnets[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"); }
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>()); }
public async Task ValidateSingleStorageAccount() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); TemplateGenerator templateGenerator = TestHelper.SetupTemplateGenerator(azureContextUSCommercial); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\Storage1")); var artifacts = new AsmArtifacts(); artifacts.StorageAccounts.Add(await azureContextUSCommercialRetriever.GetAzureAsmStorageAccount("mystorage")); TemplateResult templateResult = await templateGenerator.GenerateTemplate(TestHelper.GetTestAzureSubscription(), TestHelper.GetTestAzureSubscription(), artifacts, await TestHelper.GetTargetResourceGroup(azureContextUSCommercial), AppDomain.CurrentDomain.BaseDirectory); JObject templateJson = templateResult.GenerateTemplate(); 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>()); }