Skip to content
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
57 changes: 57 additions & 0 deletions tests/test_driver_cisco_nxos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from hier_config import get_hconfig_fast_load
from hier_config.models import Platform
from hier_config.utils import load_hconfig_v2_options


def test_line_console_terminal_settings_negation_negate_with() -> None:
"""Verify that negation_negate_with produces valid NX-OS remediation commands.

NX-OS does not accept 'no terminal length <value>' or 'no terminal width <value>'.
The correct remediation is to reset to platform defaults via negation_negate_with.
"""
driver = load_hconfig_v2_options(
{
"negation_negate_with": [
{
"lineage": [
{"equals": "line console"},
{"startswith": "terminal length"},
],
"use": "terminal length 24",
},
{
"lineage": [
{"equals": "line console"},
{"startswith": "terminal width"},
],
"use": "terminal width 80",
},
],
},
Platform.CISCO_NXOS,
)

running_config = get_hconfig_fast_load(
driver,
(
"line console",
" exec-timeout 10",
" terminal length 45",
" terminal width 160",
),
)
generated_config = get_hconfig_fast_load(
driver,
(
"line console",
" exec-timeout 10",
),
)

remediation = running_config.config_to_get_to(generated_config)

assert remediation.dump_simple() == (
"line console",
" terminal length 24",
" terminal width 80",
)
53 changes: 53 additions & 0 deletions tests/test_driver_generic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest

from hier_config import get_hconfig_fast_load
from hier_config.exceptions import DuplicateChildError
from hier_config.models import Platform
from hier_config.utils import load_hconfig_v2_options


def test_generic_snmp_scenario_1() -> None:
platform = Platform.GENERIC
running_config = get_hconfig_fast_load(platform, ("snmp-server community public",))
generated_config = get_hconfig_fast_load(
platform,
(
"snmp-server community examplekey1",
"snmp-server community examplekey2",
"snmp-server host 192.2.0.1 trap version v2c community examplekey1",
"snmp-server host 192.2.0.2 trap version v2c community examplekey2",
"snmp-server host 192.2.0.3 trap version v2c community examplekey3",
),
)
remediation_config = running_config.config_to_get_to(generated_config)
assert remediation_config.dump_simple() == (
"no snmp-server community public",
"snmp-server community examplekey1",
"snmp-server community examplekey2",
"snmp-server host 192.2.0.1 trap version v2c community examplekey1",
"snmp-server host 192.2.0.2 trap version v2c community examplekey2",
"snmp-server host 192.2.0.3 trap version v2c community examplekey3",
)


def test_generic_snmp_scenario_2() -> None:
platform = Platform.GENERIC
driver = load_hconfig_v2_options(
{
"parent_allows_duplicate_child": [
{"lineage": [{"startswith": ["snmp-server community"]}]},
],
},
platform,
)
with pytest.raises(DuplicateChildError):
get_hconfig_fast_load(
driver,
(
"snmp-server community <credentials_removed>",
"snmp-server community <credentials_removed>",
"snmp-server host 192.2.0.1 trap version v2c community <credentials_removed>",
"snmp-server host 192.2.0.2 trap version v2c community <credentials_removed>",
"snmp-server host 192.2.0.3 trap version v2c community <credentials_removed>",
),
)