示例#1
0
 def test_remove_dhcp_host_exception(self):
     """
     Test remove_dhcp_host action raises exception
     """
     with pytest.raises(
             RuntimeError,
             message=
             'action should raise an error if configure_dhcp raises an exception'
     ):
         networks = [{
             'name': 'network',
             'dhcpserver': {
                 'hosts': [{
                     'macaddress': 'address1'
                 }]
             }
         }]
         self.valid_data['networks'] = networks
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw._gateway_sal.configure_dhcp.side_effect = RuntimeError
         gw.remove_dhcp_host('network', {'macaddress': 'address1'})
         assert gw.data['networks'] == networks
         assert gw._gateway_sal.configure_dhcp.call_count == 2
         assert gw._gateway_sal.configure_cloudinit.call_count == 2
示例#2
0
 def test_remove_dhcp_host_name_doesnt_exists(self):
     """
     Test remove_dhcp_host action if network with name doesnt exist
     """
     with pytest.raises(
             LookupError,
             message=
             'action should raise an error if network with this name doesnt exist'
     ):
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.remove_dhcp_host('network', {'macaddress': 'address2'})
示例#3
0
 def test_remove_dhcp_host_before_start(self):
     """
     Test remove_dhcp_host action before gateway start
     """
     with pytest.raises(
             StateCheckError,
             message=
             'actions should raise an error if gateway isn\'t started'):
         self.valid_data['networks'] = [{
             'name': 'network',
             'dhcpserver': {
                 'hosts': [{
                     'macaddress': 'address1'
                 }]
             }
         }]
         gw = Gateway('gw', data=self.valid_data)
         gw.remove_dhcp_host('network', {'macaddress': 'address1'})
示例#4
0
 def test_remove_dhcp_host_macaddress_doesnt_exists(self):
     """
     Test remove_dhcp_host action if host with the same macaddress doesnt exist
     """
     with pytest.raises(
             LookupError,
             message=
             'action should raise an error if host with the macaddress doesnt exist'
     ):
         self.valid_data['networks'] = [{
             'name': 'network',
             'dhcpserver': {
                 'hosts': [{
                     'macaddress': 'address1'
                 }]
             }
         }]
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.remove_dhcp_host('network', {'macaddress': 'address2'})
示例#5
0
 def test_remove_dhcp_host(self):
     """
     Test remove_dhcp_host action
     """
     self.valid_data['networks'] = [{
         'name': 'network',
         'dhcpserver': {
             'hosts': [{
                 'macaddress': 'address1'
             }]
         }
     }]
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.remove_dhcp_host('network', {'macaddress': 'address1'})
     assert gw.data['networks'] == [{
         'name': 'network',
         'dhcpserver': {
             'hosts': []
         }
     }]
     gw._gateway_sal.configure_dhcp.assert_called_once_with()
     gw._gateway_sal.configure_cloudinit.assert_called_once_with()