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/VirtualizationSchemaTest.php

48 lines
1.8 KiB
PHTML

<?php
// The clean-break Agent build owns a fresh log schema; no Python schema or
// upgrade DDL is consulted by the panel.
$sql = file_get_contents(dirname(__DIR__) . '/sql/cloud_log.sql');
if (!is_string($sql)) {
throw new RuntimeException('Cloud log schema is unreadable');
}
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
foreach ([
'cloud_vm_metric_samples' => [
'host_scope CHAR(64)', 'vm_uuid CHAR(36)', 'host_id VARCHAR(64)',
'user_id BIGINT UNSIGNED', 'network_rx_bytes BIGINT UNSIGNED',
'network_tx_bytes BIGINT UNSIGNED',
'vm_metric_owner (user_id, host_id, sampled_at)',
],
'cloud_vm_traffic_totals' => [
'network_signature CHAR(64)', 'network_baseline_json JSON',
'download_rx_bytes BIGINT UNSIGNED', 'upload_tx_bytes BIGINT UNSIGNED',
'vm_traffic_owner (user_id, host_id)',
],
'cloud_vm_traffic_checkpoints' => [
'checkpoint_hour BIGINT UNSIGNED', 'first_observed_at BIGINT UNSIGNED',
'vm_traffic_checkpoint_owner (user_id, host_id, first_observed_at)',
],
] as $table => $required) {
$assert(preg_match('/CREATE TABLE IF NOT EXISTS ' . preg_quote($table, '/')
. '\s*\((.*?)\) ENGINE=/s', $sql, $match) === 1,
'Missing fresh log table: ' . $table);
foreach ($required as $fragment) {
$assert(str_contains($match[1], $fragment),
$table . ' is missing: ' . $fragment);
}
}
$assert(preg_match('/\b(?:ALTER|DROP)\s+TABLE\b/i', $sql) !== 1,
'Fresh cloud log schema contains migration/destructive DDL.');
$assert(!str_contains($sql, 'engine_vm_'),
'Fresh cloud log schema retained an engine-prefixed table.');
echo "Fresh-install Agent metric and traffic DDL contract passed.\n";