feat: place instances on verified network attachments
parent
669ca96226
commit
cdd5bbf833
@ -0,0 +1,394 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cloud;
|
||||
|
||||
use App\Models\CloudHost;
|
||||
use App\Models\CloudHostAgent;
|
||||
use App\Models\CloudHostNetworkAttachment;
|
||||
use App\Models\CloudPublicIp;
|
||||
use App\Models\CloudPublicIpPool;
|
||||
|
||||
/**
|
||||
* Exact network admission for new-instance placement.
|
||||
*
|
||||
* The caller chooses an exact resource-pool membership and owns the host lock.
|
||||
* This module resolves only that pool's line into current Agent-verified
|
||||
* attachments, applied public pools and one concrete IP ledger row.
|
||||
*/
|
||||
final class CloudPlacementNetworkService
|
||||
{
|
||||
private const MAX_PUBLIC_IPS_PER_POOL = 254;
|
||||
|
||||
/**
|
||||
* Non-locking catalog hint. Payment-time placement repeats the same
|
||||
* evidence checks under host, attachment, pool and IP row locks.
|
||||
*
|
||||
* @return array<int,bool>
|
||||
*/
|
||||
public static function advisoryAvailableHosts($candidateRows): array
|
||||
{
|
||||
$readyByHostLine = self::advisoryAvailableHostLines($candidateRows);
|
||||
$available = [];
|
||||
foreach ($candidateRows as $candidate) {
|
||||
$hostId = (int) ($candidate->id ?? 0);
|
||||
$lineId = (int) ($candidate->resource_pool_line_id ?? 0);
|
||||
if (isset($readyByHostLine[$hostId][$lineId])) {
|
||||
$available[$hostId] = true;
|
||||
}
|
||||
}
|
||||
return $available;
|
||||
}
|
||||
|
||||
/** @return array<int,array<int,bool>> keyed by host ID then line ID. */
|
||||
public static function advisoryAvailableHostLines($candidateRows): array
|
||||
{
|
||||
$hostLines = [];
|
||||
foreach ($candidateRows as $candidate) {
|
||||
$hostId = (int) ($candidate->id ?? 0);
|
||||
$lineId = (int) ($candidate->resource_pool_line_id ?? 0);
|
||||
if ($hostId > 0 && $lineId > 0) {
|
||||
$hostLines[$hostId][$lineId] = true;
|
||||
}
|
||||
}
|
||||
if ($hostLines === []) {
|
||||
return [];
|
||||
}
|
||||
$rows = CloudPublicIp::query()->join(
|
||||
'cloud_public_ip_pools as public_pool',
|
||||
'public_pool.id', '=', 'cloud_public_ips.public_ip_pool_id'
|
||||
)->join(
|
||||
'cloud_host_network_attachments as network_attachment',
|
||||
'network_attachment.id', '=', 'public_pool.network_attachment_id'
|
||||
)->join(
|
||||
'cloud_host_agents as host_agent',
|
||||
'host_agent.host_id', '=', 'cloud_public_ips.host_id'
|
||||
)->whereIn('cloud_public_ips.host_id', array_keys($hostLines))
|
||||
->where('cloud_public_ips.state', 'available')
|
||||
->whereNull('cloud_public_ips.reservation_id')
|
||||
->whereNull('cloud_public_ips.instance_id')
|
||||
->whereNull('cloud_public_ips.operation_id')
|
||||
->whereColumn('cloud_public_ips.host_id', 'public_pool.host_id')
|
||||
->whereColumn(
|
||||
'cloud_public_ips.prefix_length',
|
||||
'public_pool.guest_prefix_length'
|
||||
)
|
||||
->whereColumn(
|
||||
'cloud_public_ips.host_id',
|
||||
'network_attachment.host_id'
|
||||
)
|
||||
->where('host_agent.enabled', 1)
|
||||
->where('host_agent.last_test_status', 'healthy')
|
||||
->where('host_agent.tested_revision', '>', 0)
|
||||
->whereColumn('host_agent.tested_revision', 'host_agent.revision')
|
||||
->where('network_attachment.state', 'active')
|
||||
->where('network_attachment.verification_state', 'verified')
|
||||
->where('public_pool.state', 'active')
|
||||
->where('public_pool.sync_state', 'applied')
|
||||
->whereColumn(
|
||||
'public_pool.observed_revision',
|
||||
'>=',
|
||||
'public_pool.desired_revision'
|
||||
)
|
||||
->get([
|
||||
'cloud_public_ips.host_id',
|
||||
'cloud_public_ips.address',
|
||||
'network_attachment.line_id',
|
||||
'network_attachment.network_selector',
|
||||
'network_attachment.verified_agent_revision',
|
||||
'network_attachment.last_verified_at',
|
||||
'host_agent.host_id as agent_host_id',
|
||||
'host_agent.enabled as agent_enabled',
|
||||
'host_agent.revision as agent_revision',
|
||||
'host_agent.tested_revision as agent_tested_revision',
|
||||
'host_agent.last_test_status as agent_last_test_status',
|
||||
'host_agent.network_selectors_json as agent_network_selectors_json',
|
||||
'public_pool.pool_key',
|
||||
'public_pool.cidr',
|
||||
'public_pool.gateway',
|
||||
'public_pool.dns_servers_json',
|
||||
'public_pool.reserved_ips_json',
|
||||
]);
|
||||
|
||||
$available = [];
|
||||
foreach ($rows as $row) {
|
||||
$hostId = (int) $row->host_id;
|
||||
$lineId = (int) $row->line_id;
|
||||
if (!isset($hostLines[$hostId][$lineId])
|
||||
|| !self::agentEvidenceReady(
|
||||
self::agentFromEvidenceRow($row),
|
||||
(string) $row->network_selector,
|
||||
(int) $row->verified_agent_revision,
|
||||
(int) $row->last_verified_at
|
||||
)
|
||||
|| preg_match(
|
||||
'/^[a-f0-9]{32}$/D',
|
||||
(string) $row->pool_key
|
||||
) !== 1
|
||||
|| !self::ipv4BelongsToCidr(
|
||||
(string) $row->address,
|
||||
(string) $row->cidr
|
||||
) || !self::addressAllowedByPool(
|
||||
(string) $row->address,
|
||||
$row,
|
||||
null
|
||||
)) {
|
||||
continue;
|
||||
}
|
||||
$available[$hostId][$lineId] = true;
|
||||
}
|
||||
return $available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock and return every network candidate for one exact host/line.
|
||||
*
|
||||
* The host and current Agent row must already be locked. Attachment and
|
||||
* public-pool locks are always acquired in primary-key order.
|
||||
*
|
||||
* @return list<array{attachment:CloudHostNetworkAttachment,
|
||||
* public_pool:CloudPublicIpPool}>
|
||||
*/
|
||||
public static function lockedCandidates(int $hostId, int $lineId,
|
||||
CloudHostAgent $agent): array
|
||||
{
|
||||
if ($hostId < 1 || $lineId < 1 || !$agent->isReady()
|
||||
|| (int) $agent->host_id !== $hostId) {
|
||||
return [];
|
||||
}
|
||||
$attachments = CloudHostNetworkAttachment::where('host_id', $hostId)
|
||||
->where('line_id', $lineId)
|
||||
->where('state', 'active')
|
||||
->where('verification_state', 'verified')
|
||||
->orderBy('id')->lockForUpdate()->get();
|
||||
$eligibleAttachments = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
if (self::agentEvidenceReady(
|
||||
$agent,
|
||||
(string) $attachment->network_selector,
|
||||
(int) $attachment->verified_agent_revision,
|
||||
(int) $attachment->last_verified_at
|
||||
)) {
|
||||
$eligibleAttachments[(int) $attachment->id] = $attachment;
|
||||
}
|
||||
}
|
||||
if ($eligibleAttachments === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$pools = CloudPublicIpPool::where('host_id', $hostId)
|
||||
->whereIn('network_attachment_id', array_keys($eligibleAttachments))
|
||||
->where('state', 'active')
|
||||
->where('sync_state', 'applied')
|
||||
->whereColumn('observed_revision', '>=', 'desired_revision')
|
||||
->orderBy('id')->lockForUpdate()->get();
|
||||
$candidates = [];
|
||||
foreach ($pools as $pool) {
|
||||
$attachment = $eligibleAttachments[
|
||||
(int) $pool->network_attachment_id
|
||||
] ?? null;
|
||||
if ($attachment === null
|
||||
|| preg_match(
|
||||
'/^[a-f0-9]{32}$/D',
|
||||
(string) $pool->pool_key
|
||||
) !== 1) {
|
||||
continue;
|
||||
}
|
||||
$candidates[] = [
|
||||
'attachment' => $attachment,
|
||||
'public_pool' => $pool,
|
||||
];
|
||||
}
|
||||
usort($candidates, static function (array $left, array $right): int {
|
||||
return [
|
||||
(int) $left['attachment']->priority,
|
||||
(int) $left['public_pool']->priority,
|
||||
(int) $left['attachment']->id,
|
||||
(int) $left['public_pool']->id,
|
||||
] <=> [
|
||||
(int) $right['attachment']->priority,
|
||||
(int) $right['public_pool']->priority,
|
||||
(int) $right['attachment']->id,
|
||||
(int) $right['public_pool']->id,
|
||||
];
|
||||
});
|
||||
return $candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock one available IP after the caller has locked the capacity ledger.
|
||||
*
|
||||
* @param list<array{attachment:CloudHostNetworkAttachment,
|
||||
* public_pool:CloudPublicIpPool}> $candidates
|
||||
* @return null|array{attachment:CloudHostNetworkAttachment,
|
||||
* public_pool:CloudPublicIpPool,public_ip:CloudPublicIp}
|
||||
*/
|
||||
public static function lockAvailableSelection(int $hostId,
|
||||
array $candidates): ?array
|
||||
{
|
||||
foreach ($candidates as $candidate) {
|
||||
$attachment = $candidate['attachment'] ?? null;
|
||||
$pool = $candidate['public_pool'] ?? null;
|
||||
if (!$attachment instanceof CloudHostNetworkAttachment
|
||||
|| !$pool instanceof CloudPublicIpPool
|
||||
|| (int) $attachment->host_id !== $hostId
|
||||
|| (int) $pool->host_id !== $hostId
|
||||
|| (int) $pool->network_attachment_id
|
||||
!== (int) $attachment->id) {
|
||||
throw new CloudError('公网地址池与网络接入关联不一致', 409);
|
||||
}
|
||||
$ips = self::availablePublicIpQuery(
|
||||
$hostId,
|
||||
(int) $pool->id,
|
||||
(int) $pool->guest_prefix_length
|
||||
)->limit(self::MAX_PUBLIC_IPS_PER_POOL + 1)
|
||||
->lockForUpdate()->get();
|
||||
if ($ips->count() > self::MAX_PUBLIC_IPS_PER_POOL) {
|
||||
continue;
|
||||
}
|
||||
foreach ($ips as $ip) {
|
||||
if (self::publicIpBelongsToPool($ip, $pool)) {
|
||||
return [
|
||||
'attachment' => $attachment,
|
||||
'public_pool' => $pool,
|
||||
'public_ip' => $ip,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function agentEvidenceReady(?CloudHostAgent $agent,
|
||||
string $selector, int $verifiedRevision, int $lastVerifiedAt): bool
|
||||
{
|
||||
return $agent !== null
|
||||
&& $agent->isReady()
|
||||
&& $verifiedRevision === (int) $agent->revision
|
||||
&& $verifiedRevision === (int) $agent->tested_revision
|
||||
&& $lastVerifiedAt > 0
|
||||
&& in_array(
|
||||
$selector,
|
||||
CloudAgentSettingsService::testedNetworkSelectors($agent),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/** Hydrate joined evidence without issuing one Agent query per IP row. */
|
||||
private static function agentFromEvidenceRow($row): CloudHostAgent
|
||||
{
|
||||
$agent = new CloudHostAgent();
|
||||
$agent->setRawAttributes([
|
||||
'host_id' => (int) $row->agent_host_id,
|
||||
'enabled' => (bool) $row->agent_enabled,
|
||||
'revision' => (int) $row->agent_revision,
|
||||
'tested_revision' => (int) $row->agent_tested_revision,
|
||||
'last_test_status' => (string) $row->agent_last_test_status,
|
||||
'network_selectors_json' =>
|
||||
(string) $row->agent_network_selectors_json,
|
||||
], true);
|
||||
return $agent;
|
||||
}
|
||||
|
||||
private static function availablePublicIpQuery(int $hostId,
|
||||
int $publicPoolId, int $prefixLength)
|
||||
{
|
||||
return CloudPublicIp::where('host_id', $hostId)
|
||||
->where('public_ip_pool_id', $publicPoolId)
|
||||
->where('prefix_length', $prefixLength)
|
||||
->where('state', 'available')
|
||||
->whereNull('reservation_id')
|
||||
->whereNull('instance_id')
|
||||
->whereNull('operation_id')
|
||||
->orderBy('id');
|
||||
}
|
||||
|
||||
private static function publicIpBelongsToPool(CloudPublicIp $ip,
|
||||
CloudPublicIpPool $pool): bool
|
||||
{
|
||||
return (int) $ip->host_id === (int) $pool->host_id
|
||||
&& (int) $ip->public_ip_pool_id === (int) $pool->id
|
||||
&& (int) $ip->prefix_length === (int) $pool->guest_prefix_length
|
||||
&& self::ipv4BelongsToCidr(
|
||||
(string) $ip->address,
|
||||
(string) $pool->cidr
|
||||
) && self::addressAllowedByPool(
|
||||
(string) $ip->address,
|
||||
$pool,
|
||||
CloudHost::find((int) $pool->host_id)
|
||||
);
|
||||
}
|
||||
|
||||
private static function addressAllowedByPool(string $address, $pool,
|
||||
?CloudHost $host): bool
|
||||
{
|
||||
$blocked = [(string) $pool->gateway];
|
||||
$managementAddress = CloudPanelUsageService::managementAddress($host);
|
||||
if ($managementAddress !== null) {
|
||||
$blocked[] = $managementAddress;
|
||||
}
|
||||
foreach (['dns_servers_json', 'reserved_ips_json'] as $field) {
|
||||
try {
|
||||
$values = json_decode(
|
||||
(string) $pool->{$field},
|
||||
true,
|
||||
16,
|
||||
JSON_THROW_ON_ERROR
|
||||
);
|
||||
} catch (\Throwable $error) {
|
||||
return false;
|
||||
}
|
||||
if (!is_array($values) || !array_is_list($values)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($values as $value) {
|
||||
if (!is_string($value)
|
||||
|| filter_var(
|
||||
$value,
|
||||
FILTER_VALIDATE_IP,
|
||||
FILTER_FLAG_IPV4
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
$blocked[] = $value;
|
||||
}
|
||||
}
|
||||
return !in_array($address, $blocked, true);
|
||||
}
|
||||
|
||||
private static function ipv4BelongsToCidr(string $addressValue,
|
||||
string $cidr): bool
|
||||
{
|
||||
$parts = explode('/', $cidr, 2);
|
||||
if (count($parts) !== 2 || !ctype_digit($parts[1])) {
|
||||
return false;
|
||||
}
|
||||
$prefix = (int) $parts[1];
|
||||
$address = self::ipv4Number($addressValue);
|
||||
$network = self::ipv4Number($parts[0]);
|
||||
if ($address === null || $network === null
|
||||
|| $prefix < 24 || $prefix > 30) {
|
||||
return false;
|
||||
}
|
||||
$block = 2 ** (32 - $prefix);
|
||||
$base = (int) (floor($network / $block) * $block);
|
||||
return $address > $base && $address < $base + $block - 1;
|
||||
}
|
||||
|
||||
private static function ipv4Number(string $value): ?int
|
||||
{
|
||||
if (filter_var(
|
||||
$value,
|
||||
FILTER_VALIDATE_IP,
|
||||
FILTER_FLAG_IPV4
|
||||
) === false) {
|
||||
return null;
|
||||
}
|
||||
$packed = inet_pton($value);
|
||||
if ($packed === false || strlen($packed) !== 4) {
|
||||
return null;
|
||||
}
|
||||
$parts = unpack('Nnumber', $packed);
|
||||
return is_array($parts) && isset($parts['number'])
|
||||
? (int) sprintf('%u', $parts['number']) : null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use App\Models\CloudHostAgent;
|
||||
use App\Services\Cloud\CloudPlacementNetworkService;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$capsule = new Capsule();
|
||||
$capsule->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
], 'default');
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
$schema = $capsule->schema('default');
|
||||
|
||||
$schema->create('cloud_hosts', static function (Blueprint $table): void {
|
||||
$table->increments('id');
|
||||
$table->string('default_network');
|
||||
});
|
||||
$schema->create('cloud_host_agents', static function (Blueprint $table): void {
|
||||
$table->integer('host_id')->primary();
|
||||
$table->boolean('enabled');
|
||||
$table->integer('revision');
|
||||
$table->integer('tested_revision');
|
||||
$table->string('last_test_status');
|
||||
$table->text('network_selectors_json');
|
||||
});
|
||||
$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->integer('priority');
|
||||
$table->string('verification_state');
|
||||
$table->integer('verified_agent_revision');
|
||||
$table->integer('last_verified_at');
|
||||
// Deliberately stale: this is controller intent, not Agent evidence.
|
||||
$table->string('sync_state')->default('never');
|
||||
});
|
||||
$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->integer('priority');
|
||||
$table->integer('desired_revision');
|
||||
$table->integer('observed_revision');
|
||||
$table->string('sync_state');
|
||||
});
|
||||
$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();
|
||||
});
|
||||
|
||||
Capsule::table('cloud_hosts')->insert([
|
||||
'id' => 1,
|
||||
'default_network' => 'bridge:retired',
|
||||
]);
|
||||
Capsule::table('cloud_host_agents')->insert([
|
||||
'host_id' => 1,
|
||||
'enabled' => 1,
|
||||
'revision' => 4,
|
||||
'tested_revision' => 4,
|
||||
'last_test_status' => 'healthy',
|
||||
'network_selectors_json' => '["bridge:line-a","bridge:line-b"]',
|
||||
]);
|
||||
Capsule::table('cloud_host_network_attachments')->insert([
|
||||
[
|
||||
'id' => 10, 'host_id' => 1, 'line_id' => 10,
|
||||
'network_selector' => 'bridge:line-a', 'state' => 'active',
|
||||
'priority' => 0, 'verification_state' => 'verified',
|
||||
'verified_agent_revision' => 4, 'last_verified_at' => time(),
|
||||
'sync_state' => 'never',
|
||||
],
|
||||
[
|
||||
'id' => 20, 'host_id' => 1, 'line_id' => 20,
|
||||
'network_selector' => 'bridge:line-b', 'state' => 'active',
|
||||
'priority' => 0, 'verification_state' => 'verified',
|
||||
'verified_agent_revision' => 4, 'last_verified_at' => time(),
|
||||
'sync_state' => 'never',
|
||||
],
|
||||
]);
|
||||
Capsule::table('cloud_public_ip_pools')->insert([
|
||||
[
|
||||
'id' => 100, 'pool_key' => str_repeat('a', 32), 'host_id' => 1,
|
||||
'network_attachment_id' => 10, 'cidr' => '203.0.113.0/29',
|
||||
'gateway' => '203.0.113.1', 'guest_prefix_length' => 29,
|
||||
'dns_servers_json' => '["203.0.113.2"]',
|
||||
'reserved_ips_json' => '["203.0.113.3"]', 'state' => 'active',
|
||||
'priority' => 0, 'desired_revision' => 2, 'observed_revision' => 2,
|
||||
'sync_state' => 'applied',
|
||||
],
|
||||
[
|
||||
'id' => 200, 'pool_key' => str_repeat('b', 32), 'host_id' => 1,
|
||||
'network_attachment_id' => 20, 'cidr' => '198.51.100.8/29',
|
||||
'gateway' => '198.51.100.9', 'guest_prefix_length' => 29,
|
||||
'dns_servers_json' => '[]', 'reserved_ips_json' => '[]',
|
||||
'state' => 'active', 'priority' => 0, 'desired_revision' => 1,
|
||||
'observed_revision' => 1, 'sync_state' => 'applied',
|
||||
],
|
||||
]);
|
||||
Capsule::table('cloud_public_ips')->insert([
|
||||
['id' => 1, 'host_id' => 1, 'public_ip_pool_id' => 100,
|
||||
'address' => '203.0.113.1', 'prefix_length' => 29,
|
||||
'state' => 'available'],
|
||||
['id' => 2, 'host_id' => 1, 'public_ip_pool_id' => 100,
|
||||
'address' => '203.0.113.2', 'prefix_length' => 29,
|
||||
'state' => 'available'],
|
||||
['id' => 3, 'host_id' => 1, 'public_ip_pool_id' => 100,
|
||||
'address' => '203.0.113.3', 'prefix_length' => 29,
|
||||
'state' => 'available'],
|
||||
['id' => 4, 'host_id' => 1, 'public_ip_pool_id' => 100,
|
||||
'address' => '203.0.113.4', 'prefix_length' => 29,
|
||||
'state' => 'available'],
|
||||
['id' => 5, 'host_id' => 1, 'public_ip_pool_id' => 200,
|
||||
'address' => '198.51.100.10', 'prefix_length' => 29,
|
||||
'state' => 'available'],
|
||||
]);
|
||||
|
||||
$candidateRows = collect([
|
||||
(object) ['id' => 1, 'resource_pool_line_id' => 10],
|
||||
(object) ['id' => 1, 'resource_pool_line_id' => 20],
|
||||
]);
|
||||
$ready = CloudPlacementNetworkService::advisoryAvailableHostLines(
|
||||
$candidateRows
|
||||
);
|
||||
$assert(($ready[1][10] ?? false) && ($ready[1][20] ?? false),
|
||||
'One physical host lost one of its exact host-line readiness results.');
|
||||
$assert(CloudPlacementNetworkService::advisoryAvailableHosts(
|
||||
collect([(object) ['id' => 1, 'resource_pool_line_id' => 20]])
|
||||
) === [1 => true],
|
||||
'The exact-pool compatibility view did not preserve host readiness.');
|
||||
|
||||
Capsule::table('cloud_host_network_attachments')->where('id', 20)->update([
|
||||
'verified_agent_revision' => 3,
|
||||
]);
|
||||
$ready = CloudPlacementNetworkService::advisoryAvailableHostLines(
|
||||
$candidateRows
|
||||
);
|
||||
$assert(($ready[1][10] ?? false) && !isset($ready[1][20]),
|
||||
'A stale line verification affected another line or remained ready.');
|
||||
Capsule::table('cloud_host_network_attachments')->where('id', 20)->update([
|
||||
'verified_agent_revision' => 4,
|
||||
]);
|
||||
Capsule::table('cloud_host_network_attachments')->where('id', 10)->update([
|
||||
'last_verified_at' => 0,
|
||||
]);
|
||||
$ready = CloudPlacementNetworkService::advisoryAvailableHostLines(
|
||||
$candidateRows
|
||||
);
|
||||
$assert(!isset($ready[1][10]) && ($ready[1][20] ?? false),
|
||||
'Missing verification time remained ready or poisoned another line.');
|
||||
Capsule::table('cloud_host_network_attachments')->where('id', 10)->update([
|
||||
'last_verified_at' => time(),
|
||||
]);
|
||||
|
||||
$selection = Capsule::connection('default')->transaction(static function () {
|
||||
$agent = CloudHostAgent::find(1);
|
||||
$candidates = CloudPlacementNetworkService::lockedCandidates(
|
||||
1,
|
||||
10,
|
||||
$agent
|
||||
);
|
||||
return CloudPlacementNetworkService::lockAvailableSelection(
|
||||
1,
|
||||
$candidates
|
||||
);
|
||||
});
|
||||
$assert($selection !== null
|
||||
&& (int) $selection['attachment']->id === 10
|
||||
&& (int) $selection['public_pool']->id === 100
|
||||
&& (string) $selection['public_ip']->address === '203.0.113.4',
|
||||
'Payment-time selection used the retired default or admitted a gateway, DNS, or reserved address.');
|
||||
|
||||
Capsule::table('cloud_host_agents')->where('host_id', 1)->update([
|
||||
'network_selectors_json' => '["bridge:line-a"]',
|
||||
]);
|
||||
$ready = CloudPlacementNetworkService::advisoryAvailableHostLines(
|
||||
$candidateRows
|
||||
);
|
||||
$assert(($ready[1][10] ?? false) && !isset($ready[1][20]),
|
||||
'A selector absent from current Agent test evidence remained ready.');
|
||||
|
||||
echo "Placement network exact host-line contract passed.\n";
|
||||
Loading…
Reference in New Issue