Skip to content

Commit

Permalink
Push instead of a single buds
Browse files Browse the repository at this point in the history
When we bud a prog, we need to implement an additional label to wait it.
However, when we bud a single prog, we can achieve the same
functionality with pushing. Budding has the power to run multiple
concurrent progs.
  • Loading branch information
enescakir committed Feb 3, 2024
1 parent 6e56364 commit 88dea11
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 132 deletions.
27 changes: 8 additions & 19 deletions prog/download_boot_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,16 @@ def blob_storage_client
end

label def learn_storage
bud Prog::LearnStorage
hop_wait_learn_storage
end

label def wait_learn_storage
reap.each do |st|
case st.prog
when "LearnStorage"
kwargs = {
total_storage_gib: st.exitval.fetch("total_storage_gib"),
available_storage_gib: st.exitval.fetch("available_storage_gib")
}

vm_host.update(**kwargs)
end
end

if leaf?
if retval
kwargs = {
total_storage_gib: retval.fetch("total_storage_gib"),
available_storage_gib: retval.fetch("available_storage_gib")
}
vm_host.update(**kwargs)
hop_activate_host
end
donate

push Prog::LearnStorage
end

label def activate_host
Expand Down
39 changes: 10 additions & 29 deletions prog/vm/host_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ def before_run

label def start
register_deadline(:wait, 15 * 60)
hop_prep if retval&.dig("msg") == "rhizome user bootstrapped and source installed"

bud Prog::BootstrapRhizome, {"target_folder" => "host"}
hop_wait_bootstrap_rhizome
end

label def wait_bootstrap_rhizome
reap
hop_prep if leaf?
donate
push Prog::BootstrapRhizome, {"target_folder" => "host"}
end

label def prep
Expand Down Expand Up @@ -100,32 +94,19 @@ def before_run
end

label def setup_hugepages
bud Prog::SetupHugepages
hop_wait_setup_hugepages
end
hop_setup_spdk if retval&.dig("msg") == "hugepages installed"

label def wait_setup_hugepages
reap
hop_setup_spdk if leaf?
donate
push Prog::SetupHugepages
end

label def setup_spdk
bud(Prog::Storage::SetupSpdk,
{
"version" => frame["spdk_version"],
"start_service" => false,
"allocation_weight" => 100
})
hop_wait_setup_spdk
end
hop_prep_reboot if retval&.dig("msg") == "SPDK was setup"

label def wait_setup_spdk
reap
if leaf?
hop_prep_reboot
end
donate
push Prog::Storage::SetupSpdk, {
"version" => frame["spdk_version"],
"start_service" => false,
"allocation_weight" => 100
}
end

label def prep_reboot
Expand Down
30 changes: 5 additions & 25 deletions spec/prog/download_boot_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,13 @@
end

describe "#learn_storage" do
it "starts a number of sub-programs" do
expect(dbi).to receive(:bud).with(Prog::LearnStorage)
expect { dbi.learn_storage }.to hop("wait_learn_storage")
end
end

describe "#wait_learn_storage" do
it "updates the vm_host record from the finished programs" do
expect(vm_host).to receive(:update).with(total_storage_gib: 300, available_storage_gib: 500)
expect(dbi).to receive(:reap).and_return([
instance_double(Strand, prog: "LearnStorage", exitval: {"total_storage_gib" => 300, "available_storage_gib" => 500}),
instance_double(Strand, prog: "ArbitraryOtherProg")
])

expect { dbi.wait_learn_storage }.to hop("activate_host")
end

it "crashes if an expected field is not set for LearnStorage" do
expect(dbi).to receive(:reap).and_return([instance_double(Strand, prog: "LearnStorage", exitval: {})])
expect { dbi.wait_learn_storage }.to raise_error KeyError, "key not found: \"total_storage_gib\""
it "pushes the learn storage program" do
expect { dbi.learn_storage }.to hop("start", "LearnStorage")
end

it "donates to children if they are not exited yet" do
expect(dbi).to receive(:reap).and_return([])
expect(dbi).to receive(:leaf?).and_return(false)
expect(dbi).to receive(:donate).and_call_original
expect { dbi.wait_learn_storage }.to nap(0)
it "hops once SetupHugepages has returned" do
dbi.strand.retval = {"total_storage_gib" => 300, "available_storage_gib" => 500}
expect { dbi.learn_storage }.to hop("activate_host")
end
end

Expand Down
77 changes: 18 additions & 59 deletions spec/prog/vm/host_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,14 @@
end

describe "#start" do
it "buds a bootstrap rhizome process" do
expect(nx).to receive(:bud).with(Prog::BootstrapRhizome, {"target_folder" => "host"})
expect { nx.start }.to hop("wait_bootstrap_rhizome")
it "pushes a bootstrap rhizome process" do
expect(nx).to receive(:push).with(Prog::BootstrapRhizome, {"target_folder" => "host"}).and_call_original
expect { nx.start }.to hop("start", "BootstrapRhizome")
end
end

describe "#wait_bootstrap_rhizome" do
before { expect(nx).to receive(:reap) }

it "hops to prep if there are no sub-programs running" do
expect(nx).to receive(:leaf?).and_return true

expect { nx.wait_bootstrap_rhizome }.to hop("prep")
end

it "donates if there are sub-programs running" do
expect(nx).to receive(:leaf?).and_return false
expect(nx).to receive(:donate).and_call_original

expect { nx.wait_bootstrap_rhizome }.to nap(0)
it "hops once BootstrapRhizome has returned" do
nx.strand.retval = {"msg" => "rhizome user bootstrapped and source installed"}
expect { nx.start }.to hop("prep")
end
end

Expand Down Expand Up @@ -166,59 +154,30 @@
end

describe "#setup_hugepages" do
it "buds the hugepage program" do
expect(nx).to receive(:bud).with(Prog::SetupHugepages)
expect { nx.setup_hugepages }.to hop("wait_setup_hugepages")
it "pushes the hugepage program" do
expect { nx.setup_hugepages }.to hop("start", "SetupHugepages")
end
end

describe "#wait_setup_hugepages" do
it "enters the setup_spdk state" do
expect(nx).to receive(:reap).and_return([])
expect(nx).to receive(:leaf?).and_return true
vmh = instance_double(VmHost)
nx.instance_variable_set(:@vm_host, vmh)

expect { nx.wait_setup_hugepages }.to hop("setup_spdk")
end

it "donates its time if child strands are still running" do
expect(nx).to receive(:reap).and_return([])
expect(nx).to receive(:leaf?).and_return false
expect(nx).to receive(:donate).and_call_original

expect { nx.wait_setup_hugepages }.to nap(0)
it "hops once SetupHugepages has returned" do
nx.strand.retval = {"msg" => "hugepages installed"}
expect { nx.setup_hugepages }.to hop("setup_spdk")
end
end

describe "#setup_spdk" do
it "buds the spdk program" do
expect(nx).to receive(:bud).with(Prog::Storage::SetupSpdk,
it "pushes the spdk program" do
expect(nx).to receive(:push).with(Prog::Storage::SetupSpdk,
{
"version" => Config.spdk_version,
"start_service" => false,
"allocation_weight" => 100
})
expect { nx.setup_spdk }.to hop("wait_setup_spdk")
}).and_call_original
expect { nx.setup_spdk }.to hop("start", "Storage::SetupSpdk")
end
end

describe "#wait_setup_spdk" do
it "hops to prep_reboot if all tasks are done" do
expect(nx).to receive(:reap).and_return([])
expect(nx).to receive(:leaf?).and_return true
vmh = instance_double(VmHost)
nx.instance_variable_set(:@vm_host, vmh)

expect { nx.wait_setup_spdk }.to hop("prep_reboot")
end

it "donates its time if child strands are still running" do
expect(nx).to receive(:reap).and_return([])
expect(nx).to receive(:leaf?).and_return false
expect(nx).to receive(:donate).and_call_original

expect { nx.wait_setup_spdk }.to nap(0)
it "hops once SetupSpdk has returned" do
nx.strand.retval = {"msg" => "SPDK was setup"}
expect { nx.setup_spdk }.to hop("prep_reboot")
end
end

Expand Down

0 comments on commit 88dea11

Please sign in to comment.