Fixed: mono version check will check running mono version instead running another version
This commit is contained in:
parent
41583a8c67
commit
a4500606a9
|
@ -112,6 +112,7 @@
|
||||||
<Compile Include="Messaging\IEvent.cs" />
|
<Compile Include="Messaging\IEvent.cs" />
|
||||||
<Compile Include="Messaging\IMessage.cs" />
|
<Compile Include="Messaging\IMessage.cs" />
|
||||||
<Compile Include="PathEqualityComparer.cs" />
|
<Compile Include="PathEqualityComparer.cs" />
|
||||||
|
<Compile Include="Processes\IRuntimeProvider.cs" />
|
||||||
<Compile Include="Processes\PidFileProvider.cs" />
|
<Compile Include="Processes\PidFileProvider.cs" />
|
||||||
<Compile Include="Processes\ProcessOutput.cs" />
|
<Compile Include="Processes\ProcessOutput.cs" />
|
||||||
<Compile Include="RateGate.cs" />
|
<Compile Include="RateGate.cs" />
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Processes
|
||||||
|
{
|
||||||
|
public interface IRuntimeProvider
|
||||||
|
{
|
||||||
|
String GetVersion();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common.Processes;
|
using NzbDrone.Common.Processes;
|
||||||
using NzbDrone.Core.HealthCheck.Checks;
|
using NzbDrone.Core.HealthCheck.Checks;
|
||||||
|
@ -18,16 +17,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||||
|
|
||||||
private void GivenOutput(string version)
|
private void GivenOutput(string version)
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IProcessProvider>()
|
Mocker.GetMock<IRuntimeProvider>()
|
||||||
.Setup(s => s.StartAndCapture("mono", "--version"))
|
.Setup(s => s.GetVersion())
|
||||||
.Returns(new ProcessOutput
|
.Returns(String.Format("{0} (tarball Wed Sep 25 16:35:44 CDT 2013)", version));
|
||||||
{
|
|
||||||
Standard = new List<string>
|
|
||||||
{
|
|
||||||
String.Format("Mono JIT compiler version {0} (Debian {0}-8)", version),
|
|
||||||
"Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -46,6 +38,14 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||||
Subject.Check().ShouldBeWarning();
|
Subject.Check().ShouldBeWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_warning_when_mono_2_10_2()
|
||||||
|
{
|
||||||
|
GivenOutput("2.10.2");
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeWarning();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_return_ok_when_mono_3_2()
|
public void should_return_ok_when_mono_3_2()
|
||||||
{
|
{
|
||||||
|
@ -85,22 +85,5 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||||
|
|
||||||
Subject.Check().ShouldBeOk();
|
Subject.Check().ShouldBeOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_ok_when_mono_3_6_1_with_custom_output()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IProcessProvider>()
|
|
||||||
.Setup(s => s.StartAndCapture("mono", "--version"))
|
|
||||||
.Returns(new ProcessOutput
|
|
||||||
{
|
|
||||||
Standard = new List<string>
|
|
||||||
{
|
|
||||||
"Mono JIT compiler version 3.6.1 (master/fce3972 Fri Jul 4 01:12:43 CEST 2014)",
|
|
||||||
"Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Subject.Check().ShouldBeOk();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,13 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
||||||
{
|
{
|
||||||
public class MonoVersionCheck : HealthCheckBase
|
public class MonoVersionCheck : HealthCheckBase
|
||||||
{
|
{
|
||||||
private readonly IProcessProvider _processProvider;
|
private readonly IRuntimeProvider _runtimeProvider;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
private static readonly Regex VersionRegex = new Regex(@"(?<=\W)(?<version>\d+\.\d+\.\d+(\.\d+)?)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex VersionRegex = new Regex(@"(?<=\W)(?<version>\d+\.\d+\.\d+(\.\d+)?)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public MonoVersionCheck(IProcessProvider processProvider, Logger logger)
|
public MonoVersionCheck(IRuntimeProvider runtimeProvider, Logger logger)
|
||||||
{
|
{
|
||||||
_processProvider = processProvider;
|
_runtimeProvider = runtimeProvider;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
||||||
return new HealthCheck(GetType());
|
return new HealthCheck(GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = _processProvider.StartAndCapture("mono", "--version");
|
var versionMatch = VersionRegex.Match(_runtimeProvider.GetVersion());
|
||||||
|
|
||||||
foreach (var line in output.Standard)
|
|
||||||
{
|
|
||||||
var versionMatch = VersionRegex.Match(line);
|
|
||||||
|
|
||||||
if (versionMatch.Success)
|
if (versionMatch.Success)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +37,6 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
||||||
return new HealthCheck(GetType());
|
return new HealthCheck(GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new HealthCheck(GetType(), HealthCheckResult.Warning, "mono version is less than 3.2, upgrade for improved stability");
|
return new HealthCheck(GetType(), HealthCheckResult.Warning, "mono version is less than 3.2, upgrade for improved stability");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Processes;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono
|
||||||
|
{
|
||||||
|
public class MonoRuntimeProvider : IRuntimeProvider
|
||||||
|
{
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public MonoRuntimeProvider(Logger logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String GetVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var type = Type.GetType("Mono.Runtime");
|
||||||
|
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
var displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
|
||||||
|
if (displayName != null)
|
||||||
|
{
|
||||||
|
return displayName.Invoke(null, null).ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Unable to get mono version: " + ex.Message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,6 +70,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DiskProvider.cs" />
|
<Compile Include="DiskProvider.cs" />
|
||||||
<Compile Include="LinuxPermissionsException.cs" />
|
<Compile Include="LinuxPermissionsException.cs" />
|
||||||
|
<Compile Include="MonoRuntimeProvider.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue