Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vm.icon property #342

Merged
merged 3 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions qubes/ext/core_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,25 @@ def qubes_features_request(self, vm, event, untrusted_features):
# if this is the first time qrexec was advertised, now can finish
# template setup
yield from vm.fire_event_async('template-postinstall')

# pylint: disable=no-self-use
def set_servicevm_feature(self, subject):
if getattr(subject, 'provides_network', False):
subject.features['servicevm'] = 1
elif 'servicevm' in subject.features:
del subject.features['servicevm']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was deleting servicevm necessary? Later on this commit:

Came here from QubesOS/qubes-mgmt-salt-dom0-virtual-machines#63

    def test_100_servicevm_feature(self):
        self.vm.provides_network = True
        self.ext.set_servicevm_feature(self.vm)
        self.assertEqual(self.features['servicevm'], 1)

        self.vm.provides_network = False
        self.ext.set_servicevm_feature(self.vm)
        self.assertNotIn('servicevm', self.features)

I don't think not having provides_network must enforce not having servicevm.


@qubes.ext.handler('property-set:provides_network')
def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
# pylint: disable=unused-argument
self.set_servicevm_feature(subject)

@qubes.ext.handler('property-del:provides_network')
def on_property_del(self, subject, event, name):
# pylint: disable=unused-argument
self.set_servicevm_feature(subject)

@qubes.ext.handler('domain-load')
def on_domain_load(self, subject, event):
# pylint: disable=unused-argument
self.set_servicevm_feature(subject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all will work fine for new VMs, because default value for provides_network is false (so default not having servicevm feature is correct).
But the above miss adding the feature for existing VMs (on system update from the version before this change). The easiest way to do that is adding similar handler for domain-load event (loading a domain from qubes.xml - basically qubesd service start).

13 changes: 13 additions & 0 deletions qubes/tests/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def setUp(self):
self.features = {}
self.vm.configure_mock(**{
'features.get.side_effect': self.features.get,
'features.items.side_effect': self.features.items,
'features.__iter__.side_effect': self.features.__iter__,
'features.__contains__.side_effect': self.features.__contains__,
'features.__setitem__.side_effect': self.features.__setitem__,
'features.__delitem__.side_effect': self.features.__delitem__,
})

def test_010_notify_tools(self):
Expand Down Expand Up @@ -181,6 +184,16 @@ def test_018_notify_tools_already_installed(self):
('features.__contains__', ('gui',), {}),
])

def test_100_servicevm_feature(self):
self.vm.provides_network = True
self.ext.set_servicevm_feature(self.vm)
self.assertEqual(self.features['servicevm'], 1)

self.vm.provides_network = False
self.ext.set_servicevm_feature(self.vm)
self.assertNotIn('servicevm', self.features)


class TC_10_WindowsFeatures(qubes.tests.QubesTestCase):
def setUp(self):
super().setUp()
Expand Down