qubes/vm: move misc XML tags loading to separate method

This commit is contained in:
Marek Marczykowski-Górecki 2016-06-26 02:18:13 +02:00
parent a5e575618c
commit 0293c1c7ef
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 29 additions and 27 deletions

View File

@ -439,6 +439,16 @@ class PropertyHolder(qubes.events.Emitter):
for key, value in propvalues.items():
setattr(self, key, value)
if self.xml is not None:
# check if properties are appropriate
all_names = set(prop.__name__ for prop in self.property_list())
for node in self.xml.xpath('./properties/property'):
name = node.get('name')
if name not in all_names:
raise TypeError(
'property {!r} not applicable to {!r}'.format(
name, self.__class__.__name__))
@classmethod
def property_list(cls, load_stage=None):

View File

@ -700,6 +700,7 @@ class Qubes(qubes.PropertyHolder):
# stage 4: fill all remaining VM properties
for vm in self.domains:
vm.load_properties(load_stage=4)
vm.load_extras()
# stage 5: misc fixups

View File

@ -83,6 +83,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
node = self.xml.xpath('//domain')[0]
vm = TestVM(None, node)
vm.load_properties(load_stage=None)
vm.load_extras()
self.assertEqual(vm.qid, 1)
self.assertEqual(vm.testprop, 'testvalue')

View File

@ -183,39 +183,29 @@ class BaseVM(qubes.PropertyHolder):
#: user-specified tags
self.tags = tags or {}
if self.xml is not None:
# features
for node in xml.xpath('./features/feature'):
self.features[node.get('name')] = node.text
# devices (pci, usb, ...)
for parent in xml.xpath('./devices'):
devclass = parent.get('class')
for node in parent.xpath('./device'):
self.devices[devclass].attach(node.text)
# tags
for node in xml.xpath('./tags/tag'):
self.tags[node.get('name')] = node.text
# SEE:1815 firewall, policy.
# check if properties are appropriate
all_names = set(prop.__name__ for prop in self.property_list())
for node in self.xml.xpath('./properties/property'):
name = node.get('name')
if name not in all_names:
raise TypeError(
'property {!r} not applicable to {!r}'.format(
name, self.__class__.__name__))
#: logger instance for logging messages related to this VM
self.log = None
if hasattr(self, 'name'):
self.init_log()
def load_extras(self):
# features
for node in self.xml.xpath('./features/feature'):
self.features[node.get('name')] = node.text
# devices (pci, usb, ...)
for parent in self.xml.xpath('./devices'):
devclass = parent.get('class')
for node in parent.xpath('./device'):
self.devices[devclass].attach(node.text)
# tags
for node in self.xml.xpath('./tags/tag'):
self.tags[node.get('name')] = node.text
# SEE:1815 firewall, policy.
def init_log(self):
'''Initialise logger for this domain.'''
self.log = qubes.log.get_vm_logger(self.name)