We use number of hugepages used when installing & removing an SPDK installation. Although this is mostly static, but it is possible that we decide to change number of hugepages used when installing a new SPDK in future. In which case, we should remember what value used for older installations to update VmHost records correctly when removing them. This mismatch already happened in production last week, so making this change to avoid it in future.
107 lines
3.8 KiB
Ruby
107 lines
3.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../../model/spec_helper"
|
|
|
|
RSpec.describe Prog::Storage::SetupSpdk do
|
|
subject(:setup_spdk) {
|
|
described_class.new(described_class.assemble(
|
|
"adec2977-74a9-8b71-8473-cf3940a45ac5",
|
|
spdk_version,
|
|
start_service: true,
|
|
allocation_weight: 50
|
|
))
|
|
}
|
|
|
|
let(:spdk_version) { "v23.09-ubi-0.2" }
|
|
let(:sshable) {
|
|
instance_double(Sshable)
|
|
}
|
|
let(:vm_host) {
|
|
Sshable.create { _1.id = "adec2977-74a9-8b71-8473-cf3940a45ac5" }
|
|
VmHost.create(
|
|
location: "xyz",
|
|
arch: "x64",
|
|
used_hugepages_1g: 0,
|
|
total_hugepages_1g: 20,
|
|
total_cpus: 96
|
|
) { _1.id = "adec2977-74a9-8b71-8473-cf3940a45ac5" }
|
|
}
|
|
|
|
before do
|
|
allow(setup_spdk).to receive_messages(sshable: sshable, vm_host: vm_host)
|
|
end
|
|
|
|
describe "#start" do
|
|
it "hops to install_spdk" do
|
|
expect(vm_host).to receive(:spdk_installations).and_return([])
|
|
expect { setup_spdk.start }.to hop("install_spdk")
|
|
end
|
|
|
|
it "fails if version/arch combination is not supported" do
|
|
expect(setup_spdk).to receive(:frame).and_return({"version" => "v1.0"})
|
|
expect { setup_spdk.start }.to raise_error RuntimeError, "Unsupported version: v1.0, x64"
|
|
end
|
|
|
|
it "fails if already contains 2 installations" do
|
|
expect(vm_host).to receive(:spdk_installations).and_return(["spdk_1", "spdk_2"])
|
|
expect { setup_spdk.start }.to raise_error RuntimeError, "Can't install more than 2 SPDKs on a host"
|
|
end
|
|
|
|
it "fails if not enough hugepages" do
|
|
expect(vm_host).to receive(:used_hugepages_1g).and_return(19)
|
|
expect { setup_spdk.start }.to raise_error RuntimeError, "No available hugepages"
|
|
end
|
|
end
|
|
|
|
describe "#install_spdk" do
|
|
it "installs and hops to start_service" do
|
|
expect(sshable).to receive(:cmd).with("sudo host/bin/setup-spdk install #{spdk_version} 4")
|
|
expect { setup_spdk.install_spdk }.to hop("start_service")
|
|
end
|
|
end
|
|
|
|
describe "#start_service" do
|
|
it "installs service and hops to update_database" do
|
|
expect(sshable).to receive(:cmd).with("sudo host/bin/setup-spdk start #{spdk_version}")
|
|
expect(sshable).to receive(:cmd).with("sudo host/bin/setup-spdk verify #{spdk_version}")
|
|
expect { setup_spdk.start_service }.to hop("update_database")
|
|
end
|
|
|
|
it "skips installing service if not asked to" do
|
|
ss2 = described_class.new(described_class.assemble(vm_host.id, spdk_version, start_service: false))
|
|
expect { ss2.start_service }.to hop("update_database")
|
|
end
|
|
end
|
|
|
|
describe "#update_database" do
|
|
it "updates the database and exits" do
|
|
hugepages = 3
|
|
SpdkInstallation.create(version: spdk_version, vm_host_id: vm_host.id, hugepages: hugepages, allocation_weight: 0) { _1.id = vm_host.id }
|
|
expect { setup_spdk.update_database }.to exit({"msg" => "SPDK was setup"})
|
|
expect(vm_host.reload.used_hugepages_1g).to eq(hugepages)
|
|
expect(vm_host.spdk_installations.first.allocation_weight).to eq(50)
|
|
end
|
|
|
|
it "doesn't reserve a hugepage if service didn't start" do
|
|
SpdkInstallation.create(version: spdk_version, vm_host_id: vm_host.id, hugepages: 3, allocation_weight: 0) { _1.id = vm_host.id }
|
|
allow(setup_spdk).to receive(:frame).and_return({"version" => spdk_version, "start_service" => false, "allocation_weight" => 50})
|
|
expect { setup_spdk.update_database }.to exit({"msg" => "SPDK was setup"})
|
|
expect(vm_host.reload.used_hugepages_1g).to eq(0)
|
|
end
|
|
end
|
|
|
|
describe "#spdk_cpu_count" do
|
|
it "uses 2 cpus for AX161" do
|
|
expect(setup_spdk.spdk_cpu_count(total_host_cpus: 64)).to eq(2)
|
|
end
|
|
|
|
it "uses 4 cpus for RX220" do
|
|
expect(setup_spdk.spdk_cpu_count(total_host_cpus: 80)).to eq(4)
|
|
end
|
|
|
|
it "uses 4 cpus for AX162" do
|
|
expect(setup_spdk.spdk_cpu_count(total_host_cpus: 96)).to eq(4)
|
|
end
|
|
end
|
|
end
|