Skip to content

Commit

Permalink
Don't leave trailing hyphen in deployment name
Browse files Browse the repository at this point in the history
If the ems_id is nil, empty, or not in the expected format, it can return nil,
causing us to leave the deployment name with a trailing hyphen.  Now, we only
append the hyphen and ems_id if it's present.
  • Loading branch information
jrafanie committed Mar 21, 2023
1 parent c3ee812 commit 047680d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/miq_worker/container_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def deployment_prefix
def worker_deployment_name
@worker_deployment_name ||= begin
deployment_name = abbreviated_class_name.dup.chomp("Worker").sub("Manager", "").sub(/^Miq/, "")
deployment_name << "-#{Array(ems_id).map { |id| ApplicationRecord.split_id(id).last }.join("-")}" if respond_to?(:ems_id)
deployment_name << "-#{Array(ems_id).map { |id| ApplicationRecord.split_id(id).last }.join("-")}" if respond_to?(:ems_id) && ems_id.present?
"#{deployment_prefix}#{deployment_name.underscore.dasherize.tr("/", "-")}"
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/models/miq_worker/container_common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ def deployment_name_for(name)
expect(klass.constantize.new.worker_deployment_name.length).to be <= 60
end
end

context "ems_id" do
let(:subject) { ManageIQ::Providers::BaseManager::EventCatcher.new }

it "is appended" do
subject.queue_name = "ems_1"
expect(subject.worker_deployment_name[-2..]).to eq("-1")
end

it "isn't appended for nil queue_name" do
subject.queue_name = nil
expect(subject.worker_deployment_name[-7..]).to eq("catcher")
end

it "isn't appended for blank queue_name" do
subject.queue_name = " "
expect(subject.worker_deployment_name[-7..]).to eq("catcher")
end

it "isn't appended for invalid queue_name prefix" do
subject.queue_name = "notems_1"
expect(subject.worker_deployment_name[-7..]).to eq("catcher")
end
end
end

describe "#scale_deployment" do
Expand Down

0 comments on commit 047680d

Please sign in to comment.