On 06/11/2012 09:30 AM, Pradeep Kumar Surisetty wrote:
> * Chris Evich<cev...@redhat.com>  [2012-06-08 10:45:29]:
>
>> On 06/08/2012 02:06 AM, Onkar N Mahajan wrote:
>>> On Thu, 2012-06-07 at 10:52 -0400, Chris Evich wrote:
>>>> On 06/07/2012 04:46 AM, Onkar N Mahajan wrote:
>>> See, I have tried making nxt_free_vnc_port() available for general usage
>>> (vnc/spice/etc) as you mentioned , but this requires virsh to have
>>> vncdisplay counterparts to spice/etc - which AFAIK are currently not
>>> available.
>>
>> Annoyingly, it must be extracted from the xml :(  However, you're right
>> in that virsh only has a vncdisplay command.  Along those lines, how
>> about adding a lower-level and more generic virsh_vncdisplay() function
>> that returns the port and ip address?
>>
>> I'd like the the vm class methods to support a wider usage, even if all
>> the capabilities aren't there immediately.  When possible, methods
>> should not be tied closely to underlying implementation details.
>>
>> For example with graphics, I'd prefer a vm.graphics_info() (or similar
>> name) method provides details independent of the underlying graphics
>> device type.  But it's perfectly acceptable if support for other types
>> gets added at a later date, and it just throws exceptions for the stubs.
>>
>> With this deign, we can easily extend the tests (later) by adding
>> support for additional graphics.  It also allows for extending the
>> underlying support w/o disturbing the callers.  Make sense?

Code example of the above:

virsh_vncdisplay(name, uri=""):
     ...
     if cmdresult.exit_status:
         ... # other checks
         raise virt_vm.UnsupportedDisplayError("VM %s doesn't use vnc"
                                               "graphics" % name)

class VM(virt_vm.BaseVM):
     ...
     def graphics_info(self):
         d={}
         # only VNC graphics supported for now
         try:
             vncinfo=virsh_vncdisplay(...)
             d["ip"] = vncinfo[0]
             d["port"] = vncinfo[1]
         except virt_vm.UnsupportedDisplayError:
             raise virt_vm.NotImplementedError("Only VMs with VNC
                                               displays are supported")
         return d

In this way, we can easily add spice or whatever support to 
vm.graphics_info (or whatever name) later w/o affecting callers.  If a 
test needs to specifically only deal with VM's using VNC, they can just 
call virst_vncdisplay directly.  It also supports error testing in a 
generic way by calling vm.graphics_info() and checking making sure it 
does NOT raise UnsupportedDisplayError or NotImplementedError (presuming 
bad guest XML raises a different exception).

-- 
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to