Skip to content

Commit 164877d

Browse files
authored
Merge pull request #30 from jay7x/features
New features
2 parents 52b3633 + ba4963f commit 164877d

File tree

6 files changed

+95
-17
lines changed

6 files changed

+95
-17
lines changed

plans/cluster/create.pp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# @summary Create the cluster of Lima VMs
22
# @param name
33
# Cluster name
4+
# @param start
5+
# Start the cluster after creation
6+
# @param start_jobs
7+
# Amount of jobs to start VMs in parallel when $start is true
48
# @param clusters
59
# Hash of all defined clusters. Populated from Hiera usually.
610
# @param target
711
# The host to run the limactl on
812
plan lima::cluster::create (
913
String[1] $name,
14+
Boolean $start = false,
15+
Integer[0] $start_jobs = 0,
1016
Optional[Hash] $clusters = undef,
1117
TargetSpec $target = 'localhost',
1218
) {
@@ -66,5 +72,9 @@
6672
})
6773
}
6874

69-
return $create_res
75+
if $start {
76+
return run_plan('lima::cluster::start', name => $name, jobs => $start_jobs, clusters => $clusters, target => $target)
77+
} else {
78+
return $create_res
79+
}
7080
}

plans/cluster/delete.pp

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# @summary Delete the cluster of Lima VMs
22
# @param name
33
# Cluster name
4+
# @param stop
5+
# Stop the cluster before deleting
46
# @param force
57
# Forcibly stop the processes
68
# @param clusters
@@ -9,6 +11,7 @@
911
# The host to run the limactl on
1012
plan lima::cluster::delete (
1113
String[1] $name,
14+
Boolean $stop = false,
1215
Boolean $force = false,
1316
Optional[Hash] $clusters = undef,
1417
TargetSpec $target = 'localhost',
@@ -26,6 +29,10 @@
2629
}
2730
out::verbose("Nodes to delete: ${defined_nodes}")
2831

32+
if $stop {
33+
run_plan('lima::cluster::stop', name => $name, force => $force, clusters => $clusters, target => $target)
34+
}
35+
2936
return run_task('lima::delete', $target, {
3037
names => $defined_nodes,
3138
force => $force,

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/create_spec.rb

+25-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
}
5454
end
5555
let(:nodes_to_create) { [nodes[2], nodes[3], nodes[4]] }
56-
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
56+
let(:start) { nil }
57+
let(:start_jobs) { nil }
58+
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'start' => start, 'start_jobs' => start_jobs } }
5759

5860
context 'with non-existent cluster' do
5961
let(:cluster_name) { 'nonexistent' }
@@ -111,11 +113,29 @@
111113
expect_out_verbose.with_params("Nodes to create: [#{nodes_to_create.join(', ')}]")
112114
end
113115

114-
it 'creates the cluster' do
115-
result = run_plan(plan, plan_params)
116+
context 'with default params' do
117+
it 'creates the cluster' do
118+
expect_plan('lima::cluster::start').not_be_called
119+
120+
result = run_plan(plan, plan_params)
121+
122+
expect(result.ok?).to be(true)
123+
expect(result.value.count).to eq(3)
124+
end
125+
end
116126

117-
expect(result.ok?).to be(true)
118-
expect(result.value.count).to eq(3)
127+
context 'with start=>true' do
128+
let(:start) { true }
129+
let(:start_jobs) { 2 }
130+
let(:start_params) { { 'name' => cluster_name, 'clusters' => clusters, 'jobs' => start_jobs, 'target' => 'localhost' } }
131+
132+
it 'creates and starts the cluster' do
133+
expect_plan('lima::cluster::start').be_called_times(1).with_params(start_params)
134+
135+
result = run_plan(plan, plan_params)
136+
137+
expect(result.ok?).to be(true)
138+
end
119139
end
120140
end
121141
end

spec/plans/cluster/delete_spec.rb

+20-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
}
3030
end
3131
let(:cluster_name) { 'example' }
32-
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
33-
let(:force) { false }
32+
let(:force) { nil }
33+
let(:stop) { nil }
34+
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'stop' => stop, 'force' => force } }
3435

3536
context 'with non-existent cluster' do
3637
let(:cluster_name) { 'nonexistent' }
@@ -46,11 +47,12 @@
4647
context 'with existing cluster' do
4748
before :each do
4849
expect_plan('lima::clusters').always_return(clusters[cluster_name])
49-
expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force).always_return(delete: true)
50+
expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force ? true : false).always_return(delete: true)
5051
expect_out_verbose.with_params("Nodes to delete: [#{nodes.join(', ')}]")
52+
expect_plan('lima::cluster::stop').be_called_times(0)
5153
end
5254

53-
context 'with force unset' do
55+
context 'with default params' do
5456
it 'deletes all nodes in the cluster' do
5557
result = run_plan(plan, plan_params)
5658

@@ -62,7 +64,6 @@
6264

6365
context 'with force => true' do
6466
let(:force) { true }
65-
let(:plan_params) { super().merge('force' => force) }
6667

6768
it 'deletes all nodes in the cluster' do
6869
result = run_plan(plan, plan_params)
@@ -72,5 +73,19 @@
7273
expect(result.value[0].value).to eq('delete' => true)
7374
end
7475
end
76+
77+
context 'with stop => true' do
78+
let(:stop) { true }
79+
80+
it 'deletes all nodes in the cluster' do
81+
expect_plan('lima::cluster::stop').be_called_times(1)
82+
83+
result = run_plan(plan, plan_params)
84+
85+
expect(result.ok?).to be(true)
86+
expect(result.value.count).to eq(1)
87+
expect(result.value[0].value).to eq('delete' => true)
88+
end
89+
end
7590
end
7691
end

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)