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

Need to pass the user's group in to automate when the provision starts. #61

Merged
merged 1 commit into from
Aug 9, 2017

Conversation

lfu
Copy link
Member

@lfu lfu commented Jul 31, 2017

User's current group might have changed before the provision finishes.
So the user's current group from DB may be different from the user's group when the request is sent into automate.

Part of ManageIQ/manageiq#15696.
Blocks ManageIQ/manageiq-content#156.
Includes ManageIQ/manageiq#15760.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364

@miq-bot add_label bug, euwe/yes, fine/yes

@gmcculloug gmcculloug self-assigned this Jul 31, 2017
@gmcculloug gmcculloug requested a review from mkanoor July 31, 2017 21:30
@gmcculloug gmcculloug changed the title Need to pass the user's group in to automate when the provision starts. [WIP] Need to pass the user's group in to automate when the provision starts. Aug 1, 2017
@gmcculloug gmcculloug added the wip label Aug 1, 2017
@lfu lfu force-pushed the service_user_in_groups_1467364 branch from 415396b to 77267db Compare August 2, 2017 17:53
@gmcculloug
Copy link
Member

@lfu Please review failing tests.

@lfu lfu force-pushed the service_user_in_groups_1467364 branch from 77267db to 6db2dfb Compare August 2, 2017 18:40
@@ -250,7 +250,7 @@ def process_assertions(message)

def user_info_attributes(user)
{'user' => user, 'tenant' => user.current_tenant, 'miq_group' => user.current_group}.each do |k, v|
value = MiqAeObject.convert_value_based_on_datatype(v.id, v.class.name)
value = MiqAeMethodService::MiqAeServiceModelBase.wrap_results(v)
Copy link
Member Author

Choose a reason for hiding this comment

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

This solves the issue that the user object is got from DB with wrong current group in automate.

MiqAeObject.convert_value_based_on_datatype calls find at service model layer which fetches the object from DB then calls MiqAeMethodService::MiqAeServiceModelBase.wrap_results on the object.

Since the user object is already available with the correct current group, we can call MiqAeMethodService::MiqAeServiceModelBase.wrap_results on it directly.

With this change, then ManageIQ/manageiq-content#156 is not needed as the in-memory user object has the current group point to the group that the user is in when the request is made.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu I am not sure about this call, I am thinking the find should get the service model. Can we check if the find is doing the right thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mkanoor The find gets the user object from DB which is not what we want here since the user's current group from DB is not the correct requester group.

We should use the in-memory user object that we already have at hand and wrap it into service model object. This way we don't need to change the expose of current_group in MiqAeServiceUser because the user object has got correct current group in memory. expose itself does not query the DB.

@@ -250,7 +250,7 @@ def process_assertions(message)

def user_info_attributes(user)
{'user' => user, 'tenant' => user.current_tenant, 'miq_group' => user.current_group}.each do |k, v|
value = MiqAeObject.convert_value_based_on_datatype(v.id, v.class.name)
value = MiqAeMethodService::MiqAeServiceModelBase.wrap_results(v)
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu I am not sure about this call, I am thinking the find should get the service model. Can we check if the find is doing the right thing.

@@ -307,7 +307,8 @@ def self.ae_user_object(options = {})
raise "user_id not specified in Automation request" if options[:user_id].blank?
# raise "group_id not specified in Automation request" if options[:miq_group_id].blank?
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu Can we raise this exception because we are expecting that all calls into Automate are going to pass in the miq_group_id.

@lfu lfu force-pushed the service_user_in_groups_1467364 branch 2 times, most recently from c200e29 to d686357 Compare August 7, 2017 14:04
@lfu lfu changed the title [WIP] Need to pass the user's group in to automate when the provision starts. Need to pass the user's group in to automate when the provision starts. Aug 7, 2017
@lfu
Copy link
Member Author

lfu commented Aug 7, 2017

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Aug 7, 2017
@gmcculloug
Copy link
Member

@mkanoor Please take another look.

Copy link
Contributor

@mkanoor mkanoor left a comment

Choose a reason for hiding this comment

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

We might have to change the documentation to indicate that instead of using $evm.root['user'].current_group we should be using $evm.root['miq_group'] to get the requesters current group

@@ -305,9 +305,11 @@ def self.resolve_automation_object(uri, user_obj, attr = nil, options = {}, read

def self.ae_user_object(options = {})
raise "user_id not specified in Automation request" if options[:user_id].blank?
# raise "group_id not specified in Automation request" if options[:miq_group_id].blank?
raise "miq_group_id not specified in Automation request" if options[:miq_group_id].blank?
Copy link
Member

Choose a reason for hiding this comment

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

@lfu Do you know why this was commented out before? Are there any code paths you are aware of that might run into this new requirement?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gmcculloug miq_group_id was not required because a user's current_group is used as default.
Seems AutomationTask is not passing miq_group_id when calling into automate: here. Will fix it in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, please like the related PR back here when it is ready, I would like to have it available before merging this one since we know it will break Automation requests.

Copy link
Member Author

Choose a reason for hiding this comment

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

lfu added a commit to lfu/manageiq that referenced this pull request Aug 8, 2017
User's current group might have changed before the provision finishes.
So the user's current group from DB may be different from the user's group when the request is sent into automate.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364
@lfu lfu force-pushed the service_user_in_groups_1467364 branch from d686357 to 660b111 Compare August 9, 2017 20:45
@miq-bot
Copy link
Member

miq-bot commented Aug 9, 2017

Checked commit lfu@660b111 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 1 offense detected

lib/miq_automation_engine/engine/miq_ae_engine.rb

@@ -305,9 +305,11 @@ def self.resolve_automation_object(uri, user_obj, attr = nil, options = {}, read

def self.ae_user_object(options = {})
raise "user_id not specified in Automation request" if options[:user_id].blank?
# raise "group_id not specified in Automation request" if options[:miq_group_id].blank?
# raise "miq_group_id not specified in Automation request" if options[:miq_group_id].blank?
Copy link
Member

Choose a reason for hiding this comment

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

The raise will be re-introduced upstream after this PR is merged. This will allow the PR to be back-ported and to older branch and give more burn-in time upstream.

@gmcculloug gmcculloug merged commit 8de13ba into ManageIQ:master Aug 9, 2017
@gmcculloug gmcculloug added this to the Sprint 67 Ending Aug 21, 2017 milestone Aug 9, 2017
@simaishi
Copy link
Contributor

Fine backport (to manageiq repo) details:

$ git log -1
commit a3bb99ccd92d428c2a7c8218eb09b6e92c731500
Author: Greg McCullough <[email protected]>
Date:   Wed Aug 9 17:01:12 2017 -0400

    Merge pull request #61 from lfu/service_user_in_groups_1467364
    
    Need to pass the user's group in to automate when the provision starts.
    (cherry picked from commit 8de13ba4c7413710e4481cd7484b3675a12bd517)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1480007

@simaishi
Copy link
Contributor

Euwe backport (to manageiq repo) details:

$ git log -1
commit eea7b864c36f4cb1dadc87043bc2c8844c48c4db
Author: Greg McCullough <[email protected]>
Date:   Wed Aug 9 17:01:12 2017 -0400

    Merge pull request #61 from lfu/service_user_in_groups_1467364
    
    Need to pass the user's group in to automate when the provision starts.
    (cherry picked from commit 8de13ba4c7413710e4481cd7484b3675a12bd517)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1481859

@lfu lfu deleted the service_user_in_groups_1467364 branch September 29, 2018 14:32
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.

5 participants