From acc87e21289cbc14613dfce7e6c0bafc71602956 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Sun, 24 Mar 2024 12:51:03 +0400 Subject: [PATCH] Stop and delete the cluster in a single plan call Closes #9 --- plans/cluster/delete.pp | 7 +++++++ spec/plans/cluster/delete_spec.rb | 25 ++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/plans/cluster/delete.pp b/plans/cluster/delete.pp index 5eff656..4a8836a 100644 --- a/plans/cluster/delete.pp +++ b/plans/cluster/delete.pp @@ -1,6 +1,8 @@ # @summary Delete the cluster of Lima VMs # @param name # Cluster name +# @param stop +# Stop the cluster before deleting # @param force # Forcibly stop the processes # @param clusters @@ -9,6 +11,7 @@ # The host to run the limactl on plan lima::cluster::delete ( String[1] $name, + Boolean $stop = false, Boolean $force = false, Optional[Hash] $clusters = undef, TargetSpec $target = 'localhost', @@ -26,6 +29,10 @@ } out::verbose("Nodes to delete: ${defined_nodes}") + if $stop { + run_plan('lima::cluster::stop', name => $name, force => $force, clusters => $clusters, target => $target) + } + return run_task('lima::delete', $target, { names => $defined_nodes, force => $force, diff --git a/spec/plans/cluster/delete_spec.rb b/spec/plans/cluster/delete_spec.rb index 4126597..27e755d 100644 --- a/spec/plans/cluster/delete_spec.rb +++ b/spec/plans/cluster/delete_spec.rb @@ -29,8 +29,9 @@ } end let(:cluster_name) { 'example' } - let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } } - let(:force) { false } + let(:force) { nil } + let(:stop) { nil } + let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'stop' => stop, 'force' => force } } context 'with non-existent cluster' do let(:cluster_name) { 'nonexistent' } @@ -46,11 +47,12 @@ context 'with existing cluster' do before :each do expect_plan('lima::clusters').always_return(clusters[cluster_name]) - expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force).always_return(delete: true) + expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force ? true : false).always_return(delete: true) expect_out_verbose.with_params("Nodes to delete: [#{nodes.join(', ')}]") + expect_plan('lima::cluster::stop').be_called_times(0) end - context 'with force unset' do + context 'with default params' do it 'deletes all nodes in the cluster' do result = run_plan(plan, plan_params) @@ -62,7 +64,6 @@ context 'with force => true' do let(:force) { true } - let(:plan_params) { super().merge('force' => force) } it 'deletes all nodes in the cluster' do result = run_plan(plan, plan_params) @@ -72,5 +73,19 @@ expect(result.value[0].value).to eq('delete' => true) end end + + context 'with stop => true' do + let(:stop) { true } + + it 'deletes all nodes in the cluster' do + expect_plan('lima::cluster::stop').be_called_times(1) + + result = run_plan(plan, plan_params) + + expect(result.ok?).to be(true) + expect(result.value.count).to eq(1) + expect(result.value[0].value).to eq('delete' => true) + end + end end end