public void Scratch() { //var azure = new AzureDeploymentClient(); //var rmc = new ResourceManagementRepo(); //var token = new TokenHolder(); var baseTemplate = GetArmTemplate(); var resource = GetAResource(); var savedSearchAlias = "etagSearch"; var newVm = "fox02"; var query = rmc.GetSavedSearchFromWorkspace(tokenHolder.token, resource, savedSearchAlias).Result; //add machine to query Assert.IsNotNull(query.etag); var newQuery = QueryHelper.AddVmToComputerGroupQuery(query.properties.Query, newVm, isIdentifierVmuuid: false); var newTemplate = CreateNewTemplateFromQuery(baseTemplate, newQuery, query.etag); Assert.IsNotNull(newTemplate); var jobj = JObject.FromObject(newTemplate); var deployment = azure.NewResourceGroupDeployment(jobj.ToString(), "scratchTest01", "testingetag").Result; Assert.IsNotNull(deployment); }
public void ScratchFullTemp() { var baseTemplate = GetArmTemplate(templateType.fromAzure); var resource = GetAResource(); var savedSearchAlias = "etagSearch"; var newVm = "fox0234"; var query = rmc.GetSavedSearchFromWorkspace(tokenHolder.token, resource, savedSearchAlias).Result; //add machine to query Assert.IsNotNull(query.etag); var newQuery = QueryHelper.AddVmToComputerGroupQuery(query.properties.Query, newVm, isIdentifierVmuuid: false); var newTemplate = CreateNewTemplateFromQuery(baseTemplate, newQuery, query.etag); Assert.IsNotNull(newTemplate); var jobj = JObject.FromObject(newTemplate); var parms = JObject.Parse(File.ReadAllText(fromAzureParam)); var deployment = azure.NewSubscriptionDeployment(jobj.ToString(), parms.ToString(), "etag03").Result; Assert.IsNotNull(deployment); }
private RequestPrototype tryToUpdateQuery(RequestPrototype request, int times) { Stopwatch stopwatch = new Stopwatch(); // Begin timing. stopwatch.Start(); Random random = new Random(); int sleepPeriod = random.Next(1, 5) * 1000; Thread.Sleep(sleepPeriod); int i = 1; var newVm = request.VMName; var savedSearchAlias = "etagSearch"; var resource = GetAResource(); var baseTemplate = GetArmTemplate(); var deploymentName = $"etagTest{newVm}"; SavedSearch query = new SavedSearch(); while (i < times) { //get Query try { System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - getting query, [{i}] attempt"); query = rmc.GetSavedSearchFromWorkspace(tokenHolder.token, resource, savedSearchAlias).Result; //add machine to query if (null == query) { System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - exception was 401 error, likely need new token!"); throw new Exception("Need to get a new Bearer Token!"); } var newQuery = QueryHelper.AddVmToComputerGroupQuery(query.properties.Query, newVm, isIdentifierVmuuid: false); //update query var newTemplate = CreateNewTemplateFromQuery(baseTemplate, newQuery, query.etag); var jobj = JObject.FromObject(newTemplate); System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - conducting deployment, [{i}] attempts"); var deployment = azure.NewResourceGroupDeployment(jobj.ToString(), deploymentName, "testingetag").Result; stopwatch.Stop(); request.Elapsed = stopwatch.Elapsed.TotalSeconds; request.RetryAttempts = i; //it worked if we got here so we return true System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - added in [{i}] attempts ⌚[{request.Elapsed}]"); return(request); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - exception occurred!"); if (null == query) { System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - exception was 401 error, likely need new token!"); throw new Exception("Need to get a new Bearer Token!"); } var deployment = rmc.GetDeployment("testingetag", deploymentName).Result; //Assert.AreEqual("Conflict", deployment.Properties.Error?.Details.FirstOrDefault().Code); if ("Conflict" == deployment.Properties.Error.Details.FirstOrDefault().Code) { System.Diagnostics.Debug.WriteLine($"[{request.Region}]-[{request.VMName}] - exception was 409 Conflict, retrying...!"); i++; continue; } else { throw ex; } } } stopwatch.Stop(); request.Elapsed = stopwatch.Elapsed.TotalSeconds; request.RetryAttempts = -1; return(request); }