$entry) { $mode = $entry['recovery_mode']; if ($mode === 'generic') { $generic[] = $kind; $assert($entry['system_resolutions'] === ['applied', 'not_applied'], 'A generic leaf lost a recovery direction: ' . $kind); } if (in_array($mode, ['generic', 'create'], true)) { $automatic[] = $kind; } $assert(CloudOperationRecoveryPolicy::supports($kind) === ($mode === 'generic'), 'Generic policy mode differs from inventory: ' . $kind); $assert(CloudOperationRecoveryIdentity::supports($kind) === ($entry['identity_scope'] !== 'none'), 'Identity support differs from inventory: ' . $kind); foreach (['applied', 'not_applied', 'unknown', ''] as $resolution) { $assert(CloudOperationRecoveryPolicy::allowsSystemResolution($kind, $resolution) === in_array($resolution, $entry['system_resolutions'], true), 'System resolution differs from inventory: ' . $kind); } foreach ($entry['actions'] as $action) { $assert(CloudOperationRecoveryPolicy::allowsAction($kind, $action), 'Declared wire action is not recognized: ' . $kind . '/' . $action); $assert(!CloudOperationRecoveryPolicy::allowsAction($kind, $action . ':future') && !CloudOperationRecoveryPolicy::allowsAction($kind, $action . "\n"), 'Action matching is not exact: ' . $kind); } } $assert(CloudOperationRecoveryPolicy::kinds() === $generic, 'Generic selector does not follow the inventory.'); $assert(CloudOperationRecoveryPolicy::automaticKinds() === $automatic, 'Automatic selector does not follow the inventory.'); $assert($expected['create']['recovery_mode'] === 'create' && $expected['create']['system_resolutions'] === ['not_applied'] && !CloudOperationRecoveryPolicy::supports('create'), 'Create must retain dedicated finance recovery and one-way fence resolution.'); foreach (['host_storage_configure', 'payment_create', 'template_import', 'template_metadata_sync', 'template_delete', 'user_iso_import', 'user_iso_delete'] as $kind) { $assert($expected[$kind]['system_resolutions'] === [] && !in_array($kind, $automatic, true), 'A separately finalized operation gained system recovery: ' . $kind); } foreach (['', 'future_kind'] as $kind) { $assert(!CloudOperationRecoveryPolicy::supports($kind) && !CloudOperationRecoveryIdentity::supports($kind) && !CloudOperationRecoveryPolicy::allowsAction($kind, 'create-vm'), 'Unknown kinds must be denied.'); } $key = str_repeat('ab', 16); foreach ([ ['snapshot_create', 'create-snapshot:' . $key . ':filesystem'], ['snapshot_create', 'create-snapshot:' . $key . ':crash'], ['snapshot_restore', 'restore-snapshot:' . $key], ['snapshot_delete', 'delete-snapshot:' . $key], ['backup_create', 'create-backup:' . $key . ':filesystem'], ['backup_create', 'create-backup:' . $key . ':crash'], ['backup_restore', 'restore-backup:' . $key], ] as [$kind, $action]) { $assert(CloudOperationRecoveryPolicy::allowsAction($kind, $action), 'Valid parameterized action was rejected.'); foreach ([$action . "\n", $action . ':extra', strtoupper($action), str_replace($key, substr($key, 1), $action)] as $invalid) { $assert(!CloudOperationRecoveryPolicy::allowsAction($kind, $invalid), 'Malformed parameterized action was accepted.'); } $assert(!CloudOperationRecoveryPolicy::allowsAction('instance_settings', $action), 'An action can escape its owning kind.'); } $assert($expected['backup_restore']['recovery_mode'] === 'create' && $expected['backup_restore']['identity_scope'] === 'create' && $expected['backup_restore']['system_resolutions'] === ['not_applied'] && CloudOperationRecoveryPolicy::isCreateLike('backup_restore'), 'Backup restore must use create identity and create-like absence recovery.'); echo "PHP/Agent generated recovery inventory contract passed.\n";