Skip to content

Commit ba4963f

Browse files
committed
Restart the cluster in a single plan call
Closes #11
1 parent acc87e2 commit ba4963f

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

plans/cluster/stop.pp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# @summary Stop the cluster of Lima VMs
22
# @param name
33
# Cluster name
4+
# @param start
5+
# Start the cluster after stopping it
6+
# @param start_jobs
7+
# Amount of jobs to start VMs in parallel when $restart is true
48
# @param force
59
# Forcibly stop the processes
610
# @param clusters
@@ -9,6 +13,8 @@
913
# The host to run the limactl on
1014
plan lima::cluster::stop (
1115
String[1] $name,
16+
Boolean $start = false,
17+
Integer[0] $start_jobs = 0,
1218
Boolean $force = false,
1319
Optional[Hash] $clusters = undef,
1420
TargetSpec $target = 'localhost',
@@ -48,5 +54,9 @@
4854
})
4955
}
5056

51-
return $stop_res
57+
if $start {
58+
return run_plan('lima::cluster::start', name => $name, jobs => $start_jobs, clusters => $clusters, target => $target)
59+
} else {
60+
return $stop_res
61+
}
5262
}

spec/plans/cluster/stop_spec.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
}
4040
end
4141
let(:nodes_to_stop) { [nodes[0], nodes[2]] }
42-
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
43-
let(:force) { false }
42+
let(:force) { nil }
43+
let(:start) { nil }
44+
let(:start_jobs) { nil }
45+
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'start' => start, 'start_jobs' => start_jobs, 'force' => force } }
4446

4547
context 'with non-existent cluster' do
4648
let(:cluster_name) { 'nonexistent' }
@@ -58,13 +60,14 @@
5860
expect_plan('lima::clusters').always_return(clusters[cluster_name])
5961
expect_task('lima::list').be_called_times(1).always_return(lima_list_res)
6062
nodes_to_stop.each do |node|
61-
expect_task('lima::stop').be_called_times(1).with_params('name' => node, 'force' => force).always_return(stop: true)
63+
expect_task('lima::stop').be_called_times(1).with_params('name' => node, 'force' => force ? true : false).always_return(stop: true)
6264
end
6365
expect_out_verbose.with_params("Defined nodes: [#{nodes.join(', ')}]")
6466
expect_out_verbose.with_params("Nodes to stop: [#{nodes_to_stop.join(', ')}]")
67+
expect_plan('lima::cluster::start').be_called_times(0)
6568
end
6669

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

@@ -78,7 +81,6 @@
7881

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

8486
it 'stops all non-running nodes in the cluster' do
@@ -91,5 +93,19 @@
9193
end
9294
end
9395
end
96+
97+
context 'with start => true' do
98+
let(:start) { true }
99+
let(:start_jobs) { 2 }
100+
let(:start_params) { { 'name' => cluster_name, 'jobs' => start_jobs, 'clusters' => clusters, 'target' => 'localhost' } }
101+
102+
it 'stops the cluster and starts it again' do
103+
expect_plan('lima::cluster::start').be_called_times(1).with_params(start_params)
104+
105+
result = run_plan(plan, plan_params)
106+
107+
expect(result.ok?).to be(true)
108+
end
109+
end
94110
end
95111
end

0 commit comments

Comments
 (0)