[libvirt] [PATCH V9 0/6] Add DHCP snooping support to nwfilter
by Stefan Berger
This series of patches adds DHCP snooping support to libvirt's
nwfilter subsystem.
DHCP snooping detects DHCP leases obtained by a VM and automatically
adjusts the network traffic filters to reflect the IP addresses
with which a VM may send its traffic, thus for example preventing
IP address spoofing.
Once leases on IP addresses expire or if a VM gives up on a
lease on an IP address, the filters are also adjusted.
All leases are persisted and automatically applied upon a VM's restart.
Leases are associated with the tuple of VM-UUID and interface MAC
address.
The following interface XML activates and uses the DHCP snooping:
<interface type='bridge'>
<source bridge='virbr0'/>
<filterref filter='clean-traffic'>
<parameter name='ip_learning' value='dhcp'/>
</filterref>
</interface>
Regards,
David and Stefan
12 years, 7 months
Re: [libvirt] Start of freeze for libvirt-0.9.11 and availability of rc1
by Philipp Hahn
Hello Guido,
Am Freitag 13 April 2012 15:10:49 schrieb Guido Günther:
> könntest Du das als richtigen Patch schicken, dann apply ich das.
[Guido asks me to send a full patch, so he can apply it.]
Sure, see the attached patch.
Sincerely
Philipp
--
Philipp Hahn Open Source Software Engineer hahn(a)univention.de
Univention GmbH be open. fon: +49 421 22 232- 0
Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99
http://www.univention.de/
12 years, 7 months
[libvirt] [PATCH] blockjob: add virsh blockjob --wait
by Eric Blake
I'm tired of shell-scripting to wait for completion of a block pull,
when virsh can be taught to do the same. I couldn't quite reuse
vshWatchJob, as this is not a case of a long-running command where
a second thread must be used to probe job status (at least, not unless
I make virsh start doing blocking waits for an event to fire), but it
served as inspiration for my simpler single-threaded loop. There is
up to a half-second delay between sending SIGINT and the job being
aborted, but I didn't think it worth the complexity of a second thread
and use of poll() just to minimize that delay.
* tools/virsh.c (cmdBlockPull): Add new options to wait for
completion.
(blockJobImpl): Add argument.
(cmdBlockJob): Adjust caller.
* tools/virsh.pod (blockjob): Document new mode.
---
tools/virsh.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++-----
tools/virsh.pod | 11 ++++-
2 files changed, 119 insertions(+), 14 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 8ef57e0..c54add9 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7274,11 +7274,11 @@ repoll:
if (pollfd.revents & POLLIN &&
saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 &&
retchar == '0') {
- if (verbose) {
- /* print [100 %] */
- print_job_progress(label, 0, 1);
- }
- break;
+ if (verbose) {
+ /* print [100 %] */
+ print_job_progress(label, 0, 1);
+ }
+ break;
}
goto cleanup;
}
@@ -7295,8 +7295,9 @@ repoll:
}
GETTIMEOFDAY(&curr);
- if ( timeout && ((int)(curr.tv_sec - start.tv_sec) * 1000 + \
- (int)(curr.tv_usec - start.tv_usec) / 1000) > timeout * 1000 ) {
+ if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 +
+ (int)(curr.tv_usec - start.tv_usec) / 1000) >
+ timeout * 1000)) {
/* suspend the domain when migration timeouts. */
vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label);
if (timeout_func)
@@ -7519,7 +7520,8 @@ typedef enum {
static int
blockJobImpl(vshControl *ctl, const vshCmd *cmd,
- virDomainBlockJobInfoPtr info, int mode)
+ virDomainBlockJobInfoPtr info, int mode,
+ virDomainPtr *pdom)
{
virDomainPtr dom = NULL;
const char *name, *path;
@@ -7560,7 +7562,9 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
}
cleanup:
- if (dom)
+ if (pdom && ret == 0)
+ *pdom = dom;
+ else if (dom)
virDomainFree(dom);
return ret;
}
@@ -7580,15 +7584,109 @@ static const vshCmdOptDef opts_block_pull[] = {
{"bandwidth", VSH_OT_DATA, VSH_OFLAG_NONE, N_("Bandwidth limit in MB/s")},
{"base", VSH_OT_DATA, VSH_OFLAG_NONE,
N_("path of backing file in chain for a partial pull")},
+ {"wait", VSH_OT_BOOL, 0, N_("wait for job to finish")},
+ {"verbose", VSH_OT_BOOL, 0, N_("with --wait, display the progress")},
+ {"timeout", VSH_OT_INT, VSH_OFLAG_NONE,
+ N_("with --wait, abort if pull exceeds timeout (in seconds)")},
{NULL, 0, 0, NULL}
};
static bool
cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
{
- if (blockJobImpl(ctl, cmd, NULL, VSH_CMD_BLOCK_JOB_PULL) != 0)
+ virDomainPtr dom = NULL;
+ bool ret = false;
+ bool blocking = vshCommandOptBool(cmd, "wait");
+ bool verbose = vshCommandOptBool(cmd, "verbose");
+ int timeout = 0;
+ struct sigaction sig_action;
+ struct sigaction old_sig_action;
+ sigset_t sigmask;
+ struct timeval start;
+ struct timeval curr;
+ const char *path = NULL;
+ bool quit = false;
+
+ if (blocking) {
+ if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) {
+ if (timeout < 1) {
+ vshError(ctl, "%s", _("migrate: Invalid timeout"));
+ return false;
+ }
+
+ /* Ensure that we can multiply by 1000 without overflowing. */
+ if (timeout > INT_MAX / 1000) {
+ vshError(ctl, "%s", _("migrate: Timeout is too big"));
+ return false;
+ }
+ }
+ if (vshCommandOptString(cmd, "path", &path) < 0)
+ return false;
+
+ sigemptyset(&sigmask);
+ sigaddset(&sigmask, SIGINT);
+
+ intCaught = 0;
+ sig_action.sa_sigaction = vshCatchInt;
+ sigemptyset(&sig_action.sa_mask);
+ sigaction(SIGINT, &sig_action, &old_sig_action);
+
+ GETTIMEOFDAY(&start);
+ } else if (verbose || vshCommandOptBool(cmd, "timeout")) {
+ vshError(ctl, "%s", _("blocking control options require --wait"));
return false;
- return true;
+ }
+
+ if (blockJobImpl(ctl, cmd, NULL, VSH_CMD_BLOCK_JOB_PULL,
+ blocking ? &dom : NULL) != 0)
+ goto cleanup;
+
+ while (blocking) {
+ virDomainBlockJobInfo info;
+ int result = virDomainGetBlockJobInfo(dom, path, &info, 0);
+
+ if (result < 0) {
+ vshError(ctl, _("failed to query job for disk %s"), path);
+ goto cleanup;
+ }
+ if (result == 0)
+ break;
+
+ if (verbose)
+ print_job_progress(_("Block Pull"), info.end - info.cur, info.end);
+
+ GETTIMEOFDAY(&curr);
+ if (intCaught || (timeout &&
+ (((int)(curr.tv_sec - start.tv_sec) * 1000 +
+ (int)(curr.tv_usec - start.tv_usec) / 1000) >
+ timeout * 1000))) {
+ vshDebug(ctl, VSH_ERR_DEBUG,
+ intCaught ? "interrupted" : "timeout");
+ intCaught = 0;
+ timeout = 0;
+ quit = true;
+ if (virDomainBlockJobAbort(dom, path, 0) < 0) {
+ vshError(ctl, _("failed to abort job for disk %s"), path);
+ goto cleanup;
+ }
+ }
+
+ usleep(500 * 1000);
+ }
+
+ if (verbose && !quit) {
+ /* printf [100 %] */
+ print_job_progress(_("Block Pull"), 0, 1);
+ }
+ vshPrint(ctl, "\n%s\n", quit ? _("Pull aborted") : _("Pull complete"));
+
+ ret = true;
+cleanup:
+ if (dom)
+ virDomainFree(dom);
+ if (blocking)
+ sigaction(SIGINT, &old_sig_action, NULL);
+ return ret;
}
/*
@@ -7639,7 +7737,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
else
mode = VSH_CMD_BLOCK_JOB_INFO;
- ret = blockJobImpl(ctl, cmd, &info, mode);
+ ret = blockJobImpl(ctl, cmd, &info, mode, NULL);
if (ret < 0)
return false;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 5f3d9b1..fbc34f1 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -640,6 +640,7 @@ address of virtual interface (such as I<detach-interface> or
I<domif-setlink>) will accept the MAC address printed by this command.
=item B<blockpull> I<domain> I<path> [I<bandwidth>] [I<base>]
+[I<--wait> [I<--verbose>] [I<--timeout> B<seconds>]]
Populate a disk from its backing image chain. By default, this command
flattens the entire chain; but if I<base> is specified, containing the
@@ -647,8 +648,14 @@ name of one of the backing files in the chain, then that file becomes
the new backing file and only the intermediate portion of the chain is
pulled. Once all requested data from the backing image chain has been
pulled, the disk no longer depends on that portion of the backing chain.
-It pulls data for the entire disk in the background, the process of the
-operation can be checked with B<blockjob>.
+
+By default, this command returns as soon as possible, and data for
+the entire disk is pulled in the background; the process of the
+operation can be checked with B<blockjob>. However, if I<--wait> is
+specified, then this command will block until the operation completes,
+or cancel the operation if the optional I<timeout> in seconds elapses
+or SIGINT is sent (usually with C<Ctrl-C>). Using I<--verbose> along
+with I<--wait> will produce periodic status updates.
I<path> specifies fully-qualified path of the disk; it corresponds
to a unique target name (<target dev='name'/>) or source file (<source
--
1.7.7.6
12 years, 7 months
[libvirt] ANNOUNCE: Release of libvirt-sandbox version 0.0.3
by Daniel P. Berrange
I pleased to announce the a new public release of libvirt-sandbox,
version 0.0.3, is now available for download
ftp://libvirt.org/libvirt/sandbox/
The packages are GPG signed with
Key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF (4096R)
The libvirt-sandbox package provides an API layer on top of libvirt-gobject
which facilitates the cration of application sandboxes using virtualization
technology. An application sandbox is a virtual machine or container that
runs a single application binary, directly from the host OS filesystem.
In other words there is no separate guest operating system install to build
or manager.
At this point in time libvirt-sandbox can create sandboxes using either LXC
or KVM, and should in theory be extendable to any libvirt driver. The first
release is able to run simple command line based programs. This release has
focused on making the sandbox infrastructure more reliable and expanding
the functionality available. Dan Walsh has also contributed a new tool called
virt-sandbox-service which facilitates the creation of sandboxes for running
system services like apache.
- Ensure root/config filesystems are readonly in KVM
- Add support for mounting host disk images in guests
- Add support for binding guest filesystems to new locations
- Add support for an optional interactive shell for debugging
or administrative purposes
- Add a virt-sandbox-service script for preparing sandboxes
for system services, integrating with systemd
- Misc compiler warning fixes
- Replace invocation of insmod with direct syscalls
- Refactor API to separate interactive sandbox functionality
from base class & service sandbox functionality
- Rewrite host/guest I/O handling to separate stdout from
stderr correctly, improve reliability of startup/shutdown
handshakes and propagate exit status back to host
- Exec away the first hypervisor specific init process,
so generic init process get PID 1
- Turn on reboot-on-panic in KVM to ensure guest exists on
fatal problems
Some examples
$ virt-sandbox -c qemu:///session /bin/date
Thu Jan 12 22:30:03 GMT 2012
$ virt-sandbox -c qemu:///session /bin/cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 2
model name : QEMU Virtual CPU version 1.0
stepping : 3
cpu MHz : 2793.084
cache size : 4096 KB
fpu : yes
fpu_exception : yes
cpuid level : 4
wp : yes
flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pse36 clflush mmx fxsr sse sse2 syscall nx lm up rep_good nopl
+pni cx16 hypervisor lahf_lm
bogomips : 5586.16
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
$ virt-sandbox -c lxc:/// /bin/sh
sh-4.2$ ps -axuwf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
berrange 1 0.0 0.1 167680 4688 pts/0 S+ 22:31 0:00 libvirt-sandbox-init-common
berrange 47 0.0 0.0 13852 1608 pts/1 Ss 22:31 0:00 \_ /bin/sh
berrange 48 0.0 0.0 13124 996 pts/1 R+ 22:31 0:00 \_ ps -axuwf
Feedback / patches / etc should be directed to the main libvirt
development mailing list.
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 :|
12 years, 7 months
[libvirt] [libvirt-glib] Getter/setter for disk source's startupPolicy attribute
by Zeeshan Ali (Khattak)
From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
---
libvirt-gconfig/libvirt-gconfig-domain-disk.c | 26 +++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-disk.h | 9 ++++++++
libvirt-gconfig/libvirt-gconfig.sym | 5 +++-
libvirt-gconfig/tests/test-domain-create.c | 2 +
4 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index 5d0acb5..a29ea47 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -127,6 +127,18 @@ void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk,
type, NULL);
}
+void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskStartupPolicy policy)
+{
+ const char *str;
+
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
+ str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_DISK_STARTUP_POLICY, policy);
+ g_return_if_fail(str != NULL);
+ gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
+ "source", "startupPolicy", str);
+}
+
void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
const char *source)
{
@@ -235,6 +247,19 @@ gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk)
GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO);
}
+GVirConfigDomainDiskStartupPolicy
+gvir_config_domain_disk_get_startup_policy(GVirConfigDomainDisk *disk)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk),
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY);
+
+ return gvir_config_object_get_attribute_genum
+ (GVIR_CONFIG_OBJECT(disk),
+ "source", "startupPolicy",
+ GVIR_CONFIG_TYPE_DOMAIN_DISK_STARTUP_POLICY,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY);
+}
+
const char *
gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk)
{
@@ -291,6 +316,7 @@ gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk)
GVIR_CONFIG_TYPE_DOMAIN_DISK_CACHE_TYPE,
GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT);
}
+
GVirConfigDomainDiskBus
gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk)
{
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
index 916421d..7e85d75 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
@@ -95,6 +95,12 @@ typedef enum {
GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_EXTERNAL
} GVirConfigDomainDiskSnapshotType;
+typedef enum {
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_OPTIONAL
+} GVirConfigDomainDiskStartupPolicy;
+
GType gvir_config_domain_disk_get_type(void);
GVirConfigDomainDisk *gvir_config_domain_disk_new(void);
@@ -107,6 +113,8 @@ void gvir_config_domain_disk_set_guest_device_type(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskGuestDeviceType type);
void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskSnapshotType type);
+void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskStartupPolicy policy);
void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
const char *source);
void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk,
@@ -123,6 +131,7 @@ void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskType gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskGuestDeviceType gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskSnapshotType gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskStartupPolicy gvir_config_domain_disk_get_startup_policy(GVirConfigDomainDisk *disk);
const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk);
const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 2378a3c..8dac83a 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -1,4 +1,4 @@
-LIBVIRT_GCONFIG_0.0.7 {
+LIBVIRT_GCONFIG_0.0.8 {
global:
gvir_config_init_check;
gvir_config_init;
@@ -76,6 +76,7 @@ LIBVIRT_GCONFIG_0.0.7 {
gvir_config_domain_disk_cache_type_get_type;
gvir_config_domain_disk_guest_device_type_get_type;
gvir_config_domain_disk_snapshot_type_get_type;
+ gvir_config_domain_disk_startup_policy_get_type;
gvir_config_domain_disk_type_get_type;
gvir_config_domain_disk_new;
gvir_config_domain_disk_new_from_xml;
@@ -91,6 +92,8 @@ LIBVIRT_GCONFIG_0.0.7 {
gvir_config_domain_disk_set_snapshot_type;
gvir_config_domain_disk_get_source;
gvir_config_domain_disk_set_source;
+ gvir_config_domain_disk_get_startup_policy;
+ gvir_config_domain_disk_set_startup_policy;
gvir_config_domain_disk_get_target_bus;
gvir_config_domain_disk_set_target_bus;
gvir_config_domain_disk_get_target_dev;
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index 4ee33aa..3d7efdc 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -106,6 +106,7 @@ int main(int argc, char **argv)
gvir_config_domain_disk_set_type(disk, GVIR_CONFIG_DOMAIN_DISK_FILE);
gvir_config_domain_disk_set_guest_device_type(disk, GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK);
gvir_config_domain_disk_set_source(disk, "/tmp/foo/bar");
+ gvir_config_domain_disk_set_startup_policy (disk, GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE);
gvir_config_domain_disk_set_driver_name(disk, "foo");
gvir_config_domain_disk_set_driver_type(disk, "bar");
gvir_config_domain_disk_set_driver_name(disk, "qemu");
@@ -117,6 +118,7 @@ int main(int argc, char **argv)
g_assert(gvir_config_domain_disk_get_disk_type(disk) == GVIR_CONFIG_DOMAIN_DISK_FILE);
g_assert(gvir_config_domain_disk_get_guest_device_type(disk) == GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK);
+ g_assert(gvir_config_domain_disk_get_startup_policy (disk) == GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE);
g_str_const_check(gvir_config_domain_disk_get_source(disk), "/tmp/foo/bar");
g_assert(gvir_config_domain_disk_get_driver_cache(disk) == GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE);
g_str_const_check(gvir_config_domain_disk_get_driver_name(disk), "qemu");
--
1.7.7.6
12 years, 7 months
[libvirt] [test-API PATCH 1/2] casecfgcheck: ignore flags defined in testcase flag
by Guannan Ren
When flag defined in testcase config file like as follows
the casecfgcheck still trys to use flag 'clean' or 'sleep' as
the key to get required_params, optional_params variables.
so it reports 'KeyError' becuase no testcases named 'clean'
or 'sleep' in case_params data format. The patch ignore
the check for these flags.
domain:start
guestname
fedora16
clean
domain:shutdown
guestname
fedora16
sleep 6
domain:destroy
guestname
fedora16
---
casecfgcheck.py | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/casecfgcheck.py b/casecfgcheck.py
index a88eb74..40d7c6e 100644
--- a/casecfgcheck.py
+++ b/casecfgcheck.py
@@ -33,14 +33,18 @@ class CaseCfgCheck(object):
error_flag = 0
passed_testcase = []
for testcase in self.activity:
- case_number += 1
if testcase in passed_testcase:
continue
testcase_name = testcase.keys()[0]
- actual_params = testcase.values()[0]
+ if testcase_name == 'clean' or \
+ testcase_name == 'sleep':
+ continue
+ actual_params = testcase.values()[0]
required_params, optional_params = self.case_params[testcase_name]
+
+ case_number += 1
ret = self._check_params(required_params, optional_params, actual_params)
if ret:
error_flag = 1
--
1.7.7.5
12 years, 7 months
[libvirt] [test-API PATCH] repo: Add test for console input and output operations
by Peter Krempa
This test checks if the console input and output work as desired. The
test takes as an argument a filename, whose contents are sent to the
console. The optional parameter 'expect' can be set to a filename that
should contain expected output from the guest and is compared with the
actual output. The optional parameter 'output' can be set to a filename
where the test script saves the output of the host (useful for initial
test setup).
This test requires that the guest machine runs code that handles input and
output on the serial console (programs such as agetty or something like that).
---
repos/domain/console_io.py | 123 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
create mode 100644 repos/domain/console_io.py
diff --git a/repos/domain/console_io.py b/repos/domain/console_io.py
new file mode 100644
index 0000000..98fd5b6
--- /dev/null
+++ b/repos/domain/console_io.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+# test console interactions
+# This test sends contents of file 'input' to the guest's console
+# and reads from the console the reply and compares it to 'expect' or
+# writes the output to file 'output'
+
+import libvirt
+import signal
+import os
+
+from libvirt import libvirtError
+from exception import TestError
+
+required_params = ('guestname',)
+optional_params = ('device', 'timeout', 'input', 'output', 'expect',)
+
+def alarm_handler(signum, frame):
+ raise TestError("Timed out while waiting for console")
+
+def console_io(params):
+ """Attach to console"""
+ logger = params['logger']
+ guest = params['guestname']
+ device = params.get('device', 'serial0')
+ infile = params.get('input', None)
+ outfile = params.get('output', None)
+ expect = params.get('expect', None)
+ timeout = params.get('timeout', 5)
+
+ uri = params['uri']
+
+ #store the old signal handler
+ oldhandler = signal.getsignal(signal.SIGALRM)
+
+ try:
+ logger.info("Connecting to hypervisor: '%s'" % uri)
+ conn = libvirt.open(uri)
+ dom = conn.lookupByName(guest)
+ if not dom.isActive():
+ raise TestError("Guest '%s' not active" % guest)
+
+ logger.info("Creating stream object")
+ stream = conn.newStream(0)
+
+ logger.info("Open a new console connection")
+ dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE)
+
+ if infile != None:
+ try:
+ f = open(infile, 'r')
+ instr = f.read()
+ f.close()
+ except e:
+ raise TestError("Can't read input file '%s': %s" % (infile, str(e)))
+
+ logger.info("Sending %d bytes of contents of file '%s' to console '%s'" % (len(instr), infile, device))
+ stream.send(instr)
+
+ if expect != None or outfile != None:
+ logger.info("Recieving data from console device. Timeout %d seconds." % timeout)
+
+ # register a new signal handler
+ logger.info("Registering custom SIGALRM handler")
+ signal.signal(signal.SIGALRM, alarm_handler)
+ signal.alarm(timeout)
+
+ reply = ""
+ try:
+ while True:
+ recv = stream.recv(1024)
+ reply += recv
+ except TestError:
+ pass
+
+ logger.info("Recieved %d bytes." % len(reply))
+
+ if outfile != None:
+ try:
+ f = open(outfile, 'w')
+ f.write(reply)
+ f.close()
+ except e:
+ raise TestError("Can't write output to file '%s': %s" % (outfile, str(e)))
+
+ if expect != None:
+ try:
+ f = open(expect, 'r')
+ expectstr = f.read()
+ f.close()
+ except Exception, e:
+ raise TestError("Can't read expected output file '%s': '%s'" % (expect, str(e)))
+
+ if reply.startswith(expectstr):
+ logger.info("Recieved expected output from the host")
+ else:
+ raise TestError("Reply from the guest doesn't match with expected reply")
+
+ 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("Restoring signal handler")
+ signal.signal(signal.SIGALRM, oldhandler)
+ logger.info("Closing hypervisor connection")
+ try:
+ stream.abort()
+ except:
+ pass
+ conn.close()
+
+ logger.info("Done")
+
+ return ret
+
--
1.7.3.4
12 years, 7 months
[libvirt] [test-API PATCH 0/4]Add feature to check case file before running
by Guannan Ren
The set of patches add a new feature to examine testcase config file
before running it. The framework will do the job on behalf of testcase,
so test writer will release from the work.
Usage:
In testcase, it only needs to define two global tuple variables
required_params are the mandatory options to the testcase
optional_params are the optional options
...
required_params = ('networkname', 'autostart')
optional_params = ('optparams1', 'optparas2')
def testcase(params):
...
Checking results:
on success, it will run these testcases defined in testcase config file
on error-detected, error as follows
Unknown parameter 'whoami'
the No.2 : domain:testb
Parameter autostart is required
the No.5 : domain:testa
The idea and part of code in patches is from Osier:)
12 years, 7 months
[libvirt] Start of freeze for libvirt-0.9.11 and availability of rc1
by Daniel Veillard
As scheduled, we are entering the freeze for 0.9.11.
I think most API additions are now commited to git upstream (please
raise your voice quickly if you see something missing !)
I have made a release candidate 1 tarball (and associated rpms) at
ftp://libvirt.org/libvirt/libvirt-0.9.11-rc1.tar.gz
and the git tree is tagged.
I think I will make an release candidate 2 tarball on Wednesday, and
I'm hoping for a final release on Friday, or maybe Monday if there are
issues found.
Please give it a try ! Stability and portability feedback are really
welcome as we didn't had a release in Feb and the risk of having
something messed up is slightly higher than usual !
thanks in advance,
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
12 years, 7 months
[libvirt] [PATCH 0/3] Couple of cleanups in qemu code
by Michal Privoznik
Michal Privoznik (3):
qemu: Fix mem leak in qemuProcessInitCpuAffinity
gitignore: Reorder alphabetically
qemu: Split if condition in qemuDomainSnapshotUndoSingleDiskActive
.gitignore | 6 +++---
src/qemu/qemu_driver.c | 9 +++++++--
src/qemu/qemu_process.c | 23 +++++++++++++----------
3 files changed, 23 insertions(+), 15 deletions(-)
--
1.7.8.5
12 years, 7 months