[libvirt] [resend] fix libvirt alignment on arm platforms
by Michele Paolino
With the changes added by the latest commits (e.g.
8a29ffcf9aee45b61a0a12ee45c656cfd52333e8) related to "new events feature
v2",
we are unable to compile libvirt on ARM target (OMAP5).
The error is due to alignment:
conf/domain_event.c: In function 'virDomainEventDispatchDefaultFunc':
conf/domain_event.c:1198:30: error: cast increases required alignment of
target type [-Werror=cast-align]
conf/domain_event.c:1314:34: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
Using ATTRIBUTE_PACKED we force a structure to not follow architecture and
compiler best alignments.
---
src/conf/domain_event.c | 20 ++++++++++----------
src/conf/network_event.c | 2 +-
src/conf/object_event_private.h | 2 +-
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 64035f7..7d58367 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -76,7 +76,7 @@ struct _virDomainEventLifecycle {
int type;
int detail;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventLifecycle virDomainEventLifecycle;
typedef virDomainEventLifecycle *virDomainEventLifecyclePtr;
@@ -84,7 +84,7 @@ struct _virDomainEventRTCChange {
virDomainEvent parent;
long long offset;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventRTCChange virDomainEventRTCChange;
typedef virDomainEventRTCChange *virDomainEventRTCChangePtr;
@@ -92,7 +92,7 @@ struct _virDomainEventWatchdog {
virDomainEvent parent;
int action;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
@@ -103,7 +103,7 @@ struct _virDomainEventIOError {
char *devAlias;
int action;
char *reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventIOError virDomainEventIOError;
typedef virDomainEventIOError *virDomainEventIOErrorPtr;
@@ -113,7 +113,7 @@ struct _virDomainEventBlockJob {
char *path;
int type;
int status;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventBlockJob virDomainEventBlockJob;
typedef virDomainEventBlockJob *virDomainEventBlockJobPtr;
@@ -125,7 +125,7 @@ struct _virDomainEventGraphics {
virDomainEventGraphicsAddressPtr remote;
char *authScheme;
virDomainEventGraphicsSubjectPtr subject;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventGraphics virDomainEventGraphics;
typedef virDomainEventGraphics *virDomainEventGraphicsPtr;
@@ -136,7 +136,7 @@ struct _virDomainEventDiskChange {
char *newSrcPath;
char *devAlias;
int reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
@@ -145,7 +145,7 @@ struct _virDomainEventTrayChange {
char *devAlias;
int reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventTrayChange virDomainEventTrayChange;
typedef virDomainEventTrayChange *virDomainEventTrayChangePtr;
@@ -154,7 +154,7 @@ struct _virDomainEventBalloonChange {
/* In unit of 1024 bytes */
unsigned long long actual;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventBalloonChange virDomainEventBalloonChange;
typedef virDomainEventBalloonChange *virDomainEventBalloonChangePtr;
@@ -162,7 +162,7 @@ struct _virDomainEventDeviceRemoved {
virDomainEvent parent;
char *devAlias;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventDeviceRemoved virDomainEventDeviceRemoved;
typedef virDomainEventDeviceRemoved *virDomainEventDeviceRemovedPtr;
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index 4a02523..1ffcf6c 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -32,7 +32,7 @@ struct _virNetworkEventLifecycle {
virObjectEvent parent;
int type;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virNetworkEventLifecycle virNetworkEventLifecycle;
typedef virNetworkEventLifecycle *virNetworkEventLifecyclePtr;
diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h
index f41f432..34cd902 100644
--- a/src/conf/object_event_private.h
+++ b/src/conf/object_event_private.h
@@ -73,7 +73,7 @@ struct _virObjectEvent {
virObject parent;
int eventID;
virObjectMeta meta;
-};
+}ATTRIBUTE_PACKED;
virClassPtr
virClassForObjectEvent(void);
--
1.7.9.5
10 years, 11 months
[libvirt] [PATCH] Bump version to 1.2.1 for new dev cycle
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Pushed per agreement at
https://www.redhat.com/archives/libvir-list/2013-December/msg00657.html
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 4465e01..bb92349 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library. If not, see
dnl <http://www.gnu.org/licenses/>.
-AC_INIT([libvirt], [1.2.0], [libvir-list(a)redhat.com], [], [http://libvirt.org])
+AC_INIT([libvirt], [1.2.1], [libvir-list(a)redhat.com], [], [http://libvirt.org])
AC_CONFIG_SRCDIR([src/libvirt.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
--
1.8.3.1
10 years, 11 months
[libvirt] [PATCH] Add missing % on %{_libdir} macro in RPM
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Pushed as build breaker fix
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
libvirt.spec.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 9b34f3f..e22c373 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1957,7 +1957,7 @@ exit 0
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
-{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
+%{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
%endif
%if %{with_lxc}
--
1.8.3.1
10 years, 11 months
[libvirt] [PATCH 1/1] Make virtio as the default net device for PPC64
by Pradipta Kr. Banerjee
From: "Pradipta Kr. Banerjee" <bpradip(a)in.ibm.com>
Make virtio as the default net device for PPC64
Signed-off-by: Pradipta Kr. Banerjee <bpradip(a)in.ibm.com>
---
src/qemu/qemu_domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e964c75..db36eff 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -790,7 +790,8 @@ static const char *
qemuDomainDefaultNetModel(const virDomainDef *def)
{
if (def->os.arch == VIR_ARCH_S390 ||
- def->os.arch == VIR_ARCH_S390X)
+ def->os.arch == VIR_ARCH_S390X ||
+ def->os.arch == VIR_ARCH_PPC64)
return "virtio";
if (def->os.arch == VIR_ARCH_ARMV7L) {
--
1.8.3.1
10 years, 11 months
[libvirt] [PATCH 0/3] Reflect changes in kernel 3.12 in our cgroups code
by Martin Kletzander
To see what changed in the kernel, see explanation in PATCH 1/3.
First two patches make proper use of VIR_DOMAIN_MEMORY_PARAM_UNLIMITED,
the third one just fixes a "typo".
Martin Kletzander (3):
cgroups: Redefine what "unlimited" means wrt memory limits
qemu: Report VIR_DOMAIN_MEMORY_PARAM_UNLIMITED properly
qemu: Fix minor inconsistency in error message
src/qemu/qemu_driver.c | 27 ++++++++++++------------
src/util/vircgroup.c | 57 ++++++++++++++++++++++++++++++++++----------------
2 files changed, 53 insertions(+), 31 deletions(-)
--
1.8.4.4
10 years, 11 months
[libvirt] [PATCH] Read PCI class from sysfs class file instead of config space.
by Thadeu Lima de Souza Cascardo
When determining if a device is behind a PCI bridge, the PCI device
class is checked by reading the config space. However, there are some
devices which have the wrong class on the config space, but the class is
initialized by Linux correctly as a PCI BRIDGE. This class can be read
by the sysfs file '/sys/bus/pci/devices/xxxx:xx:xx.x/class'.
One example of such bridge is IBM PCI Bridge 1014:03b9, which is
identified as a Host Bridge when reading the config space.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo(a)linux.vnet.ibm.com>
---
src/util/virpci.c | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 8ec642f..8353411 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -344,6 +344,34 @@ virPCIDeviceRead32(virPCIDevicePtr dev, int cfgfd, unsigned int pos)
}
static int
+virPCIDeviceReadClass(virPCIDevicePtr dev, uint16_t *device_class)
+{
+ char *path = NULL;
+ char *id_str;
+ int ret = 0;
+ unsigned int value;
+
+ if (virPCIFile(&path, dev->name, "class") < 0)
+ return -1;
+
+ /* class string is '0xNNNNNN\n' ... i.e. 9 bytes */
+ if (virFileReadAll(path, 9, &id_str) < 0) {
+ VIR_FREE(path);
+ return -1;
+ }
+
+ VIR_FREE(path);
+
+ id_str[8] = '\0';
+ ret = virStrToLong_ui(id_str, NULL, 16, &value);
+ if (ret == 0)
+ *device_class = (value >> 8) & 0xFFFF;
+
+ VIR_FREE(id_str);
+ return ret;
+}
+
+static int
virPCIDeviceWrite(virPCIDevicePtr dev,
int cfgfd,
unsigned int pos,
@@ -645,8 +673,8 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevicePtr check, void *data)
return 0;
/* Is it a bridge? */
- device_class = virPCIDeviceRead16(check, fd, PCI_CLASS_DEVICE);
- if (device_class != PCI_CLASS_BRIDGE_PCI)
+ ret = virPCIDeviceReadClass(check, &device_class);
+ if (ret == -1 || device_class != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
/* Is it a plane? */
@@ -2110,6 +2138,7 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
unsigned int pos;
int fd;
int ret = 0;
+ uint16_t device_class;
if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
return -1;
@@ -2119,8 +2148,11 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
goto cleanup;
}
+ if (virPCIDeviceReadClass(dev, &device_class))
+ goto cleanup;
+
pos = dev->pcie_cap_pos;
- if (!pos || virPCIDeviceRead16(dev, fd, PCI_CLASS_DEVICE) != PCI_CLASS_BRIDGE_PCI)
+ if (!pos || device_class != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
flags = virPCIDeviceRead16(dev, fd, pos + PCI_EXP_FLAGS);
--
1.7.1
10 years, 11 months
[libvirt] RFC: Changing version number at start of dev cycle instead of end
by Daniel P. Berrange
Currently throughout the dev cycle we stick on the current release
number. The release number in configure.ac is only changed by DV
when he is actually cutting the release.
With the python bindings now being split out, this is causing us
problems. The python code aims to build against any libvirt version
that exists, so for example, the new network events APIs in libvirt
will be included with version 1.2.1. So the python binding does
#if LIBVIR_CHECK_VERSION(1, 2, 1)
static void
libvirt_virConnectNetworkEventFreeFunc(void *opaque)
{
PyObject *pyobj_conn = (PyObject*)opaque;
LIBVIRT_ENSURE_THREAD_STATE;
Py_DECREF(pyobj_conn);
LIBVIRT_RELEASE_THREAD_STATE;
}
...
This works fine if a python release is built against a libvirt
release. It does not work if a python git snapshot is built
against a libvirt git snapshot. This is bad because it prevents
us doing automated builds of GIT.
The solution here is fairly simple. We should increase the version
number in configure.ac at the *start* of each release cycle. This
means that libvirt-python can use the next version number and things
will 'just work'. I don't think this is a burden really - we already
encode the next version number in our source code when tagging new
APIs or driver methods. We're really just bringing autoconf's view
of the version number inline with the rest of the code.
So if no one objects, we should immediately change configure.ac to
be 1.2.1
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
10 years, 11 months
[libvirt] [test-API][PATCH] Add new cases for testing setSchedulerParametersFlags related API
by Xuesong Zhang
---
cases/sched_params.conf | 120 +++++++++++++++++++++++++++++++
repos/domain/sched_params.py | 136 ++++++++++++++++-------------------
repos/domain/sched_params_flag.py | 148 ++++++++++++++++++++++++++++++++++++++
3 files changed, 330 insertions(+), 74 deletions(-)
create mode 100755 cases/sched_params.conf
create mode 100644 repos/domain/sched_params_flag.py
diff --git a/cases/sched_params.conf b/cases/sched_params.conf
new file mode 100755
index 0000000..6f7acce
--- /dev/null
+++ b/cases/sched_params.conf
@@ -0,0 +1,120 @@
+domain:install_linux_cdrom
+ guestname
+ $defaultname
+ guestos
+ $defaultos
+ guestarch
+ $defaultarch
+ vcpu
+ $defaultvcpu
+ memory
+ $defaultmem
+ hddriver
+ $defaulthd
+ nicdriver
+ $defaultnic
+ imageformat
+ qcow2
+
+domain:sched_params
+ guestname
+ $defaultname
+ vcpuquota
+ 1000
+ vcpuperiod
+ 200000
+ emulatorperiod
+ 300000
+ emulatorquota
+ 4000
+ cpushares
+ 5000
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1001
+ vcpuperiod
+ 200001
+ emulatorperiod
+ 300001
+ emulatorquota
+ 4001
+ cpushares
+ 5001
+ flag
+ current
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1002
+ vcpuperiod
+ 200002
+ emulatorperiod
+ 300002
+ emulatorquota
+ 4002
+ cpushares
+ 5002
+ flag
+ live
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1003
+ vcpuperiod
+ 200003
+ emulatorperiod
+ 300003
+ emulatorquota
+ 4003
+ cpushares
+ 5003
+ flag
+ config
+
+domain:destroy
+ guestname
+ $defaultname
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1004
+ vcpuperiod
+ 200004
+ emulatorperiod
+ 300004
+ emulatorquota
+ 4004
+ cpushares
+ 5004
+ flag
+ current
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1005
+ vcpuperiod
+ 200005
+ emulatorperiod
+ 300005
+ emulatorquota
+ 4005
+ cpushares
+ 5005
+ flag
+ config
+
+domain:undefine
+ guestname
+ $defaultname
+
diff --git a/repos/domain/sched_params.py b/repos/domain/sched_params.py
index 786e357..1be5986 100644
--- a/repos/domain/sched_params.py
+++ b/repos/domain/sched_params.py
@@ -1,95 +1,83 @@
#!/usr/bin/evn python
-# To test domain scheduler parameters
-
-import os
-import sys
-import time
-import commands
+# Set and show scheduler parameters
import libvirt
+from libvirt import libvirtError
from src import sharedmod
from utils import utils
-required_params = ('guestname', 'capshares',)
+import os
+
+required_params = ('guestname', 'vcpuquota', 'vcpuperiod', 'emulatorperiod', \
+ 'emulatorquota', 'cpushares',)
optional_params = {}
-def check_guest_status(domobj):
- """Check guest current status"""
- state = domobj.info()[0]
- if state == libvirt.VIR_DOMAIN_SHUTOFF or state == libvirt.VIR_DOMAIN_SHUTDOWN:
- domobj.create()
- time.sleep(30)
- # Add check function
- return True
+def check_sched_params(guestname, sched_params_after):
+ """Check scheduler parameters validity after setting
+ """
+
+ if os.path.exists("/cgroup"):
+ """ Add the judgment method, since the cgroup path is different on
+ rhel6 and rhel7.
+ if the folder cgroup is existed, it means the host os is rhel6,
+ if not existed, it means the the host of is rhel7
+ """
+
+ cgroup_path = "cat /cgroup/cpu/libvirt/qemu/%s/" % guestname
else:
- return True
-
-def check_sched_params(*args):
- """Check scheduler parameters validity after setting"""
- hypervisor, dicts, guestname, domobj = args
- sched_dict = {}
- if hypervisor == "xen":
- sched_dict = eval(commands.getoutput('xm sched-credit -d %s'
- % guestname))
- if sched_dict['weight'] == dicts['weight'] and \
- sched_dict['cap'] == dicts['cap']:
- return 0
- else:
+ cgroup_path = "cat /sys/fs/cgroup/cpu\,cpuacct/machine.slice/" \
+ "machine-qemu\\\\x2d%s.scope/" % guestname
+
+ sched_dicts = {'vcpu_quota': 'vcpu0/cpu.cfs_quota_us', \
+ 'vcpu_period': 'vcpu0/cpu.cfs_period_us', \
+ 'emulator_period': 'emulator/cpu.cfs_period_us', \
+ 'emulator_quota': 'emulator/cpu.cfs_quota_us', \
+ 'cpu_shares': 'cpu.shares'}
+
+ for sched_key in sched_dicts:
+ cmd = cgroup_path + sched_dicts[sched_key]
+ status, cmd_value = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to get ***%s*** value" % sched_key)
return 1
- if hypervisor == "kvm":
- sched_dict = domobj.schedulerParameters()
- if sched_dict['cpu_shares'] == dicts['cpu_shares']:
- return 0
- else:
+ sched_dicts[sched_key] = int(cmd_value[0])
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
return 1
+ logger.info("set scheduler parameters success")
+ return 0
+
def sched_params(params):
- """Setting scheduler parameters, argument params is a
- dictionary data type.which includes 'weight' and 'cap'
- keys, by assigning different value to 'weight' and 'cap'
- to verify validity of the result
+ """ Change and get the scheduler parameters
"""
- hypervisor = utils.get_hypervisor()
+ global logger
logger = params['logger']
guestname = params['guestname']
- conn = sharedmod.libvirtobj['conn']
-
- domobj = conn.lookupByName(guestname)
-
- if check_guest_status(domobj):
- sched_params = domobj.schedulerParameters()
- logger.info("original scheduler parameters: %s\n" % sched_params)
-
- if 'xen' in hypervisor:
- str_weight = params['weight']
- str_cap = params['cap']
- for wgt in eval(str_weight):
- for cap in eval(str_cap):
- dicts = {'weight': wgt, 'cap': cap}
- logger.info("setting scheduler parameters: %s" % dicts)
- domobj.setSchedulerParameters(dicts)
- sched_params = domobj.schedulerParameters()
- logger.info("current scheduler parameters: %s\n" % sched_params)
-
- retval = check_sched_params(hypervisor, dicts,
- guestname, domobj)
- if retval != 0:
- return 1
- elif 'kvm' in hypervisor:
- cpu_shares = int(params['cpushares'])
- dicts = {'cpu_shares': cpu_shares}
+ dicts = {'vcpu_quota': int(params['vcpuquota']), \
+ 'vcpu_period': int(params['vcpuperiod']), \
+ 'emulator_period': int(params['emulatorperiod']), \
+ 'emulator_quota': int(params['emulatorquota']), \
+ 'cpu_shares': int(params['cpushares'])}
+
+ try:
+ conn = sharedmod.libvirtobj['conn']
+ domobj = conn.lookupByName(guestname)
+
+ sched_type = str(domobj.schedulerType()[0])
+ logger.info("the scheduler type is: %s" % sched_type)
+ sched_params_original = domobj.schedulerParameters()
+ logger.info("original scheduler parameters: %s" % sched_params_original)
logger.info("setting scheduler parameters: %s" % dicts)
domobj.setSchedulerParameters(dicts)
- sched_params = domobj.schedulerParameters()
- logger.info("current scheduler parameters: %s\n" % sched_params)
- retval = check_sched_params(hypervisor, dicts,
- guestname, domobj)
- if retval != 0:
- return 1
- else:
- logger.error("unsupported hypervisor type: %s" % hypervisor)
- return 1
+ sched_params_after = domobj.schedulerParameters()
+ logger.info("current scheduler parameters: %s" % sched_params_after)
- return 0
+ ret = check_sched_params(guestname, sched_params_after)
+
+ return ret
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
diff --git a/repos/domain/sched_params_flag.py b/repos/domain/sched_params_flag.py
new file mode 100644
index 0000000..19bcb13
--- /dev/null
+++ b/repos/domain/sched_params_flag.py
@@ -0,0 +1,148 @@
+#!/usr/bin/evn python
+# Set and show scheduler parameters with flag, such as "--current", "--live"
+# and "--config"
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+from xml.dom import minidom
+import os
+
+required_params = ('guestname', 'vcpuquota', 'vcpuperiod', 'emulatorperiod', \
+ 'emulatorquota', 'cpushares', 'flag',)
+optional_params = {}
+
+def check_sched_params_flag(guestname, domobj, sched_params_after, domstate, \
+ flags_value):
+ """Check scheduler parameters validity after setting
+ """
+
+ if (domstate == 1) and ((flags_value == 0) or (flags_value == 1)):
+ """While the domain is running and the flag is "--live" or "--current",
+ the value can be checked with the cgroup value
+ As for the other condition, the value can be checked with the domain
+ config xml
+ """
+
+ if os.path.exists("/cgroup"):
+ """ Add the judgment method, since the cgroup path is different on
+ rhel6 and rhel7.
+ if the folder cgroup is existed, it means the host os is rhel6,
+ if not existed, it means the the host of is rhel7
+ """
+
+ cgroup_path = "cat /cgroup/cpu/libvirt/qemu/%s/" % guestname
+ else:
+ cgroup_path = "cat /sys/fs/cgroup/cpu\,cpuacct/machine.slice/" \
+ "machine-qemu\\\\x2d%s.scope/" % guestname
+
+ sched_dicts = {'vcpu_quota': 'vcpu0/cpu.cfs_quota_us', \
+ 'vcpu_period': 'vcpu0/cpu.cfs_period_us', \
+ 'emulator_period': 'emulator/cpu.cfs_period_us', \
+ 'emulator_quota': 'emulator/cpu.cfs_quota_us', \
+ 'cpu_shares': 'cpu.shares'}
+
+ for sched_key in sched_dicts:
+ cmd = cgroup_path + sched_dicts[sched_key]
+ status, cmd_value = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to get ***%s*** value" % sched_key)
+ return 1
+ sched_dicts[sched_key] = int(cmd_value[0])
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
+ return 1
+
+ else:
+ guestxml = domobj.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
+ logger.debug("domain %s config xml :\n%s" % (domobj.name(), guestxml))
+
+ xmlrootnode = minidom.parseString(guestxml)
+
+ sched_dicts = {'vcpu_quota': 'quota', 'vcpu_period': 'period', \
+ 'emulator_period': 'emulator_period', \
+ 'emulator_quota': 'emulator_quota', \
+ 'cpu_shares': 'shares'}
+
+ for sched_key in sched_dicts:
+ node = xmlrootnode.getElementsByTagName(sched_dicts[sched_key])[0]
+ sched_dicts[sched_key] = int(node.childNodes[0].data)
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
+ return 1
+
+ logger.info("set scheduler parameters success")
+ return 0
+
+def sched_params_flag(params):
+ """ Change and get the scheduler parameters
+ """
+
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ dicts = {'vcpu_quota': int(params['vcpuquota']), \
+ 'vcpu_period': int(params['vcpuperiod']), \
+ 'emulator_period': int(params['emulatorperiod']), \
+ 'emulator_quota': int(params['emulatorquota']), \
+ 'cpu_shares': int(params['cpushares'])}
+ flags = params['flag']
+
+ try:
+ conn = sharedmod.libvirtobj['conn']
+ domobj = conn.lookupByName(guestname)
+
+ domstate = domobj.state(0)[0]
+ """following is the domain state:
+ '1' is running status
+ '5' is shutoff status
+ please see the following reference link:
+ http://libvirt.org/html/libvirt-libvirt.html#virDomainState
+ """
+ if domstate == 1:
+ logger.info("the state of virtual machine is ***running***")
+ elif domstate == 5:
+ logger.info("the state of virtual machine is ***shutoff***")
+ else:
+ logger.error("the state of virtual machine is not running or " \
+ "shutoff now, it is out of the check range of this " \
+ "script. Please check the domain status.")
+ return 1
+
+ """virDomainModificationImpact
+ VIR_DOMAIN_AFFECT_CURRENT = 0
+ VIR_DOMAIN_AFFECT_LIVE = 1
+ VIR_DOMAIN_AFFECT_CONFIG = 2
+ """
+
+ if flags == "current":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_CURRENT
+ elif flags == "live":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_LIVE
+ elif flags == "config":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_CONFIG
+ else:
+ logger.error("the value of flags is not correct, please check " \
+ "the conf file")
+ return 1
+
+ sched_type = str(domobj.schedulerType()[0])
+ logger.info("the scheduler type is: %s" % sched_type)
+ sched_params_original = domobj.schedulerParametersFlags(flags_value)
+ logger.info("original scheduler parameters with flag ***%s***: %s" % \
+ (flags, sched_params_original))
+ logger.info("setting scheduler parameters: %s" % dicts)
+ domobj.setSchedulerParametersFlags(dicts, flags_value)
+ sched_params_after = domobj.schedulerParametersFlags(flags_value)
+ logger.info("current scheduler parameters with flag ***%s***: %s" % \
+ (flags, sched_params_after))
+
+ ret = check_sched_params_flag(guestname, domobj, sched_params_after, \
+ domstate, flags_value)
+
+ return ret
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
--
1.8.3.1
10 years, 11 months
[libvirt] [test-API][PATCH] Add new case for listAllVolumes and update releated conf
by codong
listAllVolumes is a new API in RHEL7, so add a new case for it.
And add the case to releated conf to check the volumes list.
modified: cases/storage_dir.conf
modified: cases/storage_dir_vol_resize_delta.conf
modified: cases/storage_logical.conf
modified: cases/storage_netfs.conf
new file: repos/storage/list_volumes.py
---
cases/storage_dir.conf | 16 +++++
cases/storage_dir_vol_resize_delta.conf | 8 +++
cases/storage_logical.conf | 16 +++++
cases/storage_netfs.conf | 16 +++++
repos/storage/list_volumes.py | 97 +++++++++++++++++++++++++++++++
5 files changed, 153 insertions(+), 0 deletions(-)
create mode 100644 repos/storage/list_volumes.py
diff --git a/cases/storage_dir.conf b/cases/storage_dir.conf
index 38b349d..393d34f 100644
--- a/cases/storage_dir.conf
+++ b/cases/storage_dir.conf
@@ -20,6 +20,10 @@ storage:create_dir_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -28,18 +32,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_dir_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_dir_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_dir_vol_resize_delta.conf b/cases/storage_dir_vol_resize_delta.conf
index 58e15bf..22d3b47 100644
--- a/cases/storage_dir_vol_resize_delta.conf
+++ b/cases/storage_dir_vol_resize_delta.conf
@@ -12,6 +12,10 @@ storage:create_dir_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_resize_delta
poolname
$defaultpoolname
@@ -42,6 +46,10 @@ storage:delete_dir_volume
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_logical.conf b/cases/storage_logical.conf
index d374dfa..a0fdad6 100644
--- a/cases/storage_logical.conf
+++ b/cases/storage_logical.conf
@@ -22,6 +22,10 @@ storage:create_logical_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -30,18 +34,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_logical_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_logical_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_netfs.conf b/cases/storage_netfs.conf
index f486ff4..6880763 100644
--- a/cases/storage_netfs.conf
+++ b/cases/storage_netfs.conf
@@ -24,6 +24,10 @@ storage:create_netfs_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -32,18 +36,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_netfs_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_netfs_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/repos/storage/list_volumes.py b/repos/storage/list_volumes.py
new file mode 100644
index 0000000..9555720
--- /dev/null
+++ b/repos/storage/list_volumes.py
@@ -0,0 +1,97 @@
+#!/usr/bin/evn python
+
+import libvirt
+from libvirt import libvirtError
+from xml.dom import minidom
+
+from utils import utils
+
+from src import sharedmod
+
+required_params = ('poolname',)
+optional_params = {}
+
+
+def get_pool_path(pool_obj):
+ """
+ Get the pool path
+ """
+ poolxml = pool_obj.XMLDesc(0)
+ logger.debug("the xml description of pool is %s" % poolxml)
+
+ doc = minidom.parseString(poolxml)
+ path_element = doc.getElementsByTagName('path')[0]
+ textnode = path_element.childNodes[0]
+ path_value = textnode.data
+
+ return path_value
+
+
+def check_list_volumes(pool_obj, vol_name_list):
+ """
+ Check the result of listAllVolumes
+ """
+
+ vol_poolobj_list = pool_obj.listVolumes()
+ logger.debug("get volumes from listVolumes is %s" % vol_poolobj_list)
+
+ poolpath = get_pool_path(pool_obj)
+ logger.info("the pool path is %s" % poolpath)
+ vol_ls_cmd = "ls -a " + poolpath
+
+ (status, vol_cmd_list) = utils.exec_cmd(vol_ls_cmd, shell=True)
+ if status:
+ logger.error("Executing " + vol_ls_cmd + " failed")
+ logger.error(vol_ls_cmd)
+ return False
+ else:
+ logger.debug("get volumes from poolpath is %s" % vol_cmd_list)
+ logger.info("compare the volume list under poolpath and list from API")
+ vol_cmd_list = vol_cmd_list[2:]
+ vol_name_list.sort()
+ vol_poolobj_list.sort()
+ vol_cmd_list.sort()
+ if (cmp(vol_poolobj_list, vol_name_list) == 0) and \
+ (cmp(vol_name_list, vol_cmd_list) == 0):
+
+ return True
+ else:
+ return False
+
+
+def list_volumes(params):
+ """List all the volumes of a storage pool
+ """
+ global logger
+ logger = params['logger']
+ poolname = params['poolname']
+ vol_name_list = []
+
+ logger.info("the poolname is %s" % (poolname))
+ conn = sharedmod.libvirtobj['conn']
+ storage_pool_list = conn.listStoragePools()
+
+ if poolname not in storage_pool_list:
+ logger.error("pool %s doesn't exist or not running" % poolname)
+ return 1
+
+ pool_obj = conn.storagePoolLookupByName(poolname)
+
+ try:
+ vol_obj_list = pool_obj.listAllVolumes()
+ for vol_obj in vol_obj_list:
+ vol_name_list.append(vol_obj.name())
+ logger.info("the volume list is %s" % vol_name_list)
+
+ if check_list_volumes(pool_obj, vol_name_list):
+ logger.info("get the right volumes list successfully")
+ else:
+ logger.error("fail to get the right volumes list")
+ return 1
+
+ except libvirtError as e:
+ logger.error("API error message: %s, error code is %s"
+ % (e.message, e.get_error_code()))
+ return 1
+
+ return 0
--
1.7.1
10 years, 11 months