Skip to content

Commit

Permalink
update v3-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdub committed Nov 16, 2024
1 parent 09300ed commit fad5c11
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 197 deletions.
157 changes: 0 additions & 157 deletions docs/advanced-topics.md

This file was deleted.

4 changes: 1 addition & 3 deletions docs/custom-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ In some scenarios, configuration remediations may require handling beyond the st
1. Import and Configuration Loading

```python
import os
from hier_config import WorkflowRemediation, get_hconfig
from hier_config.models import Platform
from hier_config import WorkflowRemediation, get_hconfig, Platform
```
Necessary modules are imported, including the `WorkflowRemediation` class for handling remediation

Expand Down
4 changes: 1 addition & 3 deletions docs/future-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ Currently, this algorithm does not account for:
- and likely others

```bash
>>> from hier_config import get_hconfig
>>> from hier_config.model import Platform
>>> from hier_config import get_hconfig, Platform
>>> from hier_config.utils import load_device_config
>>> from pprint import pprint
>>>
>>> running_config_text = load_device_config("./tests/fixtures/running_config.conf")
Expand Down
3 changes: 1 addition & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Hier Config is a Python library that assists with remediating network configurat
To use `WorkflowRemediation`, you’ll import it along with `get_hconfig` (for generating configuration objects) and `Platform` (for specifying the operating system driver).

```python
>>> from hier_config import WorkflowRemediation, get_hconfig
>>> from hier_config.model import Platform
>>> from hier_config import WorkflowRemediation, get_hconfig, Platform
>>> from hier_config.utils import load_device_config
>>>
```
Expand Down
6 changes: 2 additions & 4 deletions docs/junos-style-syntax-remediation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ set interfaces irb unit 3 family inet description "switch_mgmt_10.0.4.0/24"


$ python3
>>> from hier_config import WorkflowRemediation, get_hconfig
>>> from hier_config.model import Platform
>>> from hier_config import WorkflowRemediation, get_hconfig, Platform
>>> from hier_config.utils import load_device_config
>>>
>>> running_config_text = load_device_config("./tests/fixtures/running_config_flat_junos.conf")
Expand Down Expand Up @@ -119,8 +118,7 @@ interfaces {
}

$ python3
>>> from hier_config import WorkflowRemediation, get_hconfig
>>> from hier_config.model import Platform
>>> from hier_config import WorkflowRemediation, get_hconfig, Platform
>>> from hier_config.utils import load_device_config
>>>
>>> running_config_text = load_device_config("./tests/fixtures/running_config_junos.conf")
Expand Down
3 changes: 1 addition & 2 deletions docs/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ With the tags loaded, you can create a targeted remediation based on those tags
#!/usr/bin/env python3
# Import necessary libraries
from hier_config import WorkflowRemediation, get_hconfig
from hier_config.models import Platform
from hier_config import WorkflowRemediation, get_hconfig, Platform
from hier_config.utils import load_device_config, load_hier_config_tags
# Load the running and generated configurations from files
Expand Down
3 changes: 1 addition & 2 deletions docs/unified-diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ This feature is particularly useful when comparing configurations from two netwo
Currently, the algorithm does not account for duplicate child entries (e.g., multiple `endif` statements in an IOS-XR route-policy) or enforce command order in sections where it may be critical, such as Access Control Lists (ACLs). For accurate ordering in ACLs, sequence numbers should be used if command order is important.

```bash
>>> from hier_config import get_hconfig
>>> from hier_config.model import Platform
>>> from hier_config import get_hconfig, Platform
>>> from pprint import pprint
>>>
>>> running_config_text = load_device_config("./tests/fixtures/running_config.conf")
Expand Down
30 changes: 6 additions & 24 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path # Use pathlib for handling file paths
from typing import Any, Union
from pathlib import Path

import pytest
import yaml
Expand All @@ -11,18 +10,17 @@
TAGS_FILE_PATH = "./tests/fixtures/tag_rules_ios.yml"


# Helper function to create a temporary file for testing
@pytest.fixture
def temp_file(tmp_path: Path) -> tuple[Path, str]:
def temporary_file_fixture(tmp_path: Path) -> tuple[Path, str]:
file_path = tmp_path / "temp_config.conf"
content = "interface GigabitEthernet0/1\n ip address 192.168.1.1 255.255.255.0\n no shutdown"
file_path.write_text(content)
return file_path, content


def test_load_device_config_success(temp_file: tuple[Path, str]) -> None:
def test_load_device_config_success(temporary_file_fixture: tuple[Path, str]) -> None:
"""Test that the function successfully loads a valid configuration file."""
file_path, expected_content = temp_file
file_path, expected_content = temporary_file_fixture
result = load_device_config(str(file_path))
assert result == expected_content, "File content should match expected content."

Expand All @@ -33,26 +31,10 @@ def test_load_device_config_file_not_found() -> None:
load_device_config("non_existent_file.conf")


def test_load_device_config_io_error(
monkeypatch: pytest.MonkeyPatch, temp_file: tuple[Path, str]
) -> None:
"""Test that the function raises OSError for an unexpected file access error."""
file_path, _ = temp_file

def mock_read_text(*args: Any, **kwargs: Union[dict, None]) -> None: # noqa: ANN401, ARG001
msg = "Mocked IO error"
raise OSError(msg)

monkeypatch.setattr(Path, "read_text", mock_read_text)

with pytest.raises(OSError, match="Mocked IO error"):
load_device_config(str(file_path))


def test_load_device_config_empty_file(tmp_path: Path) -> None:
"""Test that the function correctly handles an empty configuration file."""
empty_file = tmp_path / "empty.conf"
empty_file.write_text("") # Create an empty file
empty_file.write_text("")
result = load_device_config(str(empty_file))
assert not result, "Empty file should return an empty string."

Expand Down Expand Up @@ -94,7 +76,7 @@ def test_load_hier_config_tags_invalid_yaml(tmp_path: Path) -> None:
def test_load_hier_config_tags_empty_file(tmp_path: Path) -> None:
"""Test that the function raises ValidationError for an empty YAML file."""
empty_file = tmp_path / "empty.yml"
empty_file.write_text("") # Create an empty file
empty_file.write_text("")

with pytest.raises(ValidationError):
load_hier_config_tags(str(empty_file))

0 comments on commit fad5c11

Please sign in to comment.