-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't leave trailing hyphen in deployment name #22419
Don't leave trailing hyphen in deployment name #22419
Conversation
@@ -113,6 +113,35 @@ 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::Openshift::ContainerManager::EventCatcher.new } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be an Openshift::ContainerManager::EventCatcher
for the specs? Would prefer not to call out a specific provider if possible. Could you use ManageIQ::Providers::BaseManager::EventCatcher
?
end | ||
|
||
it "isn't appended for array queue_name" do | ||
subject.queue_name = %w[ems_1 ems2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only case I'm not understanding. If we have an "Array" queue_name, then the worker doesn't have an id? what happens if you have 2 separate queue_names like %w[ems_1 ems2]
and %w[ems_3 ems4]
? Wouldn't those collide?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I questioned that too. An array queue_name isn't supported as it was dropped in #20345.
I could just drop this test as it was just confirmation of how to fix the current problem. This deployment name creation code is so far from the source problem that raising in the code here would be quite unhelpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so that's telling me that foreman has a bug and needs to be fixed
|
||
it "is appended" do | ||
subject.queue_name = "ems_1" | ||
expect(subject.worker_deployment_name[-1]).to eq("1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should include the hyphen so as not to allow any false positives like -21
.
expect(subject.worker_deployment_name[-1]).to eq("1") | |
expect(subject.worker_deployment_name[-2..]).to eq("-1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, ok
Is this the only worker like this? If so, I think it's better to fix that, and then not have the special case. |
We should not be returning arrays for ems_id anymore, foreman was just missed because it doesn't follow the typical parent/child manager pattern. |
Opened ManageIQ/manageiq-providers-foreman#113 to fix the issue with foreman queue_name_for_ems returning an Array |
f0715d8
to
29dd755
Compare
Ok, I got back to this and pushed up the suggestions. Thanks. |
Checked commits jrafanie/manageiq@047680d~...29dd755 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint app/models/miq_worker/container_common.rb
|
@@ -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 << "-#{ApplicationRecord.split_id(ems_id).last}" if respond_to?(:ems_id) && ems_id.kind_of?(Fixnum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrafanie As discussed, let's change the kind_of?(FixNum) to a nil/presence check. Otherwise this LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done. PTAL
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.
ems_id comes from ems_id_from_queue_name which as of [1] can only ever return an integer or nil from parse_ems_id. [1] ManageIQ#20345
29dd755
to
0686ffd
Compare
Backported to
|
…ing_deployment_name Don't leave trailing hyphen in deployment name (cherry picked from commit e845df9)
If the
ems_id
isnil
, empty, or not in the expected format, it can returnnil
causing us to leave the deployment name with a trailing hyphen. Now, we only
append the hyphen and
ems_id
if it's present.ems_id
cannot be an array, simplifying this logic ofems_id
returning nil or an fixnumems_id
comes fromems_id_from_queue_name
which as of [1] can only ever return aninteger or nil from
parse_ems_id
.[1] #20345
Related, we need to fix the foreman provider to not return an array from queue_name_for_ems