Skip to content

Conversation

praptisharma28
Copy link
Contributor

Fixes #842

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.

A test which replicates the bug is missing.

@coveralls
Copy link

coveralls commented May 10, 2024

Coverage Status

coverage: 98.734% (-0.02%) from 98.75%
when pulling 8fd9407 on praptisharma28:subnet
into f0bdf03 on openwisp:master.

@praptisharma28
Copy link
Contributor Author

A test which replicates the bug is missing.

Okay @nemesifier will add.

)
}
)
return
Copy link
Member

Choose a reason for hiding this comment

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

This is not the right approach: we must not cover up problematic code with more code. We must instead analyze, understand and fix the existing code which is causing the issue, which lies below.

size=32, number_of_ips=1, number_of_subnets=1
)
rule.full_clean()
rule.save()
Copy link
Member

Choose a reason for hiding this comment

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

Calling save and full clean is not needed because those methods are already called by the logic in _get_vpn_subdivision_rule, please always read the logic of the methods and functions you call.

This is sufficient:

rule = self._get_vpn_subdivision_rule(
    size=32, number_of_ips=1, number_of_subnets=1
)

rule.full_clean()
rule.save()
self.assertEqual(rule.size, 32)
self.assertEqual(rule.number_of_ips, 1)
Copy link
Member

@nemesifier nemesifier May 13, 2024

Choose a reason for hiding this comment

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

These assertions here aren't really useful. The entire test suite of this submodule relies on _get_vpn_subdivision_rule to create subnet division rules so we can assume that size and number_of_ips will be correctly assigned.

In this test we need to add some code which triggers the execution of this rule at least once to ensure we successfully get a new /32 subnet with 1 ip address in it.

@nemesifier
Copy link
Member

While reviewing this PR I found out quite a few more issues with the code and I realized that the time I would have needed to explain everything was a lot higher than just fixing it myself so I went ahead and took this over.

@praptisharma28, please see my changes #860 and ask questions for any part you don't understand.

@nemesifier nemesifier closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Subnet division rule does not allow assigning only 1 ip in /32

3 participants