mgmt: add mgmt.label.Index method

QubesOS/qubes-issues#2622
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-15 13:58:20 +02:00
parent 278243d7dc
commit 027df9567c
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 23 additions and 0 deletions

View File

@ -464,6 +464,20 @@ class QubesMgmt(AbstractQubesMgmt):
return label.color
@api('mgmt.label.Index', no_payload=True)
@asyncio.coroutine
def label_index(self):
assert self.dest.name == 'dom0'
try:
label = self.app.get_label(self.arg)
except KeyError:
raise qubes.exc.QubesValueError
self.fire_event_for_permission(label=label)
return str(label.index)
@api('mgmt.label.Create')
@asyncio.coroutine
def label_create(self, untrusted_payload):

View File

@ -681,6 +681,15 @@ class TC_00_VMs(MgmtTestCase):
[unittest.mock.call('red')])
self.assertFalse(self.app.save.called)
def test_195_label_index(self):
self.app.get_label = unittest.mock.Mock()
self.app.get_label.configure_mock(**{'return_value.index': 1})
value = self.call_mgmt_func(b'mgmt.label.Index', b'dom0', b'red')
self.assertEqual(value, '1')
self.assertEqual(self.app.get_label.mock_calls,
[unittest.mock.call('red')])
self.assertFalse(self.app.save.called)
def test_200_label_create(self):
self.app.get_label = unittest.mock.Mock()
self.app.get_label.side_effect=KeyError