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

129 lines
4.4 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudError;
use App\Services\Cloud\CloudInstanceMigrationService;
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$publicNetwork = [
'contract' => 1,
'network_selector' => 'bridge:line-b',
'ipv4' => [
'pool_key' => str_repeat('b', 32),
'pool_cidr' => '8.8.4.0/24',
'address_cidr' => '8.8.4.20/24',
'gateway' => '8.8.4.1',
'gateway_on_link' => false,
],
'ipv6' => [
'pool_key' => str_repeat('c', 32),
'pool_cidr' => '2606:4700:4700:100::/64',
'address_cidr' => '2606:4700:4700:100::20/64',
'gateway' => '2606:4700:4700:100::1',
'gateway_on_link' => false,
],
'dns_servers' => ['1.1.1.1', '2606:4700:4700::1111'],
];
$source = [
'billing_marker' => 'preserved',
'guest_hostname' => 'retained.example',
'platform_network_policy_snapshot' => ['version' => 1],
'vcpu' => 1, 'cpu_cores' => 1,
'memory_mib' => 1024, 'ram_mib' => 1024,
'disk_gib' => 20, 'bandwidth_mbps' => 100,
// Clean-break migration removes retired singular fields even if an old
// source snapshot still contains them.
'network' => 'bridge:br0',
'public_pool_key' => str_repeat('a', 32),
'public_pool_cidr' => '9.9.9.0/24',
'public_ip_cidr' => '9.9.9.10/24',
'public_ip' => '9.9.9.10',
'gateway' => '9.9.9.1',
'dns_servers' => ['9.9.9.9'],
];
$body = [
'vcpu' => 4,
'memory_mib' => 8192,
'disk_gib' => 80,
'bandwidth_mbps' => 500,
'public_network' => $publicNetwork,
];
$vm = $body + [
'uuid' => '22222222-2222-4222-8222-222222222222',
'managed' => true,
];
$finalize = new ReflectionMethod(
CloudInstanceMigrationService::class,
'finalizeTargetSpec'
);
$spec = $finalize->invoke(null, $source, $body, $vm, 202);
$assert(($spec['billing_marker'] ?? null) === 'preserved'
&& ($spec['guest_hostname'] ?? null) === 'retained.example'
&& ($spec['platform_network_policy_snapshot'] ?? null) === ['version' => 1]
&& ($spec['vcpu'] ?? null) === 4
&& ($spec['cpu_cores'] ?? null) === 4
&& ($spec['memory_mib'] ?? null) === 8192
&& ($spec['ram_mib'] ?? null) === 8192
&& ($spec['disk_gib'] ?? null) === 80
&& ($spec['bandwidth_mbps'] ?? null) === 500
&& ($spec['public_network'] ?? null) === $publicNetwork
&& ($spec['resource_pool_id'] ?? null) === 202,
'Maintenance migration did not converge the dual-stack target snapshot.');
foreach ([
'network', 'public_pool_key', 'public_pool_cidr', 'public_ip_cidr',
'public_ip', 'gateway', 'dns_servers',
] as $retired) {
$assert(!array_key_exists($retired, $spec),
'Maintenance migration retained retired field: ' . $retired);
}
$mismatches = [
'vcpu' => array_replace($vm, ['vcpu' => 8]),
'bandwidth_mbps' => array_replace($vm, ['bandwidth_mbps' => 1000]),
'network_selector' => array_replace($vm, ['public_network' =>
array_replace($publicNetwork, [
'network_selector' => 'network:other-line',
])]),
'ipv4_address' => array_replace($vm, ['public_network' =>
array_replace($publicNetwork, ['ipv4' => array_replace(
$publicNetwork['ipv4'],
['address_cidr' => '8.8.4.21/24']
)])]),
'ipv6_address' => array_replace($vm, ['public_network' =>
array_replace($publicNetwork, ['ipv6' => array_replace(
$publicNetwork['ipv6'],
['address_cidr' => '2606:4700:4700:100::21/64']
)])]),
'ipv6_gateway_on_link' => array_replace($vm, ['public_network' =>
array_replace($publicNetwork, ['ipv6' => array_replace(
$publicNetwork['ipv6'],
['gateway_on_link' => true]
)])]),
'dns_servers' => array_replace($vm, ['public_network' =>
array_replace($publicNetwork, [
'dns_servers' => ['8.8.8.8', '2606:4700:4700::1001'],
])]),
];
foreach ($mismatches as $field => $mismatched) {
$rejected = false;
try {
$finalize->invoke(null, $source, $body, $mismatched, 202);
} catch (CloudError $error) {
$rejected = $error->httpStatus === 502;
}
$assert($rejected,
'Maintenance migration accepted mismatched Agent field: ' . $field);
}
echo "Maintenance migration target resource/network snapshot tests passed.\n";