Bug 1298330

Summary: Template name with a space causes problems
Product: Red Hat Enterprise Virtualization Manager Reporter: Jesus M. Rodriguez <jesusr>
Component: ovirt-engineAssignee: Shahar Havivi <shavivi>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3.5.6CC: jesusr, lsurette, masayag, michal.skrivanek, rbalakri, Rhev-m-bugs, tjelinek, yeylon, ykaul
Target Milestone: ovirt-3.6.5   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-02-23 12:01:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Virt RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
ovirt-engine export domain template screen
none
ovirt engine template display
none
screenshot showing RHEV engine version
none
ovirt engine logs none

Description Jesus M. Rodriguez 2016-01-13 19:21:48 UTC
Description of problem:
Using the python-sdk I am able to import a template with a space in the name. But I am unable to use the python-sdk to get the template and check its status. None is returned.

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

How reproducible:
Using the python-sdk we import a template giving it a name with a space in it.
  api = API(url=url, username=api_user, password=api_pass, insecure=True)
  data_center = api.datacenters.get(data_center_name)
  export_domain = data_center.storagedomains.get(export_domain_name)
  # Import appliance as a VM template
  export_domain = api.storagedomains.get(export_domain_name)
  storage_domain = api.storagedomains.get(storage_domain_name)
  cluster = api.clusters.get(name=cluster_name)
  import_template_params = params.Action(storage_domain=storage_domain, cluster=cluster)
  import_template(export_domain, vm_template_name, import_template_params)
  while api.templates.get(vm_template_name).status.state != 'ok':
    time.sleep(1)

api.templates.get(vm_template_name) returns None for our template if the name has a space in it. If the name does NOT have a space, the above works as expected.

The import_template method is defined as such:

def import_template(export_domain, vm_template_name, import_template_params, attempts=20):
    try:
        vm_templ = export_domain.templates.get(vm_template_name)
        vm_templ.import_template(import_template_params)
    except RequestError, e:
        if "Missing OVF file from VM" in e.detail and attempts > 0:
            print "Waiting to retry importing template...sleeping 30 seconds"
            time.sleep(30)
            return import_template(export_domain, vm_template_name, import_template_params, attempts=attempts-1)
        print e
        return False
    except Exception, e:
        print e
        return False
    return True

This returns True and I can see it in the RHEV Engine UI.


Actual results:
Template with a name is created in RHEV Engine but api.templates.get(vm_template_name) returns None.

Expected results:
I expect either to get back the Template that I can call status on OR a validation error that the template name is invalid.

Comment 1 Jesus M. Rodriguez 2016-01-13 19:27:14 UTC
Created attachment 1114491 [details]
ovirt-engine export domain template screen

This screenshot shows the template was successfully imported.

Comment 2 Jesus M. Rodriguez 2016-01-13 19:27:56 UTC
Created attachment 1114492 [details]
ovirt engine template display

This screenshot shows the template in the list of templates.

Comment 5 Jesus M. Rodriguez 2016-01-13 19:32:18 UTC
Created attachment 1114495 [details]
screenshot showing RHEV engine version

Comment 6 Jesus M. Rodriguez 2016-01-13 19:35:17 UTC
Created attachment 1114496 [details]
ovirt engine logs

engine.log shows the following when using a name with a space:

2016-01-13 19:32:50,296 INFO  [org.ovirt.engine.core.bll.SearchQuery] (ajp-/127.0.0.1:8702-8) ResourceManager::searchBusinessObjects - erroneous search text - Template : name=test space deployment-cfme-template
2016-01-13 19:32:50,324 INFO  [org.ovirt.engine.core.bll.SearchQuery] (ajp-/127.0.0.1:8702-6) ResourceManager::searchBusinessObjects - erroneous search text - Template : name=test space deployment-cfme-template
2016-01-13 19:32:50,353 INFO  [org.ovirt.engine.core.bll.SearchQuery] (ajp-/127.0.0.1:8702-7) ResourceManager::searchBusinessObjects - erroneous search text - Template : name=test space deployment-cfme-template

Comment 7 Jesus M. Rodriguez 2016-01-13 19:39:28 UTC
Also searching with the search bar in the UI causes the following invalid SQL to cause an exception:

  Position: 707: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT * FROM (SELECT * FROM vm_templates_view WHERE ( vmt_guid IN (SELECT distinct vm_templates_storage_domain.vmt_guid FROM  vm_templates_storage_domain   WHERE  vm_templates_view.storage_pool_name ILIKE 'Default'  AND  (  vm_templates_storage_domain.name ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.description ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.quota_name ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.storage_pool_name ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.vds_group_name ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.free_text_comment ILIKE '%deployment-cfme-template%' OR  vm_templates_storage_domain.template_version_name, template_version_number ILIKE '%deployment-cfme-template%' ) ))  ORDER BY name ASC ) as T1 OFFSET (1 -1) LIMIT 100]; nested exception is org.postgresql.util.PSQLException: ERROR: argument of OR must be type boolean, not type character varying
  Position: 707


The offending piece is:

  OR  vm_templates_storage_domain.template_version_name,

Seems it should have a value to result in a boolean, ILIKE or == etc. I'm not sure if this is related to the fact that I'm searching for a template with a space in it or not.

Comment 8 Jesus M. Rodriguez 2016-01-13 19:42:32 UTC
Script as a github gist for posterity: https://gist.github.com/jmrodri/546b26f7fd9fb302355f

Comment 9 Shahar Havivi 2016-01-18 07:35:57 UTC
How did you exported the template with space in the name for the first place?
This should be prevented...

Comment 10 Tomas Jelinek 2016-02-17 11:38:22 UTC
@Jesus: ping

Comment 11 Tomas Jelinek 2016-02-23 12:01:40 UTC
Templates with space in name are not supported in oVirt. It is validated both when creating from frontend and REST.

We could introduce support for this but it would not be simple to handle all cases where it could fail for not too big gain.

So, closing as not a bug considering the template has been created externally with a name not compatible with the ovirt's standards.

Please feel free to reopen if the above is not true.