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,
 | 
					        In case of success, return actual data. In case of error,
 | 
				
			||||||
        raise appropriate exception.
 | 
					        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':
 | 
					        if response_data[0:2] == b'\x30\x00':
 | 
				
			||||||
            return response_data[2:]
 | 
					            return response_data[2:]
 | 
				
			||||||
        elif response_data[0:2] == b'\x32\x00':
 | 
					        elif response_data[0:2] == b'\x32\x00':
 | 
				
			||||||
@ -89,7 +94,8 @@ class PropertyHolder(object):
 | 
				
			|||||||
            # TODO: handle traceback if given
 | 
					            # TODO: handle traceback if given
 | 
				
			||||||
            raise exc_class(format_string, *args)
 | 
					            raise exc_class(format_string, *args)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            raise qubesmgmt.exc.QubesException('Invalid response format')
 | 
					            raise qubesmgmt.exc.QubesDaemonCommunicationError(
 | 
				
			||||||
 | 
					                'Invalid response format')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def property_list(self):
 | 
					    def property_list(self):
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
 | 
				
			|||||||
@ -101,3 +101,13 @@ class BackupCancelledError(QubesException):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class QubesMemoryError(QubesException, MemoryError):
 | 
					class QubesMemoryError(QubesException, MemoryError):
 | 
				
			||||||
    '''Cannot start domain, because not enough memory is available'''
 | 
					    '''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')
 | 
					        self.assertEqual(str(context.exception), 'An error occurred: 1, 2')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_010_empty(self):
 | 
					    def test_010_empty(self):
 | 
				
			||||||
        self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''\
 | 
					        self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''
 | 
				
			||||||
        # FIXME: change to appropriate exception when defined
 | 
					        with self.assertRaises(qubesmgmt.exc.QubesDaemonNoResponseError) \
 | 
				
			||||||
        with self.assertRaises(qubesmgmt.exc.QubesException) as context:
 | 
					                as context:
 | 
				
			||||||
            vms = list(self.app.domains)
 | 
					            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