You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
7.0 KiB
PHP
172 lines
7.0 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
$root = dirname(__DIR__);
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$settings = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAgentSettingsService.php'
|
|
);
|
|
$worker = file_get_contents($root . '/app/Command/CloudWorker.php');
|
|
$lifecycle = file_get_contents($root . '/app/Command/CloudLifecycle.php');
|
|
$heartbeat = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudRuntimeHeartbeat.php'
|
|
);
|
|
|
|
$assert(is_string($settings)
|
|
&& str_contains($settings, "request('GET', '/v1/health', \$actor)")
|
|
&& str_contains($settings, "'GET', '/v1/capabilities', \$actor")
|
|
&& str_contains($settings, "private const REQUIRED_FEATURES = [")
|
|
&& str_contains($settings, "'create_vm', 'delete_vm', 'power', 'resources', 'settings', 'network'")
|
|
&& str_contains($settings, "'console', 'templates', 'user_iso',")
|
|
&& !str_contains($settings, "'reconciliation'")
|
|
&& str_contains($settings, "(\$capabilities['backend'] ?? null) !== 'libvirt'")
|
|
&& str_contains($settings, "\$features['uefi'] !== true")
|
|
&& str_contains($settings, "\$features['secure_boot'] !== false")
|
|
&& str_contains($settings, "'service' => 'virt-host-agent'")
|
|
&& str_contains($settings, "'agent_invalid_health'")
|
|
&& str_contains($settings, "'agent_invalid_capabilities'")
|
|
&& str_contains($settings, "'agent_capability_mismatch'")
|
|
&& str_contains($settings, "recordTest(\$hostId")
|
|
&& str_contains($settings, "'healthy'")
|
|
&& str_contains($settings, "'unhealthy'")
|
|
&& str_contains($settings, '$setting->tested_revision = 0')
|
|
&& str_contains($settings, "'agent_not_tested'")
|
|
&& str_contains($settings,
|
|
"'tested_revision' => \$status === 'healthy'"),
|
|
'Per-host Agent health test lost its signed probe or durable status.');
|
|
|
|
$capabilitySummary = new ReflectionMethod(
|
|
\App\Services\Cloud\CloudAgentSettingsService::class,
|
|
'capabilitySummary'
|
|
);
|
|
$required = [
|
|
'create_vm', 'delete_vm', 'power', 'resources', 'settings', 'network',
|
|
'reinstall', 'snapshots', 'backups', 'firewall', 'rescue', 'metrics',
|
|
'console', 'templates', 'user_iso',
|
|
];
|
|
$agentTypes = file_get_contents(
|
|
dirname($root) . '/agent/hypervisor/types.go'
|
|
);
|
|
$featureStruct = [];
|
|
$featureTags = [];
|
|
$assert(is_string($agentTypes)
|
|
&& preg_match('/type FeatureSet struct \\{(?<body>.*?)^\\}/ms',
|
|
$agentTypes, $featureStruct) === 1
|
|
&& preg_match_all('/json:"([a-z][a-z0-9_]*)"/',
|
|
$featureStruct['body'], $featureTags) !== false,
|
|
'Go Agent capability feature contract could not be read.');
|
|
$agentFeatureKeys = $featureTags[1];
|
|
$optional = ['peer_migration'];
|
|
$agentRequired = array_values(array_diff(
|
|
$agentFeatureKeys, ['uefi', 'secure_boot', ...$optional]
|
|
));
|
|
$assert($agentRequired === $required
|
|
&& $agentFeatureKeys === array_merge($required,
|
|
['uefi', 'secure_boot'], $optional),
|
|
'PHP required capabilities diverged from the Go Agent feature contract.');
|
|
$features = array_fill_keys($agentFeatureKeys, true);
|
|
$features['secure_boot'] = false;
|
|
$summary = $capabilitySummary->invoke(null, [
|
|
'backend' => 'libvirt', 'features' => $features,
|
|
'network_selectors' => ['bridge:br0', 'network:default'],
|
|
'checks' => ['storage_configuration' => ['available' => true]],
|
|
], 'bridge:br0');
|
|
$assert($summary === [
|
|
'backend' => 'libvirt',
|
|
'uefi' => true,
|
|
'secure_boot' => false,
|
|
'storage_configuration' => true,
|
|
'network_selectors' => ['bridge:br0', 'network:default'],
|
|
'required_network_selector' => 'bridge:br0',
|
|
'required_feature_count' => 15,
|
|
'available_features' => $required,
|
|
'unavailable_features' => [],
|
|
], 'Valid libvirt/UEFI/no-Secure-Boot capability response changed.');
|
|
$expectCapabilityError = static function (array $capabilities,
|
|
string $code, int $status, string $requiredSelector = 'bridge:br0') use (
|
|
$assert, $capabilitySummary
|
|
): void {
|
|
try {
|
|
$capabilitySummary->invoke(null, $capabilities, $requiredSelector);
|
|
} catch (\App\Services\Cloud\CloudAgentError $error) {
|
|
$assert($error->agentCode === $code && $error->httpStatus === $status,
|
|
'Capability mismatch returned the wrong stable error contract.');
|
|
return;
|
|
}
|
|
throw new RuntimeException('Invalid Agent capabilities were accepted.');
|
|
};
|
|
$validSelectors = [
|
|
'network_selectors' => ['bridge:br0'],
|
|
'checks' => ['storage_configuration' => ['available' => true]],
|
|
];
|
|
$invalidBackend = ['backend' => 'qemu', 'features' => $features]
|
|
+ $validSelectors;
|
|
$expectCapabilityError($invalidBackend, 'agent_invalid_capabilities', 502);
|
|
$missingFeature = $features;
|
|
unset($missingFeature['metrics']);
|
|
$expectCapabilityError(['backend' => 'libvirt', 'features' => $missingFeature]
|
|
+ $validSelectors,
|
|
'agent_invalid_capabilities', 502);
|
|
foreach ([
|
|
array_replace($features, ['metrics' => false]),
|
|
array_replace($features, ['uefi' => false]),
|
|
array_replace($features, ['secure_boot' => true]),
|
|
] as $mismatch) {
|
|
$expectCapabilityError(['backend' => 'libvirt', 'features' => $mismatch]
|
|
+ $validSelectors,
|
|
'agent_capability_mismatch', 409);
|
|
}
|
|
foreach ([
|
|
null,
|
|
[],
|
|
['public'],
|
|
['bridge:' . str_repeat('b', 16)],
|
|
['network:' . str_repeat('n', 65)],
|
|
['network:default', 'bridge:br0'],
|
|
['bridge:br0', 'bridge:br0'],
|
|
[str_repeat('a', 65)],
|
|
array_fill(0, 65, 'bridge:br0'),
|
|
] as $invalidSelectors) {
|
|
$payload = ['backend' => 'libvirt', 'features' => $features,
|
|
'checks' => ['storage_configuration' => ['available' => true]]];
|
|
if ($invalidSelectors !== null) {
|
|
$payload['network_selectors'] = $invalidSelectors;
|
|
}
|
|
$expectCapabilityError($payload, 'agent_invalid_capabilities', 502);
|
|
}
|
|
$expectCapabilityError([
|
|
'backend' => 'libvirt', 'features' => $features,
|
|
'network_selectors' => ['network:default'],
|
|
'checks' => ['storage_configuration' => ['available' => true]],
|
|
], 'agent_capability_mismatch', 409);
|
|
$expectCapabilityError([
|
|
'backend' => 'libvirt', 'features' => $features,
|
|
] + $validSelectors, 'agent_capability_mismatch', 409, 'public');
|
|
$expectCapabilityError([
|
|
'backend' => 'libvirt',
|
|
'features' => array_replace($features, ['create_vm' => false]),
|
|
'network_selectors' => ['bridge:br0'],
|
|
'checks' => ['storage_configuration' => [
|
|
'available' => false, 'reason' => 'not_configured',
|
|
]],
|
|
], 'agent_storage_not_configured', 409);
|
|
|
|
foreach ([$worker, $lifecycle] as $source) {
|
|
$assert(is_string($source)
|
|
&& !str_contains($source, 'Readiness::wait')
|
|
&& !str_contains($source, 'readiness_timeout'),
|
|
'A global virtualization readiness gate can still block a PHP worker.');
|
|
}
|
|
$assert(is_string($heartbeat)
|
|
&& !str_contains($heartbeat, "'engine_readiness'")
|
|
&& !str_contains($heartbeat, "'engine_readiness_timeout'"),
|
|
'Runtime health retained the removed global engine startup phase.');
|
|
|
|
echo "Per-host Agent readiness contract passed.\n";
|