From 0293c1c7ef31f1e8c4c81b92804026bff26aaba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 26 Jun 2016 02:18:13 +0200 Subject: [PATCH] qubes/vm: move misc XML tags loading to separate method --- qubes/__init__.py | 10 ++++++++++ qubes/app.py | 1 + qubes/tests/vm/init.py | 1 + qubes/vm/__init__.py | 44 ++++++++++++++++-------------------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/qubes/__init__.py b/qubes/__init__.py index 233f480f..650923f4 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -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): diff --git a/qubes/app.py b/qubes/app.py index ddbbc4ba..088134f0 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -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 diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 0258159c..05185f36 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -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') diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index cc6b6c43..f07512af 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -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)