Add specific exception for qubesd communication error
This commit is contained in:
		
							parent
							
								
									9d5e974c5b
								
							
						
					
					
						commit
						5615510da5
					
				@ -69,6 +69,11 @@ class PropertyHolder(object):
 | 
			
		||||
        In case of success, return actual data. In case of error,
 | 
			
		||||
        raise appropriate exception.
 | 
			
		||||
        '''
 | 
			
		||||
 | 
			
		||||
        if len(response_data) == 0:
 | 
			
		||||
            raise qubesmgmt.exc.QubesDaemonNoResponseError(
 | 
			
		||||
                'Got empty response from qubesd')
 | 
			
		||||
 | 
			
		||||
        if response_data[0:2] == b'\x30\x00':
 | 
			
		||||
            return response_data[2:]
 | 
			
		||||
        elif response_data[0:2] == b'\x32\x00':
 | 
			
		||||
@ -89,7 +94,8 @@ class PropertyHolder(object):
 | 
			
		||||
            # TODO: handle traceback if given
 | 
			
		||||
            raise exc_class(format_string, *args)
 | 
			
		||||
        else:
 | 
			
		||||
            raise qubesmgmt.exc.QubesException('Invalid response format')
 | 
			
		||||
            raise qubesmgmt.exc.QubesDaemonCommunicationError(
 | 
			
		||||
                'Invalid response format')
 | 
			
		||||
 | 
			
		||||
    def property_list(self):
 | 
			
		||||
        '''
 | 
			
		||||
 | 
			
		||||
@ -101,3 +101,13 @@ class BackupCancelledError(QubesException):
 | 
			
		||||
 | 
			
		||||
class QubesMemoryError(QubesException, MemoryError):
 | 
			
		||||
    '''Cannot start domain, because not enough memory is available'''
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class QubesDaemonCommunicationError(QubesException, IOError):
 | 
			
		||||
    '''Error while communicating with qubesd, may mean insufficient
 | 
			
		||||
    permissions, as well'''
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# pylint: disable=too-many-ancestors
 | 
			
		||||
class QubesDaemonNoResponseError(QubesDaemonCommunicationError):
 | 
			
		||||
    '''Got empty response from qubesd'''
 | 
			
		||||
 | 
			
		||||
@ -51,8 +51,9 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase):
 | 
			
		||||
        self.assertEqual(str(context.exception), 'An error occurred: 1, 2')
 | 
			
		||||
 | 
			
		||||
    def test_010_empty(self):
 | 
			
		||||
        self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''\
 | 
			
		||||
        # FIXME: change to appropriate exception when defined
 | 
			
		||||
        with self.assertRaises(qubesmgmt.exc.QubesException) as context:
 | 
			
		||||
        self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''
 | 
			
		||||
        with self.assertRaises(qubesmgmt.exc.QubesDaemonNoResponseError) \
 | 
			
		||||
                as context:
 | 
			
		||||
            vms = list(self.app.domains)
 | 
			
		||||
        self.assertEqual(str(context.exception), 'Invalid response format')
 | 
			
		||||
        self.assertEqual(str(context.exception),
 | 
			
		||||
            'Got empty response from qubesd')
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user