Importing buttons in capablanca / cfme 5.5


#1

Hi there all

I’m needing some help figuring out what to do about importing custom button configuration between my development and production engines.

Before Capablanca, we used the awesome cfme-rhtconsulting-scripts from the github repository of the same name, which worked like a charm. However, under CFME 5.5+ button imports are failing for me thus:

root@poc-cfme1 vmdb]# bin/rake rhconsulting:buttons:import[/root/git/dev/cfme-dev/buttons/buttons.yml]
[DEPRECATION] `configure` is removed in secure_headers 3.x. Instead use `default`.
Button Group: [Actions]
rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `resource_actions`
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:138:in `with_value_from_database'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_set.rb:39:in `write_from_user'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods.rb:373:in `[]='
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:118:in `block in import_custom_buttons'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:88:in `each'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:88:in `import_custom_buttons'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:146:in `block in import_custom_button_sets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:135:in `each'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:135:in `import_custom_button_sets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:7:in `block in import'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:220:in `transaction'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:6:in `import'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:231:in `block (3 levels) in <top (required)>'
Tasks: TOP => rhconsulting:buttons:import
(See full trace by running task with --trace)

It seems to my untrained eye that the problem is with a previously accessible attribute not being accessible any more.

ActiveModel::MissingAttributeError: can’t write unknown attribute resource_actions
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:138

Ok. So is this something I can workaround by tweaking the rake task, somehow? I would think not, as if resource_actions isn’t write accessible anymore, that must be defined in the model and would need a code change (which I don’t want to do on my production engines … so … )

So - is this a bug in CloudForms/ManageIQ and I should report it? Or is this a problem with the rake task I’m using, and how can I work around it?


#2

@gmccullough can you review this question raised by @Stephen_McKay or forward to a SME if necessary.


#3

@eclarizio Please review this issue. Thanks


#4

@Stephen_McKay, I think I found the issue and I believe it is with the rake task, and I believe it should be a very easy fix. CustomButton has had only one resource_action since 2013, but the rake task assumes that it has many. Here’s the snippet:
116 custom_button['visibility'] = cb['visibility'] 117 custom_button['applies_to_id'] = cb['applies_to_id'] 118 custom_button['resource_actions'] = cb['resource_actions']

Now, the exporting code seems to do it correctly, pulling from custom-button.resource_action instead of the plural resource_actions:
172 button['resource_actions'] = export_resource_actions(custom_button.resource_action)

So, I believe all that needs to change is within line 118 from custom_button['resource_actions'] to custom_button['resource_action']. It’s up to you if you want to change the exported hash key to not include the plural, since it isn’t really multiple resource_actions, but you don’t have to.

Let me know if that works!


#5

Awesome. Not quite that simple, but just I went at it heavy handed and just replaced all instances of the string “resource_actions” with “resource_action” in both the rake script and the button.yaml file… worked like a charm. :slight_smile:


#6

Actually – it didn’t work … I don’t know why it seemed to the first time, but now I’m getting the same error every time I run the modified rake script, except the error says the missing attribute is “resource_action” singular. I’ve tried both my heavy handed replace-them-all and the fix recommended by @eclarizio which is just to change the one line (118).

bin/rake rhconsulting:buttons:import[/root/miq-VMware/Buttons/buttons.yml]
[DEPRECATION] `configure` is removed in secure_headers 3.x. Instead use `default`.
Button Group: [VMware Tasks]
rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `resource_action`
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:138:in `with_value_from_database'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_set.rb:39:in `write_from_user'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods.rb:373:in `[]='
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:118:in `block in import_custom_buttons'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:88:in `each'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:88:in `import_custom_buttons'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:146:in `block in import_custom_button_sets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:135:in `each'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:135:in `import_custom_button_sets'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:7:in `block in import'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:220:in `transaction'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:6:in `import'
/var/www/miq/vmdb/lib/tasks/rhconsulting_buttons.rake:231:in `block (3 levels) in <top (required)>'
Tasks: TOP => rhconsulting:buttons:import
(See full trace by running task with --trace)

So in case anyone is thinking this is fixed, just letting you know. I’m still trying to work this out.

Question for any devs …? Why is resource_action not writable? Did it disappear from a model, or get hidden for some reason?


#7

Hey @Stephen_McKay, resource_action should be on a custom button, I don’t believe that has changed for a long time

Though I just realized it’s a relationship, not an attribute, so custom_button['resource_action']= won’t work, but custom_button.resource_action= should.

I tried it in the console and ended up with the same error using ['resource_action']= but with .resource_action= I was able to assign the resource action, so maybe give that a shot? All I think would need to change again is line 118 to custom_button.resource_action = cb['resource_actions']. Sorry for the previous non-fix :stuck_out_tongue:


#8

Awesome … that fixed it perfectly!