diff --git a/model.rb b/model.rb index 55444dea2..ade3e34c7 100644 --- a/model.rb +++ b/model.rb @@ -136,6 +136,14 @@ def monitoring_interval end end +module DisplayStatusMethods + def set_failed_on_deadline + if display_state != "failed" && Page.from_tag_parts("Deadline", id, strand.prog, strand.stack.first["deadline_target"]) + update(display_state: "failed") + end + end +end + if (level = Config.database_logger_level) require "logger" DB.loggers << Logger.new($stdout, level: level) diff --git a/model/gcp_vm.rb b/model/gcp_vm.rb index dcbf25d3b..6d306c456 100644 --- a/model/gcp_vm.rb +++ b/model/gcp_vm.rb @@ -13,6 +13,7 @@ class GcpVm < Sequel::Model include ResourceMethods include SemaphoreMethods + include DisplayStatusMethods semaphore :destroy, :start_vm, :stop_vm, :update_storage, :update_size include Authorization::HyperTagMethods diff --git a/model/lantern/lantern_resource.rb b/model/lantern/lantern_resource.rb index 423240c35..913aeb194 100644 --- a/model/lantern/lantern_resource.rb +++ b/model/lantern/lantern_resource.rb @@ -16,6 +16,7 @@ class LanternResource < Sequel::Model include ResourceMethods include SemaphoreMethods + include DisplayStatusMethods include Authorization::HyperTagMethods include Authorization::TaggableMethods diff --git a/prog/gcp_vm/nexus.rb b/prog/gcp_vm/nexus.rb index a8253bd11..8b7bc3316 100644 --- a/prog/gcp_vm/nexus.rb +++ b/prog/gcp_vm/nexus.rb @@ -78,6 +78,7 @@ def host end label def wait_create_vm + gcp_vm.set_failed_on_deadline gcp_client = Hosting::GcpApis.new vm = gcp_client.get_vm(gcp_vm.name, "#{gcp_vm.location}-a") if vm["status"] == "RUNNING" @@ -90,11 +91,12 @@ def host end label def start - register_deadline(:failed_provisioning, 10 * 60) + register_deadline(:wait, 10 * 60) hop_create_vm end label def create_vm + gcp_vm.set_failed_on_deadline gcp_client = Hosting::GcpApis.new labels = frame["labels"] gcp_client.create_vm(gcp_vm.name, "#{gcp_vm.location}-a", gcp_vm.boot_image, gcp_vm.public_key, gcp_vm.unix_user, "#{gcp_vm.family}-#{gcp_vm.cores}", gcp_vm.storage_size_gib, labels: labels) @@ -108,11 +110,6 @@ def host hop_wait_create_vm end - label def failed_provisioning - gcp_vm.update(display_state: "failed") - hop_wait - end - label def wait_sshable addr = gcp_vm.sshable.host diff --git a/prog/lantern/lantern_resource_nexus.rb b/prog/lantern/lantern_resource_nexus.rb index d07c97e54..733384138 100644 --- a/prog/lantern/lantern_resource_nexus.rb +++ b/prog/lantern/lantern_resource_nexus.rb @@ -112,19 +112,13 @@ def before_run label def start nap 5 unless representative_server.vm.strand.label == "wait" - # TODO fix - # register_deadline(:failed_provisioning, 10 * 60) + register_deadline(:wait, 10 * 60) # bud self.class, frame, :trigger_pg_current_xact_id_on_parent if lantern_resource.parent # hop_wait_trigger_pg_current_xact_id_on_parent hop_wait_servers end - label def failed_provisioning - lantern_resource.update(display_state: "failed") - hop_wait - end - # TODO:: check why is this needed # label def trigger_pg_current_xact_id_on_parent # lantern_resource.parent.representative_server.run_query("SELECT pg_current_xact_id()") @@ -138,6 +132,7 @@ def before_run # end label def wait_servers + lantern_resource.set_failed_on_deadline nap 5 if servers.any? { _1.strand.label != "wait" } hop_wait end @@ -148,7 +143,7 @@ def before_run Prog::Lantern::LanternServerNexus.assemble(resource_id: lantern_resource.id, timeline_id: lantern_resource.timeline.id, timeline_access: "fetch") end - if lantern_resource.display_state == "failed" && servers.any? { _1.strand.label == "wait" } + if lantern_resource.display_state == "failed" lantern_resource.update(display_state: nil) end diff --git a/spec/coverage_helper.rb b/spec/coverage_helper.rb index 98935dcb3..8272d2eb1 100644 --- a/spec/coverage_helper.rb +++ b/spec/coverage_helper.rb @@ -13,9 +13,9 @@ # rhizome (dataplane) and controlplane should have separate coverage reports. # They will have different coverage suites in future. add_filter "/rhizome" - add_filter "/misc" # No need to check coverage for them + add_filter "/misc" add_filter "/migrate/" add_filter "/spec/" add_filter "/db.rb" diff --git a/spec/model/display_status_methods_spec.rb b/spec/model/display_status_methods_spec.rb new file mode 100644 index 000000000..d7fce8119 --- /dev/null +++ b/spec/model/display_status_methods_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative "../spec_helper" + +RSpec.describe DisplayStatusMethods do + it "updates display_state to failed" do + [GcpVm, LanternResource].each do |klass| + instance = klass.new + expect(instance).to receive(:display_state).and_return("starting") + expect(instance).to receive(:strand).and_return(instance_double(Strand, prog: klass.name, stack: [{}])).at_least(:once) + expect(Page).to receive(:from_tag_parts).and_return(instance_double(Page)) + expect(instance).to receive(:update).with(display_state: "failed") + expect { instance.set_failed_on_deadline }.not_to raise_error + end + end +end diff --git a/spec/prog/gcp_vm/nexus_spec.rb b/spec/prog/gcp_vm/nexus_spec.rb index ada09e9e9..043cd080c 100644 --- a/spec/prog/gcp_vm/nexus_spec.rb +++ b/spec/prog/gcp_vm/nexus_spec.rb @@ -63,7 +63,7 @@ describe "#create_vm" do it "Hops to create_vm on start" do - expect(nx).to receive(:register_deadline).with(:failed_provisioning, 10 * 60) + expect(nx).to receive(:register_deadline).with(:wait, 10 * 60) expect { nx.start }.to hop("create_vm") end @@ -76,6 +76,7 @@ expect(nx.strand).to receive(:stack).and_return([frame]).at_least(:once) expect(nx.strand).to receive(:modified!).with(:stack).at_least(:once) expect(nx.strand).to receive(:save_changes).at_least(:once) + expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once) expect { nx.create_vm }.to hop("wait_create_vm") end @@ -83,6 +84,7 @@ gcp_api = instance_double(Hosting::GcpApis) expect(Hosting::GcpApis).to receive(:new).and_return(gcp_api) expect(gcp_api).to receive(:get_vm).with("dummy-vm", "us-central1-a").and_return({"status" => "PROVISIONING"}) + expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once) expect { nx.wait_create_vm }.to nap(10) end @@ -91,6 +93,7 @@ expect(Hosting::GcpApis).to receive(:new).and_return(gcp_api) expect(gcp_api).to receive(:get_vm).with("dummy-vm", "us-central1-a").and_return({"status" => "RUNNING"}) expect(gcp_api).to receive(:create_static_ipv4).with("dummy-vm", "us-central1").and_return({}) + expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once) expect { nx.wait_create_vm }.to hop("wait_ipv4") end @@ -276,12 +279,5 @@ expect(gcp_vm).to receive(:sshable).and_return(sshable) expect(nx.host).to eq("1.1.1.1") end - - describe "#failed_provisioning" do - it "updates display state" do - expect(gcp_vm).to receive(:update).with(display_state: "failed") - expect { nx.failed_provisioning }.to hop("wait") - end - end end end diff --git a/spec/prog/lantern/lantern_resource_nexus_spec.rb b/spec/prog/lantern/lantern_resource_nexus_spec.rb index 0fd3589fb..038e40105 100644 --- a/spec/prog/lantern/lantern_resource_nexus_spec.rb +++ b/spec/prog/lantern/lantern_resource_nexus_spec.rb @@ -197,11 +197,4 @@ expect { nx.destroy }.to exit({"msg" => "lantern resource is deleted"}) end end - - describe "#failed_provisioning" do - it "updates display state" do - expect(lantern_resource).to receive(:update).with(display_state: "failed") - expect { nx.failed_provisioning }.to hop("wait") - end - end end