Fixed grey label color value causing accidental green icons

fixes QubesOS/qubes-issues#3471
This commit is contained in:
Marta Marczykowska-Górecka 2020-08-13 19:16:52 +02:00
parent 66d8a78481
commit b506586089
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 56 additions and 1 deletions

View File

@ -981,6 +981,16 @@ class Qubes(qubes.PropertyHolder):
pass
node_default_fw_netvm.getparent().remove(node_default_fw_netvm)
def _migrate_labels(self):
"""Migrate changed labels"""
if self.xml is None:
return
# fix grey being green
grey_label = self.xml.find('./labels/label[@color=\'0x555753\']')
if grey_label is not None:
grey_label.set('color', '0x555555')
def load(self, lock=False):
"""Open qubes.xml
@ -992,6 +1002,8 @@ class Qubes(qubes.PropertyHolder):
fh = self._acquire_lock()
self.xml = lxml.etree.parse(fh)
self._migrate_labels()
# stage 1: load labels and pools
for node in self.xml.xpath('./labels/label'):
label = qubes.Label.fromxml(node)
@ -1211,7 +1223,7 @@ class Qubes(qubes.PropertyHolder):
2: qubes.Label(2, '0xf57900', 'orange'),
3: qubes.Label(3, '0xedd400', 'yellow'),
4: qubes.Label(4, '0x73d216', 'green'),
5: qubes.Label(5, '0x555753', 'gray'),
5: qubes.Label(5, '0x555555', 'gray'),
6: qubes.Label(6, '0x3465a4', 'blue'),
7: qubes.Label(7, '0x75507b', 'purple'),
8: qubes.Label(8, '0x000000', 'black'),

View File

@ -508,6 +508,49 @@ class TC_89_QubesEmpty(qubes.tests.QubesTestCase):
self.app.close()
del self.app
def test_101_property_migrate_label(self):
xml_template = """<?xml version="1.0" encoding="utf-8" ?>
<qubes version="3.0">
<labels>
<label id="label-1" color="{old_gray}">gray</label>
</labels>
<pools>
<pool driver="file" dir_path="/tmp/qubes-test" name="default"/>
</pools>
<domains>
<domain class="StandaloneVM" id="domain-1">
<properties>
<property name="qid">1</property>
<property name="name">sys-net</property>
<property name="provides_network">True</property>
<property name="label" ref="label-1" />
<property name="netvm"></property>
<property name="uuid">2fcfc1f4-b2fe-4361-931a-c5294b35edfa</property>
</properties>
<features/>
<devices class="pci"/>
</domain>
</domains>
</qubes>
"""
with self.subTest('replace_label'):
with open('/tmp/qubestest.xml', 'w') as xml_file:
xml_file.write(xml_template.format(old_gray='0x555753'))
self.app = qubes.Qubes('/tmp/qubestest.xml', offline_mode=True)
self.assertEqual(
self.app.get_label('gray').color, '0x555555')
self.app.close()
del self.app
with self.subTest('dont_replace_label'):
with open('/tmp/qubestest.xml', 'w') as xml_file:
xml_file.write(xml_template.format(old_gray='0x123456'))
self.app = qubes.Qubes('/tmp/qubestest.xml', offline_mode=True)
self.assertEqual(
self.app.get_label('gray').color, '0x123456')
self.app.close()
del self.app
class TC_90_Qubes(qubes.tests.QubesTestCase):
def tearDown(self):