From abbc828b704322a9d8b80ba5b0ca5620d518ac25 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 13 Apr 2013 16:18:03 -0400 Subject: [PATCH] VirtualGraphics: Don't lookup local keymap over and over Triggered with virt-manager: new vm -> customize before install with a non qemu. Guest.get_xml_config copies each device so it can set defaults in a non persistent way. Unfortunately VirtualGraphics was copied before a keymap lookup was ever done. End result was that we called util.default_keymap over and over which is slow and floods the logs. --- virtinst/VirtualGraphics.py | 3 +++ virtinst/XMLBuilderDomain.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/virtinst/VirtualGraphics.py b/virtinst/VirtualGraphics.py index 93de7d2c..835d21d1 100644 --- a/virtinst/VirtualGraphics.py +++ b/virtinst/VirtualGraphics.py @@ -127,6 +127,9 @@ class VirtualGraphics(VirtualDevice): if channels: self.channels = channels + def _cache(self): + # Make sure we've cached the _local_keymap value before copy() + self._default_keymap() def _default_keymap(self, force_local=False): if (not force_local and self.conn and diff --git a/virtinst/XMLBuilderDomain.py b/virtinst/XMLBuilderDomain.py index 74e0eed9..195c0623 100644 --- a/virtinst/XMLBuilderDomain.py +++ b/virtinst/XMLBuilderDomain.py @@ -434,10 +434,20 @@ class XMLBuilderDomain(object): except: pass + def _cache(self): + """ + This is a hook for classes to cache any state that is expensive + to lookup before we copy the object as part of Guest.get_xml_config. + Saves us from possibly doing the lookup over and over + """ + pass + + def copy(self): # Otherwise we can double free XML info if self._is_parse(): return self + self._cache() return copy.copy(self) def get_conn(self):