diff --git a/nectl/configs/cli.py b/nectl/configs/cli.py index f31aea4..f15042e 100644 --- a/nectl/configs/cli.py +++ b/nectl/configs/cli.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Nectl. If not, see . +import os import sys import click @@ -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, @@ -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.") @@ -166,7 +167,7 @@ def apply_cmd( abort=True, ) - nectl.apply_configs( + diff_dir = nectl.apply_configs( hosts=hosts.values(), username=username, password=password, @@ -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.") diff --git a/pyproject.toml b/pyproject.toml index 8b69853..654b942 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" -homepage = "" repository = "https://github.com/adamkirchberger/nectl" documentation = "https://nectl.netlify.app" keywords = [ diff --git a/tests/functional/test_cli_configs.py b/tests/functional/test_cli_configs.py index 5737db9..ee7ddf5 100644 --- a/tests/functional/test_cli_configs.py +++ b/tests/functional/test_cli_configs.py @@ -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"] @@ -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"] @@ -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