Bug 1305719 - [RFE] Importing of Reporting Widget via rake script broke
[RFE] Importing of Reporting Widget via rake script broke
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Reporting (Show other bugs)
Unspecified Unspecified
medium Severity high
: GA
: 5.6.0
Assigned To: eclarizi
Milan Falešník
: FutureFeature
Depends On:
  Show dependency treegraph
Reported: 2016-02-08 19:33 EST by Brant Evans
Modified: 2016-06-29 11:36 EDT (History)
10 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Feature: Importing of Reporting Widget via rake script Reason: Result:
Story Points: ---
Clone Of:
Last Closed: 2016-06-29 11:36:56 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description Brant Evans 2016-02-08 19:33:35 EST
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:


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-08 19:34 EST
Created attachment 1122315 [details]
Patch for vmdb/app/models/miq_widget/import_export.rb
Comment 3 Greg McCullough 2016-02-11 09:57:17 EST
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 16:38:44 EST
Changing issue to an RFE as this is not functionality we currently provide from a rake task.
Comment 8 CFME Bot 2016-02-22 14:26:23 EST
New commit detected on ManageIQ/manageiq/master:

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

    Use WidgetImportService for MiqWidget.import_from_hash method

 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 14:26:27 EST
New commit detected on ManageIQ/manageiq/master:

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

    Adjust import_from_hash_spec to expect output from WidgetImportService

 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 11:01:03 EDT
Verified in

* 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 11:36:56 EDT
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.


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