mirror of
https://github.com/actions/runner.git
synced 2025-12-16 06:57:25 +00:00
Runner register labels during configuration (#130)
* Runners will add os and architecture labels during registration * support github.localhost for dev.
This commit is contained in:
committed by
Christopher Johnson
parent
2f261f2c31
commit
f5f14d4811
@@ -1,5 +1,4 @@
|
||||
using GitHub.Runner.Common.Capabilities;
|
||||
using GitHub.Runner.Worker;
|
||||
using GitHub.Runner.Worker;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -21,12 +20,12 @@ namespace GitHub.Runner.Common.Tests
|
||||
manager.Initialize(tc);
|
||||
|
||||
// Act.
|
||||
List<ICapabilitiesProvider> extensions = manager.GetExtensions<ICapabilitiesProvider>();
|
||||
List<IActionCommandExtension> extensions = manager.GetExtensions<IActionCommandExtension>();
|
||||
|
||||
// Assert.
|
||||
Assert.True(
|
||||
extensions.Any(x => x is RunnerCapabilitiesProvider),
|
||||
$"Expected {nameof(RunnerCapabilitiesProvider)} extension to be returned as a job extension.");
|
||||
extensions.Any(x => x is SetEnvCommandExtension),
|
||||
$"Expected {nameof(SetEnvCommandExtension)} extension to be returned as a job extension.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +41,9 @@ namespace GitHub.Runner.Common.Tests
|
||||
manager.Initialize(tc);
|
||||
|
||||
// Act/Assert.
|
||||
AssertContains<GitHub.Runner.Common.Capabilities.ICapabilitiesProvider>(
|
||||
AssertContains<GitHub.Runner.Worker.IActionCommandExtension>(
|
||||
manager,
|
||||
concreteType: typeof(GitHub.Runner.Common.Capabilities.RunnerCapabilitiesProvider));
|
||||
concreteType: typeof(GitHub.Runner.Worker.SetEnvCommandExtension));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
using GitHub.Runner.Common.Capabilities;
|
||||
using GitHub.Runner.Listener.Configuration;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace GitHub.Runner.Common.Tests.Listener
|
||||
{
|
||||
public sealed class AgentCapabilitiesProviderTestL0
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Agent")]
|
||||
public async void TestGetCapabilities()
|
||||
{
|
||||
using (var hc = new TestHostContext(this))
|
||||
using (var tokenSource = new CancellationTokenSource())
|
||||
{
|
||||
Mock<IConfigurationManager> configurationManager = new Mock<IConfigurationManager>();
|
||||
hc.SetSingleton<IConfigurationManager>(configurationManager.Object);
|
||||
|
||||
// Arrange
|
||||
var provider = new RunnerCapabilitiesProvider();
|
||||
provider.Initialize(hc);
|
||||
var settings = new RunnerSettings() { AgentName = "IAmAgent007" };
|
||||
|
||||
// Act
|
||||
List<Capability> capabilities = await provider.GetCapabilitiesAsync(settings, tokenSource.Token);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(capabilities);
|
||||
Capability runnerNameCapability = capabilities.SingleOrDefault(x => string.Equals(x.Name, "Runner.Name", StringComparison.Ordinal));
|
||||
Assert.NotNull(runnerNameCapability);
|
||||
Assert.Equal("IAmAgent007", runnerNameCapability.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Agent")]
|
||||
public async void TestInteractiveSessionCapability()
|
||||
{
|
||||
using (var hc = new TestHostContext(this))
|
||||
using (var tokenSource = new CancellationTokenSource())
|
||||
{
|
||||
hc.StartupType = StartupType.AutoStartup;
|
||||
await VerifyInteractiveSessionCapability(hc, tokenSource.Token, true);
|
||||
|
||||
hc.StartupType = StartupType.Service;
|
||||
await VerifyInteractiveSessionCapability(hc, tokenSource.Token, false);
|
||||
|
||||
hc.StartupType = StartupType.Manual;
|
||||
await VerifyInteractiveSessionCapability(hc, tokenSource.Token, true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task VerifyInteractiveSessionCapability(IHostContext hc, CancellationToken token, bool expectedValue)
|
||||
{
|
||||
// Arrange
|
||||
var provider = new RunnerCapabilitiesProvider();
|
||||
provider.Initialize(hc);
|
||||
var settings = new RunnerSettings() { AgentName = "IAmAgent007" };
|
||||
|
||||
// Act
|
||||
List<Capability> capabilities = await provider.GetCapabilitiesAsync(settings, token);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(capabilities);
|
||||
Capability iSessionCapability = capabilities.SingleOrDefault(x => string.Equals(x.Name, "InteractiveSession", StringComparison.Ordinal));
|
||||
Assert.NotNull(iSessionCapability);
|
||||
bool.TryParse(iSessionCapability.Value, out bool isInteractive);
|
||||
Assert.Equal(expectedValue, isInteractive);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using GitHub.DistributedTask.WebApi;
|
||||
using GitHub.Runner.Listener;
|
||||
using GitHub.Runner.Common.Capabilities;
|
||||
using GitHub.Runner.Listener.Configuration;
|
||||
using GitHub.Runner.Common.Util;
|
||||
using GitHub.Services.WebApi;
|
||||
@@ -40,8 +39,6 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
||||
#endif
|
||||
|
||||
private Mock<IRSAKeyManager> _rsaKeyManager;
|
||||
private ICapabilitiesManager _capabilitiesManager;
|
||||
// private DeploymentGroupAgentConfigProvider _deploymentGroupAgentConfigProvider;
|
||||
private string _expectedToken = "expectedToken";
|
||||
private string _expectedServerUrl = "https://localhost";
|
||||
private string _expectedAgentName = "expectedAgentName";
|
||||
@@ -78,8 +75,6 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
||||
_serviceControlManager = new Mock<ILinuxServiceControlManager>();
|
||||
#endif
|
||||
|
||||
_capabilitiesManager = new CapabilitiesManager();
|
||||
|
||||
var expectedAgent = new TaskAgent(_expectedAgentName) { Id = 1 };
|
||||
var expectedDeploymentMachine = new DeploymentMachine() { Agent = expectedAgent, Id = _expectedDeploymentMachineId };
|
||||
expectedAgent.Authorization = new TaskAgentAuthorization
|
||||
@@ -127,7 +122,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
||||
_agentServer.Setup(x => x.GetAgentsAsync(It.IsAny<int>(), It.IsAny<string>())).Returns(Task.FromResult(expectedAgents));
|
||||
|
||||
_agentServer.Setup(x => x.AddAgentAsync(It.IsAny<int>(), It.IsAny<TaskAgent>())).Returns(Task.FromResult(expectedAgent));
|
||||
_agentServer.Setup(x => x.UpdateAgentAsync(It.IsAny<int>(), It.IsAny<TaskAgent>())).Returns(Task.FromResult(expectedAgent));
|
||||
_agentServer.Setup(x => x.ReplaceAgentAsync(It.IsAny<int>(), It.IsAny<TaskAgent>())).Returns(Task.FromResult(expectedAgent));
|
||||
|
||||
rsa = new RSACryptoServiceProvider(2048);
|
||||
|
||||
@@ -143,8 +138,6 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
||||
tc.SetSingleton<IExtensionManager>(_extnMgr.Object);
|
||||
tc.SetSingleton<IRunnerServer>(_agentServer.Object);
|
||||
tc.SetSingleton<ILocationServer>(_locationServer.Object);
|
||||
// tc.SetSingleton<IDeploymentGroupServer>(_machineGroupServer.Object);
|
||||
tc.SetSingleton<ICapabilitiesManager>(_capabilitiesManager);
|
||||
tc.SetSingleton<IRunnerWebProxy>(_runnerWebProxy.Object);
|
||||
tc.SetSingleton<IRunnerCertificateManager>(_cert.Object);
|
||||
|
||||
@@ -208,12 +201,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
||||
// validate GetAgentPoolsAsync gets called once with automation pool type
|
||||
_agentServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Automation)), Times.Once);
|
||||
|
||||
// validate GetAgentPoolsAsync not called with deployment pool type
|
||||
_agentServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Deployment)), Times.Never);
|
||||
|
||||
// For build and release agent / deployment pool, tags logic should not get trigger;
|
||||
// _machineGroupServer.Verify(x =>
|
||||
// x.UpdateDeploymentTargetsAsync(It.IsAny<Guid>(), It.IsAny<int>(), It.IsAny<List<DeploymentMachine>>()), Times.Never);
|
||||
_agentServer.Verify(x => x.AddAgentAsync(It.IsAny<int>(), It.Is<TaskAgent>(a => a.Labels.Contains("self-hosted") && a.Labels.Contains(VarUtil.OS) && a.Labels.Contains(VarUtil.OSArchitecture))), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using GitHub.Services.Common;
|
||||
using GitHub.Services.WebApi;
|
||||
using GitHub.Runner.Listener;
|
||||
using GitHub.Runner.Common.Capabilities;
|
||||
using GitHub.Runner.Listener.Configuration;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -21,7 +20,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
private Mock<IConfigurationManager> _config;
|
||||
private Mock<IRunnerServer> _agentServer;
|
||||
private Mock<ICredentialManager> _credMgr;
|
||||
private Mock<ICapabilitiesManager> _capabilitiesManager;
|
||||
|
||||
public MessageListenerL0()
|
||||
{
|
||||
@@ -30,7 +28,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
_config.Setup(x => x.LoadSettings()).Returns(_settings);
|
||||
_agentServer = new Mock<IRunnerServer>();
|
||||
_credMgr = new Mock<ICredentialManager>();
|
||||
_capabilitiesManager = new Mock<ICapabilitiesManager>();
|
||||
}
|
||||
|
||||
private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
|
||||
@@ -39,7 +36,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
tc.SetSingleton<IConfigurationManager>(_config.Object);
|
||||
tc.SetSingleton<IRunnerServer>(_agentServer.Object);
|
||||
tc.SetSingleton<ICredentialManager>(_credMgr.Object);
|
||||
tc.SetSingleton<ICapabilitiesManager>(_capabilitiesManager.Object);
|
||||
return tc;
|
||||
}
|
||||
|
||||
@@ -62,8 +58,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
tokenSource.Token))
|
||||
.Returns(Task.FromResult(expectedSession));
|
||||
|
||||
_capabilitiesManager.Setup(x => x.GetCapabilitiesAsync(_settings, It.IsAny<CancellationToken>())).Returns(Task.FromResult(new Dictionary<string, string>()));
|
||||
|
||||
_credMgr.Setup(x => x.LoadCredentials()).Returns(new VssCredentials());
|
||||
|
||||
// Act.
|
||||
@@ -106,8 +100,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
tokenSource.Token))
|
||||
.Returns(Task.FromResult(expectedSession));
|
||||
|
||||
_capabilitiesManager.Setup(x => x.GetCapabilitiesAsync(_settings, It.IsAny<CancellationToken>())).Returns(Task.FromResult(new Dictionary<string, string>()));
|
||||
|
||||
_credMgr.Setup(x => x.LoadCredentials()).Returns(new VssCredentials());
|
||||
|
||||
// Act.
|
||||
@@ -153,8 +145,6 @@ namespace GitHub.Runner.Common.Tests.Listener
|
||||
tokenSource.Token))
|
||||
.Returns(Task.FromResult(expectedSession));
|
||||
|
||||
_capabilitiesManager.Setup(x => x.GetCapabilitiesAsync(_settings, It.IsAny<CancellationToken>())).Returns(Task.FromResult(new Dictionary<string, string>()));
|
||||
|
||||
_credMgr.Setup(x => x.LoadCredentials()).Returns(new VssCredentials());
|
||||
|
||||
// Act.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using GitHub.Runner.Listener;
|
||||
using GitHub.Runner.Common.Capabilities;
|
||||
using GitHub.Runner.Listener.Configuration;
|
||||
using GitHub.Runner.Worker;
|
||||
using GitHub.Runner.Worker.Handlers;
|
||||
@@ -44,7 +43,6 @@ namespace GitHub.Runner.Common.Tests
|
||||
typeof(IHostContext),
|
||||
typeof(ITraceManager),
|
||||
typeof(IThrottlingReporter),
|
||||
typeof(ICapabilitiesProvider)
|
||||
};
|
||||
Validate(
|
||||
assembly: typeof(IHostContext).GetTypeInfo().Assembly,
|
||||
|
||||
Reference in New Issue
Block a user