ubicloud/spec/prog/install_rhizome_spec.rb
Jeremy Evans 6de231a5de Fix PostgresServerNexus#destroy to not violate strand leases
Previously, PostgresServerNexus#destroy ran:

```ruby
strand.children.each { it.destroy }
```

This is not safe as there could be an existing lease for the
strand children.  Child strands are either:

* BootstrapRhizome
* InstallRhizome (via push from Bootstrap Rhizome)
* Postgres::PostgresServerNexus (via restart from #unavailable)

Fix this by adding a destroy semaphore for all child strands,
except the Postgres::PostgresServerNexus ones, as we don't want
a child restart prog for the same server to also go into destroy.

Note that if a restart has been triggered via unavailable, and
then the destroy semaphore has been incremented, the destroy
cannot complete until after the restart commands return
successfully.

It would probably be better to have restart in a separate prog,
that could exit similarly to how Boostrap/InstallRhizome are
setup, so that destruction could proceed even if the restart
commands will not run successfully.
2025-09-16 06:11:16 +09:00

55 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require_relative "../model/spec_helper"
RSpec.describe Prog::InstallRhizome do
subject(:ir) { described_class.new(Strand.new(stack: [{"target_folder" => "host"}])) }
let(:sshable) { instance_double(Sshable) }
before do
allow(ir).to receive(:sshable).and_return(sshable)
end
it "exits if destroy is set" do
expect(ir.before_run).to be_nil
expect(ir).to receive(:when_destroy_set?).and_yield
expect { ir.before_run }.to exit({"msg" => "exiting early due to destroy semaphore"})
end
describe "#start" do
it "writes tar" do
expect(sshable).to receive(:cmd) do |*args, **kwargs|
expect(args).to eq ["tar xf -"]
expect(kwargs[:stdin].scan("Gemfile.lock").count).to be < 2
# Take offset from
# https://www.gnu.org/software/tar/manual/html_node/Standard.html
expect(kwargs[:stdin][257..261]).to eq "ustar"
end
expect { ir.start }.to hop("install_gems")
end
it "writes tar including specs" do
ir_spec = described_class.new(Strand.new(stack: [{"target_folder" => "host", "install_specs" => true}]))
expect(ir_spec).to receive(:sshable).and_return(sshable).at_least(:once)
expect(sshable).to receive(:cmd)
expect { ir_spec.start }.to hop("install_gems")
end
end
describe "#install_gems" do
it "runs some commands and exits" do
expect(sshable).to receive(:cmd).with("bundle config set --local path vendor/bundle && bundle install")
expect { ir.install_gems }.to hop
end
end
describe "#validate" do
it "runs the validate script" do
expect(sshable).to receive(:cmd).with("common/bin/validate")
expect { ir.validate }.to exit({"msg" => "installed rhizome"})
end
end
end