Bug 1380158 - Invoke a Custom Automation as an action in a policy does not work.
Summary: Invoke a Custom Automation as an action in a policy does not work.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Automate
Version: 5.6.0
Hardware: All
OS: All
high
high
Target Milestone: GA
: 5.7.0
Assignee: mkanoor
QA Contact: Dmitry Misharov
URL:
Whiteboard: automate
Depends On:
Blocks: 1384160
TreeView+ depends on / blocked
 
Reported: 2016-09-28 19:25 UTC by Josh Carter
Modified: 2019-12-16 06:56 UTC (History)
10 users (show)

Fixed In Version: 5.7.0.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1384160 (view as bug list)
Environment:
Last Closed: 2017-01-04 13:01:16 UTC
Category: ---
Cloudforms Team: CFME Core
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Proposed Patch (40.00 KB, application/x-tar)
2016-09-28 20:59 UTC, mkanoor
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:0012 0 normal SHIPPED_LIVE CFME 5.7.0 bug fixes and enhancement update 2017-01-04 17:50:36 UTC

Comment 2 Josh Carter 2016-09-28 19:27:52 UTC
Looks to possibly related to Rails 5.  Here is where it seems to be blowing up based on the stack trace:

From /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_engine.rb
====================================

  def self.deliver(*args)
    # This was added because in RAILS 5 PUMA sends multiple requests
    # to the same process and our DRb server implementation for Automate
    # Methods is not thread safe. The permit_concurrent_loads allows the
    # DRb requests which run in different threads to load constants.
    ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
      @deliver_mutex.synchronize { deliver_block(*args) }
    end
  end

Comment 3 Greg McCullough 2016-09-28 19:56:50 UTC
Madhu - Believe this is happening on 5.6.1.  Would this be fixed by PR https://github.com/ManageIQ/manageiq/pull/10445 ?

Comment 4 mkanoor 2016-09-28 20:59:50 UTC
Created attachment 1205680 [details]
Proposed Patch

Please make a back up of 
lib/miq_automation_engine/engine/miq_ae_engine.rb
lib/miq_automation_engine/engine/miq_ae_method.rb
lib/miq_automation_engine/engine/miq_ae_workspace.rb

And copy over the files from the tar which has one new file
lib/miq_automation_engine/engine/drb_remote_invoker.rb
in addition to the updates to the above 3

Comment 5 mkanoor 2016-09-28 21:00:40 UTC
Josh,
Can you please test it with the enclosed patch.
Thanks,
Madhu

Comment 6 mkanoor 2016-09-28 21:00:41 UTC
Josh,
Can you please test it with the enclosed patch.
Thanks,
Madhu

Comment 8 mkanoor 2016-10-10 20:39:30 UTC
Fixed in PR https://github.com/ManageIQ/manageiq/pull/10135

Comment 9 Shveta 2016-11-09 02:11:51 UTC
Verification steps please

Comment 10 mkanoor 2016-11-09 15:13:05 UTC
This issue started happening with Rails 5, where the multi threaded PUMA server was introduced. This PUMA server can send multiple requests into the same process, which ends up running multiple threads to handle the requests. When multiple requests are running the automate method which use the module level DRb methods were stepping on each other. So what would happen is that 2 threads running within the same process will step on the DRb variables. 
So the code was changed to use the non DRb module methods.

To test it

 You would need to define a custom button with multiple Dynamic Dialogs
 Since each Dynamic Dialog Method would have a method you can introduce a slight delay in the methods sleep(30).
 So you would click on 1 dynamic field which will say fetch a list of names
 While that is running click on the 2nd dynamic field which will fetch a list of some other names. This method should not have a delay (sleep)

Then you can check the logs to see that multiple requests came in 

3381 [----] I, [2016-11-08T17:59:57.107948 #17105:3fecb845e1d0]  INFO -- : MIQ(MiqQueue#delivered) M     essage id: [32590], State: [error], Delivered in [7.510469] seconds

In the above line #17105 is the process id and  3fecb845e1d0 is the process id.
so in this case we would be seeing multiple treads running in parallel with the same process id and the log lines would be interleaved. While the first method is waiting for 30 seconds the second would come in on a different thread and it would end before the first one ends.

Comment 12 mkanoor 2016-11-14 20:12:10 UTC
Yes dynamic fields, where you would have multiple independent dynamic fields in a dialog.

Comment 14 mkanoor 2016-11-18 16:33:33 UTC
I think you need to create a method that returns a list of items that you can use in your dynamic field.
A sample example looks like this https://github.com/ManageIQ/manageiq/blob/master/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb


This is a sample method to get a static list of values
Which can be used in a dropdown

#
# Sample method with static data
#

capital_list = { 'USA' => 'Washington DC', 'Russia' => 'Moscow', 'Japan' => 'Tokyo', 'France' => 'Paris', 'Canada' => 'Ottawa' }

capital_list[nil] = "<Choose>"

dialog_field = $evm.object

# sort_by: value / description / none
dialog_field["sort_by"] = "description"

# sort_order: ascending / descending
dialog_field["sort_order"] = "ascending"

# data_type: string / integer
dialog_field["data_type"] = "string"

# required: true / false
dialog_field["required"] = "true"

dialog_field["values"] = capital_list
dialog_field["default_value"] = nil



You can then wire that method to a drop down in a dynamic dialog.

If you need to setup a dynamic dialog please read https://access.redhat.com/mastering-cloudforms-automation

Comment 15 mkanoor 2016-11-18 16:37:32 UTC
Chapter 29 on Service Dialogs talks about how to integrate with dynamic fields.

Comment 16 Dmitry Misharov 2016-11-21 16:07:55 UTC
Verified on 5.7.0.11-rc1.20161115160629_46cf4f1. I followed the steps which were described in comment10. I created two methods and the first one contained sleep(10). In automation.log I found that these two methods executed in the separate threads and second one finished before the first one.
[----] I, [2016-11-21T10:57:57.760882 #24380:12e6818] INFO -- : <AEMethod [/Test/System/Request/Test1]> Starting
[----] I, [2016-11-21T10:57:59.758649 #24380:12e9d88] INFO -- : <AEMethod [/Test/System/Request/Test2]> Starting
[----] I, [2016-11-21T10:58:00.736631 #24380:12e9d88] INFO -- : <AEMethod [/Test/System/Request/Test2]> Ending
[----] I, [2016-11-21T10:58:09.213614 #24380:12e6818] INFO -- : <AEMethod [/Test/System/Request/Test1]> Ending

Comment 18 errata-xmlrpc 2017-01-04 13:01:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0012.html


Note You need to log in before you can comment on or make changes to this bug.