From dcde2c51c732aa7b52f53bc4ac2fccd27ed88ac5 Mon Sep 17 00:00:00 2001 From: codex Date: Mon, 2 Nov 2026 21:43:24 +0800 Subject: [PATCH] test: update aggregate recovery network fixture --- .../CloudAggregateRecoveryConvergenceTest.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/web/tests/CloudAggregateRecoveryConvergenceTest.php b/web/tests/CloudAggregateRecoveryConvergenceTest.php index f82b19e4..b48e54ed 100644 --- a/web/tests/CloudAggregateRecoveryConvergenceTest.php +++ b/web/tests/CloudAggregateRecoveryConvergenceTest.php @@ -33,6 +33,12 @@ namespace App\Services\Cloud { return [7, 8]; } + public static function testedNetworkSelectors( + \App\Models\CloudHostAgent $setting + ): array { + return $setting->testedNetworkSelectors(); + } + public static function clientForConfiguration( int $hostId, float $timeoutSeconds = 120.0 @@ -354,6 +360,7 @@ SQL); $table->integer('revision'); $table->integer('tested_revision'); $table->string('last_test_status'); + $table->text('network_selectors_json')->default('[]'); }); $schema->create('cloud_host_storage_configurations', static function ( Blueprint $table @@ -378,6 +385,48 @@ SQL); $table->integer('configured_memory_mib'); $table->integer('configured_disk_gib'); }); + $schema->create('cloud_host_network_attachments', static function ( + Blueprint $table + ): void { + $table->increments('id'); + $table->integer('host_id'); + $table->integer('line_id'); + $table->string('network_selector'); + $table->string('state'); + $table->string('verification_state'); + $table->integer('verified_agent_revision'); + $table->integer('last_verified_at'); + }); + $schema->create('cloud_public_ip_pools', static function ( + Blueprint $table + ): void { + $table->increments('id'); + $table->string('pool_key'); + $table->integer('host_id'); + $table->integer('network_attachment_id'); + $table->string('cidr'); + $table->string('gateway'); + $table->integer('guest_prefix_length'); + $table->text('dns_servers_json'); + $table->text('reserved_ips_json'); + $table->string('state'); + $table->string('sync_state'); + $table->integer('desired_revision'); + $table->integer('observed_revision'); + }); + $schema->create('cloud_public_ips', static function ( + Blueprint $table + ): void { + $table->increments('id'); + $table->integer('host_id'); + $table->integer('public_ip_pool_id'); + $table->string('address'); + $table->integer('prefix_length'); + $table->string('state'); + $table->integer('reservation_id')->nullable(); + $table->integer('instance_id')->nullable(); + $table->string('operation_id')->nullable(); + }); $schema->create('cloud_offers', static function (Blueprint $table): void { $table->increments('id'); $table->integer('plan_id'); @@ -443,6 +492,10 @@ SQL); Capsule::table('cloud_host_agents')->insert([ 'host_id' => $hostId, 'enabled' => 1, 'revision' => 1, 'tested_revision' => 1, 'last_test_status' => 'healthy', + 'network_selectors_json' => json_encode( + ['bridge:public-' . $hostId], + JSON_THROW_ON_ERROR + ), ]); Capsule::table('cloud_host_storage_configurations')->insert([ 'host_id' => $hostId, 'state' => 'applied', @@ -456,6 +509,43 @@ SQL); 'configured_memory_mib' => 32768, 'configured_disk_gib' => 512, ]); + $attachmentId = 100 + $hostId; + Capsule::table('cloud_host_network_attachments')->insert([ + 'id' => $attachmentId, + 'host_id' => $hostId, + 'line_id' => 1, + 'network_selector' => 'bridge:public-' . $hostId, + 'state' => 'active', + 'verification_state' => 'verified', + 'verified_agent_revision' => 1, + 'last_verified_at' => time(), + ]); + $publicPoolId = 200 + $hostId; + Capsule::table('cloud_public_ip_pools')->insert([ + 'id' => $publicPoolId, + 'pool_key' => str_repeat((string) $hostId, 32), + 'host_id' => $hostId, + 'network_attachment_id' => $attachmentId, + 'cidr' => '203.0.11' . $hostId . '.0/29', + 'gateway' => '203.0.11' . $hostId . '.1', + 'guest_prefix_length' => 29, + 'dns_servers_json' => '[]', + 'reserved_ips_json' => '[]', + 'state' => 'active', + 'sync_state' => 'applied', + 'desired_revision' => 1, + 'observed_revision' => 1, + ]); + Capsule::table('cloud_public_ips')->insert([ + 'host_id' => $hostId, + 'public_ip_pool_id' => $publicPoolId, + 'address' => '203.0.11' . $hostId . '.2', + 'prefix_length' => 29, + 'state' => 'available', + 'reservation_id' => null, + 'instance_id' => null, + 'operation_id' => null, + ]); } $now = time(); @@ -577,6 +667,7 @@ SQL); } foreach ($children as $index => $child) { $hostId = 1000 + (int) $child->id; + $networkSelector = 'bridge:b' . $hostId; Capsule::table('cloud_jobs')->where('id', (int) $child->id) ->update(['host_id' => $hostId]); Capsule::table('cloud_hosts')->insertOrIgnore([ @@ -586,6 +677,10 @@ SQL); Capsule::table('cloud_host_agents')->insertOrIgnore([ 'host_id' => $hostId, 'enabled' => 1, 'revision' => 1, 'tested_revision' => 1, 'last_test_status' => 'healthy', + 'network_selectors_json' => json_encode( + [$networkSelector], + JSON_THROW_ON_ERROR + ), ]); Capsule::table('cloud_host_storage_configurations') ->insertOrIgnore([ @@ -601,6 +696,47 @@ SQL); 'configured_memory_mib' => 32768, 'configured_disk_gib' => 512, ]); + $attachmentId = 100000 + $hostId; + Capsule::table('cloud_host_network_attachments') + ->insertOrIgnore([ + 'id' => $attachmentId, + 'host_id' => $hostId, + 'line_id' => 1, + 'network_selector' => $networkSelector, + 'state' => 'active', + 'verification_state' => 'verified', + 'verified_agent_revision' => 1, + 'last_verified_at' => $now, + ]); + $publicPoolId = 200000 + $hostId; + $thirdOctet = intdiv($hostId, 30) % 250; + $networkOctet = ($hostId % 30) * 8; + $networkPrefix = '198.18.' . $thirdOctet . '.'; + Capsule::table('cloud_public_ip_pools')->insertOrIgnore([ + 'id' => $publicPoolId, + 'pool_key' => md5('aggregate-network-pool:' . $hostId), + 'host_id' => $hostId, + 'network_attachment_id' => $attachmentId, + 'cidr' => $networkPrefix . $networkOctet . '/29', + 'gateway' => $networkPrefix . ($networkOctet + 1), + 'guest_prefix_length' => 29, + 'dns_servers_json' => '[]', + 'reserved_ips_json' => '[]', + 'state' => 'active', + 'sync_state' => 'applied', + 'desired_revision' => 1, + 'observed_revision' => 1, + ]); + Capsule::table('cloud_public_ips')->insertOrIgnore([ + 'host_id' => $hostId, + 'public_ip_pool_id' => $publicPoolId, + 'address' => $networkPrefix . ($networkOctet + 2), + 'prefix_length' => 29, + 'state' => 'available', + 'reservation_id' => null, + 'instance_id' => null, + 'operation_id' => null, + ]); $child->host_id = $hostId; } if (str_starts_with((string) $parent->kind, 'template_')) {