[libvirt] [PATCH] tests: detect gnutls errors
by Eric Blake
* tests/virnettlscontexttest.c (testTLSLoadKey): Report errors.
---
Something in gnutls 2.8.5 (RHEL 6) was more leniant than gnutls
2.8.6 (Fedora 14). This still doesn't solve the failure, but at
least gets us to see that newer gnutls_x509_privkey_import doesn't
like our define of PRIVATE_KEY.
tests/virnettlscontexttest.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index e70cd8b..043ccc2 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -410,10 +410,18 @@ static gnutls_x509_privkey_t testTLSLoadKey(void)
{
gnutls_x509_privkey_t key;
const gnutls_datum_t data = { (unsigned char *)PRIVATE_KEY, strlen(PRIVATE_KEY) };
+ int err;
- gnutls_x509_privkey_init(&key);
+ if ((err = gnutls_x509_privkey_init(&key)) < 0) {
+ VIR_WARN("Failed to init key %s", gnutls_strerror(err));
+ abort();
+ }
- gnutls_x509_privkey_import(key, &data, GNUTLS_X509_FMT_PEM);
+ if ((err = gnutls_x509_privkey_import(key, &data,
+ GNUTLS_X509_FMT_PEM)) < 0) {
+ VIR_WARN("Failed to init key %s", gnutls_strerror(err));
+ abort();
+ }
return key;
}
--
1.7.4.4
13 years, 4 months
[libvirt] [PATCH] rename cfs_* to vcpu_*
by Wen Congyang
In the XML file we now have
<cputune>
<shares>1024</shares>
<period>90000</period>
<quota>0</quota>
</cputune>
But the schedinfo parameter are being named
cpu_shares: 1024
cfs_period: 90000
cfs_quota: 0
The period/quota is per-vcpu value, so these new tunables should be named
'vcpu_period' and 'vcpu_quota'.
---
src/qemu/qemu_driver.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52e5d69..9cae318 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6243,10 +6243,10 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vmdef->cputune.shares = params[i].value.ul;
}
- } else if (STREQ(param->field, "cfs_period")) {
+ } else if (STREQ(param->field, "vcpu_period")) {
if (param->type != VIR_TYPED_PARAM_ULLONG) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
- _("invalid type for cfs_period tunable,"
+ _("invalid type for vcpu_period tunable,"
" expected a 'ullong'"));
goto cleanup;
}
@@ -6263,10 +6263,10 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vmdef->cputune.period = params[i].value.ul;
}
- } else if (STREQ(param->field, "cfs_quota")) {
+ } else if (STREQ(param->field, "vcpu_quota")) {
if (param->type != VIR_TYPED_PARAM_LLONG) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
- _("invalid type for cfs_quota tunable,"
+ _("invalid type for vcpu_quota tunable,"
" expected a 'llong'"));
goto cleanup;
}
@@ -6525,10 +6525,10 @@ out:
if (*nparams > saved_nparams) {
params[1].value.ul = period;
params[1].type = VIR_TYPED_PARAM_ULLONG;
- if (virStrcpyStatic(params[1].field, "cfs_period") == NULL) {
+ if (virStrcpyStatic(params[1].field, "vcpu_period") == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s",
- _("Field cfs_period too long for destination"));
+ _("Field vcpu_period too long for destination"));
goto cleanup;
}
saved_nparams++;
@@ -6537,10 +6537,10 @@ out:
if (*nparams > saved_nparams) {
params[2].value.ul = quota;
params[2].type = VIR_TYPED_PARAM_LLONG;
- if (virStrcpyStatic(params[2].field, "cfs_quota") == NULL) {
+ if (virStrcpyStatic(params[2].field, "vcpu_quota") == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s",
- _("Field cfs_quota too long for destination"));
+ _("Field vcpu_quota too long for destination"));
goto cleanup;
}
saved_nparams++;
--
1.7.1
13 years, 4 months
[libvirt] [PATCH v4 0/7] Add support for setting QoS
by Michal Privoznik
This patch series add support for setting traffic shaping and policing
on both domain's interface and network's virtual bridge. Basically,
this is done via 'tc' from iproute2 package. For shaping is HTB used,
for policing we need u32 match selector. Both should be available in
RHEL-6 kernel.
How this works:
On an virtual interface which has limits defined a root qdisc are replaced.
Ingress root for outbound traffic shaping and egress for inbound.
Basically, in inbound traffic policing is applied, on outbound shaping.
New qdiscs are set to limit the traffic to rate set in XML. For shaping
it is possible to set the size of buffer. Accepted values for rate, peak
and burst are integer numbers. Units are kilobytes per second for rate
or kilobytes for size.
Supported devices are VIR_DOMAIN_NET_TYPE_NETWORK, VIR_DOMAIN_NET_TYPE_BRIDGE
and VIR_DOMAIN_NET_TYPE_DIRECT.
diff to v3:
-Laine's review included
diff to v2:
-Jirka's review included
diff to v1:
-rebase to current HEAD
-add support for macvtap devices
Michal Privoznik (7):
bandwidth: Define schema and create documentation
bandwidth: Declare internal structures
bandwidth: Add parsing and free functions
bandwidth: Create format functions
bandwidth: Implement functions to enable and disable QoS
bandwidth: Add test cases for network
bandwidth: Add domain schema test suite
configure.ac | 4 +
docs/formatdomain.html.in | 34 +++
docs/formatnetwork.html.in | 30 ++
docs/schemas/domain.rng | 3 +
docs/schemas/network.rng | 3 +
docs/schemas/networkcommon.rng | 48 +++
libvirt.spec.in | 2 +-
src/conf/domain_conf.c | 8 +
src/conf/domain_conf.h | 1 +
src/conf/network_conf.c | 10 +
src/conf/network_conf.h | 1 +
src/libvirt_private.syms | 5 +
src/network/bridge_driver.c | 18 ++
src/qemu/qemu_command.c | 11 +-
src/util/macvtap.c | 12 +-
src/util/macvtap.h | 3 +-
src/util/network.c | 380 +++++++++++++++++++++++++
src/util/network.h | 22 ++
tests/domainschemadata/domain-bandwidth.xml | 72 +++++
tests/networkxml2xmlin/bandwidth-network.xml | 16 +
tests/networkxml2xmlout/bandwidth-network.xml | 16 +
tests/networkxml2xmltest.c | 1 +
22 files changed, 696 insertions(+), 4 deletions(-)
create mode 100644 tests/domainschemadata/domain-bandwidth.xml
create mode 100644 tests/networkxml2xmlin/bandwidth-network.xml
create mode 100644 tests/networkxml2xmlout/bandwidth-network.xml
--
1.7.5.rc3
13 years, 4 months
[libvirt] SSH URIs invoking askpass + sudo don't play well together
by Cole Robinson
$ cat test.py
import os
import sys
import libvirt
def drop_tty():
if os.fork() != 0:
os._exit(0)
os.setsid()
host = sys.argv[1]
# Need to drop controlling tty otherwise SSH won't call askpass
drop_tty()
libvirt.open("qemu+ssh://root@%s/system" % host)
$ python test.py localhost
<askpass pops up>
$ sudo python test.py localhost
libvir: RPC error : Cannot recv data: No protocol specified
(ssh-askpass:25684): Gtk-WARNING **: cannot open display: :0.0
: Connection reset by peered.
Traceback (most recent call last):
File "test.py", line 14, in <module>
libvirt.open("qemu+ssh://root@%s/system" % host)
File "/usr/lib64/python2.7/site-packages/libvirt.py", line 236, in open
if ret is None:raise libvirtError('virConnectOpen() failed')
libvirt.libvirtError: Cannot recv data: No protocol specified
(ssh-askpass:25684): Gtk-WARNING **: cannot open display: :0.0
: Connection reset by peered.
virt-manager does drop_tty by default so that users will get askpass if
applicable. however as shown above, doing sudo virt-manager prevents this from
working. The following libvirt patch makes everything work:
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index d4c0bdd..ad1c02e 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -606,7 +606,8 @@ int virNetSocketNewConnectSSH(const char *nodename,
virCommandAddEnvPass(cmd, "SSH_AUTH_SOCK");
virCommandAddEnvPass(cmd, "SSH_ASKPASS");
virCommandAddEnvPass(cmd, "DISPLAY");
- virCommandClearCaps(cmd);
+ virCommandAddEnvPass(cmd, "XAUTHORITY");
+ //virCommandClearCaps(cmd);
if (service)
virCommandAddArgList(cmd, "-p", service, NULL);
However I assume that's too heavy handed. Anyone have thoughts?
FYI I don't think this is a regression or anything, since the original BZ was
against RHEL 6.1 which doesn't have the new RPC code:
https://bugzilla.redhat.com/show_bug.cgi?id=700523
Thanks,
Cole
13 years, 4 months
[libvirt] libvirt.org outage
by Eric Blake
libvirt.org appears to be down, possibly for as long as the entire
weekend. While that doesn't help anyone trying to browse the online
documentation, we at least have the benefit of git being a distributed
version control system.
For those who would like to track what will be pushed to upstream
libvirt.git once it is back online, I've got my personal repo available
for the purpose. Assuming that I caught things just before the power
outage, then it will be a trivial sync to get everything from my master
branch back upstream once things are back to normal.
Browse the latest state at:
http://repo.or.cz/w/libvirt/ericb.git
Track the latest state of upstream patches with:
git pull git://repo.or.cz/libvirt/ericb.git master
Propose your own patches for me to merge in to the master branch (the
mob branch has no push restrictions - anyone can push there, but that
also means that anyone can rewind history there, so let me know the
commit id of anything that you have pushed there that I should then sync
into the master branch):
git push mob@repo.or.cz:/srv/git/libvirt/ericb.git +HEAD:mob
Feel free to ask questions on list or on irc://irc.oftc.net/virt if you
want to coordinate on bleeding-edge development this weekend.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
13 years, 4 months
[libvirt] [PATCH] docs: Break up 'Basic Resources' XML section
by Cole Robinson
We had a bit too many elements crammed in there. Separate it into different
headings:
- CPU Allocation (<vcpus>)
- CPU Tuning (<cputune>)
- Memory allocation (<memory> and <currentMemory>)
- Memory backing (<memoryBacking>)
- Memory tuning (<memtune>)
- Numa tuning (<numatune>)
- Block I/O tuning (<blkiotune>)
---
docs/formatdomain.html.in | 227 ++++++++++++++++++++++++++++++---------------
1 files changed, 154 insertions(+), 73 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 83146ed..847b9ed 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -282,85 +282,17 @@
</dd>
</dl>
- <h3><a name="elementsResources">Basic resources</a></h3>
+ <h3><a name="elementsCPUAllocation">CPU Allocation</a></h3>
<pre>
+<domain>
...
- <memory>524288</memory>
- <currentMemory>524288</currentMemory>
- <memoryBacking>
- <hugepages/>
- </memoryBacking>
- <blkiotune>
- <weight>800</weight>
- </blkiotune>
- <memtune>
- <hard_limit>1048576</hard_limit>
- <soft_limit>131072</soft_limit>
- <swap_hard_limit>2097152</swap_hard_limit>
- <min_guarantee>65536</min_guarantee>
- </memtune>
<vcpu cpuset="1-4,^3,6" current="1">2</vcpu>
- <cputune>
- <vcpupin vcpu="0" cpuset="1-4,^2"/>
- <vcpupin vcpu="1" cpuset="0,1"/>
- <vcpupin vcpu="2" cpuset="2,3"/>
- <vcpupin vcpu="3" cpuset="0,4"/>
- <shares>2048</shares>
- <period>1000000</period>
- <quota>-1</quota>
- </cputune>
- <numatune>
- <memory mode="strict" nodeset="1-4,^3"/>
- </numatune>
- ...</pre>
+ ...
+</domain>
+</pre>
<dl>
- <dt><code>memory</code></dt>
- <dd>The maximum allocation of memory for the guest at boot time.
- The units for this value are kilobytes (i.e. blocks of 1024 bytes)</dd>
- <dt><code>currentMemory</code></dt>
- <dd>The actual allocation of memory for the guest. This value can
- be less than the maximum allocation, to allow for ballooning
- up the guests memory on the fly. If this is omitted, it defaults
- to the same value as the <code>memory</code> element</dd>
- <dt><code>memoryBacking</code></dt>
- <dd>The optional <code>memoryBacking</code> element, may have an
- <code>hugepages</code> element set within it. This tells the
- hypervisor that the guest should have its memory allocated using
- hugepages instead of the normal native page size.</dd>
- <dt><code>blkiotune</code></dt>
- <dd> The optional <code>blkiotune</code> element provides the ability
- to tune Blkio cgroup tunable parameters for the domain. If this is
- omitted, it defaults to the OS provided defaults.</dd>
- <dt><code>weight</code></dt>
- <dd> The optional <code>weight</code> element is the I/O weight of the
- guest. The value should be in range [100, 1000].</dd>
- <dt><code>memtune</code></dt>
- <dd> The optional <code>memtune</code> element provides details
- regarding the memory tunable parameters for the domain. If this is
- omitted, it defaults to the OS provided defaults. For QEMU/KVM, the
- parameters are applied to the QEMU process as a whole. Thus, when
- counting them, one needs to add up guest RAM, guest video RAM, and
- some memory overhead of QEMU itself. The last piece is hard to
- determine so one needs guess and try.</dd>
- <dt><code>hard_limit</code></dt>
- <dd> The optional <code>hard_limit</code> element is the maximum memory
- the guest can use. The units for this value are kilobytes (i.e. blocks
- of 1024 bytes)</dd>
- <dt><code>soft_limit</code></dt>
- <dd> The optional <code>soft_limit</code> element is the memory limit to
- enforce during memory contention. The units for this value are
- kilobytes (i.e. blocks of 1024 bytes)</dd>
- <dt><code>swap_hard_limit</code></dt>
- <dd> The optional <code>swap_hard_limit</code> element is the maximum
- memory plus swap the guest can use. The units for this value are
- kilobytes (i.e. blocks of 1024 bytes). This has to be more than
- hard_limit value provided</dd>
- <dt><code>min_guarantee</code></dt>
- <dd> The optional <code>min_guarantee</code> element is the guaranteed
- minimum memory allocation for the guest. The units for this value are
- kilobytes (i.e. blocks of 1024 bytes)</dd>
<dt><code>vcpu</code></dt>
<dd>The content of this element defines the maximum number of virtual
CPUs allocated for the guest OS, which must be between 1 and
@@ -375,6 +307,28 @@
be used to specify whether fewer than the maximum number of
virtual CPUs should be enabled.
</dd>
+ </dl>
+
+
+ <h3><a name="elementsCPUTuning">CPU Tuning</a></h3>
+
+<pre>
+<domain>
+ ...
+ <cputune>
+ <vcpupin vcpu="0" cpuset="1-4,^2"/>
+ <vcpupin vcpu="1" cpuset="0,1"/>
+ <vcpupin vcpu="2" cpuset="2,3"/>
+ <vcpupin vcpu="3" cpuset="0,4"/>
+ <shares>2048</shares>
+ <period>1000000</period>
+ <quota>-1</quota>
+ </cputune>
+ ...
+</domain>
+</pre>
+
+ <dl>
<dt><code>cputune</code></dt>
<dd>
The optional <code>cputune</code> element provides details
@@ -422,6 +376,110 @@
speed. (NB: Only qemu driver support)
<span class="since">Since 0.9.4</span>
</dd>
+ </dl>
+
+
+ <h3><a name="elementsMemoryAllocation">Memory Allocation</a></h3>
+
+<pre>
+<domain>
+ ...
+ <memory>524288</memory>
+ <currentMemory>524288</currentMemory>
+ ...
+</domain>
+</pre>
+
+ <dl>
+ <dt><code>memory</code></dt>
+ <dd>The maximum allocation of memory for the guest at boot time.
+ The units for this value are kilobytes (i.e. blocks of 1024 bytes)</dd>
+ <dt><code>currentMemory</code></dt>
+ <dd>The actual allocation of memory for the guest. This value can
+ be less than the maximum allocation, to allow for ballooning
+ up the guests memory on the fly. If this is omitted, it defaults
+ to the same value as the <code>memory</code> element</dd>
+ </dl>
+
+
+ <h3><a name="elementsMemoryBacking">Memory Backing</a></h3>
+
+<pre>
+<domain>
+ ...
+ <memoryBacking>
+ <hugepages/>
+ </memoryBacking>
+ ...
+</domain>
+</pre>
+
+ <dl>
+ <dt><code>memoryBacking</code></dt>
+ <dd>The optional <code>memoryBacking</code> element, may have an
+ <code>hugepages</code> element set within it. This tells the
+ hypervisor that the guest should have its memory allocated using
+ hugepages instead of the normal native page size.</dd>
+ </dl>
+
+
+ <h3><a name="elementsMemoryTuning">Memory Tuning</a></h3>
+
+<pre>
+<domain>
+ ...
+ <memtune>
+ <hard_limit>1048576</hard_limit>
+ <soft_limit>131072</soft_limit>
+ <swap_hard_limit>2097152</swap_hard_limit>
+ <min_guarantee>65536</min_guarantee>
+ </memtune>
+ ...
+</domain>
+</pre>
+
+ <dl>
+ <dt><code>memtune</code></dt>
+ <dd> The optional <code>memtune</code> element provides details
+ regarding the memory tunable parameters for the domain. If this is
+ omitted, it defaults to the OS provided defaults. For QEMU/KVM, the
+ parameters are applied to the QEMU process as a whole. Thus, when
+ counting them, one needs to add up guest RAM, guest video RAM, and
+ some memory overhead of QEMU itself. The last piece is hard to
+ determine so one needs guess and try.</dd>
+ <dt><code>hard_limit</code></dt>
+ <dd> The optional <code>hard_limit</code> element is the maximum memory
+ the guest can use. The units for this value are kilobytes (i.e. blocks
+ of 1024 bytes)</dd>
+ <dt><code>soft_limit</code></dt>
+ <dd> The optional <code>soft_limit</code> element is the memory limit to
+ enforce during memory contention. The units for this value are
+ kilobytes (i.e. blocks of 1024 bytes)</dd>
+ <dt><code>swap_hard_limit</code></dt>
+ <dd> The optional <code>swap_hard_limit</code> element is the maximum
+ memory plus swap the guest can use. The units for this value are
+ kilobytes (i.e. blocks of 1024 bytes). This has to be more than
+ hard_limit value provided</dd>
+ <dt><code>min_guarantee</code></dt>
+ <dd> The optional <code>min_guarantee</code> element is the guaranteed
+ minimum memory allocation for the guest. The units for this value are
+ kilobytes (i.e. blocks of 1024 bytes)</dd>
+ </dl>
+
+
+ <h3><a name="elementsNUMATuning">NUMA Node Tuning</a></h3>
+
+<pre>
+<domain>
+ ...
+ <numatune>
+ <memory mode="strict" nodeset="1-4,^3"/>
+ </numatune>
+ ...
+</domain>
+</pre>
+
+ <dl>
<dt><code>numatune</code></dt>
<dd>
The optional <code>numatune</code> element provides details of
@@ -440,6 +498,29 @@
</dd>
</dl>
+
+ <h3><a name="elementsBlockTuning">Block I/O Tuning</a></h3>
+<pre>
+<domain>
+ ...
+ <blkiotune>
+ <weight>800</weight>
+ </blkiotune>
+ ...
+</domain>
+</pre>
+
+ <dl>
+ <dt><code>blkiotune</code></dt>
+ <dd> The optional <code>blkiotune</code> element provides the ability
+ to tune Blkio cgroup tunable parameters for the domain. If this is
+ omitted, it defaults to the OS provided defaults.</dd>
+ <dt><code>weight</code></dt>
+ <dd> The optional <code>weight</code> element is the I/O weight of the
+ guest. The value should be in range [100, 1000].</dd>
+ </dl>
+
+
<h3><a name="elementsCPU">CPU model and topology</a></h3>
<p>
--
1.7.4.4
13 years, 4 months
[libvirt] [PATCHv2 0/4] support the listenNetwork attribute in <graphics>
by Laine Stump
This patch series resolves the following bug:
https://bugzilla.redhat.com/show_bug.cgi?id=703851
In short, it implements support for a new "listenNetwork" attribute in
the domain's <graphics> element. When listenNetwork is specified,
libvirt will look for a network of that name (from the networks that
can be created within libvirt), and derive a listen address from the
physical interface used to connect that network to the outside
world. (More details are given in each commit message).
This is V2. The main differences from V1 are:
1) everything was rebased
2) I eliminated #if WITH_NETWORK in the .c files by defining the one
missing function as static inline when WITH_NETWORK is false.
This series is meant to be applied on top of the "network physical
device abstraction" patch series I sent a couple hours ago:
https://www.redhat.com/archives/libvir-list/2011-July/msg01294.html
Don't attempt to apply it by itself!
13 years, 4 months
[libvirt] [libvirt-test-API][PATCH 2/2] Add clean part for install_windows_cdrom
by Wayne Sun
* Add cleanup function install_windows_cdrom_clean
---
repos/domain/install_windows_cdrom.py | 88 +++++++++++++++++++++++++++-----
1 files changed, 74 insertions(+), 14 deletions(-)
diff --git a/repos/domain/install_windows_cdrom.py b/repos/domain/install_windows_cdrom.py
index f1441df..2ea0ee7 100644
--- a/repos/domain/install_windows_cdrom.py
+++ b/repos/domain/install_windows_cdrom.py
@@ -51,6 +51,15 @@ __version__ = "0.1.0"
__credits__ = "Copyright (C) 2010 Red Hat, Inc."
__all__ = ['install_windows_cdrom', 'usage']
+VIRSH_QUIET_LIST = "virsh --quiet list --all|awk '{print $2}'|grep \"^%s$\""
+VM_STAT = "virsh --quiet list --all| grep \"\\b%s\\b\"|grep off"
+VM_DESTROY = "virsh destroy %s"
+VM_UNDEFINE = "virsh undefine %s"
+
+FLOOPY_IMG = "/tmp/floppy.img"
+ISO_MOUNT_POINT = "/mnt/libvirt_windows"
+
+
def usage():
print '''usage: mandatory arguments:guesttype
guestname
@@ -132,19 +141,19 @@ def prepare_iso(iso_file, mount_point):
return 0, iso_local_path
def prepare_floppy_image(guestname, guestos, guestarch,
- windows_unattended_path, cdkey, floppy_img):
+ windows_unattended_path, cdkey, FLOOPY_IMG):
"""Making corresponding floppy images for the given guestname
"""
- if os.path.exists(floppy_img):
- os.remove(floppy_img)
+ if os.path.exists(FLOOPY_IMG):
+ os.remove(FLOOPY_IMG)
- create_cmd = 'dd if=/dev/zero of=%s bs=1440k count=1' % floppy_img
+ create_cmd = 'dd if=/dev/zero of=%s bs=1440k count=1' % FLOOPY_IMG
(status, text) = commands.getstatusoutput(create_cmd)
if status:
logger.error("failed to create floppy image")
return 1
- format_cmd = 'mkfs.msdos -s 1 %s' % floppy_img
+ format_cmd = 'mkfs.msdos -s 1 %s' % FLOOPY_IMG
(status, text) = commands.getstatusoutput(format_cmd)
if status:
logger.error("failed to format floppy image")
@@ -159,7 +168,7 @@ def prepare_floppy_image(guestname, guestos, guestarch,
os.makedirs(floppy_mount)
try:
- mount_cmd = 'mount -o loop %s %s' % (floppy_img, floppy_mount)
+ mount_cmd = 'mount -o loop %s %s' % (FLOOPY_IMG, floppy_mount)
(status, text) = commands.getstatusoutput(mount_cmd)
if status:
logger.error(
@@ -202,7 +211,7 @@ def prepare_floppy_image(guestname, guestos, guestarch,
cleanup(floppy_mount)
- os.chmod(floppy_img, 0755)
+ os.chmod(FLOOPY_IMG, 0755)
logger.info("Boot floppy created successfuly")
return 0
@@ -339,22 +348,18 @@ def install_windows_cdrom(params):
logger.info('prepare pre-installation environment...')
logger.info('mount windows nfs server to /mnt/libvirt_windows')
- iso_mount_point = "/mnt/libvirt_windows"
-
- status, iso_local_path = prepare_iso(iso_file, iso_mount_point)
+ status, iso_local_path = prepare_iso(iso_file, ISO_MOUNT_POINT)
if status:
logger.error("installation failed")
return 1
params['bootcd'] = iso_local_path
- floppy_img = "/tmp/floppy.img"
-
status = prepare_floppy_image(guestname, guestos, guestarch,
- windows_unattended_path, cdkey, floppy_img)
+ windows_unattended_path, cdkey, FLOOPY_IMG)
if status:
logger.error("making floppy image failed")
return 1
- params['floppysource'] = floppy_img
+ params['floppysource'] = FLOOPY_IMG
xmlobj = xmlbuilder.XmlBuilder()
guestxml = xmlobj.build_domain_install_win(params)
@@ -458,3 +463,58 @@ def install_windows_cdrom(params):
return return_close(conn, logger, 0)
+def install_windows_cdrom_clean(params):
+ """ clean testing environment """
+ logger = params['logger']
+ guestname = params.get('guestname')
+ guesttype = params.get('guesttype')
+
+ util = utils.Utils()
+ hypervisor = util.get_hypervisor()
+ if hypervisor == 'xen':
+ imgfullpath = os.path.join('/var/lib/xen/images', guestname)
+ elif hypervisor == 'kvm':
+ imgfullpath = os.path.join('/var/lib/libvirt/images', guestname)
+
+ (status, output) = commands.getstatusoutput(VIRSH_QUIET_LIST % guestname)
+ if status:
+ pass
+ else:
+ logger.info("remove guest %s, and its disk image file" % guestname)
+ (status, output) = commands.getstatusoutput(VM_STAT % guestname)
+ if status:
+ (status, output) = commands.getstatusoutput(VM_DESTROY % guestname)
+ if status:
+ logger.error("failed to destroy guest %s" % guestname)
+ logger.error("%s" % output)
+ else:
+ (status, output) = commands.getstatusoutput(VM_UNDEFINE % guestname)
+ if status:
+ logger.error("failed to undefine guest %s" % guestname)
+ logger.error("%s" % output)
+ else:
+ (status, output) = commands.getstatusoutput(VM_UNDEFINE % guestname)
+ if status:
+ logger.error("failed to undefine guest %s" % guestname)
+ logger.error("%s" % output)
+
+ guestos = params.get('guestos')
+ guestarch = params.get('guestarch')
+
+ envfile = os.path.join(homepath, 'env.cfg')
+ envparser = env_parser.Envparser(envfile)
+ iso_file = envparser.get_value("guest", guestos + '_' + guestarch)
+
+ status, iso_local_path = prepare_iso(iso_file, ISO_MOUNT_POINT)
+ if os.path.exists(iso_local_path):
+ os.remove(iso_local_path)
+
+ iso_local_path_1 = iso_local_path + ".1"
+ if os.path.exists(iso_local_path_1):
+ os.remove(iso_local_path_1)
+
+ if os.path.exists(imgfullpath):
+ os.remove(imgfullpath)
+
+ if os.path.exists(FLOOPY_IMG):
+ os.remove(FLOOPY_IMG)
--
1.7.6
13 years, 4 months
[libvirt] [libvirt-test-API][PATCH 2/2] Add clean part for install_windows_cdrom
by Wayne Sun
* Add cleanup function install_windows_cdrom_clean
---
repos/domain/install_windows_cdrom.py | 88 +++++++++++++++++++++++++++-----
1 files changed, 74 insertions(+), 14 deletions(-)
diff --git a/repos/domain/install_windows_cdrom.py b/repos/domain/install_windows_cdrom.py
index f1441df..2ea0ee7 100644
--- a/repos/domain/install_windows_cdrom.py
+++ b/repos/domain/install_windows_cdrom.py
@@ -51,6 +51,15 @@ __version__ = "0.1.0"
__credits__ = "Copyright (C) 2010 Red Hat, Inc."
__all__ = ['install_windows_cdrom', 'usage']
+VIRSH_QUIET_LIST = "virsh --quiet list --all|awk '{print $2}'|grep \"^%s$\""
+VM_STAT = "virsh --quiet list --all| grep \"\\b%s\\b\"|grep off"
+VM_DESTROY = "virsh destroy %s"
+VM_UNDEFINE = "virsh undefine %s"
+
+FLOOPY_IMG = "/tmp/floppy.img"
+ISO_MOUNT_POINT = "/mnt/libvirt_windows"
+
+
def usage():
print '''usage: mandatory arguments:guesttype
guestname
@@ -132,19 +141,19 @@ def prepare_iso(iso_file, mount_point):
return 0, iso_local_path
def prepare_floppy_image(guestname, guestos, guestarch,
- windows_unattended_path, cdkey, floppy_img):
+ windows_unattended_path, cdkey, FLOOPY_IMG):
"""Making corresponding floppy images for the given guestname
"""
- if os.path.exists(floppy_img):
- os.remove(floppy_img)
+ if os.path.exists(FLOOPY_IMG):
+ os.remove(FLOOPY_IMG)
- create_cmd = 'dd if=/dev/zero of=%s bs=1440k count=1' % floppy_img
+ create_cmd = 'dd if=/dev/zero of=%s bs=1440k count=1' % FLOOPY_IMG
(status, text) = commands.getstatusoutput(create_cmd)
if status:
logger.error("failed to create floppy image")
return 1
- format_cmd = 'mkfs.msdos -s 1 %s' % floppy_img
+ format_cmd = 'mkfs.msdos -s 1 %s' % FLOOPY_IMG
(status, text) = commands.getstatusoutput(format_cmd)
if status:
logger.error("failed to format floppy image")
@@ -159,7 +168,7 @@ def prepare_floppy_image(guestname, guestos, guestarch,
os.makedirs(floppy_mount)
try:
- mount_cmd = 'mount -o loop %s %s' % (floppy_img, floppy_mount)
+ mount_cmd = 'mount -o loop %s %s' % (FLOOPY_IMG, floppy_mount)
(status, text) = commands.getstatusoutput(mount_cmd)
if status:
logger.error(
@@ -202,7 +211,7 @@ def prepare_floppy_image(guestname, guestos, guestarch,
cleanup(floppy_mount)
- os.chmod(floppy_img, 0755)
+ os.chmod(FLOOPY_IMG, 0755)
logger.info("Boot floppy created successfuly")
return 0
@@ -339,22 +348,18 @@ def install_windows_cdrom(params):
logger.info('prepare pre-installation environment...')
logger.info('mount windows nfs server to /mnt/libvirt_windows')
- iso_mount_point = "/mnt/libvirt_windows"
-
- status, iso_local_path = prepare_iso(iso_file, iso_mount_point)
+ status, iso_local_path = prepare_iso(iso_file, ISO_MOUNT_POINT)
if status:
logger.error("installation failed")
return 1
params['bootcd'] = iso_local_path
- floppy_img = "/tmp/floppy.img"
-
status = prepare_floppy_image(guestname, guestos, guestarch,
- windows_unattended_path, cdkey, floppy_img)
+ windows_unattended_path, cdkey, FLOOPY_IMG)
if status:
logger.error("making floppy image failed")
return 1
- params['floppysource'] = floppy_img
+ params['floppysource'] = FLOOPY_IMG
xmlobj = xmlbuilder.XmlBuilder()
guestxml = xmlobj.build_domain_install_win(params)
@@ -458,3 +463,58 @@ def install_windows_cdrom(params):
return return_close(conn, logger, 0)
+def install_windows_cdrom_clean(params):
+ """ clean testing environment """
+ logger = params['logger']
+ guestname = params.get('guestname')
+ guesttype = params.get('guesttype')
+
+ util = utils.Utils()
+ hypervisor = util.get_hypervisor()
+ if hypervisor == 'xen':
+ imgfullpath = os.path.join('/var/lib/xen/images', guestname)
+ elif hypervisor == 'kvm':
+ imgfullpath = os.path.join('/var/lib/libvirt/images', guestname)
+
+ (status, output) = commands.getstatusoutput(VIRSH_QUIET_LIST % guestname)
+ if status:
+ pass
+ else:
+ logger.info("remove guest %s, and its disk image file" % guestname)
+ (status, output) = commands.getstatusoutput(VM_STAT % guestname)
+ if status:
+ (status, output) = commands.getstatusoutput(VM_DESTROY % guestname)
+ if status:
+ logger.error("failed to destroy guest %s" % guestname)
+ logger.error("%s" % output)
+ else:
+ (status, output) = commands.getstatusoutput(VM_UNDEFINE % guestname)
+ if status:
+ logger.error("failed to undefine guest %s" % guestname)
+ logger.error("%s" % output)
+ else:
+ (status, output) = commands.getstatusoutput(VM_UNDEFINE % guestname)
+ if status:
+ logger.error("failed to undefine guest %s" % guestname)
+ logger.error("%s" % output)
+
+ guestos = params.get('guestos')
+ guestarch = params.get('guestarch')
+
+ envfile = os.path.join(homepath, 'env.cfg')
+ envparser = env_parser.Envparser(envfile)
+ iso_file = envparser.get_value("guest", guestos + '_' + guestarch)
+
+ status, iso_local_path = prepare_iso(iso_file, ISO_MOUNT_POINT)
+ if os.path.exists(iso_local_path):
+ os.remove(iso_local_path)
+
+ iso_local_path_1 = iso_local_path + ".1"
+ if os.path.exists(iso_local_path_1):
+ os.remove(iso_local_path_1)
+
+ if os.path.exists(imgfullpath):
+ os.remove(imgfullpath)
+
+ if os.path.exists(FLOOPY_IMG):
+ os.remove(FLOOPY_IMG)
--
1.7.6
13 years, 4 months