Merge lp:~javier.collado/utah/bug1024364 into lp:utah

Proposed by Javier Collado
Status: Merged
Merged at revision: 454
Proposed branch: lp:~javier.collado/utah/bug1024364
Merge into: lp:utah
Diff against target: 74 lines (+40/-1)
3 files modified
debian/control (+1/-1)
utah/process.py (+30/-0)
utah/provisioning/vm/libvirtvm.py (+9/-0)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1024364
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Javier Collado (community) Needs Resubmitting
Review via email: mp+115160@code.launchpad.net

Description of the change

Added a few checks to make sure that neither virtualbox nor vmware are running.

The checks are based in looking at the command line of running processes. They're not 100% accurate, but they should be fine for now.

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Your note says TBD: Run this only if provisioning a KVM. Would it make sense to move the check into the VM provisioning classes, specifically, VMToolsVM and CustomVM, and have them raise an exception if they are trying to provision a KVM? I think VMToolsVM always tries to provision a kvm (I'm not exactly sure, since that class uses an external command for provision) and I know that in CustomKVM as part of __init__, we pick an emulator if we weren't passed one, so we know then whether we're going to try qemu or kvm. I think having this in the provisioning classes would let us leverage it in future scripts.

That being said, this implementation is fine, so if you think it's better off this way, we can go with this, and it does have the advantage of already being written.

Also, at some point, I'd like to get run_test_vm and run_install_tests changed so that they share code better, but that's not really relevant to this, I just keep noticing how you have to duplicate code in these merges, so I'd like to fix that.

lp:~javier.collado/utah/bug1024364 updated
426. By Javier Collado

Moved process checking code to utah.provisioning.vm.libvirtvm.CustomVM

427. By Javier Collado

Refactored code to an object oriented design

Revision history for this message
Javier Collado (javier.collado) wrote :

I've followed your advice and now I think the code looks cleaner.

review: Needs Resubmitting
Revision history for this message
Max Brustkern (nuclearbob) wrote :

This looks good. Do we need to check for other emulators when we're running qemu, or just kvm? If we don't need that check for qemu, we can move it down to after we check the emulator, and only check if it's kvm. Either way, I'll go ahead and do the merge, it's definitely an improvement on what we have now.

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

How do I force utah to use qemu without kvm? Should I set target architecture to arm?

Revision history for this message
Max Brustkern (nuclearbob) wrote :

When running run_utah_tests.py or run_install_test.py, pass -e qemu.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2012-07-13 15:10:47 +0000
3+++ debian/control 2012-07-17 09:20:23 +0000
4@@ -10,7 +10,7 @@
5
6 Package: utah
7 Architecture: all
8-Depends: ${misc:Depends}, ${python:Depends}, python-libvirt, python-apt, python-yaml, libvirt-bin, bzr, git, bsdtar, lzma
9+Depends: ${misc:Depends}, ${python:Depends}, python-libvirt, python-apt, python-yaml, python-psutil, libvirt-bin, bzr, git, bsdtar, lzma
10 Recommends: kvm, vm-tools
11 Provides: utah-client, ubuntu-automation-test-harness, ubuntu-automation-test-harness-client
12 Conflicts: utah-client, ubuntu-automation-test-harness, ubuntu-automation-test-harness-client
13
14=== added file 'utah/process.py'
15--- utah/process.py 1970-01-01 00:00:00 +0000
16+++ utah/process.py 2012-07-17 09:20:23 +0000
17@@ -0,0 +1,30 @@
18+"""
19+Process checking utilities
20+"""
21+import psutil
22+
23+
24+class ProcessChecker(object):
25+ """
26+ Check all running process looking for a given pattern
27+ """
28+ MESSAGE_TEMPLATE = \
29+ ("{app} application is running.\n"
30+ "Please stop it before launching utah since "
31+ "it won't interact properly with KVM "
32+ "(Kernel-based Virtual Machine)\n")
33+
34+ def check_cmdline(self, pattern):
35+ """
36+ Check if the command line of any process matches the given pattern
37+ """
38+ pids = psutil.get_pid_list()
39+ processes = (psutil.Process(pid) for pid in pids)
40+ cmdlines = (' '.join(process.cmdline) for process in processes)
41+ return any(pattern in cmdline for cmdline in cmdlines)
42+
43+ def get_error_message(self, app):
44+ """
45+ Return error message for an incompatible application process running
46+ """
47+ return self.MESSAGE_TEMPLATE.format(app=app)
48
49=== modified file 'utah/provisioning/vm/libvirtvm.py'
50--- utah/provisioning/vm/libvirtvm.py 2012-07-16 21:50:15 +0000
51+++ utah/provisioning/vm/libvirtvm.py 2012-07-17 09:20:23 +0000
52@@ -16,6 +16,7 @@
53 from utah.provisioning import *
54 from utah.provisioning.vm import *
55 from utah import config
56+from utah.process import ProcessChecker
57
58 class LibvirtVM(VM):
59 """
60@@ -267,6 +268,14 @@
61
62 class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
63 def __init__(self, arch=None, boot=None, disksizes=None, emulator=None, image=None, initrd=None, installtype=None, kernel=None, machineid=None, macs=[], name=None, prefix='utah', preseed=None, series=None, xml=None, *args, **kw):
64+ # Make sure that no other virtualization solutions are running
65+ process_checker = ProcessChecker()
66+ for cmdline, app in [('/usr/lib/virtualbox/VirtualBox', 'VirtualBox'),
67+ ('/usr/lib/vmware/bin', 'VMware')]:
68+ if process_checker.check_cmdline(cmdline):
69+ message = process_checker.get_error_message(app)
70+ raise UTAHVMProvisioningException(message)
71+
72 if disksizes is None:
73 self.disksizes = [8]
74 else:

Subscribers

People subscribed via source and target branches