Bug 1590300

Summary: Creating DB without the UUID extension messes scripts in the data director and causing an error.
Product: [oVirt] ovirt-engine Reporter: shani <sleviim>
Component: Database.CoreAssignee: Eli Mesika <emesika>
Status: CLOSED CURRENTRELEASE QA Contact: Lucie Leistnerova <lleistne>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.3.0CC: bugs, dfediuck, emesika, lleistne, lsvaty, mperina, rnori
Target Milestone: ovirt-4.2.5Flags: rule-engine: ovirt-4.2+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-07-31 15:27:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description shani 2018-06-12 11:48:29 UTC
Description of problem:
When DB is created without the UUID extension, the upgrade messes some scripts in the data directory.
The DB is engine_dao_tests and it was created as described here: https://github.com/oVirt/ovirt-engine#dao-tests

Version-Release number of selected component (if applicable):
master - commit efea806942d

How reproducible:
100%

Steps to Reproduce:
1. Create DB:
su - postgres -c "create database engine_dao_tests owner engine template template0 encoding 'UTF8' lc_collate 'en_US.UTF-8' lc_ctype 'en_US.UTF-8';"

2. run:
PGPASSWORD=engine \
  ./packaging/dbscripts/schema.sh \
    -c apply -u engine -d engine_dao_tests

Actual results:
Running upgrade sql script './packaging/dbscripts/upgrade/04_00_0070_enable_ballon_for_blank_template.sql'...
psql:./packaging/dbscripts/upgrade/04_00_0070_enable_ballon_for_blank_template.sql:44: ERROR:  insert or update on table "vm_device" violates foreign key constraint "fk_vm_device_vm_static"
DETAIL:  Key (vm_id)=(00000000-0000-0000-0000-000000000000) is not present in table "vm_static".
CONTEXT:  SQL statement "INSERT INTO vm_device (
            device_id,
            vm_id,
            type,
            device,
            address,
            boot_order,
            spec_params,
            is_managed,
            is_plugged,
            is_readonly,
            _create_date,
            _update_date,
            alias
            )
        SELECT uuid_generate_v1(),
            '00000000-0000-0000-0000-000000000000',
            'balloon',
            'memballoon',
            '',
            0,
            '{"model" : "virtio"}',
            true,
            true,
            true,
            'now',
            NULL,
            NULL"
PL/pgSQL function __temp_add_balloon_to_blank_if_not_present() line 11 at SQL statement
FATAL: Cannot execute sql command: --file=./packaging/dbscripts/upgrade/04_00_0070_enable_ballon_for_blank_template.sql

Expected results:
no error

Additional info:
---

Comment 1 Doron Fediuck 2018-06-13 06:18:56 UTC
Is there a way to prevent this at install time by making sure the UUID extension is installed?

Comment 2 Eli Mesika 2018-06-17 09:38:15 UTC
(In reply to Doron Fediuck from comment #1)
> Is there a way to prevent this at install time by making sure the UUID
> extension is installed?

Yes, please refer to the fixing patch

Comment 3 Lucie Leistnerova 2018-07-23 09:58:28 UTC
Running schema.sh on database without UUID extension fails with proper error.

uuid-ossp extension is missing
Please install uuid-ossp extension in the database by running:
'CREATE EXTENSION "uuid-ossp";'

Otherwise it runs successfully.

verified in ovirt-engine-4.2.5.1-0.1.el7ev.noarch, ovirt-engine-dbscripts-4.2.5.1-0.1.el7ev.noarch

Comment 4 Sandro Bonazzola 2018-07-31 15:27:23 UTC
This bugzilla is included in oVirt 4.2.5 release, published on July 30th 2018.

Since the problem described in this bug report should be
resolved in oVirt 4.2.5 release, it has been closed with a resolution of CURRENT RELEASE.

If the solution does not work for you, please open a new bug report.