def test_add_dhcp_host_exception(self): """ Test add_dhcp_host action raises exception """ with pytest.raises( ValueError, message= 'action should raise an error if configure_dhcp raises an exception' ): self.valid_data['networks'] = [{ 'name': 'network', 'dhcpserver': { 'hosts': [{ 'macaddress': 'address1', 'hostname': 'one' }] } }] gw = Gateway('gw', data=self.valid_data) gw.state.set('actions', 'start', 'ok') gw.add_dhcp_host('network', { 'macaddress': 'address2', 'hostname': 'one' }) assert gw.data['networks'] == [] assert gw._gateway_sal.configure_dhcp.call_count == 2 assert gw._gateway_sal.configure_cloudinit.call_count == 2
def test_add_dhcp_host(self): """ Test add_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.add_dhcp_host('network', {'macaddress': 'address2'}) assert gw.data['networks'] == [{ 'name': 'network', 'dhcpserver': { 'hosts': [{ 'macaddress': 'address1' }, { 'macaddress': 'address2' }] } }] gw._gateway_sal.configure_dhcp.assert_called_once_with() gw._gateway_sal.configure_cloudinit.assert_called_once_with()
def test_add_dhcp_host_name_doesnt_exists(self): """ Test add_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.add_dhcp_host('network', {'macaddress': 'address2'})
def test_add_dhcp_host_before_start(self): """ Test add_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.add_dhcp_host('network', {'macaddress': 'address2'})
def test_add_http_proxy_macaddress_exists(self): """ Test add_dhcp_host action if host with the same macaddress exists """ with pytest.raises( ValueError, message= 'action should raise an error if another host with the same macaddress exists' ): self.valid_data['networks'] = [{ 'name': 'network', 'dhcpserver': { 'hosts': [{ 'macaddress': 'address1' }] } }] gw = Gateway('gw', data=self.valid_data) gw.state.set('actions', 'start', 'ok') gw.add_dhcp_host('network', {'macaddress': 'address1'})