Skip to content

Commit

Permalink
Refactor prog to use force flag
Browse files Browse the repository at this point in the history
  • Loading branch information
enescakir committed Feb 20, 2024
1 parent d983182 commit 91d1e80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions prog/download_boot_image.rb
Expand Up @@ -26,11 +26,9 @@ def blob_storage_client
end

label def wait_draining
unless vm_host.vms.empty?
nap 15
end
sshable.cmd("sudo rm -f /var/storage/images/#{image_name.shellescape}.raw")
hop_download
hop_download if vm_host.vms.empty?

nap 15
end

label def download
Expand Down Expand Up @@ -73,6 +71,9 @@ def blob_storage_client
end

label def activate_host
# Verify that the image was downloaded
sshable.cmd("ls /var/storage/images/#{image_name}.raw")

vm_host.update(allocation_state: "accepting")

pop "#{image_name} downloaded"
Expand Down
2 changes: 1 addition & 1 deletion rhizome/host/bin/download-boot-image
Expand Up @@ -14,4 +14,4 @@ require_relative "../lib/vm_setup"
certs = $stdin.read
ca_path = "/usr/lib/ssl/certs/ubicloud_images_blob_storage_certs.crt"
safe_write_to_file(ca_path, certs)
VmSetup.new("").download_boot_image(boot_image, custom_url: custom_url, ca_path: ca_path)
VmSetup.new("").download_boot_image(boot_image, force: true, custom_url: custom_url, ca_path: ca_path)
2 changes: 1 addition & 1 deletion spec/prog/download_boot_image_spec.rb
Expand Up @@ -28,7 +28,6 @@

it "hops if it's drained" do
expect(vm_host).to receive(:vms).and_return([])
expect(sshable).to receive(:cmd).with("sudo rm -f /var/storage/images/my-image.raw")
expect { dbi.wait_draining }.to hop("download")
end
end
Expand Down Expand Up @@ -99,6 +98,7 @@

describe "#activate_host" do
it "activates vm host again" do
expect(sshable).to receive(:cmd).with("ls /var/storage/images/my-image.raw")
expect {
expect { dbi.activate_host }.to exit({"msg" => "my-image downloaded"})
}.to change { vm_host.reload.allocation_state }.from("unprepared").to("accepting")
Expand Down

0 comments on commit 91d1e80

Please sign in to comment.