Bug 1931932 - Adding VM to an existing affinity group always returns an error although the action was successful
Summary: Adding VM to an existing affinity group always returns an error although the ...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine
Classification: oVirt
Component: BLL.Virt
Version: 4.4.5.6
Hardware: Unspecified
OS: Unspecified
unspecified
urgent
Target Milestone: ovirt-4.4.5
: ---
Assignee: Liran Rotenberg
QA Contact: Polina
URL:
Whiteboard:
Depends On:
Blocks: 1932320
TreeView+ depends on / blocked
 
Reported: 2021-02-23 15:38 UTC by Gal Zaidman
Modified: 2021-03-18 15:13 UTC (History)
5 users (show)

Fixed In Version: ovirt-engine-4.4.5.8
Doc Type: Bug Fix
Doc Text:
Previously, when adding a VM to the affinity group using the API we got an action response. Now, it will return a response containing the VM element, making the SDKs and API documentation get the expected response.
Clone Of:
Environment:
Last Closed: 2021-03-18 15:13:22 UTC
oVirt Team: Virt
Embargoed:
pm-rhel: ovirt-4.4+
ahadas: blocker-
pm-rhel: exception+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 113732 0 master MERGED api: fix add vm to affinity group 2021-03-02 10:56:09 UTC

Description Gal Zaidman 2021-02-23 15:38:54 UTC
Description of problem:

I tried to add a new VM to an existing affinity group with:

```
SystemService().
    ClustersService().
    ClusterService(cID).
    AffinityGroupsService().
    GroupService(ag.MustId()).
    VmsService().
    Add().
    Vm(vm).Send()
```

and that call always returned an error in my go code:
"Tag not matched: expect <vm> but got <action>"

When I looked at the VM on the engine I saw that the VM was added to the affinity group successfully.

I tried to run a POST request to the engine to add the VM to the affinity group, and got a 200 status with body:
```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action>
    <status>complete</status>
</action>
```

When I looked in the go-ovirt code on services.go line 2429 I saw:
```
result, err := XMLVmReadOne(reader, nil, "")
```

And when you look at the "XMLVmReadOne" you see:
```
if expectedTag == "" {
    expectedTag = "vm"
}
if start.Name.Local != expectedTag {
    return nil, XMLTagNotMatchError{start.Name.Local, expectedTag}
}
```

Meaning because on the "AffinityGroupVmsServiceAddRequest" we sent an expectedTag on "" then it tried to find a "vm" tag and returned an error.

As I see it there are 2 solutions:
1. call "XMLVmAffinityReadOne" function instead of "XMLVmReadOne" - XMLVmAffinityReadOne doesn'y have an expected tag logic
2. change the expectedTag to be "action" and not "" meaning:
```
result, err := XMLVmReadOne(reader, nil, "action")
```

Since the go-ovirt sdk is generated I think that this problem is much bigger then the go-ovirt sdk, and probably starts at the original SDK of ovirt

Comment 1 Sandro Bonazzola 2021-02-24 08:53:42 UTC
According to Ori:

> I've found the problem, it is here: 
> https://github.com/oVirt/ovirt-engine/blob/68721ead04cef0378937cd331fae3170b4c275ba/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAffinityGroupVmsResource.java#L39
> editAffinityGroup() indeed returns an Action, incongruent with the declaration in the AffinityGroupVmsService.java. 
> So the bug should actually be on ovirt-engine

Comment 2 Arik 2021-02-24 12:05:19 UTC
Ori, wouldn't it be considered breaking backward compatibility if we change it now?

Comment 3 Gal Zaidman 2021-02-24 13:29:17 UTC
Can't we just change the SDKs/API to return action instead?
https://github.com/oVirt/ovirt-engine-api-model/blob/master/src/main/java/services/AffinityGroupVmsService.java#L68

Comment 4 Arik 2021-02-24 14:19:05 UTC
(In reply to Gal Zaidman from comment #3)
> Can't we just change the SDKs/API to return action instead?
> https://github.com/oVirt/ovirt-engine-api-model/blob/master/src/main/java/
> services/AffinityGroupVmsService.java#L68

I think that's the only thing we can actually do - since we guarantee not to break existing clients so if we used to return an action, we should keep doing that but I'd like to check this with Ori

Comment 5 Ori Liel 2021-03-01 08:36:29 UTC
I think it's not considered breaking backwards-compatibility, because we are fixing a bug. I mean, it never worked as documented and intended. 

Also, this is happening at the 3rd level of the API tree (Clusters -> Affinity-Groups -> Vms), I can't imagine that there's tons of scripts out there messing with this. 

I think it's ok to fix it and return Vms instead of Action.

(by the way in case anyone is wondering how this but is possible in a type-safe language (Java) - the reason is that the return value is always wrapped in a Response object)

Comment 6 Polina 2021-03-11 16:42:12 UTC
verified on ovirt-engine-4.4.5.9-0.1.el8ev.noarch

POST https://{{host}}/ovirt-engine/api/clusters/{clusterId}/affinitygroups/{affinityGroupId}/vms
body
<vm id="ae1b93a1-f504-48ec-bec2-ec95e269e95d"/>

Returns response :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vm id="ae1b93a1-f504-48ec-bec2-ec95e269e95d"/>

and not <action> as it was on the previous version

Comment 7 Sandro Bonazzola 2021-03-18 15:13:22 UTC
This bugzilla is included in oVirt 4.4.5 release, published on March 18th 2021.

Since the problem described in this bug report should be resolved in oVirt 4.4.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.


Note You need to log in before you can comment on or make changes to this bug.