[kimchi-devel][PATCH 0/2] Fix error usage of feature tests

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Feature tests depend on running kimchi server should not be used in model tests, while coincidently, command "qemu-io -r http://localhost:8080/images/icon-fedora.png -c 'read -v 0 512'" return code is 0 so we cannot count on the return code. This patch forces module usage without running kimchi server to return false, and fixes testcase accordingly. REF: https://github.com/kimchi-project/kimchi/issues/579 https://github.com/kimchi-project/kimchi/issues/580 Royce Lv (2): Avoid using server dependent feature tests when server not running Fix wrong usage of feature tests src/kimchi/model/featuretests.py | 5 ++++- src/kimchi/utils.py | 8 ++++++++ tests/test_model.py | 16 +++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) -- 1.9.3

From: Royce Lv <lvroyce@linux.vnet.ibm.com> This patch forces all server dependent feature tests return False to prevent wrong results returned when used as imported module. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model/featuretests.py | 5 ++++- src/kimchi/utils.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kimchi/model/featuretests.py b/src/kimchi/model/featuretests.py index c187f86..c1ab972 100644 --- a/src/kimchi/model/featuretests.py +++ b/src/kimchi/model/featuretests.py @@ -29,7 +29,7 @@ from lxml.builder import E from kimchi.rollbackcontext import RollbackContext -from kimchi.utils import kimchi_log, run_command +from kimchi.utils import kimchi_log, run_command, servermethod ISO_STREAM_XML = """ @@ -135,6 +135,7 @@ class FeatureTests(object): return True @staticmethod + @servermethod def qemu_supports_iso_stream(): host = cherrypy.server.socket_host port = cherrypy.server.socket_port @@ -146,6 +147,7 @@ class FeatureTests(object): return len(stderr) == 0 @staticmethod + @servermethod def qemu_iso_stream_dns(): host = socket.getfqdn(cherrypy.server.socket_host) port = cherrypy.server.socket_port @@ -153,6 +155,7 @@ class FeatureTests(object): (host, port), "-c", "'read -v 0 512'"] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + thread = threading.Thread(target=proc.communicate) thread.start() thread.join(5) diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index fc5245f..28e547e 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -388,3 +388,11 @@ def get_unique_file_name(all_names, name): max_num = max(max_num, int(match.group(re_group_num))) return u'%s (%d)' % (name, max_num + 1) + + +def servermethod(f): + def wrapper(*args, **kwargs): + if str(cherrypy.engine.state) != "states.STARTED": + return False + return f(*args, **kwargs) + return wrapper -- 1.9.3

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Feature tests qemu_supports_iso_stream() and qemu_iso_stream_dns() count on running kimchi server to get result, so it is wrong to use them in model tests. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- tests/test_model.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index f80f1c9..161f705 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -528,15 +528,13 @@ class ModelTests(unittest.TestCase): cdrom_info = inst.vmstorage_lookup(vm_name, cdrom_dev) cur_cdrom_path = re.sub(":80/", '/', cdrom_info['path']) - # Check QEMU stream DNS to determine the cdrom path - qemu_stream_dns = FeatureTests.qemu_iso_stream_dns() - if not qemu_stream_dns: - output = urlparse.urlparse(valid_remote_iso_path) - hostname = socket.gethostbyname(output.hostname) - url = valid_remote_iso_path.replace(output.hostname, hostname) - self.assertEquals(url, cur_cdrom_path) - else: - self.assertEquals(valid_remote_iso_path, cur_cdrom_path) + # As Kimchi server is not running during this test case + # CapabilitiesModel.qemu_stream_dns will be always False + # so we need to convert the hostname to IP + output = urlparse.urlparse(valid_remote_iso_path) + hostname = socket.gethostbyname(output.hostname) + url = valid_remote_iso_path.replace(output.hostname, hostname) + self.assertEquals(url, cur_cdrom_path) @unittest.skipUnless(utils.running_as_root(), 'Must be run as root') def test_vm_storage_provisioning(self): -- 1.9.3

On 03/02/2015 06:47, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Feature tests depend on running kimchi server should not be used in model tests, while coincidently, command "qemu-io -r http://localhost:8080/images/icon-fedora.png -c 'read -v 0 512'" return code is 0 so we cannot count on the return code. This patch forces module usage without running kimchi server to return false, and fixes testcase accordingly.
What is the error you are getting when running the tests with the current upstream code?
REF: https://github.com/kimchi-project/kimchi/issues/579 https://github.com/kimchi-project/kimchi/issues/580
Those issues seem duplicated for me.
Royce Lv (2): Avoid using server dependent feature tests when server not running Fix wrong usage of feature tests
src/kimchi/model/featuretests.py | 5 ++++- src/kimchi/utils.py | 8 ++++++++ tests/test_model.py | 16 +++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-)

On 02/05/2015 12:14 PM, Aline Manera wrote:
On 03/02/2015 06:47, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Feature tests depend on running kimchi server should not be used in model tests, while coincidently, command "qemu-io -r http://localhost:8080/images/icon-fedora.png -c 'read -v 0 512'" return code is 0 so we cannot count on the return code. This patch forces module usage without running kimchi server to return false, and fixes testcase accordingly.
What is the error you are getting when running the tests with the current upstream code?
Reproduced with current upstream code: ====================================================================== FAIL: test_vm_cdrom (test_model.ModelTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_model.py", line 539, in test_vm_cdrom self.assertEquals(valid_remote_iso_path, cur_cdrom_path) AssertionError: u'http://fedora.mirrors.tds.net/pub/fedora/releases/20/Live/x86_64/Fedora-Live...' != 'http://204.246.0.137/pub/fedora/releases/20/Live/x86_64/Fedora-Live-Desktop-...' ---------------------------------------------------------------------- Ran 34 tests in 126.156s please review
REF: https://github.com/kimchi-project/kimchi/issues/579 https://github.com/kimchi-project/kimchi/issues/580
Those issues seem duplicated for me.
Royce Lv (2): Avoid using server dependent feature tests when server not running Fix wrong usage of feature tests
src/kimchi/model/featuretests.py | 5 ++++- src/kimchi/utils.py | 8 ++++++++ tests/test_model.py | 16 +++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-)

On 11/03/2015 06:00, Royce Lv wrote:
On 02/05/2015 12:14 PM, Aline Manera wrote:
On 03/02/2015 06:47, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Feature tests depend on running kimchi server should not be used in model tests, while coincidently, command "qemu-io -r http://localhost:8080/images/icon-fedora.png -c 'read -v 0 512'" return code is 0 so we cannot count on the return code. This patch forces module usage without running kimchi server to return false, and fixes testcase accordingly.
What is the error you are getting when running the tests with the current upstream code?
Reproduced with current upstream code: ====================================================================== FAIL: test_vm_cdrom (test_model.ModelTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_model.py", line 539, in test_vm_cdrom self.assertEquals(valid_remote_iso_path, cur_cdrom_path) AssertionError: u'http://fedora.mirrors.tds.net/pub/fedora/releases/20/Live/x86_64/Fedora-Live...' != 'http://204.246.0.137/pub/fedora/releases/20/Live/x86_64/Fedora-Live-Desktop-...'
---------------------------------------------------------------------- Ran 34 tests in 126.156s
please review
Sure. I was just trying to understand the problem. =)
REF: https://github.com/kimchi-project/kimchi/issues/579 https://github.com/kimchi-project/kimchi/issues/580
Those issues seem duplicated for me.
Royce Lv (2): Avoid using server dependent feature tests when server not running Fix wrong usage of feature tests
src/kimchi/model/featuretests.py | 5 ++++- src/kimchi/utils.py | 8 ++++++++ tests/test_model.py | 16 +++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-)
participants (3)
-
Aline Manera
-
lvroyce@linux.vnet.ibm.com
-
Royce Lv