Skip to content

Commit

Permalink
Restart the cluster in a single plan call
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
jay7x committed Jun 2, 2024
1 parent acc87e2 commit ba4963f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 11 additions & 1 deletion plans/cluster/stop.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# @summary Stop the cluster of Lima VMs
# @param name
# Cluster name
# @param start
# Start the cluster after stopping it
# @param start_jobs
# Amount of jobs to start VMs in parallel when $restart is true
# @param force
# Forcibly stop the processes
# @param clusters
Expand All @@ -9,6 +13,8 @@
# The host to run the limactl on
plan lima::cluster::stop (
String[1] $name,
Boolean $start = false,
Integer[0] $start_jobs = 0,
Boolean $force = false,
Optional[Hash] $clusters = undef,
TargetSpec $target = 'localhost',
Expand Down Expand Up @@ -48,5 +54,9 @@
})
}

return $stop_res
if $start {
return run_plan('lima::cluster::start', name => $name, jobs => $start_jobs, clusters => $clusters, target => $target)
} else {
return $stop_res
}
}
26 changes: 21 additions & 5 deletions spec/plans/cluster/stop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
}
end
let(:nodes_to_stop) { [nodes[0], nodes[2]] }
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
let(:force) { false }
let(:force) { nil }
let(:start) { nil }
let(:start_jobs) { nil }
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'start' => start, 'start_jobs' => start_jobs, 'force' => force } }

context 'with non-existent cluster' do
let(:cluster_name) { 'nonexistent' }
Expand All @@ -58,13 +60,14 @@
expect_plan('lima::clusters').always_return(clusters[cluster_name])
expect_task('lima::list').be_called_times(1).always_return(lima_list_res)
nodes_to_stop.each do |node|
expect_task('lima::stop').be_called_times(1).with_params('name' => node, 'force' => force).always_return(stop: true)
expect_task('lima::stop').be_called_times(1).with_params('name' => node, 'force' => force ? true : false).always_return(stop: true)
end
expect_out_verbose.with_params("Defined nodes: [#{nodes.join(', ')}]")
expect_out_verbose.with_params("Nodes to stop: [#{nodes_to_stop.join(', ')}]")
expect_plan('lima::cluster::start').be_called_times(0)
end

context 'with force unset' do
context 'with default params' do
it 'stops all non-running nodes in the cluster' do
result = run_plan(plan, plan_params)

Expand All @@ -78,7 +81,6 @@

context 'with force => true' do
let(:force) { true }
let(:plan_params) { super().merge('force' => force) }
let(:nodes_to_stop) { [nodes[0], nodes[1], nodes[2]] }

it 'stops all non-running nodes in the cluster' do
Expand All @@ -91,5 +93,19 @@
end
end
end

context 'with start => true' do
let(:start) { true }
let(:start_jobs) { 2 }
let(:start_params) { { 'name' => cluster_name, 'jobs' => start_jobs, 'clusters' => clusters, 'target' => 'localhost' } }

it 'stops the cluster and starts it again' do
expect_plan('lima::cluster::start').be_called_times(1).with_params(start_params)

result = run_plan(plan, plan_params)

expect(result.ok?).to be(true)
end
end
end
end

0 comments on commit ba4963f

Please sign in to comment.