Skip to content

Commit

Permalink
Reenable vm deletion in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed May 1, 2024
1 parent 53c29c6 commit cd8899e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
1 change: 1 addition & 0 deletions lib/hosting/gcp_apis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def resize_vm_disk(zone, disk_source, storage_size_gib)
def list_objects(bucket, prefix)
connection = Excon.new("https://storage.googleapis.com", headers: @host[:headers])
query = {prefix: prefix}
puts "Query is #{query}"
response = connection.get(path: "/storage/v1/b/#{bucket}/o", query: query, expects: [200, 400])
Hosting::GcpApis.check_errors(response)
data = JSON.parse(response.body)
Expand Down
9 changes: 8 additions & 1 deletion misc/misc_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ def self.update_collation_on_all_databases
# We didn't need to update rebuild indexes this time as we didn't have any indexes with collation coming from libc
resources = LanternResource.all
resources.each do |resource|
resource.representative_server.run_query("ALTER DATABASE template1 REFRESH COLLATION VERSION")
update_collation resource
end
end

def self.update_collation(resource)
all_dbs = resource.representative_server.run_query("SELECT datname from pg_database WHERE datname != 'template0'").split("\n")
all_dbs.each do |db|
resource.representative_server.run_query("ALTER DATABASE #{db} REFRESH COLLATION VERSION")
end
end
end
11 changes: 4 additions & 7 deletions prog/gcp_vm/nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,10 @@ def host
label def destroy
DB.transaction do
gcp_vm.update(display_state: "deleting")
# TODO:: disable vm deletion until stable release
if !Config.production? || Config.e2e_test?
gcp_client = Hosting::GcpApis.new
gcp_client.delete_vm(gcp_vm.name, "#{gcp_vm.location}-a")
if gcp_vm.has_static_ipv4
gcp_client.release_ipv4(gcp_vm.name, gcp_vm.location)
end
gcp_client = Hosting::GcpApis.new
gcp_client.delete_vm(gcp_vm.name, "#{gcp_vm.location}-a")
if gcp_vm.has_static_ipv4
gcp_client.release_ipv4(gcp_vm.name, gcp_vm.location)
end
strand.children.each { _1.destroy }
gcp_vm.projects.map { gcp_vm.dissociate_with_project(_1) }
Expand Down
20 changes: 0 additions & 20 deletions spec/prog/gcp_vm/nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,6 @@
end

describe "#destroy" do
it "does not delete vm if production" do
expect(Config).to receive(:production?).and_return(true)
expect(gcp_vm).to receive(:update).with({display_state: "deleting"})
expect(gcp_vm).to receive(:destroy)
expect(gcp_vm).not_to receive(:has_static_ipv4)
expect { nx.destroy }.to exit({"msg" => "gcp vm deleted"})
end

it "deletes vm if production but in e2e_test" do
expect(Config).to receive(:production?).and_return(true)
expect(Config).to receive(:e2e_test?).and_return(true)
expect(gcp_vm).to receive(:update).with({display_state: "deleting"})
expect(gcp_vm).to receive(:destroy)
expect(gcp_vm).to receive(:has_static_ipv4).and_return(false)
gcp_api = instance_double(Hosting::GcpApis)
expect(Hosting::GcpApis).to receive(:new).and_return(gcp_api)
expect(gcp_api).to receive(:delete_vm).with("dummy-vm", "us-central1-a")
expect { nx.destroy }.to exit({"msg" => "gcp vm deleted"})
end

it "exits after run destroy" do
expect(gcp_vm).to receive(:has_static_ipv4).and_return(false)
expect(gcp_vm).to receive(:update).with({display_state: "deleting"})
Expand Down

0 comments on commit cd8899e

Please sign in to comment.