Bug 1378477

Summary: ActiveRecord::RecordInvalid]: Validation failed: Name has already been taken in when trying to refresh Openshift provider
Product: Red Hat CloudForms Management Engine Reporter: Jared Deubel <jdeubel>
Component: ProvidersAssignee: Mooli Tayer <mtayer>
Status: CLOSED DUPLICATE QA Contact: Gilad Shefer <gshefer>
Severity: high Docs Contact:
Priority: high    
Version: 5.6.0CC: cben, cpelland, dron, fsimonce, jdeubel, jfrey, jhardy, jocarter, mbarrett, mtayer, myoder, obarenbo, saali, tachoi
Target Milestone: GA   
Target Release: 5.7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: container
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-15 16:59:38 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: Container Management Target Upstream Version:
Embargoed:

Description Jared Deubel 2016-09-22 13:41:30 UTC
Description of problem:
Getting ActiveRecord::RecordInvalid]: Validation failed: Name has already been taken  in when trying to refresh Openshift provider. 


Snippet from evm.log
=================================
[----] E, [2016-09-21T02:01:33.643782 #28861:557990] ERROR -- : MIQ(ManageIQ::Providers::OpenshiftEnterprise::ContainerManager::Refresher#refresh) EMS: [CTC Core], id: [10000000000001] Refresh failed
[----] E, [2016-09-21T02:01:33.643940 #28861:557990] ERROR -- : [ActiveRecord::RecordInvalid]: Validation failed: Name has already been taken  Method:[rescue in block in refresh]
[----] E, [2016-09-21T02:01:33.644013 #28861:557990] ERROR -- : /opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/validations.rb:78:in `raise_validation_error'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/validations.rb:50:in `save!'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/transactions.rb:324:in `block in save!'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/transactions.rb:211:in `transaction'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/transactions.rb:324:in `save!'
/opt/rh/cfme-gemset/bundler/gems/rails-3d9d4f56c1ee/activerecord/lib/active_record/suppressor.rb:45:in `save!'
/var/www/miq/vmdb/app/models/container_label_tag_mapping.rb:88:in `create_tag'
====================================

After looking through the OpenShift Refresh Parser, we see many things that have these tags associated with them. Every inventory item has labels
(and labels will translate into tags). We speculate that you have multiple things that end up as Labels that have a nil value and so they get a name like :empty:, or they actually have things that end up as labels with the same names. We will have more information on this in a little bit. 


Version-Release number of selected component (if applicable):
5.6.0.13, build=20160624114606_13a9153

Comment 3 tachoi 2016-09-23 04:58:43 UTC
Collaborator note
#######################
Imported customer db and checked table

db query:
vmdb_production=# select provider_id,parent_ems_id,tenant_id,name,realm,last_refresh_error from ext_management_systems ;
 provider_id | parent_ems_id |   tenant_id    |   name   | realm |               last_refresh_error               
-------------+---------------+----------------+----------+-------+------------------------------------------------
             |               | 10000000000001 | CTC DMZ  |       | 
             |               | 10000000000001 | CTC_Core |       | Validation failed: Name has already been taken


evm err msg: 
MIQ(ManageIQ::Providers::OpenshiftEnterprise::ContainerManager::Refresher#refresh) EMS: [CTC Core], id: [10000000000001] Refresh failed

Seems like tenant_id is conflict or missing provider_id.
My understanding, tenant_id could be same as long as under different provider_id.

Need update from engineering.

Comment 4 Mooli Tayer 2016-09-23 05:21:34 UTC
Problem in container_label_tag_mapping breaking refresh.
Seems to be a different error from bug 1358257

I need dumps of container_label_tag_mappings and tags

Possible work around(did not test this): 
0. validate refresh broken
1. dump container_label_tag_mappings table
2. note: auto tagging would not work
3. test if refresh still breaks

Comment 7 Mooli Tayer 2016-09-23 15:53:28 UTC
Note: besides handling this specific flow we might want to suppress and log exceptions (ERROR)  during refresh. That would allow it to complete regardless of
label to tag mapping

Federico what is your opinion on this?

Comment 8 Federico Simoncelli 2016-09-23 15:59:35 UTC
(In reply to Mooli Tayer from comment #7)
> Note: besides handling this specific flow we might want to suppress and log
> exceptions (ERROR)  during refresh. That would allow it to complete
> regardless of
> label to tag mapping
> 
> Federico what is your opinion on this?

OK to continue refresh but do not suppress the errors too much (e.g. stacktrace etc.) because we want to be able to debug the issues.

Errors must be extremely evident.

Comment 15 Jared Deubel 2016-09-27 21:57:35 UTC
Created attachment 1205334 [details]
evm.log

This log has the debug patch in it.

Comment 16 Jared Deubel 2016-09-27 22:00:06 UTC
Created attachment 1205335 [details]
production.log

The production.log has rails debug logging on if that is needed.

Comment 24 Beni Paskin-Cherniavsky 2016-10-09 08:48:51 UTC
Short update: in support call last week we "fixed" refresh for the customer by deleting a few mapping lines — but the bugs are still there.

I believe this was caused by bug 1382347.
bug 1382361 could affect this customer too.
We're working on fixing all that + adding UI for auto-tagging (work in progress https://github.com/ManageIQ/manageiq/pull/11591).

Let's keep development updates to those BZs / github PRs;
this BZ will remain focused on the specific customer's refresh issue, in case it re-surfaces.

Comment 28 Saif Ali 2016-10-20 16:03:12 UTC
[----] E, [2016-10-20T08:21:53.931633 #24787:cc5998] ERROR -- :
MIQ(ManageIQ::Providers::OpenshiftEnterprise::ContainerM
anager::Refresher#refresh) EMS: [Pathfinder], id: [1000000000001] Refresh
failed
[----] E, [2016-10-20T08:21:53.931948 #24787:cc5998] ERROR -- :
[ActiveRecord::RecordInvalid]: Validation failed: Name h
as already been taken  Method:[rescue in block in refresh]
[----] E, [2016-10-20T08:21:53.932055 #24787:cc5998] ERROR -- :
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active
_record/validations.rb:78:in `raise_validation_error'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/validations.rb:50:in
`save!'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods/dirty.rb:30:in
`save!'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:324:in
`block in save!'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:395:in
`block in with_transaction_return
ing_status'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:
in `block in transaction'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in
`with
in_new_transaction'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:
in `transaction'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in
`transaction'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:392:in
`with_transaction_returning_statu
s'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:324:in
`save!'
/opt/rh/cfme-gemset/gems/activerecord-5.0.0.1/lib/active_record/suppressor.rb:45:in
`save!'

Comment 29 Federico Simoncelli 2016-10-20 19:40:30 UTC
Saif can you elaborate on the assistance you need?

Comment 30 Saif Ali 2016-10-20 19:47:01 UTC
Federico _ that most recent error the customer provided.

Comment 31 Saif Ali 2016-10-25 19:32:48 UTC
the customer attached the database dump to the case but its too large to added the bugzilla.

Comment 35 Beni Paskin-Cherniavsky 2016-11-03 23:33:00 UTC
Short update on underlying work:

Refresh & auto-tagging breakages - bug 1382347, bug 1382361 - PR merged (master, 5.7 and 5.6), on QE.
We implemented UI for auto-tagging - bug 1383405 - PR merged (master, 5.7).
Also, enabled auto-tagging tags in reports - bug 1388659 - PR merged (master, 5.7, 5.6).

Of course QE testing of all that may uncover additional problems.

There is also ongoing work to support direct use of labels in reports (without mapping them to tags) - bug 1382720.

Comment 36 Beni Paskin-Cherniavsky 2016-11-03 23:49:07 UTC
*** Bug 1373712 has been marked as a duplicate of this bug. ***

Comment 37 Beni Paskin-Cherniavsky 2016-11-15 15:29:22 UTC
removing "Blocks:" 4 unrelated bugs, I don't know why bugzilla decided I added them.