Re: [libvirt] [Qemu-devel] QEMU fstatfs(2) and libvirt SELinux policy

2012-03-24 Thread Christoph Hellwig
On Fri, Mar 09, 2012 at 06:16:54PM +0100, Paolo Bonzini wrote:
  I'm wondering whether it's worth expanding the SELinux policy if we
  will have no fstatfs(2) callers in QEMU.  Are you planning to drop the
  XFS code?
 
 Chris Wedgwood said that on XFS you want to do discard even if the file
 is preallocated, while this is not true on other filesystems.  So I
 guess the detection code should stay.

In generaly you do not want to discard on a preallocated file, especially
not the low-granularity discard you'd get for example from a Win7 box.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [Qemu-devel] QEMU fstatfs(2) and libvirt SELinux policy

2012-03-24 Thread Christoph Hellwig
On Fri, Mar 09, 2012 at 04:07:43PM +, Stefan Hajnoczi wrote:
 Paolo, your discard improvements in QEMU add FALLOC_FL_PUNCH_HOLE
 support.  XFS supports this fallocate() flag in current kernels,
 thereby making the XFS-specific support obsolete.
 
 I'm wondering whether it's worth expanding the SELinux policy if we
 will have no fstatfs(2) callers in QEMU.  Are you planning to drop the
 XFS code?

FALLOC_FL_PUNCH_HOLE is a very recent feature, while the ioctl has been
around for more than 10 years.  Using FALLOC_FL_PUNCH_HOLE by default
is fine, so systems that have selinux and support it will still work.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [test-API PATCH 0/6] General improvements and fixes

2012-03-24 Thread Martin Kletzander
This series fixed some of the issues I came across while trying to
make some tests working. I still haven't managed to run more than
define, start, destroy and undefine tests, but at least this should
help someone to get a start at this.

There are many things that could (should?) be changed (either with or
without a discussion), but maybe I missed something, so feel free to
comment on all the patches if you have any input, I'll be glad to
discuss/change anything in order to move forward.

Each of the patches has it's own description and they are not that
much related to each other, so I won't describe it all here again, I
just didn't want to create unnecessary threads in the mailing list, so
I'm sending this as a series.

Martin Kletzander (6):
  Slight cross-distribution support
  Added support for Gentoo
  Fixed domain/start.py
  Add default 'uri' parameter to all tests
  Cleanup and fix of domain/define test
  Make use of new 'uri' parameter in tests

 env_inspect.py = dist/gentoo/env_inspect.py   |   88 +-
 env_inspect.py = dist/redhat/env_inspect.py   |0
 generator.py   |   18 +++-
 repos/domain/attach_disk.py|2 +-
 repos/domain/attach_interface.py   |2 +-
 repos/domain/autostart.py  |2 +-
 repos/domain/balloon_memory.py |2 +-
 repos/domain/blkstats.py   |2 +-
 repos/domain/cpu_affinity.py   |2 +-
 repos/domain/cpu_topology.py   |2 +-
 repos/domain/create.py |2 +-
 repos/domain/define.py |  132 +++
 repos/domain/destroy.py|2 +-
 repos/domain/detach_disk.py|2 +-
 repos/domain/detach_interface.py   |2 +-
 repos/domain/domain_blkinfo.py |2 +-
 repos/domain/domain_id.py  |2 +-
 repos/domain/domain_uuid.py|2 +-
 repos/domain/dump.py   |2 +-
 repos/domain/eventhandler.py   |2 +-
 repos/domain/ifstats.py|2 +-
 repos/domain/install_image.py  |6 +-
 repos/domain/install_linux_cdrom.py|6 +-
 repos/domain/install_linux_check.py|2 +-
 repos/domain/install_linux_net.py  |7 +-
 repos/domain/install_windows_cdrom.py  |7 +-
 repos/domain/ownership_test.py |2 +-
 repos/domain/reboot.py |2 +-
 repos/domain/restore.py|2 +-
 repos/domain/resume.py |2 +-
 repos/domain/save.py   |2 +-
 repos/domain/sched_params.py   |2 +-
 repos/domain/shutdown.py   |2 +-
 repos/domain/start.py  |   17 ++-
 repos/domain/suspend.py|2 +-
 repos/domain/undefine.py   |2 +-
 repos/domain/update_devflag.py |2 +-
 repos/interface/create.py  |2 +-
 repos/interface/define.py  |2 +-
 repos/interface/destroy.py |2 +-
 repos/interface/undefine.py|2 +-
 repos/libvirtd/qemu_hang.py|2 +-
 repos/libvirtd/restart.py  |2 +-
 repos/network/autostart.py |2 +-
 repos/network/create.py|2 +-
 repos/network/define.py|2 +-
 repos/network/destroy.py   |2 +-
 repos/network/network_list.py  |2 +-
 repos/network/network_name.py  |2 +-
 repos/network/network_uuid.py  |2 +-
 repos/network/start.py |2 +-
 repos/network/undefine.py  |2 +-
 repos/nodedevice/detach.py |2 +-
 repos/nodedevice/reattach.py   |2 +-
 repos/nodedevice/reset.py  |2 +-
 repos/npiv/create_virtual_hba.py   |2 +-
 .../multiple_thread_block_on_domain_create.py  |2 +-
 repos/sVirt/domain_nfs_start.py|4 +-
 repos/snapshot/delete.py   |2 +-
 repos/snapshot/file_flag.py|2 +-
 repos/snapshot/flag_check.py   |2 +-
 repos/snapshot/internal_create.py  |2 +-
 repos/snapshot/revert.py   |2 +-
 repos/storage/activate_pool.py |2 +-
 repos/storage/build_dir_pool.py  

[libvirt] [test-API PATCH 5/6] Cleanup and fix of domain/define test

2012-03-24 Thread Martin Kletzander
I added support for 'uri' parameter and moved some functions into
util/Python/utils.py in order not to lose them from the code and keep
them accessible for other tests.
---
 repos/domain/define.py |  132 
 utils/Python/utils.py  |   45 -
 2 files changed, 65 insertions(+), 112 deletions(-)

diff --git a/repos/domain/define.py b/repos/domain/define.py
index 8f0095a..25630c5 100644
--- a/repos/domain/define.py
+++ b/repos/domain/define.py
@@ -19,7 +19,7 @@
 __author__ = 'Alex Jia: a...@redhat.com'
 __date__ = 'Mon Jan 28, 2010'
 __version__ = '0.1.0'
-__credits__ = 'Copyright (C) 2009 Red Hat, Inc.'
+__credits__ = 'Copyright (C) 2009, 2012 Red Hat, Inc.'
 __all__ = ['usage', 'check_define_domain', 'define']

 import os
@@ -63,9 +63,6 @@ def usage():
macaddr
ifacetype
source
-   target_machine
-   username
-   password
   '''

 def check_params(params):
@@ -107,58 +104,17 @@ def ssh_keygen(logger):

 return 0

-def ssh_tunnel(hostname, username, password, logger):
-setup a tunnel to a give host
-logger.info(setup ssh tunnel with host %s % hostname)
-user_host = %s@%s % (username, hostname)
-child = pexpect.spawn(SSH_COPY_ID, [ user_host])
-while True:
-index = child.expect(['yes\/no', 'password: ',
-   pexpect.EOF,
-   pexpect.TIMEOUT])
-if index == 0:
-child.sendline(yes)
-elif index == 1:
-child.sendline(password)
-elif index == 2:
-logger.debug(string.strip(child.before))
-child.close()
-return 0
-elif index == 3:
-logger.error(setup tunnel timeout)
-logger.debug(string.strip(child.before))
-child.close()
-return 1
-
-return 0
-
-def check_define_domain(guestname, guesttype, target_machine, username, \
-password, util, logger):
-Check define domain result, if define domain is successful,
-   guestname.xml will exist under /etc/libvirt/qemu/
-   and can use virt-xml-validate tool to check the file validity
+def check_define_domain(conn, guestname, logger):
+Check define domain result. To make this work on all
+hypervisors and with all configuration posibilities, use the
+default way through libvirt to check if the guest was defined
 
-if kvm in guesttype:
-path = /etc/libvirt/qemu/%s.xml % guestname
-elif xen in guesttype:
-path = /etc/xen/%s % guestname
-else:
-logger.error(unknown guest type)
-
-if target_machine:
-cmd = ls %s % path
-ret, output = util.remote_exec_pexpect(target_machine, username, \
-   password, cmd)
-if ret:
-logger.error(guest %s xml file doesn't exsits % guestname)
-return False
-else:
-return True
-else:
-if os.access(path, os.R_OK):
-return True
-else:
-return False
+try:
+conn.lookupByName(guestname + 'asdf')
+return True
+except libvirtError, e:
+logger.error(e.message())
+return False

 def define(params):
 Define a domain from xml
@@ -169,41 +125,10 @@ def define(params):
 logger = params['logger']
 guestname = params['guestname']
 guesttype = params['guesttype']
+uri = params['uri']
 test_result = False

-if params.has_key('target_machine'):
-logger.info(define domain on remote host)
-target_machine = params['target_machine']
-username = params['username']
-password = params['password']
-else:
-logger.info(define domain on local host)
-target_machine = None
-username = None
-password = None
-
 # Connect to hypervisor connection URI
-util = utils.Utils()
-if target_machine:
-uri = util.get_uri(target_machine)
-
-#generate ssh key pair
-ret = ssh_keygen(logger)
-if ret:
-logger.error(failed to generate RSA key)
-return 1
-#setup ssh tunnel with target machine
-ret = ssh_tunnel(target_machine, username, password, logger)
-if ret:
-logger.error(faild to setup ssh tunnel with target machine %s % \
-  target_machine)
-return 1
-
-commands.getstatusoutput(ssh-add)
-
-else:
-uri = util.get_uri('127.0.0.1')
-
 conn = connectAPI.ConnectAPI()
 virconn = conn.open(uri)

@@ -222,35 +147,20 @@ def define(params):

 # Define domain from xml
 try:
-try:
-dom_obj.define(dom_xml)
-if check_define_domain(guestname, guesttype, target_machine, \
-   

[libvirt] [test-API PATCH 1/6] Slight cross-distribution support

2012-03-24 Thread Martin Kletzander
There is no support for distributions without 'rpm' as a package
manager. This patch modifies (at this time) the only
distribution-specific import in order to ease the broadening of
distribution list supported by libvirt-test-API.
---
 env_inspect.py = dist/redhat/env_inspect.py |0
 generator.py |   12 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 dist/__init__.py
 create mode 100644 dist/redhat/__init__.py
 rename env_inspect.py = dist/redhat/env_inspect.py (100%)

diff --git a/dist/__init__.py b/dist/__init__.py
new file mode 100644
index 000..e69de29
diff --git a/dist/redhat/__init__.py b/dist/redhat/__init__.py
new file mode 100644
index 000..e69de29
diff --git a/env_inspect.py b/dist/redhat/env_inspect.py
similarity index 100%
rename from env_inspect.py
rename to dist/redhat/env_inspect.py
diff --git a/generator.py b/generator.py
index 6108963..4f4478b 100644
--- a/generator.py
+++ b/generator.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# libvirt-test-API is copyright 2010 Red Hat, Inc.
+# libvirt-test-API is copyright 2010, 2012 Red Hat, Inc.
 #
 # libvirt-test-API is free software: you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -23,10 +23,18 @@ import sys
 import traceback

 import mapper
-import env_inspect
 from utils.Python import log
 from utils.Python import format

+# Import of distribution-specific code.  If this is needed somewhere
+# else in the future, please don't copy-paste this, but create some
+# sensible distribution-specific package
+import os
+for dist in os.listdir('dist'):
+if os.path.exists('/etc/%s-release' % dist):
+exec('from dist.%s import env_inspect' % dist)
+break
+
 class FuncGen(object):
  To generate a callable testcase
 def __init__(self, cases_func_ref_dict,
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [test-API PATCH 2/6] Added support for Gentoo

2012-03-24 Thread Martin Kletzander
In order to support libvirt-test-API on more distributions, this
commit adds support for Gentoo.
The file is copy-paste from dist/redhat/env_update.py just modified to
make the get_* functions work on Gentoo, some removed.
---
 dist/gentoo/env_inspect.py |   98 
 1 files changed, 98 insertions(+), 0 deletions(-)
 create mode 100644 dist/gentoo/__init__.py
 create mode 100644 dist/gentoo/env_inspect.py

diff --git a/dist/gentoo/__init__.py b/dist/gentoo/__init__.py
new file mode 100644
index 000..e69de29
diff --git a/dist/gentoo/env_inspect.py b/dist/gentoo/env_inspect.py
new file mode 100644
index 000..e8fccc0
--- /dev/null
+++ b/dist/gentoo/env_inspect.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# libvirt-test-API is copyright 2010, 2012 Red Hat, Inc.
+#
+# libvirt-test-API is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version. This program is distributed in
+# the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+# even the implied warranties of TITLE, NON-INFRINGEMENT,
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# The GPL text is available in the file COPYING that accompanies this
+# distribution and at http://www.gnu.org/licenses.
+#
+# Filename: envinspect.py
+# Summary: To generate a callable class for clearing testing environment
+# Description: The module match the reference of clearing function
+#  from each testcase to the corresponding testcase's
+#  argument in the order of testcase running
+
+import os
+import portage
+
+vt_dbapi = portage.db[portage.root]['vartree'].dbapi
+
+def get_libvirt_ver():
+pkg = vt_dbapi.match('app-emulation/libvirt')
+if pkg:
+return 0, pkg[-1]
+else:
+return 100, No libvirt installed
+
+def get_libvirt_pyth_ver():
+pkgs = vt_dbapi.match('app-emulation/libvirt')
+for pkg in pkgs:
+if 'python' in vt_dbapi.aux_get(pkg, ['USE'])[0].split():
+return 0, '%s[python]' % pkg
+
+return 100, USE flag 'python' not enabled for libvirt
+
+def get_qemu_kvm_ver():
+pkg = vt_dbapi.match('qemu-kvm') or vt_dbapi.match('qemu')
+if pkg:
+return 0, pkg[-1]
+else:
+return 100, No qemu installed
+
+def get_kernel_ver():
+# on Gentoo, there is no need to check for kernel
+return 0, os.uname()[2]
+
+
+class EnvInspect(object):
+to check and collect the testing enviroment infomation
+   before performing testing
+
+
+def __init__(self, logger):
+self.logger = logger
+
+def env_checking(self):
+flag = 0
+result = 
+if get_libvirt_ver()[0] == 100:
+result = NOTOK
+flag = 1
+else:
+result = OK
+self.logger.info(%-36s%-6s % (get_libvirt_ver()[1], result))
+
+if get_libvirt_pyth_ver()[0] == 100:
+result = NOTOK
+flag = 1
+else:
+result = OK
+self.logger.info(%-36s%-6s % (get_libvirt_pyth_ver()[1], result))
+
+if get_qemu_kvm_ver()[0] == 150 and flag == 0:
+flag = 0
+elif get_qemu_kvm_ver()[0] == 150 and flag == 1:
+flag = 1
+else:
+pass
+self.logger.info(%-36s%-6s % (get_qemu_kvm_ver()[1], OK))
+
+if get_kernel_ver()[0] == 100:
+result = NOTOK
+flag = 1
+else:
+result = OK
+self.logger.info(%-36s%-6s % (get_kernel_ver()[1], result))
+
+return flag
+
+
+OK = ok
+NOTOK = not ok
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [test-API PATCH 3/6] Fixed domain/start.py

2012-03-24 Thread Martin Kletzander
Function usage() was called in the code but was missing.
Parameter 'flags' was defined as optional but it was still required in
the code, so I fixed the handling of it.
---
 repos/domain/start.py |   15 +++
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/repos/domain/start.py b/repos/domain/start.py
index cd028bf..38bad7f 100644
--- a/repos/domain/start.py
+++ b/repos/domain/start.py
@@ -1,12 +1,13 @@
 #!/usr/bin/env python
 for testing the start function of domain
mandatory arguments: guestname
+   optional arguments: flags
 

 __author__ = Osier Yang jy...@redhat.com
 __date__ = Tue Oct 27, 2009
 __version__ = 0.1.0
-__credits__ = Copyright (C) 2009 Red Hat, Inc.
+__credits__ = Copyright (C) 2009, 2012 Red Hat, Inc.
 __all__ = ['start', 'check_params', 'parse_opts',
'usage', 'version', 'append_path']

@@ -34,6 +35,11 @@ from exception import LibvirtAPI
 NONE = 0
 START_PAUSED = 1

+def usage():
+print '''usage: mandatory arguments: guestname
+   optional arguments: flags
+  '''
+
 def return_close(conn, logger, ret):
 conn.close()
 logger.info(closed hypervisor connection)
@@ -48,7 +54,7 @@ def check_params(params):

 logger = params['logger']

-keys = ['guestname', 'flags', 'logger']
+keys = ['guestname', 'logger']
 for key in keys:
 if key not in params:
 logger.error(key '%s' is required % key)
@@ -66,7 +72,7 @@ def start(params):

 logger -- an object of utils/Python/log.py
 mandatory arguments : guestname -- same as the domain name
-   optional arguments : flags -- domain create flags 
none|start_paused|noping
+optional arguments : flags -- domain create flags 
none|start_paused|noping

 Return 0 on SUCCESS or 1 on FAILURE
 
@@ -75,7 +81,7 @@ def start(params):
 check_params(params)
 domname = params['guestname']
 logger = params['logger']
-flags = params['flags']
+flags = params.get('flags', [])

 if none in flags and start_paused in flags:
 logger.error(Flags error: Can't specify none and start_paused 
simultaneously)
@@ -98,6 +104,7 @@ def start(params):
 elif start_paused in flags:
 dom_obj.start_with_flags(domname, START_PAUSED)
 else:
+# this covers flags = None as well as flags = 'noping'
 dom_obj.start(domname)
 except LibvirtAPI, e:
 logger.error(str(e))
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [test-API PATCH 4/6] Add default 'uri' parameter to all tests

2012-03-24 Thread Martin Kletzander
Tests should be able to run on various hypervisors and machines. Now
we have only two tests that have an option to do something
remotely. This commit allows tests to see 'uri' parameter that they
should connect to. However it doesn't have to be used always
(migration etc.)
---
 generator.py |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/generator.py b/generator.py
index 4f4478b..5a4652a 100644
--- a/generator.py
+++ b/generator.py
@@ -154,6 +154,12 @@ class FuncGen(object):
 clean_ret = -1
 try:
 try:
+# having 'None' as default ensures we use the
+# correct URI taken from libvirt (configuration,
+# environment variables, etc.), but one can always
+# specify a different machine
+if 'uri' not in case_params:
+case_params['uri'] = None
 if case_ref_name != 'sleep':
 case_params['logger'] = case_logger

-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [test-API PATCH 6/6] Make use of new 'uri' parameter in tests

2012-03-24 Thread Martin Kletzander
I changed all tests to make use of the 'uri' parameter. This change
should be more re-factored and lots of things could be changed to make
the code more readable, but unfortunately there's no time for that
right now, so at least this small step towards the goal.
---
 repos/domain/attach_disk.py|2 +-
 repos/domain/attach_interface.py   |2 +-
 repos/domain/autostart.py  |2 +-
 repos/domain/balloon_memory.py |2 +-
 repos/domain/blkstats.py   |2 +-
 repos/domain/cpu_affinity.py   |2 +-
 repos/domain/cpu_topology.py   |2 +-
 repos/domain/create.py |2 +-
 repos/domain/destroy.py|2 +-
 repos/domain/detach_disk.py|2 +-
 repos/domain/detach_interface.py   |2 +-
 repos/domain/domain_blkinfo.py |2 +-
 repos/domain/domain_id.py  |2 +-
 repos/domain/domain_uuid.py|2 +-
 repos/domain/dump.py   |2 +-
 repos/domain/eventhandler.py   |2 +-
 repos/domain/ifstats.py|2 +-
 repos/domain/install_image.py  |6 --
 repos/domain/install_linux_cdrom.py|6 +++---
 repos/domain/install_linux_check.py|2 +-
 repos/domain/install_linux_net.py  |7 ---
 repos/domain/install_windows_cdrom.py  |7 ---
 repos/domain/ownership_test.py |2 +-
 repos/domain/reboot.py |2 +-
 repos/domain/restore.py|2 +-
 repos/domain/resume.py |2 +-
 repos/domain/save.py   |2 +-
 repos/domain/sched_params.py   |2 +-
 repos/domain/shutdown.py   |2 +-
 repos/domain/start.py  |2 +-
 repos/domain/suspend.py|2 +-
 repos/domain/undefine.py   |2 +-
 repos/domain/update_devflag.py |2 +-
 repos/interface/create.py  |2 +-
 repos/interface/define.py  |2 +-
 repos/interface/destroy.py |2 +-
 repos/interface/undefine.py|2 +-
 repos/libvirtd/qemu_hang.py|2 +-
 repos/libvirtd/restart.py  |2 +-
 repos/network/autostart.py |2 +-
 repos/network/create.py|2 +-
 repos/network/define.py|2 +-
 repos/network/destroy.py   |2 +-
 repos/network/network_list.py  |2 +-
 repos/network/network_name.py  |2 +-
 repos/network/network_uuid.py  |2 +-
 repos/network/start.py |2 +-
 repos/network/undefine.py  |2 +-
 repos/nodedevice/detach.py |2 +-
 repos/nodedevice/reattach.py   |2 +-
 repos/nodedevice/reset.py  |2 +-
 repos/npiv/create_virtual_hba.py   |2 +-
 .../multiple_thread_block_on_domain_create.py  |2 +-
 repos/sVirt/domain_nfs_start.py|4 ++--
 repos/snapshot/delete.py   |2 +-
 repos/snapshot/file_flag.py|2 +-
 repos/snapshot/flag_check.py   |2 +-
 repos/snapshot/internal_create.py  |2 +-
 repos/snapshot/revert.py   |2 +-
 repos/storage/activate_pool.py |2 +-
 repos/storage/build_dir_pool.py|2 +-
 repos/storage/build_disk_pool.py   |2 +-
 repos/storage/build_logical_pool.py|2 +-
 repos/storage/build_netfs_pool.py  |2 +-
 repos/storage/create_dir_pool.py   |2 +-
 repos/storage/create_dir_volume.py |2 +-
 repos/storage/create_fs_pool.py|2 +-
 repos/storage/create_iscsi_pool.py |2 +-
 repos/storage/create_logical_volume.py |2 +-
 repos/storage/create_netfs_pool.py |2 +-
 repos/storage/create_netfs_volume.py   |2 +-
 repos/storage/create_partition_volume.py   |2 +-
 repos/storage/define_dir_pool.py   |2 +-
 repos/storage/define_disk_pool.py  |2 +-
 repos/storage/define_iscsi_pool.py |2 +-
 repos/storage/define_logical_pool.py   |2 +-