public bool CleanupAsync() { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); logger.Info("Success in getting token for cleanup-async!"); logger.Info("Deleting deployment..."); Task t = AzureHelper.DeleteResourceGroupAsync( credential, groupName, subscriptionId); logger.Info("Deletion of resource group triggered!!"); return(true); }
public override bool Validate() { // TODO add these under a timeout try { // TODO Include test name in the logs logger.Info("Validations for Linux in progress..."); var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); bool ifCustomDataValid = true; PublicIPAddress ipAddress = AzureHelper.GetPublicAddressAsync(credential, groupName, subscriptionId, "myPublicIP").Result; using (var client = new SshClient(ipAddress.IpAddress, username, password)) { client.Connect(); SshCommand command = client.RunCommand("echo 'hello'"); logger.Info("Result of command 'x': " + command.Result); if (!string.IsNullOrWhiteSpace(customData)) { command = client.RunCommand("echo '<PASSWORD>' | sudo -S cat /var/lib/waagent/CustomData"); ifCustomDataValid = command.Result.Contains(customData); } client.Disconnect(); } if (!ifCustomDataValid) { throw new ArgumentException("Incorrect custom data!!"); } logger.Info("Validations for Linux...success!!"); } catch (Exception e) { logger.Error(e); return(false); } return(true); }
public bool Cleanup() { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); logger.Info("Success in getting token for cleanup!"); logger.Info("Deleting deployment..."); Task t = AzureHelper.DeleteResourceGroupAsync( credential, groupName, subscriptionId); t.Wait(TimeSpan.FromMinutes(15)); logger.Info("Success in deleting deployment!!"); return(true); }
public static void CleanupLeakedResourceGroups() { try { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); List <string> resourceGroups = AzureHelper.GetResourceGroups(credential, ConfigurationManager.SubscriptionId, ConfigurationManager.Locations); foreach (string resourceGroup in resourceGroups) { Task t = AzureHelper.DeleteResourceGroupAsync(credential, resourceGroup, ConfigurationManager.SubscriptionId); } } catch (Exception e) { } }
public bool Create() { logger.Info("Doing the work to deploy IaaS VM"); var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); logger.Info("Success in getting token for deployment creation!"); try { logger.Info("Creating the resource group..."); var rgResult = AzureHelper.CreateResourceGroupAsync( credential, groupName, subscriptionId, location); logger.Info("Success in generating RG. ProvisioningState: " + rgResult.Result.Properties.ProvisioningState); Console.WriteLine("Creating the template deployment..."); Task <DeploymentExtended> dpResult = AzureHelper.CreateTemplateDeploymentAsync( credential, groupName, deploymentName, subscriptionId, template, templateParameters); logger.Info("Successfully created deployment. ProvisioningState: " + dpResult.Result.Properties.ProvisioningState); } catch (Exception e) { logger.Error("During deployment, exception: " + e); return(false); } return(true); }
public override bool Validate() { // TODO failures in create and cleanup should be ignored for couple of times // TODO Add retries in validation logic // TODO talk to guest agent and gets it version and validate if latest object t = Impersonation.Impersonate(ConfigurationManager.UserName, ConfigurationManager.Password); try { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); PublicIPAddress ipAddress = AzureHelper.GetPublicAddressAsync(credential, groupName, subscriptionId, "myPublicIP").Result; // TODO: make username-password at one place instead of at both ARM and here SecureString securePwd = new SecureString(); password.ToCharArray().ToList().ForEach(p => securePwd.AppendChar(p)); // this is the entrypoint to interact with the system (interfaced for testing). var remoteComputer = new Uri(string.Format("{0}://{1}:5986", "https", ipAddress.IpAddress)); var connection = new WSManConnectionInfo(remoteComputer, String.Empty, new PSCredential(username, securePwd)); var option = new PSSessionOption(); option.SkipCACheck = true; option.SkipCNCheck = true; option.SkipRevocationCheck = true; connection.SetSessionOptions(option); connection.AuthenticationMechanism = AuthenticationMechanism.Negotiate; // TODO What if powershell session gets stuck in between var runspace = RunspaceFactory.CreateRunspace(connection); runspace.Open(); var powershell = PowerShell.Create(); powershell.Runspace = runspace; powershell.AddScript("get-psdrive –psprovider filesystem"); var results = powershell.Invoke(); foreach (var output in results.Where(o => o != null)) { } bool ifCustomData = true; if (!string.IsNullOrWhiteSpace(customData)) { powershell.AddScript("Get-Content C:\\AzureData\\CustomData.bin -Encoding UTF8"); results = powershell.Invoke(); ifCustomData = (results.Where(o => o != null).ToList().Count == 1); foreach (var output in results.Where(o => o != null)) { logger.Info(string.Format("Expected: {0} Actual: {1}", customData, output)); ifCustomData &= (output.ToString() == customData); } } runspace.Close(); if (!ifCustomData) { throw new ArgumentException("Incorrect custom data!!"); } } catch (Exception e) { logger.Error(e); return(false); } finally { Impersonation.UndoImpersonation(t); } return(true); }