Dan Kenigsberg has uploaded a new change for review.
Change subject: faqemu: move hook logic out of vdsm
......................................................................
faqemu: move hook logic out of vdsm
Vdsm-proper has been aware of the faqemu hook. Now that we have an
after_get_caps hook point, this is no longer necessary. This patch move
the faking logic, so that it does not need to be shipped on production
systems and clutter the code.
Change-Id: I46d0079491f707b0abd3fbbe2d47f63697dac9c5
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M vdsm.spec.in
M vdsm/caps.py
M vdsm_hooks/faqemu/Makefile.am
A vdsm_hooks/faqemu/after_get_caps.py
4 files changed, 110 insertions(+), 42 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/05/27705/1
diff --git a/vdsm.spec.in b/vdsm.spec.in
index c620174..e6db372 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1464,6 +1464,7 @@
%defattr(-, root, root, -)
%doc COPYING
%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/10_faqemu
+%{_libexecdir}/%{vdsm_name}/hooks/after_get_caps/10_faqemu
%if 0%{?with_gluster}
%files gluster
diff --git a/vdsm/caps.py b/vdsm/caps.py
index 46094f3..7c1e520 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -1,5 +1,5 @@
#
-# Copyright 2011 Red Hat, Inc.
+# Copyright 2011-2014 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -197,7 +197,7 @@
@utils.memoized
-def _getLiveSnapshotSupport(arch, capabilities=None):
+def getLiveSnapshotSupport(arch, capabilities=None):
if capabilities is None:
capabilities = _getCapsXMLStr()
caps = minidom.parseString(capabilities)
@@ -295,7 +295,7 @@
@utils.memoized
-def _getEmulatedMachines(arch, capabilities=None):
+def getEmulatedMachines(arch, capabilities=None):
if capabilities is None:
capabilities = _getCapsXMLStr()
caps = minidom.parseString(capabilities)
@@ -444,13 +444,6 @@
return dict(release=release, version=version, name=osname)
-def getTargetArch():
- if config.getboolean('vars', 'fake_kvm_support'):
- return config.get('vars', 'fake_kvm_architecture')
- else:
- return platform.machine()
-
-
def _getSELinuxEnforceMode():
"""
Returns the SELinux mode as reported by kernel.
@@ -480,13 +473,11 @@
def get():
- targetArch = getTargetArch()
+ targetArch = platform.machine()
caps = {}
- caps['kvmEnabled'] = \
- str(config.getboolean('vars', 'fake_kvm_support') or
- os.path.exists('/dev/kvm')).lower()
+ caps['kvmEnabled'] = str(os.path.exists('/dev/kvm')).lower()
cpuInfo = CpuInfo()
cpuTopology = CpuTopology()
@@ -498,30 +489,9 @@
caps['cpuThreads'] = str(cpuTopology.threads())
caps['cpuSockets'] = str(cpuTopology.sockets())
caps['cpuSpeed'] = cpuInfo.mhz()
- if config.getboolean('vars', 'fake_kvm_support'):
- if targetArch == Architecture.X86_64:
- caps['cpuModel'] = 'Intel(Fake) CPU'
-
- flagList = ['vmx', 'sse2', 'nx']
-
- if targetArch == platform.machine():
- flagList += cpuInfo.flags()
-
- flags = set(flagList)
-
- caps['cpuFlags'] = ','.join(flags) +
',model_486,model_pentium,' \
- 'model_pentium2,model_pentium3,model_pentiumpro,' \
- 'model_qemu32,model_coreduo,model_core2duo,model_n270,' \
- 'model_Conroe,model_Penryn,model_Nehalem,model_Opteron_G1'
- elif targetArch == Architecture.PPC64:
- caps['cpuModel'] = 'POWER 7 (fake)'
- caps['cpuFlags'] = 'powernv,model_POWER7_v2.3'
- else:
- raise RuntimeError('Unsupported architecture: %s' % targetArch)
- else:
- caps['cpuModel'] = cpuInfo.model()
- caps['cpuFlags'] = ','.join(cpuInfo.flags() +
- _getCompatibleCpuModels())
+ caps['cpuModel'] = cpuInfo.model()
+ caps['cpuFlags'] = ','.join(cpuInfo.flags() +
+ _getCompatibleCpuModels())
caps.update(_getVersionInfo())
caps.update(netinfo.get())
@@ -534,7 +504,7 @@
caps['operatingSystem'] = osversion()
caps['uuid'] = utils.getHostUUID()
caps['packages2'] = _getKeyPackages()
- caps['emulatedMachines'] = _getEmulatedMachines(targetArch)
+ caps['emulatedMachines'] = getEmulatedMachines(targetArch)
caps['ISCSIInitiatorName'] = _getIscsiIniName()
caps['HBAInventory'] = storage.hba.HBAInventory()
caps['vmTypes'] = ['kvm']
@@ -550,7 +520,7 @@
caps['selinux'] = _getSELinux()
- liveSnapSupported = _getLiveSnapshotSupport(targetArch)
+ liveSnapSupported = getLiveSnapshotSupport(targetArch)
if liveSnapSupported is not None:
caps['liveSnapshot'] = str(liveSnapSupported).lower()
diff --git a/vdsm_hooks/faqemu/Makefile.am b/vdsm_hooks/faqemu/Makefile.am
index 3e1b0c0..e93c943 100644
--- a/vdsm_hooks/faqemu/Makefile.am
+++ b/vdsm_hooks/faqemu/Makefile.am
@@ -1,5 +1,5 @@
#
-# Copyright 2011-2012 Red Hat, Inc.
+# Copyright 2011-2014 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -24,12 +24,18 @@
config.log
EXTRA_DIST = \
- before_vm_start.py
+ before_vm_start.py \
+ after_get_caps.py \
+ $(NULL)
install-data-local:
$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
+ $(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/after_get_caps
$(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \
$(DESTDIR)$(vdsmhooksdir)/before_vm_start/10_faqemu
+ $(INSTALL_SCRIPT) $(srcdir)/after_get_caps.py \
+ $(DESTDIR)$(vdsmhooksdir)/after_get_caps/10_faqemu
uninstall-local:
$(RM) $(DESTDIR)$(vdsmhooksdir)/before_vm_start/10_faqemu
+ $(RM) $(DESTDIR)$(vdsmhooksdir)/after_get_caps/10_faqemu
diff --git a/vdsm_hooks/faqemu/after_get_caps.py b/vdsm_hooks/faqemu/after_get_caps.py
new file mode 100644
index 0000000..a4a008b
--- /dev/null
+++ b/vdsm_hooks/faqemu/after_get_caps.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import platform
+import sys
+import traceback
+
+# using vdsm internals in a hook is dangerous and frowned upon,
+# as internal APIs may change without notice.
+# However, faqemu is a bit different, as it is not expected to be ever used in
+# production.
+sys.path.append('/usr/share/vdsm')
+import caps
+import hooking
+from vdsm.config import config
+
+
+def fake_caps(c, target_arch):
+ c['kvmEnabled'] = 'True'
+ cpu_info = caps.CpuInfo()
+ if target_arch == caps.Architecture.X86_64:
+ c['cpuModel'] = 'Intel(Fake) CPU'
+
+ flagList = ['vmx', 'sse2', 'nx']
+
+ if target_arch == platform.machine():
+ flagList += cpu_info.flags()
+
+ flags = set(flagList)
+
+ c['cpuFlags'] = ','.join(flags) +
',model_486,model_pentium,' \
+ 'model_pentium2,model_pentium3,model_pentiumpro,' \
+ 'model_qemu32,model_coreduo,model_core2duo,model_n270,' \
+ 'model_Conroe,model_Penryn,model_Nehalem,model_Opteron_G1'
+ elif target_arch == caps.Architecture.PPC64:
+ c['cpuModel'] = 'POWER 7 (fake)'
+ c['cpuFlags'] = 'powernv,model_POWER7_v2.3'
+ else:
+ raise RuntimeError('Unsupported architecture: %s' % target_arch)
+
+ if target_arch != platform.machine():
+ c['emulatedMachines'] = caps.getEmulatedMachines(target_arch)
+
+ liveSnapSupported = caps.getLiveSnapshotSupport(target_arch)
+ if liveSnapSupported is not None:
+ caps['liveSnapshot'] = str(liveSnapSupported).lower()
+
+ return c
+
+
+def main():
+ if config.getboolean('vars', 'fake_kvm_support'):
+ try:
+ c = hooking.read_json()
+ target_arch = config.get('vars', 'fake_kvm_architecture')
+ c = fake_caps(c, target_arch)
+ hooking.write_json(c)
+ except:
+ hooking.exit_hook('faqemu: %s\n'
+ % traceback.format_exc())
+ sys.exit(2)
+
+
+def test():
+ from pprint import pprint
+ pprint(fake_caps({}, 'ppc64'))
+
+
+if __name__ == '__main__':
+ if '--test' in sys.argv:
+ test()
+ else:
+ main()
--
To view, visit
http://gerrit.ovirt.org/27705
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I46d0079491f707b0abd3fbbe2d47f63697dac9c5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>