public void Deploy_Ensure_Tools_Are_Configured() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); var paramsFileContent = File.ReadAllText(Path.Combine(packagePath, "azure_website_params.json")); var parameters = JObject.Parse(paramsFileContent)["parameters"].ToString(); var psScript = @" $ErrorActionPreference = 'Continue' az --version Get-AzureEnvironment az group list"; ActionHandlerTestBuilder.CreateAsync <AzureResourceGroupActionHandler, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Inline"); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplate, File.ReadAllText(Path.Combine(packagePath, "azure_website_template.json"))); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplateParameters, parameters); context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.CustomScripts); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.Deploy, ScriptSyntax.PowerShell), psScript); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PreDeploy, ScriptSyntax.CSharp), "Console.WriteLine(\"Hello from C#\");"); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PostDeploy, ScriptSyntax.FSharp), "printfn \"Hello from F#\""); context.WithFilesToCopy(packagePath); }) .Execute(); }
public void WebApp_Is_Not_Found() { var randomName = SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60); var clientId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionClientId); var clientSecret = ExternalVariables.Get(ExternalVariable.AzureSubscriptionPassword); var tenantId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionTenantId); var subscriptionId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionId); ActionHandlerTestBuilder.CreateAsync <AzureWebAppHealthCheckActionHandler, Program>() .WithArrange(context => { context.Variables.Add(AccountVariables.SubscriptionId, subscriptionId); context.Variables.Add(AccountVariables.TenantId, tenantId); context.Variables.Add(AccountVariables.ClientId, clientId); context.Variables.Add(AccountVariables.Password, clientSecret); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupName, randomName); context.Variables.Add(SpecialVariables.Action.Azure.WebAppName, randomName); context.Variables.Add(SpecialVariables.AccountType, AccountTypes.AzureServicePrincipalAccountType.ToString()); }) .WithAssert(result => result.WasSuccessful.Should().BeFalse()) .Execute(false); }
public void Test1() { ActionHandlerTestBuilder.CreateAsync <MyActionHandler, Program>() .WithArrange(context => { }) .Execute(); }
public void Deploy_with_template_in_package() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); ActionHandlerTestBuilder.CreateAsync <AzureResourceGroupActionHandler, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Package"); context.Variables.Add("Octopus.Action.Azure.ResourceGroupTemplate", "azure_website_template.json"); context.Variables.Add("Octopus.Action.Azure.ResourceGroupTemplateParameters", "azure_website_params.json"); context.WithFilesToCopy(packagePath); }) .Execute(); }
public void ExecuteAnInlineWindowsPowerShellScript() { var psScript = @" $ErrorActionPreference = 'Continue' az --version Get-AzureEnvironment az group list"; ActionHandlerTestBuilder.CreateAsync <AzurePowerShellActionHandler, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(KnownVariables.Action.Script.ScriptSource, KnownVariableValues.Action.Script.ScriptSource.Inline); context.Variables.Add(KnownVariables.Action.Script.Syntax, ScriptSyntax.PowerShell.ToString()); context.Variables.Add(KnownVariables.Action.Script.ScriptBody, psScript); }) .Execute(); }
public void Deploy_with_template_inline() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); var paramsFileContent = File.ReadAllText(Path.Combine(packagePath, "azure_website_params.json")); var parameters = JObject.Parse(paramsFileContent)["parameters"].ToString(); ActionHandlerTestBuilder.CreateAsync <AzureResourceGroupActionHandler, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Inline"); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplate, File.ReadAllText(Path.Combine(packagePath, "azure_website_template.json"))); context.Variables.Add(SpecialVariables.Action.AzureResourceGroup.ResourceGroupTemplateParameters, parameters); context.WithFilesToCopy(packagePath); }) .Execute(); }
public void ExecuteAnInlinePowerShellCoreScriptAgainstAnInvalidAzureEnvironment() { var psScript = @" $ErrorActionPreference = 'Continue' az --version Get-AzureEnvironment az group list"; ActionHandlerTestBuilder.CreateAsync <AzurePowerShellActionHandler, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add("Octopus.Action.Azure.Environment", "NotARealAzureEnvironment"); context.Variables.Add(Calamari.Common.Plumbing.Variables.PowerShellVariables.Edition, "Core"); context.Variables.Add(KnownVariables.Action.Script.ScriptSource, KnownVariableValues.Action.Script.ScriptSource.Inline); context.Variables.Add(KnownVariables.Action.Script.Syntax, ScriptSyntax.PowerShell.ToString()); context.Variables.Add(KnownVariables.Action.Script.ScriptBody, psScript); }) .Execute(false); // Should fail due to invalid azure environment }
//[Test] public async Task Deploy_WebAppZip() { var tempPath = TemporaryDirectory.Create(); _tempDirs.Add(new DirectoryInfo(tempPath.DirectoryPath)); new DirectoryInfo(tempPath.DirectoryPath).CreateSubdirectory("AzureZipDeployPackage"); await File.WriteAllTextAsync(Path.Combine($"{tempPath.DirectoryPath}/AzureZipDeployPackage", "index.html"), "Hello #{Greeting}"); ZipFile.CreateFromDirectory($"{tempPath.DirectoryPath}/AzureZipDeployPackage", $"{tempPath.DirectoryPath}/AzureZipDeployPackage.1.0.0.zip"); ActionHandlerTestBuilder.CreateAsync <AzureAppServiceActionHandler, Program>() .WithArrange(context => { AddDefaults(context, _webappName); context.WithPackage($"{tempPath.DirectoryPath}/AzureZipDeployPackage.1.0.0.zip", "AzureZipDeployPackage", "1.0.0"); }) .Execute(runOutOfProc: true); await AssertContent($"{_webappName}.azurewebsites.net", "Hello World"); }
public void ConfiguredProxy_IsUsedForHealthCheck() { // Arrange var randomName = SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60); var clientId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionClientId); var clientSecret = ExternalVariables.Get(ExternalVariable.AzureSubscriptionPassword); var tenantId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionTenantId); var subscriptionId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionId); // Act var result = ActionHandlerTestBuilder.CreateAsync <AzureWebAppHealthCheckActionHandler, Program>() .WithArrange(context => { context.Variables.Add(AccountVariables.SubscriptionId, subscriptionId); context.Variables.Add(AccountVariables.TenantId, tenantId); context.Variables.Add(AccountVariables.ClientId, clientId); context.Variables.Add(AccountVariables.Password, clientSecret); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupName, randomName); context.Variables.Add(SpecialVariables.Action.Azure.WebAppName, randomName); context.Variables.Add(SpecialVariables.AccountType, AccountTypes.AzureServicePrincipalAccountType.ToString()); }) .Execute(assertWasSuccess: false); // Assert result.Outcome.Should().Be(ExecutionOutcome.Unsuccessful); // This also operates differently locally vs on CI, so combine both StdErr and Calamari Log to get // the full picture var windowsNetFxDnsError = "The remote name could not be resolved: 'non-existent-proxy.local'"; var ubuntuDnsError = "Resource temporarily unavailable (non-existent-proxy.local:3128)"; var generalLinuxDnsError = "Name or service not known (non-existent-proxy.local:3128)"; var windowsDotNetDnsError = "No such host is known. (non-existent-proxy.local:3128)"; var calamariOutput = result.FullLog + errorStream; calamariOutput.Should().ContainAny(windowsDotNetDnsError, ubuntuDnsError, generalLinuxDnsError, windowsNetFxDnsError); }
public async Task WebApp_Is_Found() { var resourceGroupName = SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60); var clientId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionClientId); var clientSecret = ExternalVariables.Get(ExternalVariable.AzureSubscriptionPassword); var tenantId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionTenantId); var subscriptionId = ExternalVariables.Get(ExternalVariable.AzureSubscriptionId); var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud); var azure = Microsoft.Azure.Management.Fluent.Azure .Configure() .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(credentials) .WithSubscription(subscriptionId); IResourceGroup resourceGroup = null; try { resourceGroup = await azure.ResourceGroups .Define(resourceGroupName) .WithRegion(Region.USWest) .CreateAsync(); var appServicePlan = await azure.AppServices.AppServicePlans .Define(SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60)) .WithRegion(resourceGroup.Region) .WithExistingResourceGroup(resourceGroup) .WithPricingTier(PricingTier.BasicB1) .WithOperatingSystem(OperatingSystem.Windows) .CreateAsync(); var webAppName = SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60); await azure.WebApps .Define(webAppName) .WithExistingWindowsPlan(appServicePlan) .WithExistingResourceGroup(resourceGroup) .WithRuntimeStack(WebAppRuntimeStack.NETCore) .CreateAsync(); ActionHandlerTestBuilder.CreateAsync <AzureWebAppHealthCheckActionHandler, Program>() .WithArrange(context => { context.Variables.Add(AccountVariables.SubscriptionId, subscriptionId); context.Variables.Add(AccountVariables.TenantId, tenantId); context.Variables.Add(AccountVariables.ClientId, clientId); context.Variables.Add(AccountVariables.Password, clientSecret); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupName, resourceGroupName); context.Variables.Add(SpecialVariables.Action.Azure.WebAppName, webAppName); context.Variables.Add(SpecialVariables.AccountType, AccountTypes.AzureServicePrincipalAccountType.ToString()); }) .WithAssert(result => result.WasSuccessful.Should().BeTrue()) .Execute(); } finally { if (resourceGroup != null) { azure.ResourceGroups.DeleteByNameAsync(resourceGroupName).Ignore(); } } }