|
|
|
|
@ -492,6 +492,7 @@ namespace {
|
|
|
|
|
$addIp(201, 13, 4, '8.8.9.20');
|
|
|
|
|
$addIp(202, 13, 4, '8.8.9.21');
|
|
|
|
|
$addIp(203, 13, 4, '8.8.9.22');
|
|
|
|
|
$addIp(204, 13, 4, '8.8.9.23');
|
|
|
|
|
$addIp(301, 21, 4, '9.9.9.30');
|
|
|
|
|
$addIp(302, 21, 4, '9.9.9.31');
|
|
|
|
|
$addIp(401, 22, 6, '2404:c140:156:3c::1000');
|
|
|
|
|
@ -638,6 +639,8 @@ namespace {
|
|
|
|
|
'8.8.8.19', '2404:c140:156:3a::1009', 10);
|
|
|
|
|
$addInstance(11, 111, 1021, 1022, 121, 122,
|
|
|
|
|
'8.8.8.20', '2404:c140:156:3a::100a', 10);
|
|
|
|
|
$addInstance(12, 112, 1023, 1024, 123, 124,
|
|
|
|
|
'8.8.8.21', '2404:c140:156:3a::100b', 10);
|
|
|
|
|
|
|
|
|
|
$sourceClaims = Capsule::table('cloud_resource_reservation_ips')
|
|
|
|
|
->where('reservation_id', 101)->where('active_claim', 1)
|
|
|
|
|
@ -731,6 +734,58 @@ namespace {
|
|
|
|
|
&& Capsule::table('cloud_resource_reservation_ips')
|
|
|
|
|
->where('reservation_id', 101)->count() === 3,
|
|
|
|
|
'Exact replay consulted mutable target catalog or duplicated resources.');
|
|
|
|
|
Capsule::table('cloud_hosts')->where('id', 1)
|
|
|
|
|
->update(['enabled' => 0]);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)->update([
|
|
|
|
|
'status' => 'suspended',
|
|
|
|
|
'service_status' => 'expired_grace',
|
|
|
|
|
'spec_json' => '{}',
|
|
|
|
|
]);
|
|
|
|
|
$mutableReplay = CloudPublicNetworkTransitionWorkflow::begin($admin);
|
|
|
|
|
$assert($mutableReplay->replayed()
|
|
|
|
|
&& $mutableReplay->transitionId() === $dispatch->transitionId()
|
|
|
|
|
&& Capsule::table('cloud_jobs')->count() === 1,
|
|
|
|
|
'Exact replay was coupled to mutable host or instance eligibility.');
|
|
|
|
|
Capsule::table('cloud_hosts')->where('id', 1)
|
|
|
|
|
->update(['enabled' => 1]);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)->update([
|
|
|
|
|
'status' => 'active',
|
|
|
|
|
'service_status' => 'active',
|
|
|
|
|
'spec_json' => json_encode([
|
|
|
|
|
'managed' => true,
|
|
|
|
|
'os_source' => 'cloud_template',
|
|
|
|
|
'public_network' => $sourceSnapshot(
|
|
|
|
|
'8.8.8.10',
|
|
|
|
|
'2404:c140:156:3a::1000'
|
|
|
|
|
),
|
|
|
|
|
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES),
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)
|
|
|
|
|
->update(['host_id' => 2]);
|
|
|
|
|
$rejects(
|
|
|
|
|
static fn () => CloudPublicNetworkTransitionWorkflow::begin($admin),
|
|
|
|
|
'Exact replay accepted a drifted immutable host association.'
|
|
|
|
|
);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)
|
|
|
|
|
->update(['host_id' => 1]);
|
|
|
|
|
Capsule::table('cloud_public_network_transitions')
|
|
|
|
|
->where('id', $dispatch->transitionId())->update([
|
|
|
|
|
'state' => 'succeeded',
|
|
|
|
|
'effect_resolution' => 'applied',
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)
|
|
|
|
|
->update(['host_id' => 2]);
|
|
|
|
|
$rejects(
|
|
|
|
|
static fn () => CloudPublicNetworkTransitionWorkflow::begin($admin),
|
|
|
|
|
'Corrupt terminal-shaped replay bypassed the active host fence.'
|
|
|
|
|
);
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)
|
|
|
|
|
->update(['host_id' => 1]);
|
|
|
|
|
Capsule::table('cloud_public_network_transitions')
|
|
|
|
|
->where('id', $dispatch->transitionId())->update([
|
|
|
|
|
'state' => 'queued',
|
|
|
|
|
'effect_resolution' => 'not_applicable',
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_public_ip_pools')->where('id', 13)
|
|
|
|
|
->update(['state' => 'active']);
|
|
|
|
|
|
|
|
|
|
@ -1303,6 +1358,64 @@ namespace {
|
|
|
|
|
Capsule::table('cloud_invoices')->where('id', $invoice->id)
|
|
|
|
|
->update(['amount' => '5.00']);
|
|
|
|
|
|
|
|
|
|
// The private reservation seam must share begin()'s one transaction. A
|
|
|
|
|
// failure at the final job insert rolls back wallet, invoice, transition,
|
|
|
|
|
// target claim and address fencing as one unit.
|
|
|
|
|
$rollbackCommand = CloudPublicNetworkTransitionCommand::userPaidAutomatic(
|
|
|
|
|
12,
|
|
|
|
|
10,
|
|
|
|
|
'tenant-network-rollback-0012',
|
|
|
|
|
'5.00'
|
|
|
|
|
);
|
|
|
|
|
$rollbackBefore = [
|
|
|
|
|
'money' => (string) Capsule::table('user')->where('id', 10)
|
|
|
|
|
->value('money'),
|
|
|
|
|
'invoices' => Capsule::table('cloud_invoices')->count(),
|
|
|
|
|
'transitions' => Capsule::table(
|
|
|
|
|
'cloud_public_network_transitions'
|
|
|
|
|
)->count(),
|
|
|
|
|
'legs' => Capsule::table(
|
|
|
|
|
'cloud_public_network_transition_ips'
|
|
|
|
|
)->count(),
|
|
|
|
|
'jobs' => Capsule::table('cloud_jobs')->count(),
|
|
|
|
|
'claims' => Capsule::table('cloud_resource_reservation_ips')
|
|
|
|
|
->where('reservation_id', 112)->count(),
|
|
|
|
|
];
|
|
|
|
|
Capsule::connection()->statement(
|
|
|
|
|
'CREATE TRIGGER fail_transition_job_insert '
|
|
|
|
|
. 'BEFORE INSERT ON cloud_jobs '
|
|
|
|
|
. "WHEN NEW.request_idempotency_key = "
|
|
|
|
|
. "'tenant-network-rollback-0012' "
|
|
|
|
|
. "BEGIN SELECT RAISE(ABORT, 'fault injection'); END"
|
|
|
|
|
);
|
|
|
|
|
$rollbackRejected = false;
|
|
|
|
|
try {
|
|
|
|
|
CloudPublicNetworkTransitionWorkflow::begin($rollbackCommand);
|
|
|
|
|
} catch (Throwable) {
|
|
|
|
|
$rollbackRejected = true;
|
|
|
|
|
}
|
|
|
|
|
Capsule::connection()->statement('DROP TRIGGER fail_transition_job_insert');
|
|
|
|
|
$assert($rollbackRejected
|
|
|
|
|
&& (string) Capsule::table('user')->where('id', 10)->value('money')
|
|
|
|
|
=== $rollbackBefore['money']
|
|
|
|
|
&& Capsule::table('cloud_invoices')->count()
|
|
|
|
|
=== $rollbackBefore['invoices']
|
|
|
|
|
&& Capsule::table('cloud_public_network_transitions')->count()
|
|
|
|
|
=== $rollbackBefore['transitions']
|
|
|
|
|
&& Capsule::table('cloud_public_network_transition_ips')->count()
|
|
|
|
|
=== $rollbackBefore['legs']
|
|
|
|
|
&& Capsule::table('cloud_jobs')->count() === $rollbackBefore['jobs']
|
|
|
|
|
&& Capsule::table('cloud_resource_reservation_ips')
|
|
|
|
|
->where('reservation_id', 112)->count()
|
|
|
|
|
=== $rollbackBefore['claims']
|
|
|
|
|
&& Capsule::table('cloud_public_ips')->whereIn('id', [203, 204])
|
|
|
|
|
->where('state', 'available')
|
|
|
|
|
->whereNull('reservation_id')
|
|
|
|
|
->whereNull('reservation_ip_claim_id')
|
|
|
|
|
->whereNull('instance_id')
|
|
|
|
|
->whereNull('operation_id')->count() === 2,
|
|
|
|
|
'Extracted reservation seam committed a partial transition.');
|
|
|
|
|
|
|
|
|
|
$batchCommand = CloudPublicNetworkTransitionCommand::poolReplacement(
|
|
|
|
|
10,
|
|
|
|
|
99,
|
|
|
|
|
@ -1346,5 +1459,86 @@ namespace {
|
|
|
|
|
&& Capsule::table('cloud_jobs')->count() === $beforeBatchJobs,
|
|
|
|
|
'Pool-replacement parent identity was mutable or left writes.');
|
|
|
|
|
|
|
|
|
|
// The internal batch caller may replay only the exact locked parent. A
|
|
|
|
|
// drifted parent FK must fail even when the frozen request fingerprint is
|
|
|
|
|
// otherwise unchanged.
|
|
|
|
|
$seedJob = CloudJob::find($dispatch->jobId());
|
|
|
|
|
$parentA = $seedJob->replicate();
|
|
|
|
|
$parentA->operation_id = str_repeat('d', 32);
|
|
|
|
|
$parentA->request_idempotency_key = 'pool-parent-replay-a-0001';
|
|
|
|
|
$parentA->request_fingerprint = hash('sha256', 'parent-a');
|
|
|
|
|
$parentA->parent_job_id = null;
|
|
|
|
|
$parentA->instance_id = null;
|
|
|
|
|
$parentA->host_id = null;
|
|
|
|
|
$parentA->public_network_transition_id = null;
|
|
|
|
|
$parentA->kind = 'public_ip_pool_replacement_batch';
|
|
|
|
|
$parentA->execution_mode = 'local';
|
|
|
|
|
$parentA->created_at = $parentA->updated_at = time();
|
|
|
|
|
$parentA->save();
|
|
|
|
|
$parentB = $parentA->replicate();
|
|
|
|
|
$parentB->operation_id = str_repeat('e', 32);
|
|
|
|
|
$parentB->request_idempotency_key = 'pool-parent-replay-b-0001';
|
|
|
|
|
$parentB->request_fingerprint = hash('sha256', 'parent-b');
|
|
|
|
|
$parentB->created_at = $parentB->updated_at = time();
|
|
|
|
|
$parentB->save();
|
|
|
|
|
$batchReplayCommand = CloudPublicNetworkTransitionCommand::poolReplacement(
|
|
|
|
|
1,
|
|
|
|
|
99,
|
|
|
|
|
'admin-network-0001',
|
|
|
|
|
(int) $parentA->id,
|
|
|
|
|
77,
|
|
|
|
|
[4 => [
|
|
|
|
|
'pool_key' => str_repeat('c', 32),
|
|
|
|
|
'address_cidr' => '8.8.9.20/24',
|
|
|
|
|
]]
|
|
|
|
|
);
|
|
|
|
|
Capsule::table('cloud_public_network_transitions')
|
|
|
|
|
->where('id', $dispatch->transitionId())->update([
|
|
|
|
|
'kind' => 'pool_replacement',
|
|
|
|
|
'pool_replacement_batch_item_id' => 77,
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', $dispatch->jobId())->update([
|
|
|
|
|
'parent_job_id' => (int) $parentA->id,
|
|
|
|
|
'request_fingerprint' => $batchReplayCommand->fingerprint(),
|
|
|
|
|
]);
|
|
|
|
|
$reserve = new ReflectionMethod(
|
|
|
|
|
CloudPublicNetworkTransitionWorkflow::class,
|
|
|
|
|
'reserveTransitionLocked'
|
|
|
|
|
);
|
|
|
|
|
$invokeBatchReplay = static function () use (
|
|
|
|
|
$reserve,
|
|
|
|
|
$batchReplayCommand
|
|
|
|
|
) {
|
|
|
|
|
return Capsule::connection()->transaction(static function () use (
|
|
|
|
|
$reserve,
|
|
|
|
|
$batchReplayCommand
|
|
|
|
|
) {
|
|
|
|
|
$actor = \App\Models\User::where('id', 99)
|
|
|
|
|
->lockForUpdate()->first();
|
|
|
|
|
return $reserve->invoke(null, $batchReplayCommand, $actor);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
$batchReplay = $invokeBatchReplay();
|
|
|
|
|
$assert($batchReplay->replayed()
|
|
|
|
|
&& $batchReplay->transitionId() === $dispatch->transitionId(),
|
|
|
|
|
'Exact batch parent replay did not return its frozen dispatch.');
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', $dispatch->jobId())
|
|
|
|
|
->update(['parent_job_id' => (int) $parentB->id]);
|
|
|
|
|
$rejects(
|
|
|
|
|
$invokeBatchReplay,
|
|
|
|
|
'Batch replay accepted a drifted parent job association.'
|
|
|
|
|
);
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', $dispatch->jobId())->update([
|
|
|
|
|
'parent_job_id' => null,
|
|
|
|
|
'request_fingerprint' => $admin->fingerprint(),
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_public_network_transitions')
|
|
|
|
|
->where('id', $dispatch->transitionId())->update([
|
|
|
|
|
'kind' => 'admin_manual',
|
|
|
|
|
'pool_replacement_batch_item_id' => null,
|
|
|
|
|
]);
|
|
|
|
|
CloudJob::whereIn('id', [(int) $parentA->id, (int) $parentB->id])
|
|
|
|
|
->delete();
|
|
|
|
|
|
|
|
|
|
echo "Public-network transition begin workflow tests passed.\n";
|
|
|
|
|
}
|
|
|
|
|
|