Bug 1505033 - [RFE] Service pane service/explorer Unexpecting error encountered
Summary: [RFE] Service pane service/explorer Unexpecting error encountered
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Automate
Version: 5.8.0
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: GA
: 5.10.0
Assignee: drew uhlmann
QA Contact: Dave Johnson
URL:
Whiteboard:
Depends On:
Blocks: 1515894 1518372
TreeView+ depends on / blocked
 
Reported: 2017-10-21 09:30 UTC by Franck Grosjean
Modified: 2019-08-06 20:04 UTC (History)
8 users (show)

Fixed In Version: 5.10.0.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1515894 1518372 (view as bug list)
Environment:
Last Closed: 2018-06-21 20:25:10 UTC
Category: ---
Cloudforms Team: CFME Core
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
UI error when sevice name is nil (85.40 KB, image/png)
2017-10-21 09:30 UTC, Franck Grosjean
no flags Details

Description Franck Grosjean 2017-10-21 09:30:00 UTC
Created attachment 1341536 [details]
UI error when sevice name is nil

Description of problem:
As a user I should encounter an error when automation code tries to set a service.name to nil.
A nil service name breaks the web UI and an "undefined method 'downcase' for nil:NilClass [service/explorer]" error in the service explorer pane (/service/explorer)

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

How reproducible:
set service name to nil when provisioning a service (automation code)

Steps to Reproduce:
1. Automation code provision a service with service.name=nil
2. Access to the Web UI /service/explorer

Actual results:
Web UI is broken

Expected results:
Automation engine should raise an error when provisioning a service.name=nil

There is no not nil constraint in the database onto to service name
vmdb_production=# \d services
                                          Table "public.services"
        Column        |            Type             |                       Modifiers                       
----------------------+-----------------------------+-------------------------------------------------------
 id                   | bigint                      | not null default nextval('services_id_seq'::regclass)
 name                 | character varying           | 
 description          | character varying           | 
 guid                 | character varying           | 
 type                 | character varying           | 
 service_template_id  | bigint                      | 
 options              | text                        | 
...
 ancestry             | character varying           | 
 initiator            | character varying           | 
Indexes:
    "services_pkey" PRIMARY KEY, btree (id)
    "index_services_on_ancestry" btree (ancestry)
    "index_services_on_ancestry_vpo" btree (ancestry varchar_pattern_ops)

There is no check about name attribute in miq_ae_service_service.rb

Additional info:

Comment 3 Greg McCullough 2017-10-23 13:02:49 UTC
Franck - Can you provide a little more detail, or script if you are using custom logic, on how you are setting the service name to nil.

I would expect the validation at the app/model level to raise an error if name is nil.

"validates_presence_of :name"
https://github.com/ManageIQ/manageiq/blob/master/app/models/service.rb#L77


Drew - One option might be to change the service model for service to call a save method that will immediately raise an error.

For example:
https://github.com/ManageIQ/manageiq-automation_engine/blob/master/lib/miq_automation_engine/service_models/miq_ae_service_service.rb#L56-L57

Could be changed from:
  @object.name = new_name
  @object.save

to:
  @object.update!(:name => new_name)

which would raise the error "ActiveRecord::RecordInvalid: Validation failed: Name can't be blank" if a nil was used.

Comment 4 Franck Grosjean 2017-10-25 16:05:18 UTC
I don't have relevant automation code anymore nevertheless it was mostly like 

----------------------------------------------------------------
service_template_provision_task = $evm.root['service_template_provision_task']
service = service_template_provision_task.destination
dialog_options = service_template_provision_task.dialog_options
service.name = "#{dialog_options['dialog_service_name']}"
----------------------------------------------------------------

Since I had a typo in the service dialog element name dialog_options['dialog_service_name'] didn't exist and it seems service.name was set to nil. I have to query db services table and update entries where name is null

rails db
vmdb_production=# update services set name='dummy' where name IS NULL;

WebUI service/explorer pane display service with name dummy instead screenshot attached


In automation.log I had the following errors

[----] F, [2017-10-12T16:31:10.481250 #2856:172d084] FATAL -- : Error caught: [NoMethodError] undefined method `downcase' for nil:NilClass
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder_services.rb:44:in `block in x_get_tree_custom_kids'
/opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/delegation.rb:40:in `each'
/opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/delegation.rb:40:in `each'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder_services.rb:44:in `sort_by'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder_services.rb:44:in `x_get_tree_custom_kids'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_kids.rb:35:in `x_get_tree_kids'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:246:in `x_get_tree_objects'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:270:in `x_build_node'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:291:in `x_build_node_tree'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:216:in `block in x_build_tree'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:211:in `map'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:211:in `x_build_tree'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:142:in `build_tree'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/presenters/tree_builder.rb:26:in `initialize'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/application_controller/feature.rb:28:in `new'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/application_controller/feature.rb:28:in `build_tree'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/application_controller.rb:2363:in `block in build_accordions_and_trees'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/application_controller.rb:2363:in `collect'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/application_controller.rb:2363:in `build_accordions_and_trees'
/opt/rh/cfme-gemset/bundler/gems/manageiq-ui-classic-ed1f7171072a/app/controllers/service_controller.rb:53:in `explorer'
/opt/rh/cfme-gemset/gems/actionpack-5.0.3/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/opt/rh/cfme-gemset/gems/actionpack-5.0.3/lib/abstract_controller/base.rb:188:in `process_action'
/opt/rh/cfme-gemset/gems/actionpack-5.0.3/lib/action_controller/metal/rendering.rb:30:in `process_action'
/opt/rh/cfme-gemset/gems/actionpack-5.0.3/lib/abstract_controller/callbacks.rb:20:in `block in process_action'


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