AvevaPrerequisites.CheckAllAsync walks eight probe categories producing PrerequisiteCheck rows each with Name (e.g. 'service:aaBootstrap', 'sql:ZB', 'com:LMXProxy', 'registry:ArchestrA.Framework'), Category (AvevaCoreService / AvevaSoftService / AvevaInstall / MxAccessCom / GalaxyRepository / AvevaHistorian / OtOpcUaService / Environment), Status (Pass / Warn / Fail / Skip), and operator-facing Detail message. Report aggregates them: IsLivetestReady (no Fails anywhere) and IsAvevaSideReady (AVEVA-side categories pass, our v2 services can be absent while still considering the environment AVEVA-ready) so different test tiers can use the right threshold.
Individual probes: ServiceProbe.Check queries the Windows Service Control Manager via System.ServiceProcess.ServiceController — treats DemandStart+Stopped as Warn (NmxSvc is DemandStart by design; master pulls it up) but AutoStart+Stopped as Fail; not-installed is Fail for hard-required services, Warn for soft ones; non-Windows hosts get Skip; transitional states like StartPending get Warn with a 'try again' hint. RegistryProbe reads HKLM\SOFTWARE\WOW6432Node\ArchestrA\{Framework,Framework\Platform,MSIInstall} — Framework key presence + populated InstallPath/RootPath values mean System Platform installed; PfeConfigOptions in the Platform subkey (format 'PlatformId=N,EngineId=N,...') indicates a Platform has been deployed from the IDE (PlatformId=0 means never deployed — MXAccess will connect but every subscription will be Bad quality); RebootRequired='True' under MSIInstall surfaces as a loud warn since post-patch behavior is undefined. MxAccessComProbe resolves the LMXProxy.LMXProxyServer ProgID → CLSID → HKLM\SOFTWARE\Classes\WOW6432Node\CLSID\{guid}\InprocServer32, verifying the registered file exists on disk (catches the orphan-registry case where a previous uninstall left the ProgID registered but the DLL is gone — distinguishes it from the 'totally not installed' case by message); also emits a Warn when the test process is 64-bit (MXAccess COM activation fails with REGDB_E_CLASSNOTREG 0x80040154 regardless of registration, so seeing this warning tells operators why the activation would fail even on a fully-installed machine). SqlProbe tests Galaxy Repository via Microsoft.Data.SqlClient using the Windows-auth localhost connection string the repo code defaults to — distinguishes 'SQL Server unreachable' (connection fails) from 'ZB database does not exist' (SELECT DB_ID('ZB') returns null) because they have different remediation paths (sc.exe start MSSQLSERVER vs. restore from .cab backup); a secondary CheckDeployedObjectCountAsync query on 'gobject WHERE deployed_version > 0' warns when the count is zero because discovery smoke tests will return empty hierarchies. NamedPipeProbe opens a 2s NamedPipeClientStream against OtOpcUaGalaxyHost's pipe ('OtOpcUaGalaxy' per the installer default) — pipe accepting a connection proves the Host service is listening; disconnects immediately so we don't consume a session slot.
Service lists kept as internal static data so tests can inspect + override: CoreServices (aaBootstrap + aaGR + NmxSvc + MSSQLSERVER — hard fail if missing), SoftServices (aaLogger + aaUserValidator + aaGlobalDataCacheMonitorSvr — warn only; stack runs without them but diagnostics/auth are degraded), HistorianServices (aahClientAccessPoint + aahGateway — opt-in via Options.CheckHistorian, only matters for HistoryRead IPC paths), OtOpcUaServices (our OtOpcUaGalaxyHost hard-required for end-to-end live tests + OtOpcUa warn + GLAuth warn). Narrower entry points CheckRepositoryOnlyAsync and CheckGalaxyHostPipeOnlyAsync for tests that only care about specific subsystems — avoid paying the full probe cost on every GalaxyRepositoryLiveSmokeTests fact.
Multi-targeting mechanics: System.ServiceProcess.ServiceController + Microsoft.Win32.Registry are NuGet packages on net10 but in-box BCL references on net48; csproj conditions Package vs Reference by TargetFramework. Microsoft.Data.SqlClient v6 supports both frameworks so single PackageReference. Net48Polyfills.cs provides IsExternalInit shim (records/init-only setters) and SupportedOSPlatformAttribute stub so the same Probe sources compile on both frameworks without per-callsite preprocessor guards — lets Roslyn's platform-compatibility analyzer stay useful on net10 without breaking net48 builds.
Existing GalaxyRepositoryLiveSmokeTests updated to delegate its skip decision to AvevaPrerequisites.CheckRepositoryOnlyAsync (legacy ZbReachableAsync kept as a compatibility adapter so the in-test 'if (!await ZbReachableAsync()) return;' pattern keeps working while the surrounding fixtures gradually migrate to Assert.Skip-with-reason). Slnx file registers the new project.
Tests — AvevaPrerequisitesLiveTests (8 new Integration cases, Category=LiveGalaxy): the helper correctly reports Framework install (registry pass), aaBootstrap Running (service pass), aaGR Running (service pass), MxAccess COM registered (com pass), ZB database reachable (sql pass), deployed-object count > 0 (warn-upgraded-to-pass because this box has 49 objects deployed), the AVEVA side is ready even when our own services (OtOpcUaGalaxyHost) aren't installed yet (IsAvevaSideReady=true), and the helper emits rows for OtOpcUaGalaxyHost + OtOpcUa + GLAuth even when not installed (regression guard — nobody can accidentally ship a check that omits our own services). Full Galaxy.Host.Tests Category=LiveGalaxy suite: 13 pass (5 prior smoke + 8 new prerequisites). Full solution build clean, 0 errors.
What's NOT in this PR: end-to-end Galaxy stack smoke (Proxy → Host pipe → MXAccess → real Galaxy tag). That's the next PR — this one is the gate the end-to-end smoke will call first to produce actionable skip messages instead of silent returns.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
163 lines
7.4 KiB
C#
163 lines
7.4 KiB
C#
using System.Runtime.InteropServices;
|
|
using System.Runtime.Versioning;
|
|
using Microsoft.Win32;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.TestSupport.Probes;
|
|
|
|
/// <summary>
|
|
/// Reads HKLM registry keys to confirm ArchestrA Framework / System Platform install
|
|
/// markers. Matches the registered paths documented in
|
|
/// <c>docs/v2/implementation/</c> — System Platform is 32-bit so keys live under
|
|
/// <c>HKLM\SOFTWARE\WOW6432Node\ArchestrA\...</c>.
|
|
/// </summary>
|
|
public static class RegistryProbe
|
|
{
|
|
// Canonical install roots per the research on our dev box (System Platform 2020 R2).
|
|
public const string ArchestrARootKey = @"SOFTWARE\WOW6432Node\ArchestrA";
|
|
public const string FrameworkKey = @"SOFTWARE\WOW6432Node\ArchestrA\Framework";
|
|
public const string PlatformKey = @"SOFTWARE\WOW6432Node\ArchestrA\Framework\Platform";
|
|
public const string MsiInstallKey = @"SOFTWARE\WOW6432Node\ArchestrA\MSIInstall";
|
|
|
|
public static PrerequisiteCheck CheckFrameworkInstalled()
|
|
{
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Framework", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Skip, "Registry probes only run on Windows.");
|
|
}
|
|
return FrameworkInstalledWindows();
|
|
}
|
|
|
|
public static PrerequisiteCheck CheckPlatformDeployed()
|
|
{
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Platform", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Skip, "Registry probes only run on Windows.");
|
|
}
|
|
return PlatformDeployedWindows();
|
|
}
|
|
|
|
public static PrerequisiteCheck CheckRebootPending()
|
|
{
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.RebootPending", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Skip, "Registry probes only run on Windows.");
|
|
}
|
|
return RebootPendingWindows();
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static PrerequisiteCheck FrameworkInstalledWindows()
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.LocalMachine.OpenSubKey(FrameworkKey);
|
|
if (key is null)
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Framework", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Fail,
|
|
$"Missing {FrameworkKey} — ArchestrA Framework isn't installed. Install AVEVA System Platform from the setup media.");
|
|
}
|
|
|
|
var installPath = key.GetValue("InstallPath") as string;
|
|
var rootPath = key.GetValue("RootPath") as string;
|
|
if (string.IsNullOrWhiteSpace(installPath) || string.IsNullOrWhiteSpace(rootPath))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Framework", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"Framework key exists but InstallPath/RootPath values missing — install may be incomplete.");
|
|
}
|
|
|
|
return new PrerequisiteCheck("registry:ArchestrA.Framework", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Pass,
|
|
$"Installed at {installPath} (RootPath {rootPath}).");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Framework", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"Probe failed: {ex.GetType().Name}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static PrerequisiteCheck PlatformDeployedWindows()
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.LocalMachine.OpenSubKey(PlatformKey);
|
|
var pfeConfig = key?.GetValue("PfeConfigOptions") as string;
|
|
if (string.IsNullOrWhiteSpace(pfeConfig))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Platform.Deployed", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"No Platform object deployed locally (Platform\\PfeConfigOptions empty). MXAccess will connect but subscriptions will fail. Deploy a Platform from the IDE.");
|
|
}
|
|
|
|
// PfeConfigOptions format: "PlatformId=N,EngineId=N,EngineName=...,..."
|
|
// A non-deployed state leaves PlatformId=0 or the key empty.
|
|
if (pfeConfig.Contains("PlatformId=0,", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Platform.Deployed", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"Platform never deployed (PfeConfigOptions has PlatformId=0). Deploy a Platform from the IDE before running live tests.");
|
|
}
|
|
|
|
return new PrerequisiteCheck("registry:ArchestrA.Platform.Deployed", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Pass,
|
|
$"Platform deployed ({pfeConfig}).");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.Platform.Deployed", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"Probe failed: {ex.GetType().Name}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static PrerequisiteCheck RebootPendingWindows()
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.LocalMachine.OpenSubKey(MsiInstallKey);
|
|
var rebootRequired = key?.GetValue("RebootRequired") as string;
|
|
if (string.Equals(rebootRequired, "True", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.RebootPending", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
"An ArchestrA patch has been installed but the machine hasn't rebooted. Post-patch behavior is undefined until a reboot.");
|
|
}
|
|
return new PrerequisiteCheck("registry:ArchestrA.RebootPending", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Pass,
|
|
"No pending reboot flagged.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new PrerequisiteCheck("registry:ArchestrA.RebootPending", PrerequisiteCategory.AvevaInstall,
|
|
PrerequisiteStatus.Warn,
|
|
$"Probe failed: {ex.GetType().Name}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Read the registered <see cref="ComProgIdCheck"/> CLSID for the given ProgID and
|
|
/// resolve the 32-bit <c>InprocServer32</c> file path. Returns null when either is missing.
|
|
/// </summary>
|
|
[SupportedOSPlatform("windows")]
|
|
internal static (string? Clsid, string? InprocDllPath) ResolveProgIdToInproc(string progId)
|
|
{
|
|
using var progIdKey = Registry.ClassesRoot.OpenSubKey($@"{progId}\CLSID");
|
|
var clsid = progIdKey?.GetValue(null) as string;
|
|
if (string.IsNullOrWhiteSpace(clsid)) return (null, null);
|
|
|
|
// 32-bit COM server under Wow6432Node\CLSID\{guid}\InprocServer32 default value.
|
|
using var inproc = Registry.LocalMachine.OpenSubKey(
|
|
$@"SOFTWARE\Classes\WOW6432Node\CLSID\{clsid}\InprocServer32");
|
|
var dll = inproc?.GetValue(null) as string;
|
|
return (clsid, dll);
|
|
}
|
|
}
|