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

66 lines
2.7 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if (!is_string($contents)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$schema = $read('sql/cloud.sql');
$setup = $read('app/Command/CloudSetup.php');
$routes = $read('config/routes_cloud.php');
$service = $read('app/Services/Cloud/CloudHostStorageConfigurationService.php');
$agentSettings = $read('app/Services/Cloud/CloudAgentSettingsService.php');
$placement = $read('app/Services/Cloud/CloudPlacementService.php');
$template = $read('resources/views/venix/admin/hosts/index.tpl');
$browser = $read('public/cloud/admin.js');
preg_match(
'/CREATE TABLE IF NOT EXISTS cloud_host_storage_configurations \((.*?)\n\) ENGINE=/s',
$schema,
$storageTable
);
$storageTable = $storageTable[1] ?? '';
$assert($storageTable !== ''
&& str_contains($storageTable, 'operation_id VARCHAR(80)')
&& !str_contains($storageTable, 'applied_revision')
&& !str_contains($storageTable, 'request_hash')
&& !str_contains($storageTable, 'last_error_code')
&& !str_contains($storageTable, '_pool_name')
&& str_contains($setup, "'cloud_host_storage_configurations'"),
'The minimal per-host storage table contract is missing.');
$assert(str_contains($routes,
"'/admin/hosts/{id:[1-9][0-9]*}/storage-configuration'"),
'Host storage API route is missing.');
$assert(str_contains($service,
"'POST', '/v1/storage/configuration'")
&& !str_contains($service,
"'GET', '/v1/storage/configuration'")
&& str_contains($service,
"\$body = ['operation_id' => \$operationId] + \$paths;"),
'Storage registration lost its Agent request contract.');
$assert(str_contains($agentSettings,
'cloud_host_storage_configurations as host_storage')
&& str_contains($placement,
'cloud_host_storage_configurations as host_storage')
&& str_contains($placement, '!$storage->isApplied()'),
'Storage readiness or scheduling gate is missing.');
$assert(str_contains($template, 'data-admin-host-storage-drawer')
&& str_contains($template, 'storage_path_roots')
&& str_contains($template, '不会创建目录')
&& str_contains($template,
'/var/lib/libvirt/images/virt-cloud/disks')
&& str_contains($browser, '/storage-configuration')
&& str_contains($browser, 'operation_id'),
'Host page is missing the minimal storage registration workflow.');
echo "Host storage configuration web and Agent contract passed.\n";