Bug 1425731 - APIv4: StorageDomainVmService.register should have reassign_bad_macs, not import_
Summary: APIv4: StorageDomainVmService.register should have reassign_bad_macs, not imp...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: Core
Version: 4.1.0a
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ovirt-4.1.1
: 4.1.1
Assignee: Ondra Machacek
QA Contact: Ori Ben Sasson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-02-22 09:10 UTC by Ondřej Svoboda
Modified: 2017-04-21 09:33 UTC (History)
5 users (show)

Fixed In Version: python-ovirt-engine-sdk4-4.1.1-1.el7ev
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-04-21 09:33:24 UTC
oVirt Team: Network
Embargoed:
rule-engine: ovirt-4.1+
rule-engine: exception+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 72896 0 master MERGED Move vnicProfileMappings and reassignBadMacs from import to register. 2017-02-22 16:57:12 UTC
oVirt gerrit 72918 0 model_4.1 MERGED Move vnicProfileMappings and reassignBadMacs from import to register. 2017-02-22 16:59:48 UTC
oVirt gerrit 73332 0 master MERGED restapi: Update to model 4.2.6 2017-03-01 11:29:19 UTC
oVirt gerrit 73333 0 master MERGED Update to model 4.2.6 and metamodel 1.2.2 2017-03-01 10:11:23 UTC
oVirt gerrit 73336 0 sdk_4.1 MERGED Update to model 4.1.31 and metamodel 1.1.12 2017-03-01 11:30:28 UTC
oVirt gerrit 73349 0 master MERGED Update to model 4.2.6 and metamodel 1.2.2 2017-03-01 16:00:23 UTC
oVirt gerrit 73380 0 sdk_4.1 MERGED Update to model 4.1.31 and metamodel 1.1.12 2017-03-01 16:38:03 UTC
oVirt gerrit 73434 0 ovirt-engine-4.1 MERGED restapi: Update to model 4.1.31 2017-03-02 11:24:07 UTC
oVirt gerrit 74062 0 ovirt-engine-4.1.1.z MERGED restapi: Update to model 4.1.33 2017-03-14 14:19:48 UTC

Description Ondřej Svoboda 2017-02-22 09:10:53 UTC
I am running ovirt-system-tests (basic-suite-master) to write storage domain reattachment tests.

When trying to import an "unregistered" VM from a reattached storage domain, I found out that the correct REST command to do so is not "import" (this gives me 404 because the VM is not registered) but "register", if I also want to "Reassign Bad MACs".

I followed documentation (REST API Guide accessible from the https://engine/ovirt-engine/ main page) and the generated v4 API, and both of them wrongly suggest that "import" accepts this parameter (reassign_bad_macs) and "register" doesn't.

First, I verified that the Engine accepted the parameter with the "register" action manually with cURL and then I fixed /usr/lib/python2.7/site-packages/ovirtsdk4/services.py and copied handling of the parameter to the "register" method. Now my tests work, the VM is imported and its MACs are reassigned in the MAC pool.

May I ask that the code (from which REST API bindings are generated) is fixed and the parameter moved to the correct function? Thanks :-)

Comment 1 Ondřej Svoboda 2017-02-22 17:27:34 UTC
A fix has been merged and backported.

Comment 2 Juan Hernández 2017-02-22 19:53:03 UTC
Before considering this MODIFIED a new release of the API specification has to be published, containing the fix, and then the Python SDK needs to be updated to use that version. I am moving the bug back to NEW and reassigning it.

Comment 3 Ori Ben Sasson 2017-03-28 07:25:50 UTC
Hi Ondra,
could you please explain me how to verify this bug?

Comment 4 Ondra Machacek 2017-03-28 08:28:44 UTC
As explained in the description the 'register' action missed the option to specify following attributes:


  - vnic_profile_mappings
  - reassign_bad_macs

during the register operation. So in order to test it try to pass that parameters to the register action:

---
import logging

import ovirtsdk4 as sdk
import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='example.log')

# This example will connect to the server and start a virtual machine.

# Create the connection to the server:
connection = sdk.Connection(
    url='https://engine/ovirt-engine/api',
    username='admin@internal',
    password='123',
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

# Get the reference to the "storage_domains" service:
storage_domains_service = connection.system_service().storage_domains_service()

# Find the storage domain with unregistered VM:
sd = storage_domains_service.list(search='name=mysd')[0]

# Locate the service that manages the storage domain, as that is where
# the action methods are defined:
storage_domain_service = storage_domains_service.storage_domain_service(sd.id)

# Locate the service that manages the VMs in storage domain:
vms_service = storage_domain_service.vms_service()

# Find the the unregistered VM we want to register:
vms = vms_service.list(unregistered=True)
vm = next(
    (v for v in vms if v.name == 'myvm'),
    None
)

# Locate the service that manages the storage domain, as that is where
# the action methods are defined:
vm_service = vms_service.vm_service(vm.id)

# Register the VM into the system:
vm = vm_service.register(
    cluster=types.Cluster(
        name='mycluster',
    ),
    vm=types.Vm(
        name='exported_myvm',
    ),
    vnic_profile_mappings=[
        types.VnicProfileMapping(
            source_network_name='mynetwork',
            source_network_profile_name='mynetwork',
            target_vnic_profile=types.VnicProfile(
                name='mynetwork',
            ),
        ),
    ],
    reassign_bad_macs=True,
)

# Close the connection to the server:
connection.close()
---

Comment 5 Ori Ben Sasson 2017-03-28 12:54:51 UTC
Verified on python-ovirt-engine-sdk4-4.1.3-1.el7ev.x86_64


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