From c7436fe5d18ba266b2737d13c6ae9093daea65ca Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Sat, 4 May 2024 21:29:36 -0700 Subject: [PATCH] wait for timeline on setup_docker_stack --- model/lantern/lantern_server.rb | 4 +--- prog/lantern/lantern_server_nexus.rb | 3 +++ spec/model/lantern/lantern_server_spec.rb | 2 -- spec/prog/lantern/lantern_server_nexus_spec.rb | 10 ++++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/model/lantern/lantern_server.rb b/model/lantern/lantern_server.rb index 0bf3f50ee..b86d7e3f7 100644 --- a/model/lantern/lantern_server.rb +++ b/model/lantern/lantern_server.rb @@ -129,9 +129,7 @@ def configure_hash end def update_walg_creds - # fetching again to be sure it is the updated data - lantern_timeline = LanternTimeline[timeline.id] - walg_config = lantern_timeline.generate_walg_config + walg_config = timeline.generate_walg_config vm.sshable.cmd("sudo lantern/bin/update_env", stdin: JSON.generate([ ["WALG_GS_PREFIX", walg_config[:walg_gs_prefix]], ["GOOGLE_APPLICATION_CREDENTIALS_WALG_B64", walg_config[:gcp_creds_b64]], diff --git a/prog/lantern/lantern_server_nexus.rb b/prog/lantern/lantern_server_nexus.rb index 05c8aee53..fc88c9f65 100644 --- a/prog/lantern/lantern_server_nexus.rb +++ b/prog/lantern/lantern_server_nexus.rb @@ -123,6 +123,9 @@ def before_run raise "GCP_CREDS_GCR_B64 is required to setup docker stack for Lantern" end + # wait for service account to be created + nap 10 if lantern_server.timeline.strand.label != "wait_leader" + case vm.sshable.cmd("common/bin/daemonizer --check configure_lantern") when "Succeeded" vm.sshable.cmd("common/bin/daemonizer --clean configure_lantern") diff --git a/spec/model/lantern/lantern_server_spec.rb b/spec/model/lantern/lantern_server_spec.rb index 8943e7ef8..e91dd9833 100644 --- a/spec/model/lantern/lantern_server_spec.rb +++ b/spec/model/lantern/lantern_server_spec.rb @@ -448,9 +448,7 @@ it "calls update_env on vm" do timeline = instance_double(LanternTimeline) expect(timeline).to receive(:generate_walg_config).and_return({gcp_creds_b64: "test-creds-push", walg_gs_prefix: "test-bucket-push"}).at_least(:once) - expect(timeline).to receive(:id).and_return("test").at_least(:once) expect(lantern_server).to receive(:timeline).and_return(timeline).at_least(:once) - expect(LanternTimeline).to receive(:[]).and_return(timeline).at_least(:once) walg_config = timeline.generate_walg_config expect(vm.sshable).to receive(:cmd).with("sudo lantern/bin/update_env", stdin: JSON.generate([ ["WALG_GS_PREFIX", walg_config[:walg_gs_prefix]], diff --git a/spec/prog/lantern/lantern_server_nexus_spec.rb b/spec/prog/lantern/lantern_server_nexus_spec.rb index 153c24b37..78b157447 100644 --- a/spec/prog/lantern/lantern_server_nexus_spec.rb +++ b/spec/prog/lantern/lantern_server_nexus_spec.rb @@ -197,6 +197,16 @@ end describe "#setup_docker_stack" do + before do + allow(lantern_server.timeline).to receive(:strand).and_return(instance_double(Strand, label: "wait_leader")) + end + + it "naps if timeline is not ready" do + expect(lantern_server.timeline).to receive(:strand).and_return(instance_double(Strand, label: "start")) + expect(Config).to receive(:gcp_creds_gcr_b64).and_return("test-creds") + expect { nx.setup_docker_stack }.to nap(10) + end + it "raises if gcr credentials are not provided" do expect(Config).to receive(:gcp_creds_gcr_b64).and_return(nil) expect { nx.setup_docker_stack }.to raise_error "GCP_CREDS_GCR_B64 is required to setup docker stack for Lantern"