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.
virt/web/tests/CloudPublicNetworkPlannedBu...

64 lines
2.7 KiB
PHP

<?php
$root = dirname(__DIR__);
$allocator = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkAllocationService.php'
);
$constraint = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkBundleConstraint.php'
);
$catalog = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkCandidateCatalog.php'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$plannedStart = is_string($allocator)
? strpos($allocator, 'public static function reservePlannedBundle(')
: false;
$plannedEnd = $plannedStart === false ? false : strpos(
$allocator,
'private static function reserveBundleUsingConstraint(',
$plannedStart
);
$plannedMethod = $plannedStart !== false && $plannedEnd !== false
? substr($allocator, $plannedStart, $plannedEnd - $plannedStart) : '';
$assert($plannedMethod !== ''
&& str_contains($plannedMethod, '$constraint->assertScope(')
&& str_contains($plannedMethod, 'reserveBundleUsingConstraint(')
&& !str_contains($plannedMethod, "DB::table('cloud_public_ips')"),
'Planned bundle interface bypassed the shared allocator core.');
$assert(is_string($allocator)
&& str_contains($allocator,
'self::lockPoolCatalog(' . "\n" . ' $hostId,')
&& str_contains($allocator, 'self::selectAvailablePoolPair(')
&& str_contains($allocator, '$selector->planAllocation(')
&& str_contains($allocator, "->where('address_binary',")
&& str_contains($allocator, '->lockForUpdate()->first()')
&& is_string($catalog)
&& str_contains($catalog, 'planConstrainedAllocation(')
&& str_contains($catalog, '$constraint->assertMatches(')
&& !str_contains($catalog, 'DB::')
&& !str_contains($catalog, 'lockForUpdate('),
'Planned bundle allocation introduced an independent IP selector.');
foreach (['host_id', 'line_id', 'network_attachment_id', 'attachment_key',
'network_selector', 'attachment_config_revision',
'attachment_verified_agent_revision', 'ipv4_pool', 'ipv6_pool',
'public_ip_pool_id', 'pool_key', 'address_family', 'desired_revision',
'observed_revision'] as $field) {
$assert(is_string($constraint) && str_contains($constraint, "'{$field}'"),
"Bundle constraint no longer freezes {$field}.");
}
$assert(!str_contains((string) $constraint, 'available_units')
&& str_contains((string) $constraint,
'$value[\'observed_revision\'] !== $value[\'desired_revision\']')
&& str_contains((string) $constraint,
'Public network bundle pools must be distinct.'),
'Bundle constraint accepted mutable capacity or incomplete pool identity.');
echo "Planned dual-stack bundle contract tests passed.\n";