Skip to content

Commit

Permalink
push back
Browse files Browse the repository at this point in the history
  • Loading branch information
enescakir committed Feb 21, 2024
1 parent b120ab6 commit 97576c6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 62 deletions.
7 changes: 3 additions & 4 deletions prog/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ def retval
strand.retval
end

def push(prog, new_frame = {}, label = "start")
old_prog = strand.prog
old_label = strand.label
new_frame = {"subject_id" => @subject_id, "link" => [strand.prog, old_label]}.merge(new_frame)
def push(prog, new_frame = {}, label = "start", next_prog: nil, next_label: nil)
old_prog, old_label = strand.prog, strand.label
new_frame = {"subject_id" => @subject_id, "link" => [next_prog || old_prog, next_label || old_label]}.merge(new_frame)

fail Hop.new(old_prog, old_label,
{prog: Strand.prog_verify(prog), label: label,
Expand Down
8 changes: 5 additions & 3 deletions prog/bootstrap_rhizome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def user
end

label def setup
pop "rhizome user bootstrapped and source installed" if retval&.dig("msg") == "installed rhizome"

key_data = sshable.keys.map(&:private_key)
Util.rootish_ssh(sshable.host, user, key_data, <<SH)
set -ueo pipefail
Expand All @@ -29,6 +27,10 @@ def user
echo #{sshable.keys.map(&:public_key).join("\n").shellescape} | sudo tee /home/rhizome/.ssh/authorized_keys > /dev/null
SH

push Prog::InstallRhizome, {"target_folder" => frame["target_folder"]}
push Prog::InstallRhizome, {"target_folder" => frame["target_folder"]}, next_label: "finish"
end

label def finish
pop "rhizome user bootstrapped and source installed"
end
end
3 changes: 1 addition & 2 deletions prog/postgres/postgres_server_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ def before_run
postgres_server.run_query(commands)

when_initial_provisioning_set? do
hop_wait if retval&.dig("msg") == "postgres server is restarted"
push self.class, frame, "restart"
push self.class, frame, "restart", next_label: "wait"
end

hop_wait
Expand Down
4 changes: 2 additions & 2 deletions prog/test/hetzner_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ def verify_specs_installation(installed: true)

label def install_bdev_ubid
version = "v23.09-ubi-0.2"
hop_wait if vm_host.spdk_installations.find { _1.version == version } || retval&.dig("msg") == "SPDK was setup"
hop_wait if vm_host.spdk_installations.find { _1.version == version }

# disable the default installation and install a bdev_ubi enabled spdk
vm_host.spdk_installations_dataset.update(allocation_weight: 0)
push Prog::Storage::SetupSpdk, {subject_id: vm_host.id, version: version, start_service: true, allocation_weight: 100}
push Prog::Storage::SetupSpdk, {subject_id: vm_host.id, version: version, start_service: true, allocation_weight: 100}, next_label: "wait"
end

label def wait
Expand Down
12 changes: 3 additions & 9 deletions prog/vm/host_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def before_run

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

push Prog::BootstrapRhizome, {"target_folder" => "host"}
push Prog::BootstrapRhizome, {"target_folder" => "host"}, next_label: "prep"
end

label def prep
Expand Down Expand Up @@ -95,19 +93,15 @@ def before_run
end

label def setup_hugepages
hop_setup_spdk if retval&.dig("msg") == "hugepages installed"

push Prog::SetupHugepages
push Prog::SetupHugepages, next_label: "setup_spdk"
end

label def setup_spdk
hop_prep_reboot if retval&.dig("msg") == "SPDK was setup"

push Prog::Storage::SetupSpdk, {
"version" => frame["spdk_version"],
"start_service" => false,
"allocation_weight" => 100
}
}, next_label: "prep_reboot"
end

label def prep_reboot
Expand Down
14 changes: 9 additions & 5 deletions spec/prog/bootstrap_rhizome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
describe "#setup" do
before { br.strand.label = "setup" }

it "runs initializing shell wih public keys" do
it "runs initializing shell wih public keys and returns to finish label" do
sshable = instance_double(Sshable, host: "hostname", keys: [instance_double(SshKey, public_key: "test key", private_key: "test private key")])
allow(br).to receive(:sshable).and_return(sshable)
expect(Util).to receive(:rootish_ssh).with "hostname", "root", ["test private key"], <<FIXTURE
Expand All @@ -48,12 +48,16 @@
echo test\\ key | sudo tee /home/rhizome/.ssh/authorized_keys > /dev/null
FIXTURE

expect { br.setup }.to hop("start", "InstallRhizome")
expect { br.setup }.to hop("start", "InstallRhizome").with_hop { |hopped|
expect(br).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { br.pop("exit") }.to hop("finish")
end
end

it "exits once InstallRhizome has returned" do
br.strand.retval = {"msg" => "installed rhizome"}
expect { br.setup }.to exit({"msg" => "rhizome user bootstrapped and source installed"})
describe "#finish" do
it "exits" do
expect { br.finish }.to exit({"msg" => "rhizome user bootstrapped and source installed"})
end
end
end
14 changes: 5 additions & 9 deletions spec/prog/postgres/postgres_server_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,14 @@
end

describe "#update_superuser_password" do
it "updates password and pushes restart during the initial provisioning" do
it "updates password and pushes restart during the initial provisioning and returns to wait label" do
expect(nx).to receive(:when_initial_provisioning_set?).and_yield
expect(postgres_server).to receive(:run_query).with(/log_statement = 'none'.*\n.*SCRAM-SHA-256/)
expect(nx).to receive(:push).with(described_class, {}, "restart").and_call_original
expect { nx.update_superuser_password }.to hop("restart")
end

it "updates password and hops to wait during initial provisioning if restart is already executed" do
expect(nx).to receive(:when_initial_provisioning_set?).and_yield
expect(postgres_server).to receive(:run_query).with(/log_statement = 'none'.*\n.*SCRAM-SHA-256/)
expect(nx.strand).to receive(:retval).and_return({"msg" => "postgres server is restarted"})
expect { nx.update_superuser_password }.to hop("wait")
expect { nx.update_superuser_password }.to hop("restart").with_hop { |hopped|
expect(nx).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { nx.pop("exit") }.to hop("wait")
end

it "updates password and hops to wait at times other than the initial provisioning" do
Expand Down
13 changes: 8 additions & 5 deletions spec/prog/test/hetzner_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@
end

describe "#install_bdev_ubid" do
it "hops to wait if it's installed" do
expect(hs_test).to receive(:retval).and_return({"msg" => "SPDK was setup"})
expect { hs_test.install_bdev_ubid }.to hop("wait")
it "setups spdk with bdev_ubi and returns to wait label" do
expect { hs_test.install_bdev_ubid }.to hop("start", "Storage::SetupSpdk").with_hop { |hopped|
expect(hs_test).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { hs_test.pop("exit") }.to hop("wait")
end

it "setups spdk with bdev_ubi" do
expect { hs_test.install_bdev_ubid }.to hop("start", "Storage::SetupSpdk")
it "skips bdev_ubi installation if it's installed already" do
expect(vm_host).to receive(:spdk_installations).and_return([instance_double(SpdkInstallation, version: "v23.09-ubi-0.2")])
expect { hs_test.install_bdev_ubid }.to hop("wait")
end
end

Expand Down
39 changes: 16 additions & 23 deletions spec/prog/vm/host_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@
end

describe "#start" do
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

it "hops once BootstrapRhizome has returned" do
nx.strand.retval = {"msg" => "rhizome user bootstrapped and source installed"}
expect { nx.start }.to hop("prep")
it "pushes a bootstrap rhizome process and returns to prep label" do
expect { nx.start }.to hop("start", "BootstrapRhizome").with_hop { |hopped|
expect(nx).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { nx.pop("exit") }.to hop("prep")
end
end

Expand Down Expand Up @@ -155,30 +152,26 @@
end

describe "#setup_hugepages" do
it "pushes the hugepage program" do
expect { nx.setup_hugepages }.to hop("start", "SetupHugepages")
end

it "hops once SetupHugepages has returned" do
nx.strand.retval = {"msg" => "hugepages installed"}
expect { nx.setup_hugepages }.to hop("setup_spdk")
it "pushes the hugepage program and returns to setup_spdk label" do
expect { nx.setup_hugepages }.to hop("start", "SetupHugepages").with_hop { |hopped|
expect(nx).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { nx.pop("exit") }.to hop("setup_spdk")
end
end

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

it "hops once SetupSpdk has returned" do
nx.strand.retval = {"msg" => "SPDK was setup"}
expect { nx.setup_spdk }.to hop("prep_reboot")
}, next_label: "prep_reboot").and_call_original
expect { nx.setup_spdk }.to hop("start", "Storage::SetupSpdk").with_hop { |hopped|
expect(nx).to receive(:frame).and_return(hopped.strand_update_args[:stack].first)
}
expect { nx.pop("exit") }.to hop("prep_reboot")
end
end

Expand Down

0 comments on commit 97576c6

Please sign in to comment.