On 07/03/2012 04:39 AM, Chris Evich wrote:
> On 06/26/2012 01:28 PM, Alex Jia wrote:
>> With this module, we will be able to implement a virt-v2v test.
>>
>> As of implementation details, we uses virt-v2v command line tool
>> to convert an existing VM into libvirt-managed KVM, or an open
>> manageable virtualized environment - oVirt.
>>
>> Signed-off-by: Alex Jia<a...@redhat.com>
>> Signed-off-by: Wayne Sun<g...@redhat.com>
>> ---
>>   client/virt/virt_v2v.py |   59 
>> ++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 59 insertions(+)
>>   create mode 100644 client/virt/virt_v2v.py
>>
>> diff --git a/client/virt/virt_v2v.py b/client/virt/virt_v2v.py
>> new file mode 100644
>> index 0000000..973d8ca
>> --- /dev/null
>> +++ b/client/virt/virt_v2v.py
>> @@ -0,0 +1,59 @@
>> +"""
>> +Utility functions to handle Virtual Machine conversion using virt-v2v.
>> +
>> +@copyright: 2008-2012 Red Hat Inc.
>> +"""
>> +
>> +import logging
>> +from autotest.client import os_dep, utils
>> +from autotest.server.hosts.ssh_host import SSHHost
>> +import virt_v2v_utils as v2v_utils
>> +
>> +DEBUG = False
>> +
>> +try:
>> +    V2V_EXEC = os_dep.command('virt-v2v')
>> +except ValueError:
>> +    V2V_EXEC = None
>> +
>> +
>> +def v2v_cmd(params):
>> +    """
>> +    Append cmd to 'virt-v2v' and execute, optionally return full 
>> results.
>> +
>> +    @param: params: A dictionary includes all of required parameters 
>> such as
>> +                    'target', 'hypervisor', 'hostname', 'storage', 
>> 'network'.
>> +    @return: stdout of command
>> +    """
>> +    if V2V_EXEC is None:
>> +        raise ValueError('Missing command: virt-v2v')
>> +
>> +    target = params.get('target')
>> +    hypervisor = params.get('hypervisor')
>> +    hostname = params.get('hostname')
>> +    storage = params.get('storage')
>> +    network = params.get('network')
>> +    username = params.get('username')
>> +    password = params.get('password')
>> +
>> +    uri_obj = v2v_utils.URI(hypervisor)
>> +    # Return actual 'uri' according to 'hostname' and 'hypervisor'
>> +    uri = uri_obj.get_uri(hostname)
>> +
>> +    tgt_obj = v2v_utils.TARGERT(target, uri)
>
> I thought TARGERT was a typo here, but I see from v2v_utils it is not.
Yeah, will global replace it with 'Target' and keep consistent with 
virt_v2v_utils module.
>
>> +    # Return virt-v2v command line options based on 'target' and 
>> 'hypervisor'
>> +    options = tgt_obj.get_cmd_options(params)
>> +
>> +    # Convert a existing VM without or with connection autoorization.
>
> Typo, "Authorization" (one 'o')
Yeah, s/autoorization/ authorization/.
>
>> +    if hypervisor == 'esx':
>> +        v2v_utils.build_esx_no_verify(params)
>> +    elif hypervisor == 'xen':
>> +        SSHHost(hostname, user=username, port=22, password=password)
>
> I'm unclear on what this is doing.  It seems to create instance but 
> then throw it away (N/B/ I only took quick look at SSHHost code).
I also think some comments are necessary in here.
>
>> +    else:
>> +        pass
>> +
>> +    # Construct a final virt-v2v command
>> +    cmd = '%s %s' % (V2V_EXEC, options)
>> +    logging.debug('%s' % cmd)
>> +    cmd_result = utils.run(cmd, verbose=DEBUG)
>> +    return cmd_result.stdout.strip()
>
> Maybe it makes sense to just return cmd_result directly?  This would 
> let tests exercise v2v tools with invalid options or scrutinize result 
> more thoroughly if they need to.  Just an idea.
I tend to agree with you then the upper caller will deal with cmd_result 
according to actual requirement.

Chris, thanks.
>
>

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to