Skip to content

Commit

Permalink
[Rpc]Expand environment variables in worker.config.json after hydrati…
Browse files Browse the repository at this point in the history
…ng worker path (Azure#6352)
  • Loading branch information
pragnagopa authored Jul 15, 2020
1 parent c5e9479 commit 16ee578
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal void AddProvider(string workerDir)
workerDescription.FormatWorkerPathIfNeeded(_systemRuntimeInformation, _environment, _logger);
workerDescription.ThrowIfFileNotExists(workerDescription.DefaultWorkerPath, nameof(workerDescription.DefaultWorkerPath));
_workerDescripionDictionary[workerDescription.Language] = workerDescription;
workerDescription.ExpandEnvironmentVariables();
_logger.LogDebug($"Added WorkerConfig for language: {workerDescription.Language}");
}
}
Expand Down
1 change: 0 additions & 1 deletion src/WebJobs.Script/Workers/Rpc/RpcWorkerDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public override void ApplyDefaultsAndValidate(string workerDirectory, ILogger lo
{
DefaultWorkerPath = Path.Combine(WorkerDirectory, DefaultWorkerPath);
}
ExpandEnvironmentVariables();
if (string.IsNullOrEmpty(Language))
{
throw new ValidationException($"WorkerDescription {nameof(Language)} cannot be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Workers;
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
using Microsoft.Extensions.Configuration;
using Moq;
using Xunit;

namespace Microsoft.Azure.WebJobs.Script.Tests.Workers.Rpc
Expand Down Expand Up @@ -106,29 +104,47 @@ public void JavaPath_FromEnvVars()
[Fact]
public void DefaultWorkerConfigs_Overrides_DefaultWorkerRuntimeVersion_AppSetting()
{
var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
["languageWorkers:python:defaultRuntimeVersion"] = "3.8"
});
var config = configBuilder.Build();
var scriptSettingsManager = new ScriptSettingsManager(config);
var testLogger = new TestLogger("test");
var testEnvVariables = new Dictionary<string, string>
{
{ "languageWorkers:python:defaultRuntimeVersion", "3.8" }
};
var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
.AddInMemoryCollection(testEnvVariables);
var config = configBuilder.Build();
var scriptSettingsManager = new ScriptSettingsManager(config);
var testLogger = new TestLogger("test");
using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
{
var configFactory = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());
var workerConfigs = configFactory.GetConfigs();
var pythonWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("python", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
var powershellWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("powershell", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
Assert.Equal(4, workerConfigs.Count);
Assert.NotNull(pythonWorkerConfig);
Assert.NotNull(powershellWorkerConfig);
Assert.Equal("3.8", pythonWorkerConfig.Description.DefaultRuntimeVersion);
Assert.Equal("6", powershellWorkerConfig.Description.DefaultRuntimeVersion);
}
}

[Fact]
public void DefaultWorkerConfigs_Overrides_VersionAppSetting()
{
var testEnvironment = new TestEnvironment();
testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME_VERSION", "7.0");
testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "powerShell");
var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder();
var config = configBuilder.Build();
var scriptSettingsManager = new ScriptSettingsManager(config);
var testLogger = new TestLogger("test");
var configFactory = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, testEnvironment, new TestMetricsLogger());
var workerConfigs = configFactory.GetConfigs();
var powershellWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("powershell", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
Assert.Equal(1, workerConfigs.Count);
Assert.NotNull(powershellWorkerConfig);
Assert.Equal("7", powershellWorkerConfig.Description.DefaultRuntimeVersion);
}

[Theory]
[InlineData("python", "Python", false, true)]
[InlineData("python", "NOde", false, false)]
Expand Down

0 comments on commit 16ee578

Please sign in to comment.