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/CloudProvisioningPublicNetw...

122 lines
5.8 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if (!is_string($contents)) {
throw new RuntimeException('Unreadable contract source: ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$order = $read('app/Services/Cloud/CloudOrderService.php');
$placement = $read('app/Services/Cloud/CloudPlacementService.php');
$worker = $read('app/Services/Cloud/CloudWorkerService.php');
$invoice = $read('app/Services/Cloud/CloudInvoiceService.php');
$recovery = $read('app/Services/Cloud/CloudOperationRecoveryIdentity.php');
$reservation = $read('app/Models/CloudResourceReservation.php');
$assert(!str_contains($order, "'public_pool_key' => ''")
&& !str_contains($order, "'public_pool_cidr' => ''")
&& !str_contains($order, "'public_ip_cidr' => ''")
&& !str_contains($order, "'gateway' => ''"),
'Unpaid orders still define the retired scalar public-network contract.');
$snapshotGate = strpos($order,
"if (\$source === 'deployment_snapshot') {");
$purchaseTransaction = strpos($order,
"return (new User())->getConnection()->transaction(");
$assert($snapshotGate !== false && $purchaseTransaction !== false
&& $snapshotGate < $purchaseTransaction
&& str_contains(substr($order, $snapshotGate,
$purchaseTransaction - $snapshotGate),
'云快照创建实例正在升级双栈网络,暂不可用'),
'Deferred cloud-snapshot provisioning is not blocked before billing state is created.');
$paymentStart = strpos($order,
'public static function queuePaidProvision(');
$paymentPlacement = strpos($order,
'CloudPlacementService::reserve(',
$paymentStart === false ? 0 : $paymentStart);
$paymentGate = $paymentStart === false || $paymentPlacement === false
? '' : substr($order, $paymentStart,
$paymentPlacement - $paymentStart);
$assert(str_contains($paymentGate,
"if (\$source === 'deployment_snapshot')")
&& str_contains($paymentGate,
'云快照创建实例正在升级双栈网络,暂不可用'),
'A pre-existing unpaid cloud-snapshot order can cross the payment boundary.');
$compactOrder = preg_replace('/\s+/', ' ', $order) ?? $order;
$assert(str_contains($compactOrder,
"\$orderSpec['public_network'] = \$placement['public_network']->toArray();")
&& str_contains($order,
"\$placement['payload']['body']['public_network']"),
'Paid order and dispatched job do not freeze the same public-network snapshot.');
foreach (['reserveBundle(', 'commitBundle(', 'fenceBundle(',
'releaseBundle(', 'releaseCommittedBundle('] as $call) {
$assert(preg_match(
'/CloudPublicNetworkAllocationService::\s*'
. preg_quote($call, '/') . '/',
$placement
) === 1,
'Provisioning placement does not use bundle operation: ' . $call);
}
$assert(str_contains($placement,
"\$payload['body']['public_network'] = \$publicNetwork->toArray();")
&& str_contains($placement,
"'public_network' => \$publicNetwork"),
'Placement does not return and dispatch one immutable dual-stack snapshot.');
$assert(!str_contains($reservation,
"foreach (['network_attachment_id', 'public_ip_pool_id',")
&& str_contains($reservation, 'cloud_resource_reservation_ips'),
'Resource reservations still treat one public_ip_id as network authority.');
$compactWorker = preg_replace('/\s+/', ' ', $worker) ?? $worker;
$workerFinalizationStart = strpos($worker,
'$provisionInvoice = CloudInvoice::where(');
$workerCommit = strpos($worker, 'CloudPlacementService::commit(',
$workerFinalizationStart === false ? 0 : $workerFinalizationStart);
$workerPreCommit = $workerFinalizationStart === false || $workerCommit === false
? '' : substr($worker, $workerFinalizationStart,
$workerCommit - $workerFinalizationStart);
$assert($workerPreCommit !== ''
&& !str_contains($workerPreCommit, 'CloudResourceReservation::where('),
'Create success locks the reservation before canonical placement commit.');
$tryHostStart = strpos($placement, 'private static function tryHost(');
$allocatorCall = strpos(
$placement,
'CloudPublicNetworkAllocationService::reserveBundle(',
$tryHostStart === false ? 0 : $tryHostStart
);
$preAllocator = $tryHostStart === false || $allocatorCall === false
? '' : substr($placement, $tryHostStart,
$allocatorCall - $tryHostStart);
$assert($preAllocator !== ''
&& !str_contains($preAllocator, 'lockedCandidates(')
&& !str_contains($preAllocator, 'hasCompleteDualStackCandidate('),
'tryHost can bypass the canonical allocator through a stale precheck.');
$assert(substr_count($worker,
'CloudPublicNetworkSnapshot::fromArray(') >= 2
&& str_contains($compactWorker,
"\$instanceSpec['public_network'] = \$confirmedPublicNetwork->toArray();")
&& str_contains($worker,
"\$requestedPublicNetwork->fingerprint()")
&& str_contains($worker,
"\$confirmedPublicNetwork->fingerprint()"),
'Create finalization does not compare and persist the exact dual-stack identity.');
$assert(str_contains($invoice, 'CloudPublicNetworkSnapshot::fromArray(')
&& str_contains($invoice, "\$spec['public_network']")
&& !str_contains($invoice, "\$spec['public_ip_cidr']"),
'Provision-success mail still treats scalar public_ip_cidr as authoritative.');
$assert(substr_count($recovery,
'CloudPublicNetworkSnapshot::fromArray(') >= 2
&& str_contains($recovery, "\$orderSpec['public_network']")
&& str_contains($recovery, "\$body['public_network']"),
'Create recovery identity is not bound to the frozen dual-stack snapshot.');
echo "Dual-stack provisioning call-chain contract passed.\n";