diff --git a/CHANGES.md b/CHANGES.md index c47f299..b5a7db1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,12 @@ - Summary: - Insert something here +## Version: 0.7.32 + +- Released: 2024-03-17 +- Summary: + - Update tests + ## Version: 0.7.12 - 0.7.31 - Released: 2024-03-17 diff --git a/Makefile b/Makefile index 764a61a..371be65 100644 --- a/Makefile +++ b/Makefile @@ -45,19 +45,20 @@ install_build: # Install the newly-built package pip install --force-reinstall dist/*.tar.gz -.PHONY: pypi -pypi: +.PHONY: cicd +cicd: @echo "$(COL_CYAN)>> Use CI/CD to publish ciscoconfparse2 pypi artifacts$(COL_END)" make clean # upgrade packaging infra and ciscoconfparse2 dependencies... make dep git commit --all -m "Version $$VERSION" - # tag the repo with $$VERSION + # tag the repo with $$VERSION, upon git tag push, + # this triggers .github/workflows/cicd-publish.yml git tag $$VERSION git checkout main git merge develop git push origin main - # push tag to github origin, which triggers a github CICD action + # push tag to github origin, which triggers a github CICD action (see above) git push origin $$VERSION git checkout develop git pull origin main @@ -225,7 +226,7 @@ clean: help: @# An @ sign prevents outputting the command itself to stdout @echo "help : You figured that out ;-)" - @echo "pypi : Build the project and push to pypi" + @echo "cicd : Git commit, build the project w/ CICD, and push to pypi" @echo "repo-push : Build the project and push to github" @echo "test : Run all doctests and unit tests" @echo "dev : Get all dependencies for the dev environment" diff --git a/ciscoconfparse2/cli_script.py b/ciscoconfparse2/cli_script.py index 2f3b3be..6e403d8 100644 --- a/ciscoconfparse2/cli_script.py +++ b/ciscoconfparse2/cli_script.py @@ -328,7 +328,7 @@ def build_command_args_ipgrep(self) -> None: "-n", "--show-networks", default=False, action='store_true', - help="Only print the network portion of subnets instead of IP hosts (implies --show-cidr). Host-networks (i.e. IPv4 /32 and IPv6 /128 are included by default).") + help="Only print the network portion of subnets instead of IP hosts (implies --show-cidr). Hosts (i.e. IPv4 /32 and IPv6 /128 networks) are also included by default.") parser_optional.add_argument( "-H", "--exclude-hosts", @@ -336,12 +336,6 @@ def build_command_args_ipgrep(self) -> None: action='store_true', help="Exclude all hosts from output (should be used with --show-networks).") - parser_optional.add_argument( - "-X", "--exclude-networks", - default=False, - action='store_true', - help="Exclude all network addresses from output (i.e. only hosts are shown).") - parser_optional_exclusive = parser_optional.add_mutually_exclusive_group() parser_optional_exclusive.add_argument( @@ -759,43 +753,30 @@ def find_ip46_addr_matches(self, # Append if not already in retval... if append_addr: + if self.check_ip46_host_exclusion_args(addr): + continue + if self.check_ip46_net_exclusion_args(addr): + continue + if self.show_networks: - if self.check_ip46_host_exclusion_args(addr): - continue - if self.check_ip46_net_exclusion_args(addr): - continue retval.append(addr.as_cidr_net) elif not self.show_cidr and not self.show_networks: - if self.check_ip46_host_exclusion_args(addr): - continue - if self.check_ip46_net_exclusion_args(addr): - continue retval.append(str(addr.ip)) elif not self.show_networks and self.show_cidr: - if self.check_ip46_host_exclusion_args(addr): - continue - if self.check_ip46_net_exclusion_args(addr): - continue retval.append(addr.as_cidr_addr) + else: + if self.check_ip46_net_exclusion_args(addr): + continue + if self.check_ip46_host_exclusion_args(addr): + continue + # Append unconditionally... if self.show_networks: - if self.check_ip46_net_exclusion_args(addr): - continue - if self.check_ip46_host_exclusion_args(addr): - continue retval.append(addr.as_cidr_net) elif not self.show_cidr and not self.show_networks: - if self.check_ip46_net_exclusion_args(addr): - continue - if self.check_ip46_host_exclusion_args(addr): - continue retval.append(str(addr.ip)) elif not self.show_networks and self.show_cidr: - if self.check_ip46_net_exclusion_args(addr): - continue - if self.check_ip46_host_exclusion_args(addr): - continue retval.append(addr.as_cidr_addr) return retval @@ -837,8 +818,10 @@ def check_ip46_net_exclusion_args(self, addr: Union[IPv4Obj, IPv6Obj]) -> bool: # (even though technically a /128 is also a network) return False - # it's a network if the network address equals the ip address - elif str(addr.as_cidr_net) == str(addr.as_cidr_addr): + else: + # Since we are showing networks, any address (on the + # subnet number or not) should return True if the + # cases above did not match. return True return False diff --git a/pyproject.toml b/pyproject.toml index c17cd67..e15fa3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [project] name = "ciscoconfparse2" -version = "0.7.31" +version = "0.7.32" description = "Parse, Audit, Query, Build, and Modify Cisco IOS-style and JunOS-style configs" readme = "README.md" license = "GPL-3.0-only" diff --git a/tests/test_Cli_Script.py b/tests/test_Cli_Script.py index e9041c9..beece36 100644 --- a/tests/test_Cli_Script.py +++ b/tests/test_Cli_Script.py @@ -253,7 +253,7 @@ def testValues_ccp_script_entry_cliapplication_ipgrep_14(): assert cliapp.subnets == '0.0.0.0/0' assert cliapp.stdout == ['192.0.2.0/24',] -def testValues_ccp_script_entry_cliapplication_ipgrep_14(): +def testValues_ccp_script_entry_cliapplication_ipgrep_15(): """Ensure that CliApplication() ipgrep with --show-networks --exclude-hosts and --show-cidr is three IPv6 networks from sample_01.txt""" cliapp = ccp_script_entry("ccp_faked ipgrep --show-networks --exclude-hosts -6 fixtures/plain_text/sample_01.txt") assert len(cliapp.stdout) == 3 @@ -263,6 +263,26 @@ def testValues_ccp_script_entry_cliapplication_ipgrep_14(): '2001:db8::/64', '2001:db8::/64',] +def testValues_ccp_script_entry_cliapplication_ipgrep_16(): + """Ensure that CliApplication() ipgrep with --show-networks --exclude-hosts is no IPv6 networks from sample_01.txt""" + cliapp = ccp_script_entry("ccp_faked ipgrep --exclude-hosts --show-networks -6 fixtures/plain_text/sample_01.txt") + assert len(cliapp.stdout) == 0 + assert cliapp.unique is False + assert cliapp.subnets == '::/0' + assert cliapp.stdout == [] + +def testValues_ccp_script_entry_cliapplication_ipgrep_16(): + """Ensure that CliApplication() ipgrep with --unique --show-networks -ipv4 -ipv6 is no IPv6 networks from sample_01.txt""" + cliapp = ccp_script_entry("ccp_faked ipgrep --unique --show-networks -4 -6 fixtures/plain_text/sample_01.txt") + assert len(cliapp.stdout) == 5 + assert cliapp.unique is True + assert cliapp.subnets == '0.0.0.0/0,::/0' + assert cliapp.stdout == ['2001:db8::/127', + '2001:db8::1/128', + '192.0.2.0/24', + '192.0.2.3/32', + '2001:db8::/64',] + def testValues_ccp_script_entry_cliapplication_branch_01(): """Ensure that CliApplication() branch as original output flag set is a list of one IP address""" cliapp = ccp_script_entry("ccp_faked branch -o original -a 'interface Null0' fixtures/configs/sample_01.ios")