Bug 1305719 - [RFE] Importing of Reporting Widget via rake script broke
Summary: [RFE] Importing of Reporting Widget via rake script broke
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Reporting
Version: 5.4.0
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: GA
: 5.6.0
Assignee: eclarizi
QA Contact: Milan Falešník
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-09 00:33 UTC by Brant Evans
Modified: 2019-11-14 07:25 UTC (History)
10 users (show)

Fixed In Version: 5.6.0.0
Doc Type: Enhancement
Doc Text:
Feature: Importing of Reporting Widget via rake script Reason: Result:
Clone Of:
Environment:
Last Closed: 2016-06-29 15:36:56 UTC
Category: ---
Cloudforms Team: ---
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
rake script for importing/exporting widgets (1.70 KB, text/plain)
2016-02-09 00:33 UTC, Brant Evans
no flags Details
Patch for vmdb/app/models/miq_widget/import_export.rb (816 bytes, patch)
2016-02-09 00:34 UTC, Brant Evans
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2016:1348 0 normal SHIPPED_LIVE CFME 5.6.0 bug fixes and enhancement update 2016-06-29 18:50:04 UTC

Description Brant Evans 2016-02-09 00:33:35 UTC
Created attachment 1122314 [details]
rake script for importing/exporting widgets

Description of problem:

Rake script that uses MiqWidget.import_from_hash fails due to the MiqSchedule object of the exported YAML file.

The traceback of the rake execution is:

[root@cmfe-test vmdb]# bin/rake --trace rhconsulting:miq_widgets:import[/tmp/brant/widgets]
** Invoke rhconsulting:miq_widgets:import (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute rhconsulting:miq_widgets:import
rake aborted!
ActiveRecord::UnknownAttributeError: unknown attribute: MiqSchedule
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes'
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/attribute_assignment.rb:78:in `each'
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/base.rb:498:in `initialize'
/opt/rh/cfme-gemset/gems/default_value_for-2.0.3/lib/default_value_for.rb:138:in `initialize'
/var/www/miq/vmdb/app/models/miq_widget/import_export.rb:24:in `new'
/var/www/miq/vmdb/app/models/miq_widget/import_export.rb:24:in `import_from_hash'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:34:in `block (3 levels) in import_widgets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:33:in `each'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:33:in `block (2 levels) in import_widgets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:31:in `glob'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:31:in `block in import_widgets'
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/opt/rh/cfme-gemset/bundler/gems/rails-4842a8377644/activerecord/lib/active_record/transactions.rb:208:in `transaction'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:30:in `import_widgets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:17:in `import'
/var/www/miq/vmdb/lib/tasks/rhconsulting_widgets.rake:58:in `block (3 levels) in <top (required)>'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rh/ruby200/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/opt/rh/cfme-gemset/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/opt/rh/cfme-gemset/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
bin/rake:16:in `load'
bin/rake:16:in `<main>'
Tasks: TOP => rhconsulting:miq_widgets:import




Version-Release number of selected component (if applicable):

CFME 5.4.3


How reproducible:

Always


Steps to Reproduce:
1. Create a custom reporting widget
2. Install rhconsulting_widget.rake script in /var/www/miq/vmdb/lib/tasks (attached)
3. Export widget using Web UI or rhconsulting_widget.rake
4. From /var/www/miq/vmdb execute 'bin/rake rhconsulting:miq_widgets:import[/path/to/directory/of/export/file]
4. Error importing widget will be generated


Actual results:

Rake Error


Expected results:

Report Widget is successfully imported.


Additional info:

I have compared vmdb/app/models/miq_widget/import_export.rb which is called when calling MiqWidget.import_from_hash from a rake script and vmdb/app/services/widget_import_service.rb which is used when importing via the Web UI.

When importing via the Web UI the MiqSchedule object is handled and deleted from the MiqWidget before the widget is created or found in the vmdb.

I have modified vmdb/app/models/miq_widget/import_export.rb to handle the MiqSchedule object and attach it to the widget when importing. The changes I made are based on the code that is used in widget_import_service.rb. The patch diff for import_export.rb is attached.

Comment 2 Brant Evans 2016-02-09 00:34:41 UTC
Created attachment 1122315 [details]
Patch for vmdb/app/models/miq_widget/import_export.rb

Comment 3 Greg McCullough 2016-02-11 14:57:17 UTC
Erik - Can you take a look, I am hoping there is an easy way to make this logic common instead of duplicating it.

Comment 6 Greg McCullough 2016-02-16 21:38:44 UTC
Changing issue to an RFE as this is not functionality we currently provide from a rake task.

Comment 8 CFME Bot 2016-02-22 19:26:23 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/1840a69dcf5881147b51a0e292058152c7de7c22

commit 1840a69dcf5881147b51a0e292058152c7de7c22
Author:     Erik Clarizio <eclarizi>
AuthorDate: Tue Feb 16 06:52:17 2016 -0800
Commit:     Erik Clarizio <eclarizi>
CommitDate: Tue Feb 16 06:52:17 2016 -0800

    Use WidgetImportService for MiqWidget.import_from_hash method
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1305719

 app/models/miq_widget/import_export.rb       | 45 +------------------
 app/services/widget_import_service.rb        | 28 +++++++-----
 spec/models/miq_widget/import_export_spec.rb | 66 +++++++++++++++++++---------
 spec/services/widget_import_service_spec.rb  | 15 +++++++
 4 files changed, 78 insertions(+), 76 deletions(-)

Comment 9 CFME Bot 2016-02-22 19:26:27 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/5bc8db9e208ebf708694658cc64fa57d04441a77

commit 5bc8db9e208ebf708694658cc64fa57d04441a77
Author:     Erik Clarizio <eclarizi>
AuthorDate: Mon Feb 22 08:27:00 2016 -0800
Commit:     Erik Clarizio <eclarizi>
CommitDate: Mon Feb 22 08:43:11 2016 -0800

    Adjust import_from_hash_spec to expect output from WidgetImportService
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1305719

 spec/models/miq_widget/import_from_hash_spec.rb | 183 +++---------------------
 1 file changed, 19 insertions(+), 164 deletions(-)

Comment 15 Milan Falešník 2016-06-17 15:01:03 UTC
Verified in 5.6.0.11-rc2.2

I:
* installed the rake script
* created a report widget
* exported the widget
* deleted the widget
* uploaded the .yaml file to the appliance's /root/ (the extension MUST be yaml)
* ran bin/rake rhconsulting:miq_widgets:import[/root/]  # It only works with folders, not files)
* the widget was imported

Comment 17 errata-xmlrpc 2016-06-29 15:36:56 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://access.redhat.com/errata/RHBA-2016:1348


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