Skip to content

Commit

Permalink
Allow zones to be deleted with servers when in pods
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonin committed Feb 5, 2020
1 parent 7d05fa6 commit 9c1afbc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def ntp_reload_queue

def message_for_invalid_delete
return _("cannot delete default zone") if name == "default"
return _("cannot delete maintenance zone") if self == miq_region.maintenance_zone
return _("zone name '%{name}' is used by a server") % {:name => name} if miq_servers.present?
return _("cannot delete maintenance zone") if self == self.class.maintenance_zone
return _("zone name '%{name}' is used by a server") % {:name => name} if !MiqEnvironment::Command.is_podified? && miq_servers.present?
_("zone name '%{name}' is used by a provider") % {:name => name} if ext_management_systems.present?
end

Expand Down
34 changes: 34 additions & 0 deletions spec/models/zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,38 @@
expect(MiqServer.find_by(:id => server.id)).to be_nil
end
end

describe "#message_for_invalid_delete" do
it "returns an error for the default zone" do
described_class.seed
message = described_class.default_zone.message_for_invalid_delete
expect(message).to eq("cannot delete default zone")
end

it "returns an error for the maintenance zone" do
described_class.seed
message = described_class.maintenance_zone.message_for_invalid_delete
expect(message).to eq("cannot delete maintenance zone")
end

it "returns an error when the zone has providers" do
zone = FactoryBot.create(:zone)
FactoryBot.create(:ext_management_system, :zone => zone)
message = zone.message_for_invalid_delete
expect(message).to eq("zone name '#{zone.name}' is used by a provider")
end

it "returns an error when the zone has servers and not running in pods" do
zone = FactoryBot.create(:miq_server).zone
message = zone.message_for_invalid_delete
expect(message).to eq("zone name '#{zone.name}' is used by a server")
end

it "does not return an error when the zone has a server and running in pods" do
allow(MiqEnvironment::Command).to receive(:is_podified?).and_return(true)
zone = FactoryBot.create(:miq_server).zone
message = zone.message_for_invalid_delete
expect(message).to be_nil
end
end
end

0 comments on commit 9c1afbc

Please sign in to comment.