public async Task ValidateSingleVnetWithNoSubnetsGetsNewDefaultSubet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET4")); AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial); var artifacts = new ExportArtifacts(); // todo artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmnet")); await 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")); 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"); }
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>()); }
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"); }
public static async Task <AzureGenerator> SetupTemplateGenerator(AzureContext azureContext) { ITelemetryProvider telemetryProvider = new FakeTelemetryProvider(); AzureGenerator azureGenerator = new AzureGenerator(azureContext.LogProvider, azureContext.StatusProvider); return(azureGenerator); }
public async Task ValidateSingleVnetWithNsgAndRT() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET2")); AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial); var artifacts = new ExportArtifacts(); // todo artifacts.VirtualNetworks.Add(await azureContextUSCommercialRetriever.GetAzureAsmVirtualNetwork("asmtest")); // todo 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 static async Task <AzureGenerator> SetupTemplateGenerator(AzureContext azureContext) { ITelemetryProvider telemetryProvider = new FakeTelemetryProvider(); AzureGenerator azureGenerator = new AzureGenerator(azureContext.LogProvider, azureContext.StatusProvider); // For Tests, we'll set the target subscription of the Azure Generator to the Azure Context provided by the AzureContext azureGenerator.TargetSubscription = azureContext.AzureSubscription; return(azureGenerator); }
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"); }
public async Task ValidateSingleVnetWithExpressRouteGateway() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET3")); AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial); var artifacts = new ExportArtifacts(); // todo 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"); }
private Dictionary <string, string> GetProcessedItems(AzureGenerator templateResult) { Dictionary <string, string> processedItems = new Dictionary <string, string>(); foreach (ArmResource resource in templateResult.Resources) { if (!processedItems.ContainsKey(resource.type + resource.name)) { processedItems.Add(resource.type + resource.name, resource.location); } } return(processedItems); }
public async Task ValidateComplexSingleVnet() { AzureContext azureContextUSCommercial = TestHelper.SetupAzureContext(); FakeAzureRetriever azureContextUSCommercialRetriever = (FakeAzureRetriever)azureContextUSCommercial.AzureRetriever; azureContextUSCommercialRetriever.LoadDocuments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDocs\\VNET1")); AzureGenerator templateGenerator = await TestHelper.SetupTemplateGenerator(azureContextUSCommercial); var artifacts = new ExportArtifacts(); // todo 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")); 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()); }
public void PostTelemetryRecord(AzureGenerator templateGenerator) { TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.ExecutionId = templateGenerator.ExecutionGuid; telemetryrecord.SubscriptionId = templateGenerator.SourceSubscription.SubscriptionId; telemetryrecord.TenantId = templateGenerator.SourceSubscription.AzureAdTenantId; telemetryrecord.OfferCategories = templateGenerator.SourceSubscription.offercategories; telemetryrecord.SourceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); telemetryrecord.ProcessedResources = this.GetProcessedItems(templateGenerator); string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.migaz.tools/v1/telemetry/ARMtoARM"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); } catch (Exception exception) { DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public MigAzForm() { InitializeComponent(); _logProvider = new FileLogProvider(); _logProvider.OnMessage += _logProvider_OnMessage; _statusProvider = new UIStatusProvider(this.toolStripStatusLabel1); _appSettingsProvider = new AppSettingsProvider(); _AzureEnvironments = AzureEnvironment.GetAzureEnvironments(); _AzureRetriever = new AzureRetriever(_logProvider, _statusProvider); _TargetAzureContext = new AzureContext(_AzureRetriever, _appSettingsProvider.GetTargetSettings(), app.Default.LoginPromptBehavior); _AzureGenerator = new AzureGenerator(_logProvider, _statusProvider); if (app.Default.UserDefinedAzureEnvironments != null && app.Default.UserDefinedAzureEnvironments != String.Empty) { _UserDefinedAzureEnvironments = JsonConvert.DeserializeObject <List <AzureEnvironment> >(app.Default.UserDefinedAzureEnvironments); } targetAzureContextViewer.Bind(_TargetAzureContext, _AzureRetriever, _AzureEnvironments, ref _UserDefinedAzureEnvironments); propertyPanel1.Clear(); splitContainer2.SplitterDistance = this.Height / 2; splitContainer3.SplitterDistance = splitContainer3.Width / 2; splitContainer4.SplitterDistance = 45; lblLastOutputRefresh.Text = String.Empty; txtDestinationFolder.Text = AppDomain.CurrentDomain.BaseDirectory; // Future thought, do away with the "Set"s and consolidate to a Bind? this.targetTreeView1.LogProvider = this.LogProvider; this.targetTreeView1.StatusProvider = this.StatusProvider; this.targetTreeView1.ImageList = this.imageList1; this.targetTreeView1.TargetSettings = _appSettingsProvider.GetTargetSettings(); this.propertyPanel1.TargetTreeView = targetTreeView1; this.propertyPanel1.PropertyChanged += PropertyPanel1_PropertyChanged; AlertIfNewVersionAvailable(); }
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>()); }
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"); }
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>()); }
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>()); }
public void PostTelemetryRecord(AzureGenerator templateResult) { }
public void PostTelemetryRecord(Guid appSessionGuid, string migrationSourceType, AzureSubscription sourceSubscription, AzureGenerator templateGenerator) { if (templateGenerator == null) { throw new ArgumentException("Template Generator cannot be null."); } TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.AppSessionGuid = appSessionGuid; telemetryrecord.Id = templateGenerator.ExecutionGuid; telemetryrecord.MigrationSourceType = migrationSourceType; #if DEBUG telemetryrecord.ConfigurationMode = "Debug"; #else telemetryrecord.ConfigurationMode = "Release"; #endif if (sourceSubscription != null) { telemetryrecord.SourceEnvironment = sourceSubscription.AzureEnvironment.ToString(); telemetryrecord.SourceSubscriptionGuid = sourceSubscription.SubscriptionId; telemetryrecord.SourceTenantGuid = sourceSubscription.AzureAdTenantId; telemetryrecord.OfferCategories = String.Empty; // templateGenerator.SourceSubscription.offercategories; } if (templateGenerator.TargetSubscription != null) { telemetryrecord.TargetEnvironment = templateGenerator.TargetSubscription.AzureEnvironment.ToString(); telemetryrecord.TargetSubscriptionGuid = templateGenerator.TargetSubscription.SubscriptionId; telemetryrecord.TargetTenantGuid = templateGenerator.TargetSubscription.AzureAdTenantId; } telemetryrecord.SourceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); telemetryrecord.ProcessedResources = this.GetProcessedItems(templateGenerator); string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://migaz.azurewebsites.net/api/v2"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); } catch (Exception exception) { // DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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>()); }