diff --git a/app/Provisioning/Steps/Customer/ResizeVirtualMachine.php b/app/Provisioning/Steps/Customer/ResizeVirtualMachine.php index d1b582a..385edbd 100644 --- a/app/Provisioning/Steps/Customer/ResizeVirtualMachine.php +++ b/app/Provisioning/Steps/Customer/ResizeVirtualMachine.php @@ -85,13 +85,17 @@ class ResizeVirtualMachine extends CustomerStep * when that is less than the machine already has. * * The target is the customer's WHOLE allowance — package plus booked storage - * packs — with the package's own system overhead left on top of it. That - * overhead is read off the package and never invented: the catalogue's four - * packages ship 120/100, 540/500, 1050/1000 and 2100/2000 GB, which is 20, - * 40, 50 and 100 GB of room beside the customer's files and is a decision the - * owner makes per package, not a ratio anybody may derive. A pack of extra - * storage is that much more FOR THE CUSTOMER, so it is added to the - * allowance and the package's overhead rides along unchanged. + * packs — with TWO overheads left on top of it, never one. The package's own + * system overhead is read off the package and never invented: the catalogue's + * four packages ship 120/100, 540/500, 1050/1000 and 2100/2000 GB, which is + * 20, 40, 50 and 100 GB of room beside the customer's files and is a decision + * the owner makes per package, not a ratio anybody may derive. Every booked + * pack brings ITS OWN overhead the same way, frozen on the booking rather + * than on the package — what it gives the customer and what it takes on the + * host are two different figures, and only their difference belongs here. + * Without it, a stack of packs would sit on the package's headroom alone and + * thin it out with every pack added, which is exactly the shape the rule + * exists to refuse. * * With no packs booked the sum is exactly the package's own `disk_gb`, which * is what this step has always used. diff --git a/tests/Feature/Provisioning/StoragePackHeadroomTest.php b/tests/Feature/Provisioning/StoragePackHeadroomTest.php index cea8fa1..233e365 100644 --- a/tests/Feature/Provisioning/StoragePackHeadroomTest.php +++ b/tests/Feature/Provisioning/StoragePackHeadroomTest.php @@ -1,10 +1,12 @@ active()->create(['datacenter' => 'fsn', 'node' => 'pve']); + $order = Order::factory()->withSubscription()->create(['datacenter' => 'fsn', 'plan' => 'start']); + $instance = Instance::factory()->create([ + 'order_id' => $order->id, 'customer_id' => $order->customer_id, + 'host_id' => $host->id, 'vmid' => 101, 'status' => 'provisioning', + ]); + $run = ProvisioningRun::factory()->create([ + 'subject_type' => Order::class, 'subject_id' => $order->id, 'pipeline' => 'customer', + 'context' => [ + 'instance_id' => $instance->id, 'host_id' => $host->id, 'node' => 'pve', + 'vmid' => 101, 'subdomain' => $instance->subdomain, 'plan' => 'start', + ], + ]); - $target = $allowance->totalGb() - + max(0, $planDisk - $planQuota) - + ($allowance->packDiskGb() - $allowance->packGb()); + return compact('host', 'order', 'instance', 'run'); +} - expect($target)->toBe(106); -}); - -// Den Schritt selbst fahren: reservedRun() (aus CustomerStepsTest.php) baut ein -// 'start'-Paket (100 GB Kontingent, 120 GB Platte — 20 GB Kopfraum des Pakets). -// Drei Blöcke zu 20 GB nutzbar / 22 GB belegt kommen direkt als +// Drei Blöcke à 20 GB nutzbar / 22 GB belegt kommen direkt als // SubscriptionAddon-Zeile dazu, statt über BookAddon zu buchen — das würde -// einen Lieferlauf anstoßen und Stripe befragen, was hier nichts zur Sache tut; -// gefragt ist nur, was ResizeVirtualMachine aus einer bereits gebuchten Zeile -// macht. +// einen Lieferlauf anstoßen und Stripe befragen, was hier nichts zur Sache +// tut; gefragt ist nur, was ResizeVirtualMachine aus einer bereits gebuchten +// Zeile macht. // // Ziel: 100 (Kontingent) + 60 (drei Blöcke à 20) + 20 (Kopfraum des Pakets, // 120-100) + 6 (Kopfraum der Blöcke, 66-60 belegt) = 186 GB. it('vergrößert die Platte um Paket- und Block-Kopfraum, und nur einmal', function () { $s = fakeServices(); - ['run' => $run, 'instance' => $instance, 'order' => $order] = reservedRun(); + ['run' => $run, 'instance' => $instance, 'order' => $order] = packHeadroomRun(); SubscriptionAddon::create([ 'subscription_id' => $order->subscription->id,