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

103 lines
4.7 KiB
PHTML

<?php
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
if (!is_string($schema)) {
throw new RuntimeException('Cloud schema is unreadable.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$table = static function (string $name) use ($schema): string {
$start = strpos($schema, 'CREATE TABLE ' . $name . ' (');
if ($start === false) {
return '';
}
$end = strpos($schema,
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;',
$start
);
return $end === false ? '' : substr($schema, $start, $end - $start);
};
$pools = $table('cloud_public_ip_pools');
$ips = $table('cloud_public_ips');
$claims = $table('cloud_resource_reservation_ips');
$assert($pools !== ''
&& str_contains($pools, 'address_family TINYINT UNSIGNED NOT NULL')
&& str_contains($pools,
'cidr VARCHAR(49) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
&& str_contains($pools,
'gateway VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
&& str_contains($pools,
'gateway_on_link TINYINT UNSIGNED NOT NULL DEFAULT 0')
&& str_contains($pools,
'allocation_start VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL')
&& str_contains($pools,
'allocation_end VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL')
&& str_contains($pools,
'allocation_cursor VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL')
&& str_contains($pools,
'max_allocations INT UNSIGNED NOT NULL DEFAULT 0'),
'Public pool storage cannot describe bounded sparse IPv6 allocation.');
$assert(str_contains($pools,
'UNIQUE KEY cloud_public_ip_pool_cidr (host_id, address_family, cidr)')
&& str_contains($pools,
'KEY cloud_public_ip_pool_attachment (network_attachment_id, address_family, state, priority, id)')
&& str_contains($pools, 'CONSTRAINT chk_cloud_public_ip_pool_family')
&& str_contains($pools, 'CONSTRAINT chk_cloud_public_ip_pool_allocation'),
'Public pool family identity or sparse-allocation invariants are missing.');
$assert($ips !== ''
&& str_contains($ips, 'address_family TINYINT UNSIGNED NOT NULL')
&& str_contains($ips, 'address_binary VARBINARY(16) NOT NULL')
&& str_contains($ips,
'UNIQUE KEY cloud_public_ip_address (address_family, address_binary)')
&& str_contains($ips,
'UNIQUE KEY cloud_public_ip_reservation (reservation_id, address_family)')
&& str_contains($ips,
'UNIQUE KEY cloud_public_ip_operation (operation_id, address_family)')
&& str_contains($ips, 'CONSTRAINT chk_cloud_public_ip_family'),
'Concrete public-address rows are not family-aware and dual-stack safe.');
$assert($claims !== ''
&& str_contains($claims, 'reservation_id BIGINT UNSIGNED NOT NULL')
&& str_contains($claims, 'address_family TINYINT UNSIGNED NOT NULL')
&& str_contains($claims, 'network_attachment_id BIGINT UNSIGNED NOT NULL')
&& str_contains($claims, 'public_ip_pool_id BIGINT UNSIGNED NOT NULL')
&& str_contains($claims, 'public_ip_id BIGINT UNSIGNED NOT NULL')
&& str_contains($claims,
'UNIQUE KEY cloud_reservation_ip_family (reservation_id, address_family)')
&& str_contains($claims,
'UNIQUE KEY cloud_reservation_ip_operation (operation_id, address_family)')
&& str_contains($claims,
'KEY cloud_reservation_ip_address (public_ip_id, state, id)')
&& str_contains($claims, 'CONSTRAINT chk_cloud_reservation_ip_family')
&& str_contains($claims, 'CONSTRAINT chk_cloud_reservation_ip_state'),
'Reservation-to-address ownership cannot retain two atomic family claims.');
$poolModel = file_get_contents($root . '/app/Models/CloudPublicIpPool.php');
$ipModel = file_get_contents($root . '/app/Models/CloudPublicIp.php');
$claimModelPath = $root . '/app/Models/CloudResourceReservationIp.php';
$claimModel = is_file($claimModelPath)
? file_get_contents($claimModelPath) : false;
$assert(is_string($poolModel)
&& str_contains($poolModel, "'address_family' => 'int'")
&& str_contains($poolModel, "'gateway_on_link' => 'bool'")
&& str_contains($poolModel, "'max_allocations' => 'int'"),
'Public pool model does not expose canonical dual-stack casts.');
$assert(is_string($ipModel)
&& str_contains($ipModel, "'address_family' => 'int'"),
'Public IP model does not expose its address family.');
$assert(is_string($claimModel)
&& str_contains($claimModel,
"protected \$table = 'cloud_resource_reservation_ips';")
&& str_contains($claimModel, "'address_family' => 'int'"),
'Reservation address-claim model is missing.');
echo "Dual-stack public-network schema tests passed.\n";