|
|
|
|
@ -5,7 +5,13 @@ namespace App\Services {
|
|
|
|
|
{
|
|
|
|
|
public static function get($name, $default = null)
|
|
|
|
|
{
|
|
|
|
|
return $name === 'cloud_max_renewal_periods_ahead' ? 24 : $default;
|
|
|
|
|
if ($name === 'cloud_max_renewal_periods_ahead') {
|
|
|
|
|
return 24;
|
|
|
|
|
}
|
|
|
|
|
if ($name === 'cloud_data_key') {
|
|
|
|
|
return base64_encode(str_repeat('k', 32));
|
|
|
|
|
}
|
|
|
|
|
return $default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -15,6 +21,7 @@ namespace {
|
|
|
|
|
|
|
|
|
|
use App\Services\Cloud\CloudInstancePageService;
|
|
|
|
|
use App\Services\Cloud\CloudInstanceRuntimeService;
|
|
|
|
|
use App\Services\Cloud\CloudSecrets;
|
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
|
|
|
|
|
@ -89,6 +96,14 @@ namespace {
|
|
|
|
|
$table->integer('created_at')->default(0);
|
|
|
|
|
$table->integer('updated_at')->default(0);
|
|
|
|
|
});
|
|
|
|
|
$schema->create('cloud_jobs', static function (Blueprint $table): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->integer('instance_id')->nullable();
|
|
|
|
|
$table->string('kind');
|
|
|
|
|
$table->string('status');
|
|
|
|
|
$table->text('sealed_payload');
|
|
|
|
|
$table->integer('updated_at')->default(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_hosts')->insert([
|
|
|
|
|
'id' => 7, 'region' => 'internal-host-location', 'country_code' => 'ZZ',
|
|
|
|
|
@ -216,6 +231,117 @@ namespace {
|
|
|
|
|
$assertNoPlacement($ownedStatuses,
|
|
|
|
|
'Instance batch status identity exposed internal placement.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 101, 'instance_id' => 1, 'kind' => 'action', 'status' => 'queued',
|
|
|
|
|
'sealed_payload' => CloudSecrets::encrypt([
|
|
|
|
|
'body' => ['action' => 'start'],
|
|
|
|
|
], 'job-payload'),
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 102, 'instance_id' => 2, 'kind' => 'reinstall', 'status' => 'running',
|
|
|
|
|
'sealed_payload' => 'must-not-expose-foreign-job',
|
|
|
|
|
]);
|
|
|
|
|
$startingSnapshots = CloudInstancePageService::forActorIds($owner, [1, 2]);
|
|
|
|
|
$starting = CloudInstancePageService::powerStatus($startingSnapshots[0], [
|
|
|
|
|
'uuid' => $startingSnapshots[0]['uuid'], 'state' => 'running',
|
|
|
|
|
]);
|
|
|
|
|
$assert(count($startingSnapshots) === 1
|
|
|
|
|
&& $starting['state_transitioning'] === true
|
|
|
|
|
&& $starting['state_transition'] === 'start'
|
|
|
|
|
&& $starting['operation_transition'] === 'start'
|
|
|
|
|
&& !array_key_exists('sealed_payload', $starting)
|
|
|
|
|
&& !array_key_exists('host_id', $starting),
|
|
|
|
|
'Owner-scoped polling did not expose a queued start transition safely.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 101)->update(['status' => 'succeeded']);
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 103, 'instance_id' => 1, 'kind' => 'reinstall', 'status' => 'running',
|
|
|
|
|
'sealed_payload' => 'must-not-expose-reinstall-job',
|
|
|
|
|
]);
|
|
|
|
|
$reinstallSnapshot = CloudInstancePageService::forActorIds($owner, [1])[0];
|
|
|
|
|
$reinstalling = CloudInstancePageService::powerStatus($reinstallSnapshot, [
|
|
|
|
|
'uuid' => $reinstallSnapshot['uuid'], 'state' => 'running',
|
|
|
|
|
]);
|
|
|
|
|
$assert($reinstalling['state_transitioning'] === true
|
|
|
|
|
&& $reinstalling['state_transition'] === 'reinstall'
|
|
|
|
|
&& $reinstalling['operation_transition'] === 'reinstall',
|
|
|
|
|
'A running reinstall was not projected into the instance list.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 103)->update(['status' => 'uncertain']);
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 104, 'instance_id' => 1, 'kind' => 'action', 'status' => 'running',
|
|
|
|
|
'sealed_payload' => CloudSecrets::encrypt([
|
|
|
|
|
'body' => ['action' => 'shutdown'],
|
|
|
|
|
], 'job-payload'),
|
|
|
|
|
]);
|
|
|
|
|
$shutdownSnapshot = CloudInstancePageService::forActorIds($owner, [1])[0];
|
|
|
|
|
$shuttingDown = CloudInstancePageService::powerStatus($shutdownSnapshot, [
|
|
|
|
|
'uuid' => $shutdownSnapshot['uuid'], 'state' => 'shutoff',
|
|
|
|
|
]);
|
|
|
|
|
$assert($shuttingDown['state_transitioning'] === true
|
|
|
|
|
&& $shuttingDown['state_transition'] === 'shutdown'
|
|
|
|
|
&& $shuttingDown['operation_transition'] === 'shutdown',
|
|
|
|
|
'A running shutdown was not projected into the instance list.');
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 104)->update([
|
|
|
|
|
'status' => 'succeeded', 'updated_at' => time(),
|
|
|
|
|
]);
|
|
|
|
|
$convergenceSnapshot = CloudInstancePageService::forActorIds($owner, [1])[0];
|
|
|
|
|
$converging = CloudInstancePageService::powerStatus($convergenceSnapshot, [
|
|
|
|
|
'uuid' => $convergenceSnapshot['uuid'], 'state' => 'running',
|
|
|
|
|
]);
|
|
|
|
|
$assert($converging['state_transitioning'] === true
|
|
|
|
|
&& $converging['state_transition'] === 'shutdown'
|
|
|
|
|
&& $converging['operation_transition'] === null
|
|
|
|
|
&& is_int($converging['shutdown_convergence_until']),
|
|
|
|
|
'A recently succeeded shutdown stopped converging on a transient running observation.');
|
|
|
|
|
$stopped = CloudInstancePageService::powerStatus($convergenceSnapshot, [
|
|
|
|
|
'uuid' => $convergenceSnapshot['uuid'], 'state' => 'shutoff',
|
|
|
|
|
]);
|
|
|
|
|
$assert($stopped['state_transitioning'] === false
|
|
|
|
|
&& $stopped['state_transition'] === null
|
|
|
|
|
&& $stopped['shutdown_convergence_until'] === null,
|
|
|
|
|
'A confirmed stopped state did not finish shutdown convergence.');
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 104)->update([
|
|
|
|
|
'updated_at' => time() - 61,
|
|
|
|
|
]);
|
|
|
|
|
$terminal = CloudInstancePageService::powerStatus(
|
|
|
|
|
CloudInstancePageService::forActorIds($owner, [1])[0]
|
|
|
|
|
);
|
|
|
|
|
$assert($terminal['state_transitioning'] === false
|
|
|
|
|
&& $terminal['state_transition'] === null
|
|
|
|
|
&& $terminal['operation_transition'] === null
|
|
|
|
|
&& $terminal['shutdown_convergence_until'] === null,
|
|
|
|
|
'Expired or uncertain jobs were presented as active instance transitions.');
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 104)->update([
|
|
|
|
|
'updated_at' => time(),
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 105, 'instance_id' => 1, 'kind' => 'action',
|
|
|
|
|
'status' => 'uncertain', 'updated_at' => time(),
|
|
|
|
|
'sealed_payload' => CloudSecrets::encrypt([
|
|
|
|
|
'body' => ['action' => 'start'],
|
|
|
|
|
], 'job-payload'),
|
|
|
|
|
]);
|
|
|
|
|
$superseded = CloudInstancePageService::powerStatus(
|
|
|
|
|
CloudInstancePageService::forActorIds($owner, [1])[0]
|
|
|
|
|
);
|
|
|
|
|
$assert($superseded['state_transitioning'] === false
|
|
|
|
|
&& $superseded['shutdown_convergence_until'] === null,
|
|
|
|
|
'A newer uncertain start inherited an older shutdown convergence window.');
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 106, 'instance_id' => 1, 'kind' => 'action',
|
|
|
|
|
'status' => 'failed', 'updated_at' => time(),
|
|
|
|
|
'sealed_payload' => CloudSecrets::encrypt([
|
|
|
|
|
'body' => ['action' => 'shutdown'],
|
|
|
|
|
], 'job-payload'),
|
|
|
|
|
]);
|
|
|
|
|
$failedShutdown = CloudInstancePageService::powerStatus(
|
|
|
|
|
CloudInstancePageService::forActorIds($owner, [1])[0]
|
|
|
|
|
);
|
|
|
|
|
$assert($failedShutdown['state_transitioning'] === false
|
|
|
|
|
&& $failedShutdown['shutdown_convergence_until'] === null,
|
|
|
|
|
'A failed shutdown incorrectly opened a convergence window.');
|
|
|
|
|
|
|
|
|
|
$adminPage = CloudInstancePageService::forActor($admin, 1, 20);
|
|
|
|
|
$assert($adminPage['stats']['total'] === 2,
|
|
|
|
|
'Read-only administrator lost the historical all-instance view.');
|
|
|
|
|
|