Skip to content
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

Adds task to subservices for correct retirement completion #17912

Merged
merged 2 commits into from
Sep 21, 2018

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Aug 27, 2018

This changes the signature of the create_retire_subtask method to include the task, per the conversation @tinaafitz and @mkanoor and I had a week or so ago.

It's a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1608958

Issue #17993 opened to track virtual attributes occasionally returned by attributes method.
#17996 opened by Keenan to fix 17993.
Tested with 17996, works as expected. Yay. So the workaround for excluding virtual attributes directly from the service task creation is in this PR because I have no idea when 17996 will get in.

There's no point in opening the rails pr as mentioned because it's fixed in 5.2 and a bunch of the attribute stuff changed.

TODO: use changes in #17996 to not have to filter out virtual attrs from nh attr list.

... update: 17996 is merged and #18019 opened to clean up the now-defunct TODO.

@miq-bot

This comment has been minimized.

@miq-bot

This comment has been minimized.

@miq-bot

This comment has been minimized.

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 11, 2018

@tinaafitz can you take a look at this please to make sure it's okay before I spend time fixing the tests?

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 13, 2018

@tinaafitz can you please take a look? I need to fix the blocker bug that depends on this change.

@d-m-u d-m-u changed the title [WIP] Remove doubled service bundle children retirement call from RAAR Remove doubled service bundle children retirement call from RAAR Sep 13, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 13, 2018

@miq-bot remove_label wip

@@ -42,6 +41,7 @@ def create_retire_subtasks(parent_service)
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks
nh['options'][:dialog] = {}
new_task = create_task(svc_rsc, parent_service, nh)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u We need to pass the task(as parent_task) into the create_task method.

Then, we should set the parent_task_id to the parent_task.id here:

:parent_task_id => id,

And, we should set the parent_task.miq_request_tasks accordingly:

new_task.source = svc_rsc.resource

parent_task.miq_request_tasks << new_task

@d-m-u d-m-u force-pushed the bz1608958 branch 2 times, most recently from 2a74486 to 7d6e8c7 Compare September 14, 2018 13:48
Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u Looks good.
@mkanoor Please review.

@gmcculloug
Copy link
Member

@d-m-u Please review failing test.

@@ -41,23 +40,25 @@ def create_retire_subtasks(parent_service)
nh['options'] = options.except(:child_tasks)
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks
nh['options'][:dialog] = {}
new_task = create_task(svc_rsc, parent_service, nh)
new_task = create_task(svc_rsc, parent_service, nh, parent_task)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u The nh has is pulling in virtual columns which is causing the test failure:

Failure/Error: new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
ActiveModel::MissingAttributeError:
  can't write unknown attribute `href_slug`
# ./app/models/service_retire_task.rb:53:in `create_task'
# ./app/models/service_retire_task.rb:43:in `block in create_retire_subtasks'
...

You can fix this by excluding the virtual columns on line 39 using self.class.virtual_attribute_names

nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message", *self.class.virtual_attribute_names)

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 17, 2018

@mkanoor can you please review?

@d-m-u d-m-u changed the title Remove doubled service bundle children retirement call from RAAR [WIP] Remove doubled service bundle children retirement call from RAAR Sep 17, 2018
@miq-bot miq-bot added the wip label Sep 17, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 18, 2018

The test failure addressed by the removal of the virtual attributes (see https://github.com/ManageIQ/manageiq/pull/17912/files#r217853506) is a TODO that needs to be addressed subsequently. It'd be nice to get this merged as is because it's a bug fix. I vote that we address the virtual attribute weirdness later, I'll open an issue for it. Input, @gmcculloug @tinaafitz @Fryguy ??

@tinaafitz
Copy link
Member

@d-m-u I agree that we should address the virtual attribute issue separately.
@gmcculloug We really need these changes for Service Retirement as a Request to work properly.
Can we merge this PR?

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 18, 2018

The issue is #17993

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 18, 2018

@miq-bot add_label blocker

@gmcculloug
Copy link
Member

Agreed. Since this is a blocker the suggested work-around to ensure we exclude virtual attributes from the new hash should be good for now.

@Fryguy any issue with this work-around while we try to address the deeper active_record bug?

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by comment

(@d-m-u pinged me earlier, so I got a bit nerd sniped...)

parent_service.service_resources.collect do |svc_rsc|
next unless svc_rsc.resource.try(:retireable?)
# TODO: the next line deals with the filtering for provisioning
# (https://github.com/ManageIQ/manageiq/blob/3921e87915b5a69937b9d4a70bb24ab71b97c165/app/models/service_template/filter.rb#L5)
# which should be extended to retirement as part of later work
# svc_rsc.resource_type != "ServiceTemplate" || self.class.include_service_template?(self, srr.id, parent_service)
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message")
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message", *self.class.virtual_attribute_names)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an alternative to @gmcculloug 's suggestion:

nh = attributes.slice(self.class.column_names)
               .except!("id", "created_on", "updated_on", "type", "state", "status", "message")

Just makes it so that the list you are starting with is always what is available as columns from the database, and then it excludes columns from there, in the rare case that someone has fetch this current instance of this object was fetched using a custom SELECT statement that included some other derived columns.

... Not that I would know anyone who would do that, for say, performance reasons or anything...

( ͡° ͜ʖ ͡°)

Note: I just used .except! here to not dup the hash a second time, but that is probably peanuts in the grand scheme of things.

@d-m-u d-m-u changed the title Remove doubled service bundle children retirement call from RAAR Adds task to subservices for correct retirement completion Sep 19, 2018
@d-m-u d-m-u force-pushed the bz1608958 branch 6 times, most recently from b483770 to 88f5cf0 Compare September 20, 2018 19:15
@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 20, 2018

@gmcculloug @NickLaMuro @anyone_with_more_power_than_me


# TODO: use changes here: https://github.com/ManageIQ/manageiq/pull/17996 to not have to filter by col_names
# 17996 removes virtual attributes from @attrs list
nh = attributes.slice(self.class.column_names).except!("id", "created_on", "updated_on", "type", "state", "status", "message")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u slice expects *keys not an array of names. (https://apidock.com/rails/Hash/slice)

You need nh = attributes.slice(*self.class.column_names)...

When I run the command the way it is here I get an empty hash. Now my concern is that tests are passing with invalid data. 😱

Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to correct call to slice and import test validation based on https://github.com/ManageIQ/manageiq/pull/17912/files#r219315906

@miq-bot
Copy link
Member

miq-bot commented Sep 20, 2018

Checked commits d-m-u/manageiq@fd5f912~...75f18ee with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@gmcculloug gmcculloug merged commit 8d4bf78 into ManageIQ:master Sep 21, 2018
@gmcculloug gmcculloug added this to the Sprint 95 Ending Sep 24, 2018 milestone Sep 21, 2018
@d-m-u d-m-u deleted the bz1608958 branch February 1, 2019 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants