Bug 854492

Summary: Failed to activate ISO domain that is already attached to 2 DC
Product: Red Hat Enterprise Virtualization Manager Reporter: Eli Mesika <emesika>
Component: ovirt-engineAssignee: Eli Mesika <emesika>
Status: CLOSED CURRENTRELEASE QA Contact: Leonid Natapov <lnatapov>
Severity: high Docs Contact:
Priority: high    
Version: 3.1.0CC: abaron, amureini, dron, dyasny, hateya, iheim, lpeer, Rhev-m-bugs, yeylon, ykaul
Target Milestone: ---   
Target Release: 3.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: storage
Fixed In Version: SI18 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Storage RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eli Mesika 2012-09-05 07:33:31 UTC
Description of problem:
This Bug was reported by Dan Yasny on a 3.1 clean install
After the installation, the ISO Storage Domain was already addatched to the Default DC.
Adding a new DC and attaching the ISO domain to it as well 
Then, trying to activate the ISO domain on the new DC generates a SQL ERROR:

"more than one row returned by a subquery used as an expression"

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

How reproducible:
always

Steps to Reproduce:
1.Clean install
2.Add a new DC 
3.Attach ISO domain to the new DC
4.Activate the ISO domain in new DC
  
Actual results:
SQL Exception
"more than one row returned by a subquery used as an expression"

Expected results:
Activate should succeed

Additional info:

This is a general error that might hav afffect on other flows as well.

During the activate a call to get_entity_permissions SQL function is issued
This in turn calls : fn_get_entity_parents
For the relevant scenario the following code is executed :

 WHEN v_entity_type = 11 THEN -- Storage Domain

                RETURN QUERY
                        SELECT system_root_id AS id
                        UNION
                        SELECT storage_pool_id as id FROM storage_pool_iso_map WHERE storage_id = v_entity_id
                        UNION
                        SELECT v_entity_id AS id;

Postgres assumes that 
SELECT storage_pool_id as id FROM storage_pool_iso_map 
is returning a literal
In order to fix that we must change in fn_get_entity_parents for all v_entity_type to use UNION ALL instead of UNION
i.e in this case the following code will work:


 WHEN v_entity_type = 11 THEN -- Storage Domain

                RETURN QUERY
                        SELECT system_root_id AS id
                        UNION ALL
                        SELECT storage_pool_id as id FROM storage_pool_iso_map WHERE storage_id = v_entity_id
                        UNION ALL
                        SELECT v_entity_id AS id;

Comment 1 Eli Mesika 2012-09-06 08:34:06 UTC
http://gerrit.ovirt.org/#/c/7804/1

Comment 3 Leonid Natapov 2012-09-20 11:04:00 UTC
si18. can attach ISO domain to several DC. (more than 2).