Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixed subnet /32 & /128 pie chart error #129 #134

Merged

Conversation

Aryamanz29
Copy link
Member

@Aryamanz29 Aryamanz29 commented Feb 20, 2022

See comment #129 (comment)

Screenshot from 2022-02-20 23-47-07

@Aryamanz29 Aryamanz29 changed the title [fix] Fixed subnet /32 pie chart #129 [fix] Fixed subnet /32 pie chart error #129 Feb 20, 2022
@coveralls
Copy link

coveralls commented Feb 22, 2022

Coverage Status

Coverage increased (+0.001%) to 99.854% when pulling dda339c on Aryamanz29:issue-129/subnet-32-fix-chart into 4f15237 on openwisp:master.

@Aryamanz29
Copy link
Member Author

Coverage is decreasing, I need to work on this 😅

Only for subnet /32, it returns single host that's why we encountered tis bug
To fix this we can use _prefixlen with subnet.subnet.max_prefixlen inside count()

Fixes openwisp#129
@Aryamanz29
Copy link
Member Author

Coverage is decreasing, I need to work on this sweat_smile

Done 👍

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aryamanz29 there's no new test for testing this fix explicitly. Can you add a test that fails without this fix?

openwisp_ipam/api/views.py Outdated Show resolved Hide resolved
openwisp_ipam/api/views.py Outdated Show resolved Hide resolved
openwisp_ipam/api/views.py Show resolved Hide resolved
@Aryamanz29
Copy link
Member Author

@pandafy Done requested changes 👍

@pandafy pandafy self-requested a review February 23, 2022 19:08
@pandafy pandafy added this to In progress in OpenWISP Priorities for next releases via automation Feb 23, 2022
@pandafy pandafy moved this from In progress to Ready for review/testing in OpenWISP Priorities for next releases Feb 23, 2022
@devkapilbansal devkapilbansal moved this from Ready for review/testing to In progress in OpenWISP Priorities for next releases Feb 23, 2022
@devkapilbansal devkapilbansal moved this from In progress to Ready for review/testing in OpenWISP Priorities for next releases Feb 23, 2022
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aryamanz29 the solution work and the code is good. I haven't tried the test yet but I will.

I have one request: I am not sure why I didn't test the same for IPv6 too but it seems to me that the problem happens there too with /128 subnets, can you fix that as well please? The solution and test used can be equivalent.

@Aryamanz29
Copy link
Member Author

Aryamanz29 commented Feb 25, 2022

@Aryamanz29 the solution work and the code is good. I haven't tried the test yet but I will.

I have one request: I am not sure why I didn't test the same for IPv6 too but it seems to me that the problem happens there too with /128 subnets, can you fix that as well please? The solution and test used can be equivalent.

Sure, I'll check with /128 subnets and update 👍

@Aryamanz29
Copy link
Member Author

@Aryamanz29 the solution work and the code is good. I haven't tried the test yet but I will.
I have one request: I am not sure why I didn't test the same for IPv6 too but it seems to me that the problem happens there too with /128 subnets, can you fix that as well please? The solution and test used can be equivalent.

Sure, I'll check with /128 subnets and update +1

Update :
Yes it's not showing pie chart with subnet/128, Also instead of raising ValueError at this endpoint http://127.0.0.1:8000/api/v1/ipam/subnet/64d5dfc7-7845-42c1-8856-d3436dddc750/hosts/, It is returning empty host list.

Screenshot from 2022-02-26 21-34-15,

@Aryamanz29
Copy link
Member Author

PR now ready for testing 👍

@Aryamanz29 Aryamanz29 changed the title [fix] Fixed subnet /32 pie chart error #129 [fix] Fixed subnet /32 & /128 pie chart error #129 Feb 26, 2022
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress @Aryamanz29, we're almost there, I noticed an issue with the visualization though, it happens both on IPv4 and IPv6:

Screenshot from 2022-03-01 12-58-07

In this case I created the IP address for this subnet to ensure the pie chart shows correctly.
However, the "subnet visual display" below is showing an address that doesn't belong to the subnet,

It should be showing 192.168.0.250 but it's instead showing the next address, it happens also on IPv6 can you fix that please?

Screenshot from 2022-03-01 13-01-05

OpenWISP Priorities for next releases automation moved this from Ready for review/testing to In progress Mar 1, 2022
@Aryamanz29
Copy link
Member Author

@nemesisdesign
This problem occurs due to this line 👇

host = self.subnet.subnet._address_class(self.network + 1 + i + self.start)

because of extra +1 in host (But don't know why we're adding +1 here 🤔 ), It always shows the next address. After removing, It looks good 👇

Screenshot from 2022-03-01 21-52-17

@Aryamanz29
Copy link
Member Author

Update : Only in case of single hosts (ie . in case of subnet /32 and /128), We must return first address otherwise It can starts from next address.

import ipaddress

subnet128 = ipaddress.ip_network('2001:db00::/128')
subnet32 = ipaddress.ip_network('198.168.0.250/32')
subnet8 = ipaddress.ip_network('10.0.0.0/8')

print(list(subnet128.hosts()))
print(list(subnet32.hosts()))
# Contains 16777214 hosts
print(list(subnet8.hosts())[:5])
(env) ➜  ipam-test py test.py
[IPv6Address('2001:db00::')]
[IPv4Address('198.168.0.250')]
[IPv4Address('10.0.0.1'), IPv4Address('10.0.0.2'), IPv4Address('10.0.0.3'), IPv4Address('10.0.0.4'), IPv4Address('10.0.0.5')]

openwisp_ipam/api/views.py Outdated Show resolved Hide resolved
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @Aryamanz29, there's one outstanding issue which I highlighted below.

openwisp_ipam/tests/test_admin.py Outdated Show resolved Hide resolved
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@nemesifier nemesifier merged commit c10548f into openwisp:master Mar 2, 2022
OpenWISP Priorities for next releases automation moved this from In progress to Done Mar 2, 2022
@Aryamanz29 Aryamanz29 deleted the issue-129/subnet-32-fix-chart branch April 29, 2022 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Subnet /32 gives error in pie chart
5 participants