app: switch get_local_name method to property

This commit is contained in:
Frédéric Pierret (fepitre) 2019-10-20 21:12:31 +02:00
parent f7740546c9
commit 03bc15dd38
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2
3 changed files with 13 additions and 13 deletions

View File

@ -153,8 +153,6 @@ class QubesBase(qubesadmin.base.PropertyHolder):
log = None
#: do not check for object (VM, label etc) existence before really needed
blind_mode = False
#: local name
local_name = None
def __init__(self):
super(QubesBase, self).__init__(self, 'admin.property.', 'dom0')
@ -166,6 +164,7 @@ class QubesBase(qubesadmin.base.PropertyHolder):
#: cache for available storage pool drivers and options to create them
self._pool_drivers = None
self.log = logging.getLogger('app')
self._local_name = None
def list_vmclass(self):
"""Call Qubesd in order to obtain the vm classes list"""
@ -228,12 +227,13 @@ class QubesBase(qubesadmin.base.PropertyHolder):
""" Remove a storage pool """
self.qubesd_call('dom0', 'admin.pool.Remove', name, None)
def get_local_name(self):
@property
def local_name(self):
""" Get localhost name """
if not self.local_name:
self.local_name = os.uname()[1]
if not self._local_name:
self._local_name = os.uname()[1]
return self.local_name
return self._local_name
def get_label(self, label):
"""Get label as identified by index or name

View File

@ -399,7 +399,7 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase):
('test-vm', 'admin.vm.property.Get', 'guivm', None)] = \
b'0\x00default=False type=vm gui-vm'
self.app.local_name = 'gui-vm'
self.app._local_name = 'gui-vm'
vm = self.app.domains['test-vm']
mock_start_vm = unittest.mock.Mock()
mock_start_stubdomain = unittest.mock.Mock()
@ -681,7 +681,7 @@ HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 206mm x
('test-vm4', 'admin.vm.property.Get', 'guivm', None)] = \
b'0\x00default=False type=vm gui-vm'
self.app.local_name = 'gui-vm'
self.app._local_name = 'gui-vm'
vm = self.app.domains['test-vm']
vm2 = self.app.domains['test-vm2']

View File

@ -253,7 +253,7 @@ class GUILauncher(object):
:param monitor_layout: monitor layout configuration
"""
guivm = getattr(vm, 'guivm', None)
if guivm != vm.app.get_local_name():
if guivm != vm.app.local_name:
vm.log.info('GUI connected to {}. Skipping.'.format(guivm))
return
@ -316,7 +316,7 @@ class GUILauncher(object):
"""Send monitor layout to all (running) VMs"""
monitor_layout = get_monitor_layout()
for vm in self.app.domains:
if getattr(vm, 'guivm', None) != vm.app.get_local_name():
if getattr(vm, 'guivm', None) != vm.app.local_name:
continue
if vm.klass == 'AdminVM':
continue
@ -329,7 +329,7 @@ class GUILauncher(object):
def on_domain_spawn(self, vm, _event, **kwargs):
"""Handler of 'domain-spawn' event, starts GUI daemon for stubdomain"""
try:
if getattr(vm, 'guivm', None) != vm.app.get_local_name():
if getattr(vm, 'guivm', None) != vm.app.local_name:
return
if not vm.features.check_with_template('gui', True):
return
@ -342,7 +342,7 @@ class GUILauncher(object):
def on_domain_start(self, vm, _event, **kwargs):
"""Handler of 'domain-start' event, starts GUI daemon for actual VM"""
try:
if getattr(vm, 'guivm', None) != vm.app.get_local_name():
if getattr(vm, 'guivm', None) != vm.app.local_name:
return
if not vm.features.check_with_template('gui', True):
return
@ -360,7 +360,7 @@ class GUILauncher(object):
for vm in self.app.domains:
if vm.klass == 'AdminVM':
continue
if getattr(vm, 'guivm', None) != vm.app.get_local_name():
if getattr(vm, 'guivm', None) != vm.app.local_name:
continue
if not vm.features.check_with_template('gui', True):
continue