MartijnBraam / python-isc-dhcp-leases

Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server
MIT License
123 stars 47 forks source link

Fixed crash when record has hardware but not ends fields #16

Closed colinjc closed 7 years ago

colinjc commented 7 years ago

When parsing our dhcpd.leases file the library was crashing on a record because it has the hardware field but not he ends field, so it tries to construct and fails with a KeyError here

        if properties['ends'] == 'never':

lease 172.23.251.150 { starts 4 2015/09/10 00:29:00; tstp 4 2015/09/10 00:28:44; tsfp 4 2015/09/10 00:29:00; atsfp 4 2015/09/10 00:29:00; binding state free; hardware ethernet 00:21:cc:06:94:e9; uid "\001\000!\314\006\224\351"; }

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling bff0693783b04cbd544eeb367b756869a46e2286 on colinjc:master into 310e61bbba54e789453161961d66f1eaad6f382b on MartijnBraam:master.

andir commented 7 years ago

LGTM.

Out of curiousity how did you produce that lease? Static lease?

andir commented 7 years ago

One more thing: Do you mind adding that kind of case to the tests?

colinjc commented 7 years ago

@andir Honestly, I'm not sure how the lease was produced since I had nothing to do with the configuration of the server. I assume that you're right and it is a static lease though judging from the age.

I can quickly add a test, but I'm not sure where to add them. Should I add a record to the debian7 file and put the test in test_iscDhcpLeases.py?

MartijnBraam commented 7 years ago

Thanks for the contribution.

The test code should go in test_iscDhcpLeases.py and the record should go in a seperate file in the test_files directory (the same as the unittest for the options)

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 523d79501153fb7eab8b6d52dc94d81464165056 on colinjc:master into 310e61bbba54e789453161961d66f1eaad6f382b on MartijnBraam:master.

MartijnBraam commented 7 years ago

Looks great, thanks!