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

Create IP randomization function for test suites #27

Open
dgjustice opened this issue Jun 18, 2021 · 6 comments
Open

Create IP randomization function for test suites #27

dgjustice opened this issue Jun 18, 2021 · 6 comments

Comments

@dgjustice
Copy link
Contributor

dgjustice commented Jun 18, 2021

Environment

  • netutils version:

Proposed Functionality

This functionality is largely supported in Faker, but I am proposing a stand-alone utility with extra nerd knobs.

generate_random_ip(*args) and/or generate_random_network(*args)

args:

  • address family
  • class
  • mask length

returns:

  • str
  • ipaddress.ip_address/ipaddress.ip_network
  • packed bytes?
  • optional?

Use Case

Random IP/networks for unit testing

@itdependsnetworks @jeffkala

@dgjustice
Copy link
Contributor Author

I was also thinking about supporting a whitelist or blacklist. e.g. pass it a list of blocks to exclude due to business logic restrictions etc.

@jeffkala
Copy link
Collaborator

I like the thought of a whitelist/blacklist, sounds like it would be very useful.

@itdependsnetworks
Copy link
Contributor

Another use case I have considered in the past is maintaining octet size. This comes into play when replacing IP addresses that change the whitespace of the output. As networking is still heavy parsing, this has bit me before.
Imagine

IP          Name        description
-------------------------------------------------------
10.1.1.1    Hello       description should start on char 25
10.1.1.2    World       description should start on char 25

turns into

IP          Name        description
-------------------------------------------------------
100.30.182.1    Hello         description should start on char 25
1.1.1.2    World       description should start on char 25

@dgjustice
Copy link
Contributor Author

For that use case, would it be better to address the issue in the template that generates test cases?

template = """IP             Name        description
-------------------------------------------------------
{ip1}    Hello         description should start on char 25
{ip2}    World         description should start on char 25
"""

ip1 = "100.30.182.1"
ip2 = "1.1.1.2"

print(template.format(ip1=ip1, ip2=ip2))

template = """IP             Name        description
-------------------------------------------------------
{ip1:<14} Hello         description should start on char 25
{ip2:<14} World         description should start on char 25
"""

print(template.format(ip1=ip1, ip2=ip2))
IP             Name        description
-------------------------------------------------------
100.30.182.1    Hello         description should start on char 25
1.1.1.2    World         description should start on char 25

IP             Name        description
-------------------------------------------------------
100.30.182.1   Hello         description should start on char 25
1.1.1.2        World         description should start on char 25

Would this address your concern?

@itdependsnetworks
Copy link
Contributor

The use case is anonymizing and generating the data. Imagine taking in dozens of outputs for an ntc-templates PR and you obviously cannot use your companies IPs, so you want to anonymize. If you anonymize without keeping the octet structure the same, you will end up with bad data.

@dgjustice
Copy link
Contributor Author

I've poked around with this quite a bit this week, and I hope to have a draft submitted tomorrow. I think randomization and obfuscation should be dealt with in different functions. I am happy to add the latter based on the work you shared from the ansible module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants