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.
68 lines
2.9 KiB
PHP
68 lines
2.9 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'
|
|
);
|
|
$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) : '';
|
|
$selectorStart = is_string($allocator)
|
|
? strpos($allocator, 'private static function selectPlannedPoolPair(')
|
|
: false;
|
|
$selectorEnd = $selectorStart === false ? false : strpos(
|
|
$allocator,
|
|
'private static function lockReservableAddressCandidate(',
|
|
$selectorStart
|
|
);
|
|
$selector = $selectorStart !== false && $selectorEnd !== false
|
|
? substr($allocator, $selectorStart, $selectorEnd - $selectorStart) : '';
|
|
|
|
$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, '$constraint->assertMatches(')
|
|
&& $selector !== ''
|
|
&& str_contains($selector, 'self::lockReservableAddressCandidate(')
|
|
&& !str_contains($selector, "DB::table('cloud_public_ips')"),
|
|
'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";
|