core/qubes.py: ensure that all default_*vm are present in collection

References to invalid qids are None'd. Failure to do so may cause KeyErrors even
on fixing ntpd service during instantiation of QubesVmCollection.
This commit is contained in:
Wojtek Porczyk 2015-02-17 14:35:38 +01:00
parent c37390e33f
commit 241cf2e089

View File

@ -734,6 +734,25 @@ class QubesVmCollection(dict):
self.default_kernel = element.get("default_kernel")
def _check_global(self, attr, default):
qid = getattr(self, attr)
if qid is None:
return
try:
self[qid]
except KeyError:
setattr(self, attr, default)
def check_globals(self):
'''Ensure that all referenced qids are present in the collection'''
self._check_global('default_template_qid', None)
self._check_global('default_fw_netvm_qid', None)
self._check_global('default_netvm_qid', self.default_fw_netvm_qid)
self._check_global('updatevm_qid', self.default_netvm_qid)
self._check_global('clockvm_qid', self.default_netvm_qid)
def load(self):
self.clear()
@ -774,6 +793,8 @@ class QubesVmCollection(dict):
os.path.basename(sys.argv[0]), vm_class_name, err))
return False
self.check_globals()
# if there was no clockvm entry in qubes.xml, try to determine default:
# root of default NetVM chain
if tree.getroot().get("clockvm") is None: