Re: [libvirt] [test-API PATCHv2 2/2] repo: Add test for mutualy exclusive console access
On 04/05/2012 01:58 PM, Peter Krempa wrote: This test case checks if the console connection code works in a safe way that the connection don't get messed up. --- Diff to v1: -- removed semicolons at the end of statements (the C language left some habits :D) -- added call to usage function (I thought it's called automaticaly. With this this could be another good function to incorporate in the class and free the test-writer from re-implementing it again and again) -- added cleanup function (same comment as above; note: there are some tests that don't have this func.) -- refactored getting of optional parameter device -- added cleanup of stream objects (they'd got cleaned up automaticaly with the disconnect, but this is safer and enables testing if the stream was in a good state) repos/domain/console_mutex.py | 107 + 1 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 repos/domain/console_mutex.py diff --git a/repos/domain/console_mutex.py b/repos/domain/console_mutex.py new file mode 100644 index 000..50730e0 --- /dev/null +++ b/repos/domain/console_mutex.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python + A test case to test console mutual exclusivity +mandatory arguments: guestname + +import libvirt +from libvirt import libvirtError +from exception import TestError + +from utils.Python import utils Sorry for rubbing in this after it's pushed, but why do you need utils? + +def usage(params): +Verify parameter dictionary +logger = params['logger'] +keys = ['guestname'] +for key in keys: +if key not in params: +logger.error(%s is required %key) +return 1 + +def console_mutex(params): +Attach to console +usage(params); +logger = params['logger'] +guest = params['guestname'] +device = params.get('device', 'serial0') + +util = utils.Utils() This is the only line using it and I believe util is not used anywhere. Maybe it's copy-paste error from other tests where these were leftover even though they are not needed anymore after the cleanup of get_uri(). +uri = params['uri'] + +try: +logger.info(Connecting to hypervisor: '%s' % uri) +conn = libvirt.open(uri) +dom = conn.lookupByName(guest) + +if not dom.isActive(): +raise TestError(Guest '%s' is not active % guest) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +logger.info(Forcibly open console on domain) +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Creating another stream object) +stream2 = conn.newStream(0) + +logger.info(Open safe console connection while an existing one is open) +try: +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_OPERATION_FAILED: +logger.info(Opening failed - OK) +else: +raise e +else: +raise TestError(Opening of console succeeded although shoud fail) + +logger.info(Abort the existing stream) +stream.abort() + +logger.info(Re-try connecting to the console) +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) + +logger.info(Re-try forcibly on already open console) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Clean up streams) +stream.finish() + +try: +stream2.finish() +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_RPC and \ + e.get_error_domain() == libvirt.VIR_FROM_STREAMS: +logger.info(Stream was aborted successfuly) +else: +raise e +else: +raise TestError(stream2 should be aborted after forced console connection) + +except libvirtError, e: +logger.error(Libvirt call failed: + str(e)) +ret = 1 + +except TestError, e: +logger.error(Test failed: + str(e)) +ret = 1 + +else: +logger.info(All tests succeeded) +ret = 0 + +finally: +logger.info(Closing hypervisor connection) +conn.close() + +logger.info(Done) + +return ret + +def console_mutex_clean(params): +clean testing environment +pass -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [test-API PATCHv2 2/2] repo: Add test for mutualy exclusive console access
This test case checks if the console connection code works in a safe way that the connection don't get messed up. --- Diff to v1: -- removed semicolons at the end of statements (the C language left some habits :D) -- added call to usage function (I thought it's called automaticaly. With this this could be another good function to incorporate in the class and free the test-writer from re-implementing it again and again) -- added cleanup function (same comment as above; note: there are some tests that don't have this func.) -- refactored getting of optional parameter device -- added cleanup of stream objects (they'd got cleaned up automaticaly with the disconnect, but this is safer and enables testing if the stream was in a good state) repos/domain/console_mutex.py | 107 + 1 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 repos/domain/console_mutex.py diff --git a/repos/domain/console_mutex.py b/repos/domain/console_mutex.py new file mode 100644 index 000..50730e0 --- /dev/null +++ b/repos/domain/console_mutex.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python + A test case to test console mutual exclusivity +mandatory arguments: guestname + +import libvirt +from libvirt import libvirtError +from exception import TestError + +from utils.Python import utils + +def usage(params): +Verify parameter dictionary +logger = params['logger'] +keys = ['guestname'] +for key in keys: +if key not in params: +logger.error(%s is required %key) +return 1 + +def console_mutex(params): +Attach to console +usage(params); +logger = params['logger'] +guest = params['guestname'] +device = params.get('device', 'serial0') + +util = utils.Utils() +uri = params['uri'] + +try: +logger.info(Connecting to hypervisor: '%s' % uri) +conn = libvirt.open(uri) +dom = conn.lookupByName(guest) + +if not dom.isActive(): +raise TestError(Guest '%s' is not active % guest) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +logger.info(Forcibly open console on domain) +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Creating another stream object) +stream2 = conn.newStream(0) + +logger.info(Open safe console connection while an existing one is open) +try: +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_OPERATION_FAILED: +logger.info(Opening failed - OK) +else: +raise e +else: +raise TestError(Opening of console succeeded although shoud fail) + +logger.info(Abort the existing stream) +stream.abort() + +logger.info(Re-try connecting to the console) +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) + +logger.info(Re-try forcibly on already open console) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Clean up streams) +stream.finish() + +try: +stream2.finish() +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_RPC and \ + e.get_error_domain() == libvirt.VIR_FROM_STREAMS: +logger.info(Stream was aborted successfuly) +else: +raise e +else: +raise TestError(stream2 should be aborted after forced console connection) + +except libvirtError, e: +logger.error(Libvirt call failed: + str(e)) +ret = 1 + +except TestError, e: +logger.error(Test failed: + str(e)) +ret = 1 + +else: +logger.info(All tests succeeded) +ret = 0 + +finally: +logger.info(Closing hypervisor connection) +conn.close() + +logger.info(Done) + +return ret + +def console_mutex_clean(params): +clean testing environment +pass -- 1.7.3.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [test-API PATCHv2 2/2] repo: Add test for mutualy exclusive console access
On 04/05/2012 07:58 PM, Peter Krempa wrote: This test case checks if the console connection code works in a safe way that the connection don't get messed up. --- Diff to v1: -- removed semicolons at the end of statements (the C language left some habits :D) -- added call to usage function (I thought it's called automaticaly. With this this could be another good function to incorporate in the class and free the test-writer from re-implementing it again and again) -- added cleanup function (same comment as above; note: there are some tests that don't have this func.) the clean flag was added after some testcases. So... need to update them later. -- refactored getting of optional parameter device -- added cleanup of stream objects (they'd got cleaned up automaticaly with the disconnect, but this is safer and enables testing if the stream was in a good state) repos/domain/console_mutex.py | 107 + 1 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 repos/domain/console_mutex.py diff --git a/repos/domain/console_mutex.py b/repos/domain/console_mutex.py new file mode 100644 index 000..50730e0 --- /dev/null +++ b/repos/domain/console_mutex.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python + A test case to test console mutual exclusivity +mandatory arguments: guestname + +import libvirt +from libvirt import libvirtError +from exception import TestError + +from utils.Python import utils + +def usage(params): +Verify parameter dictionary +logger = params['logger'] +keys = ['guestname'] +for key in keys: +if key not in params: +logger.error(%s is required %key) +return 1 + +def console_mutex(params): +Attach to console +usage(params); +logger = params['logger'] +guest = params['guestname'] +device = params.get('device', 'serial0') + +util = utils.Utils() +uri = params['uri'] + +try: +logger.info(Connecting to hypervisor: '%s' % uri) +conn = libvirt.open(uri) +dom = conn.lookupByName(guest) + +if not dom.isActive(): +raise TestError(Guest '%s' is not active % guest) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +logger.info(Forcibly open console on domain) +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Creating another stream object) +stream2 = conn.newStream(0) + +logger.info(Open safe console connection while an existing one is open) +try: +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_OPERATION_FAILED: +logger.info(Opening failed - OK) +else: +raise e +else: +raise TestError(Opening of console succeeded although shoud fail) + +logger.info(Abort the existing stream) +stream.abort() + +logger.info(Re-try connecting to the console) +dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE) + +logger.info(Re-try forcibly on already open console) + +logger.info(Creating stream object) +stream = conn.newStream(0) + +dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE) + +logger.info(Clean up streams) +stream.finish() + +try: +stream2.finish() +except libvirtError, e: +if e.get_error_code() == libvirt.VIR_ERR_RPC and \ + e.get_error_domain() == libvirt.VIR_FROM_STREAMS: +logger.info(Stream was aborted successfuly) +else: +raise e +else: +raise TestError(stream2 should be aborted after forced console connection) + +except libvirtError, e: +logger.error(Libvirt call failed: + str(e)) +ret = 1 + +except TestError, e: +logger.error(Test failed: + str(e)) +ret = 1 + +else: +logger.info(All tests succeeded) +ret = 0 + +finally: +logger.info(Closing hypervisor connection) +conn.close() + +logger.info(Done) + +return ret + +def console_mutex_clean(params): +clean testing environment +pass Thanks, pushed. Guannan Ren -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list