Bug 1176820

Summary: Failed to set user defined scheduling policy via REST
Product: Red Hat Enterprise Virtualization Manager Reporter: Artyom <alukiano>
Component: ovirt-engineAssignee: Roman Mohr <rmohr>
Status: CLOSED ERRATA QA Contact: Artyom <alukiano>
Severity: high Docs Contact:
Priority: urgent    
Version: 3.5.0CC: bazulay, dfediuck, gklein, iheim, istein, lsurette, mgoldboi, mtessun, rbalakri, rgolan, Rhev-m-bugs, yeylon, ykaul, ylavi
Target Milestone: ovirt-3.6.1Keywords: Triaged
Target Release: 3.6.1Flags: mgoldboi: Triaged+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Prior to Red Hat Enterprise Virtualization 3.5, the <policy>name</policy> tag was used to define the name of the scheduling policy to select. In 3.5, the <name>name</name> tag was introduced. By accident the policy tag was removed, which should be there for backward compatibility. As a result, user REST scripts for setting scheduling policies sometimes did not work. With this release, support for the <policy/> tag has been re-added. The <policy/> tag can now be used again, but <name/> is preferred if it is also present.
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-09 20:53:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: SLA RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Artyom 2014-12-23 11:45:03 UTC
Description of problem:
I created new scheduling policy and wanted to attach it to cluster via REST, but operation failed with next error:
<fault>
<reason>Invalid value</reason>
<detail>
cpu_filter is not a member of SchedulingPolicyType. Possible values for SchedulingPolicyType are: evenly_distributed, power_saving, none, vm_evenly_distributed
</detail>
</fault>

Version-Release number of selected component (if applicable):
rhevm-3.5.0-0.26.el6ev.noarch

How reproducible:
Always

Steps to Reproduce:
1. Create some custom scheduling policy
via REST looks like:
<scheduling_policy href= "/ovirt-engine/api/schedulingpolicies/18abab9b-a780-45c8-9727-3a925fda1703" id="18abab9b-a780-45c8-9727-3a925fda1703">
<name>cpu_filter</name>
<link href= "/ovirt-engine/api/schedulingpolicies/18abab9b-a780-45c8-9727-3a925fda1703/filters" rel="filters"/>
<link href= "/ovirt-engine/api/schedulingpolicies/18abab9b-a780-45c8-9727-3a925fda1703/weights" rel="weights"/>
<link href= "/ovirt-engine/api/schedulingpolicies/18abab9b-a780-45c8-9727-3a925fda1703/balances" rel="balances"/>
<link href= "/ovirt-engine/api/schedulingpolicies/18abab9b-a780-45c8-9727-3a925fda1703/clusters" rel="clusters"/>
<locked>false</locked>
<default_policy>false</default_policy>
</scheduling_policy>
2. Try to attach scheduling to policy via REST:
PUT to specific cluster
<cluster>
    <scheduling_policy>
        <policy>cpu_filter</policy>
    </scheduling_policy>
</cluster>
3.

Actual results:
<fault>
<reason>Invalid value</reason>
<detail>
cpu_filter is not a member of SchedulingPolicyType. Possible values for SchedulingPolicyType are: evenly_distributed, power_saving, none, vm_evenly_distributed
</detail>
</fault>

Expected results:
scheduling policy attached to cluster without any error messages

Additional info:
Via UI all works fine

Comment 1 Juan Hernández 2015-01-07 09:52:08 UTC
In the past scheduling policies used to be built-in entities, but recently they have been promoted to regular entities that the user can add/modify/delete. This means that the "policy" attribute can now be anything. But we didn't take this into account when we validate the value.

However, take into account that the recommended way to reference a scheduling policy is using the "id" or "name" attributes, so you could add the scheduling policy to the cluster with requests like this (using the id):

  PUT /clusters/{cluster:id}
  <cluster>
    <scheduling_policy id="{schedulingpolicy:id}"/>
  </cluster>

Or this (using the name):

  PUT /clusters/{cluster:id}
  <cluster>
    <scheduling_policy>
      <name>{schedulingpolicy:name}</name>
    </scheduling_policy>
  </cluster>

Using the "policy" attribute should work at least for the old built-in scheduling policies. It is good if it works for the new ones as well, but not a must in my opinion.

Anyhow, users (including the Python SDK) tend to update entities taking a complete entity and sending it again with all the attributes, not just the modified ones, so this problem will appear in many use cases.

I think that we should at least remove the validation of the policy type that we have in SchedulingPolicyValidator, and it would be good to also make sure that the "policy" attribute is accepted like "id" and "name" are.

Comment 2 Artyom 2015-01-08 16:23:19 UTC
Thanks to Juan

Comment 4 Roman Mohr 2015-10-21 12:42:20 UTC
Just checked the code and tried to reproduce the error. The property <policy/> does not exist anymore in 3.6. Only <name/> and <id/> can be used. 

The comment of Juan perfectly describes the situation in 3.5. <policy/> property can be used to add internal policies to the cluster, for custom policies <name/> or <id/> must be used.

Comment 6 Artyom 2015-11-29 09:36:13 UTC
Verified on rhevm-restapi-3.6.0.3-0.1.el6.noarch
<cluster>
    <scheduling_policy>
        <name>test_policy</name>
    </scheduling_policy>
</cluster>
Works fine.

Comment 9 errata-xmlrpc 2016-03-09 20:53:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

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

https://rhn.redhat.com/errata/RHEA-2016-0376.html