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: cli total diff to count created diff files #27

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions nectl/configs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Nectl. If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import click

Expand Down Expand Up @@ -102,7 +103,7 @@ def diff_cmd(
role=role,
deployment_group=deployment_group,
)
nectl.diff_configs(
diff_dir = nectl.diff_configs(
hosts=hosts.values(),
username=username,
password=password,
Expand All @@ -112,7 +113,7 @@ def diff_cmd(
print(f"Error: {e}")
sys.exit(1)

print(f"{len(hosts)} config diffs created.")
print(f"{len(next(os.walk(diff_dir))[2])} config diffs created.")


@configs.command(name="apply", help="Apply staged config onto host.")
Expand Down Expand Up @@ -166,7 +167,7 @@ def apply_cmd(
abort=True,
)

nectl.apply_configs(
diff_dir = nectl.apply_configs(
hosts=hosts.values(),
username=username,
password=password,
Expand All @@ -176,7 +177,7 @@ def apply_cmd(
print(f"Error: {e}")
sys.exit(1)

print(f"{len(hosts)} config diffs created.")
print(f"{len(next(os.walk(diff_dir))[2])} config diffs created.")


@configs.command(name="get", help="Get active config from hosts.")
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.18.2"
description = "An end-to-end Python-based Infrastructure as Code framework for network automation and orchestration."
authors = ["Adam Kirchberger <[email protected]>"]
readme = "README.md"
homepage = ""
repository = "https://github.com/adamkirchberger/nectl"
documentation = "https://nectl.netlify.app"
keywords = [
Expand Down
20 changes: 18 additions & 2 deletions tests/functional/test_cli_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ def test_should_run_get_when_running_cli_configs_get_command(

@patch("nectl.configs.cli.Nectl")
def test_should_run_diff_when_running_cli_configs_diff_command(
mock_nectl, cli_runner, mock_settings
mock_nectl, cli_runner, mock_settings, tmp_path
):
# GIVEN mock settings
settings = mock_settings

# GIVEN diff method returns diff path with no files
mock_nectl.return_value.diff_configs.return_value = tmp_path

# GIVEN args
args = ["configs", "diff"]

Expand All @@ -97,14 +100,24 @@ def test_should_run_diff_when_running_cli_configs_diff_command(
# THEN expect to be successful
assert result.exit_code == 0

# THEN expect output to mention 0 diff was created
assert "0 config diffs created." in result.output


@patch("nectl.configs.cli.Nectl")
def test_should_run_apply_when_running_cli_configs_apply_command(
mock_nectl, cli_runner, mock_settings
mock_nectl, cli_runner, mock_settings, tmp_path
):
# GIVEN mock settings
settings = mock_settings

# GIVEN diff directory with diff file
diff_dir = tmp_path
(diff_dir / "foonode.txt").write_text("foobar\n")

# GIVEN apply method returns diff path
mock_nectl.return_value.apply_configs.return_value = diff_dir

# GIVEN args
args = ["configs", "apply", "-y"]

Expand All @@ -116,3 +129,6 @@ def test_should_run_apply_when_running_cli_configs_apply_command(

# THEN expect to be successful
assert result.exit_code == 0

# THEN expect output to mention 1 diff was created
assert "1 config diffs created." in result.output