Skip to content
Closed
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
19 changes: 14 additions & 5 deletions aci-preupgrade-validation-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6832,16 +6832,25 @@ def n9k_c93180yc_fx3_switch_memory_check(fabric_nodes, **kwargs):
result = NA
msg = 'No N9K-C93180YC-FX3 switches found. Skipping.'
else:
query = 'procMemUsage.json?query-target-filter=and(wcard(procMemUsage.dn,"memusage-sup"),lt(procMemUsage.Total,"{}"))'.format(
min_memory_kb
)
proc_mem_mos = icurl('class', query)

node_ids = [node['fabricNode']['attributes']['id'] for node in affected_nodes]
node_id_to_attrs = {
node['fabricNode']['attributes']['id']: node['fabricNode']['attributes']
for node in affected_nodes
}

# batch_size=20 for APIC's 20-expression cap
batch_size = 20
proc_mem_mos = []
for i in range(0, len(node_ids), batch_size):
batch_ids = node_ids[i:i + batch_size]
node_filter = 'or({})'.format(','.join(
'wcard(procMemUsage.dn,"node-{}/")'.format(nid) for nid in batch_ids
))
query = 'procMemUsage.json?query-target-filter=and({},wcard(procMemUsage.dn,"memusage-sup"),lt(procMemUsage.Total,"{}"))'.format(
node_filter, min_memory_kb
)
proc_mem_mos += icurl('class', query)

for memory_mo in proc_mem_mos:
attrs = memory_mo['procMemUsage']['attributes']
dn_match = re.search(node_regex, attrs['dn'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,105 @@
result = run_check(
fabric_nodes=fabric_nodes,
)
assert result.result == expected_result

Check failure on line 114 in tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py

View workflow job for this annotation

GitHub Actions / py38 report

test_n9k_c93180yc_fx3_switch_memory_check.test_logic[fabric_nodes2-icurl_outputs2-PASS--expected_data2]

AssertionError: assert 'ERROR !!' == 'PASS' - PASS + ERROR !!
Raw output
run_check = <function run_check.<locals>._run_check at 0x7f1cd4292040>
mock_icurl = None
fabric_nodes = [{'fabricNode': {'attributes': {'dn': 'topology/pod-1/node-101', 'id': '101', 'model': 'N9K-C93180YC-FX3', 'name': 'leaf101', ...}}}]
expected_result = 'PASS', expected_msg = '', expected_data = []

    @pytest.mark.parametrize(
        "fabric_nodes, icurl_outputs, expected_result, expected_msg, expected_data",
        [
            # No nodes returned
            (
                [],
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # Non-N9K-C93180YC-FX3 node (N9K-C9508)
            (
                read_data(dir, "fabricNode_N9K-C9508.json"),
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # N9K-C93180YC-FX3 node with >=32GB memory - API returns empty (filtered by lt)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Multiple nodes, only N9K-C93180YC-FX3 checked, all >=32GB - API returns empty
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Low-memory results for other switch models are ignored
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb_unaffected.json"),
                },
                script.PASS,
                '',
                [],
            ),
            # Query remains below APIC's 20-expression limit on large fabrics
            (
                make_fx3_nodes(55),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # N9K-C93180YC-FX3 node with <32GB memory (fail case)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb.json"),
                },
                script.FAIL_O,
                (
                    'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. '
                    'One or more switches with less than 32GB of memory may experience service instability. '
                    'Upgrade the switch memory to at least 32GB.'
                ),
                [["101", "leaf101", "N9K-C93180YC-FX3", 16.0]],
            ),
        ],
    )
    def test_logic(run_check, mock_icurl, fabric_nodes, expected_result, expected_msg, expected_data):
        result = run_check(
            fabric_nodes=fabric_nodes,
        )
>       assert result.result == expected_result
E       AssertionError: assert 'ERROR !!' == 'PASS'
E         - PASS
E         + ERROR !!

tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py:114: AssertionError

Check failure on line 114 in tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py

View workflow job for this annotation

GitHub Actions / py38 report

test_n9k_c93180yc_fx3_switch_memory_check.test_logic[fabric_nodes3-icurl_outputs3-PASS--expected_data3]

AssertionError: assert 'ERROR !!' == 'PASS' - PASS + ERROR !!
Raw output
run_check = <function run_check.<locals>._run_check at 0x7f1cd40f2c10>
mock_icurl = None
fabric_nodes = [{'fabricNode': {'attributes': {'dn': 'topology/pod-1/node-101', 'id': '101', 'model': 'N9K-C93180YC-FX3', 'name': 'le...cNode': {'attributes': {'dn': 'topology/pod-1/node-102', 'id': '102', 'model': 'N9K-C9364C', 'name': 'leaf102', ...}}}]
expected_result = 'PASS', expected_msg = '', expected_data = []

    @pytest.mark.parametrize(
        "fabric_nodes, icurl_outputs, expected_result, expected_msg, expected_data",
        [
            # No nodes returned
            (
                [],
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # Non-N9K-C93180YC-FX3 node (N9K-C9508)
            (
                read_data(dir, "fabricNode_N9K-C9508.json"),
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # N9K-C93180YC-FX3 node with >=32GB memory - API returns empty (filtered by lt)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Multiple nodes, only N9K-C93180YC-FX3 checked, all >=32GB - API returns empty
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Low-memory results for other switch models are ignored
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb_unaffected.json"),
                },
                script.PASS,
                '',
                [],
            ),
            # Query remains below APIC's 20-expression limit on large fabrics
            (
                make_fx3_nodes(55),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # N9K-C93180YC-FX3 node with <32GB memory (fail case)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb.json"),
                },
                script.FAIL_O,
                (
                    'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. '
                    'One or more switches with less than 32GB of memory may experience service instability. '
                    'Upgrade the switch memory to at least 32GB.'
                ),
                [["101", "leaf101", "N9K-C93180YC-FX3", 16.0]],
            ),
        ],
    )
    def test_logic(run_check, mock_icurl, fabric_nodes, expected_result, expected_msg, expected_data):
        result = run_check(
            fabric_nodes=fabric_nodes,
        )
>       assert result.result == expected_result
E       AssertionError: assert 'ERROR !!' == 'PASS'
E         - PASS
E         + ERROR !!

tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py:114: AssertionError

Check failure on line 114 in tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py

View workflow job for this annotation

GitHub Actions / py38 report

test_n9k_c93180yc_fx3_switch_memory_check.test_logic[fabric_nodes4-icurl_outputs4-PASS--expected_data4]

AssertionError: assert 'ERROR !!' == 'PASS' - PASS + ERROR !!
Raw output
run_check = <function run_check.<locals>._run_check at 0x7f1cd40f2280>
mock_icurl = None
fabric_nodes = [{'fabricNode': {'attributes': {'dn': 'topology/pod-1/node-101', 'id': '101', 'model': 'N9K-C93180YC-FX3', 'name': 'le...cNode': {'attributes': {'dn': 'topology/pod-1/node-102', 'id': '102', 'model': 'N9K-C9364C', 'name': 'leaf102', ...}}}]
expected_result = 'PASS', expected_msg = '', expected_data = []

    @pytest.mark.parametrize(
        "fabric_nodes, icurl_outputs, expected_result, expected_msg, expected_data",
        [
            # No nodes returned
            (
                [],
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # Non-N9K-C93180YC-FX3 node (N9K-C9508)
            (
                read_data(dir, "fabricNode_N9K-C9508.json"),
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # N9K-C93180YC-FX3 node with >=32GB memory - API returns empty (filtered by lt)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Multiple nodes, only N9K-C93180YC-FX3 checked, all >=32GB - API returns empty
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Low-memory results for other switch models are ignored
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb_unaffected.json"),
                },
                script.PASS,
                '',
                [],
            ),
            # Query remains below APIC's 20-expression limit on large fabrics
            (
                make_fx3_nodes(55),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # N9K-C93180YC-FX3 node with <32GB memory (fail case)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb.json"),
                },
                script.FAIL_O,
                (
                    'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. '
                    'One or more switches with less than 32GB of memory may experience service instability. '
                    'Upgrade the switch memory to at least 32GB.'
                ),
                [["101", "leaf101", "N9K-C93180YC-FX3", 16.0]],
            ),
        ],
    )
    def test_logic(run_check, mock_icurl, fabric_nodes, expected_result, expected_msg, expected_data):
        result = run_check(
            fabric_nodes=fabric_nodes,
        )
>       assert result.result == expected_result
E       AssertionError: assert 'ERROR !!' == 'PASS'
E         - PASS
E         + ERROR !!

tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py:114: AssertionError

Check failure on line 114 in tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py

View workflow job for this annotation

GitHub Actions / py38 report

test_n9k_c93180yc_fx3_switch_memory_check.test_logic[fabric_nodes5-icurl_outputs5-PASS--expected_data5]

AssertionError: assert 'ERROR !!' == 'PASS' - PASS + ERROR !!
Raw output
run_check = <function run_check.<locals>._run_check at 0x7f1cd40f23a0>
mock_icurl = None
fabric_nodes = [{'fabricNode': {'attributes': {'dn': 'topology/pod-1/node-101', 'id': '101', 'model': 'N9K-C93180YC-FX3', 'name': 'le...ttributes': {'dn': 'topology/pod-1/node-106', 'id': '106', 'model': 'N9K-C93180YC-FX3', 'name': 'leaf106', ...}}}, ...]
expected_result = 'PASS', expected_msg = '', expected_data = []

    @pytest.mark.parametrize(
        "fabric_nodes, icurl_outputs, expected_result, expected_msg, expected_data",
        [
            # No nodes returned
            (
                [],
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # Non-N9K-C93180YC-FX3 node (N9K-C9508)
            (
                read_data(dir, "fabricNode_N9K-C9508.json"),
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # N9K-C93180YC-FX3 node with >=32GB memory - API returns empty (filtered by lt)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Multiple nodes, only N9K-C93180YC-FX3 checked, all >=32GB - API returns empty
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Low-memory results for other switch models are ignored
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb_unaffected.json"),
                },
                script.PASS,
                '',
                [],
            ),
            # Query remains below APIC's 20-expression limit on large fabrics
            (
                make_fx3_nodes(55),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # N9K-C93180YC-FX3 node with <32GB memory (fail case)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb.json"),
                },
                script.FAIL_O,
                (
                    'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. '
                    'One or more switches with less than 32GB of memory may experience service instability. '
                    'Upgrade the switch memory to at least 32GB.'
                ),
                [["101", "leaf101", "N9K-C93180YC-FX3", 16.0]],
            ),
        ],
    )
    def test_logic(run_check, mock_icurl, fabric_nodes, expected_result, expected_msg, expected_data):
        result = run_check(
            fabric_nodes=fabric_nodes,
        )
>       assert result.result == expected_result
E       AssertionError: assert 'ERROR !!' == 'PASS'
E         - PASS
E         + ERROR !!

tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py:114: AssertionError

Check failure on line 114 in tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py

View workflow job for this annotation

GitHub Actions / py38 report

test_n9k_c93180yc_fx3_switch_memory_check.test_logic[fabric_nodes6-icurl_outputs6-FAIL - OUTAGE WARNING!!-N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. One or more switches with less than 32GB of memory may experience service instability. Upgrade the switch memory to at least 32GB.-expected_data6]

AssertionError: assert 'ERROR !!' == 'FAIL - OUTAGE WARNING!!' - FAIL - OUTAGE WARNING!! + ERROR !!
Raw output
run_check = <function run_check.<locals>._run_check at 0x7f1cd40f2d30>
mock_icurl = None
fabric_nodes = [{'fabricNode': {'attributes': {'dn': 'topology/pod-1/node-101', 'id': '101', 'model': 'N9K-C93180YC-FX3', 'name': 'leaf101', ...}}}]
expected_result = 'FAIL - OUTAGE WARNING!!'
expected_msg = 'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. One or more switches with less than 32GB of memory may experience service instability. Upgrade the switch memory to at least 32GB.'
expected_data = [['101', 'leaf101', 'N9K-C93180YC-FX3', 16.0]]

    @pytest.mark.parametrize(
        "fabric_nodes, icurl_outputs, expected_result, expected_msg, expected_data",
        [
            # No nodes returned
            (
                [],
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # Non-N9K-C93180YC-FX3 node (N9K-C9508)
            (
                read_data(dir, "fabricNode_N9K-C9508.json"),
                {},
                script.NA,
                'No N9K-C93180YC-FX3 switches found. Skipping.',
                [],
            ),
            # N9K-C93180YC-FX3 node with >=32GB memory - API returns empty (filtered by lt)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Multiple nodes, only N9K-C93180YC-FX3 checked, all >=32GB - API returns empty
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # Low-memory results for other switch models are ignored
            (
                read_data(dir, "fabricNode_two.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb_unaffected.json"),
                },
                script.PASS,
                '',
                [],
            ),
            # Query remains below APIC's 20-expression limit on large fabrics
            (
                make_fx3_nodes(55),
                {
                    proc_mem_query: [],
                },
                script.PASS,
                '',
                [],
            ),
            # N9K-C93180YC-FX3 node with <32GB memory (fail case)
            (
                read_data(dir, "fabricNode_one.json"),
                {
                    proc_mem_query: read_data(dir, "procMemUsage_lt32gb.json"),
                },
                script.FAIL_O,
                (
                    'N9K-C93180YC-FX3 requires a minimum of 32GB RAM for proper operation in ACI mode. '
                    'One or more switches with less than 32GB of memory may experience service instability. '
                    'Upgrade the switch memory to at least 32GB.'
                ),
                [["101", "leaf101", "N9K-C93180YC-FX3", 16.0]],
            ),
        ],
    )
    def test_logic(run_check, mock_icurl, fabric_nodes, expected_result, expected_msg, expected_data):
        result = run_check(
            fabric_nodes=fabric_nodes,
        )
>       assert result.result == expected_result
E       AssertionError: assert 'ERROR !!' == 'FAIL - OUTAGE WARNING!!'
E         - FAIL - OUTAGE WARNING!!
E         + ERROR !!

tests/checks/n9k_c93180yc_fx3_switch_memory_check/test_n9k_c93180yc_fx3_switch_memory_check.py:114: AssertionError
assert result.msg == expected_msg
if result.data:
assert result.data == expected_data
else:
assert result.unformatted_data == expected_data
assert result.unformatted_data == expected_data


# --- Batch query coverage ---
# Mirrors the check's batch_size so tests break if the constant drifts.
BATCH_SIZE = 20


def _fx3_fabric_nodes(node_ids):
return [
{
"fabricNode": {
"attributes": {
"dn": "topology/pod-1/node-{}".format(nid),
"id": nid,
"name": "leaf{}".format(nid),
"model": "N9K-C93180YC-FX3",
"role": "leaf",
}
}
}
for nid in node_ids
]


def _batch_query(node_ids, min_memory_kb=32000000):
node_filter = 'or({})'.format(','.join(
'wcard(procMemUsage.dn,"node-{}/")'.format(nid) for nid in node_ids
))
return 'procMemUsage.json?query-target-filter=and({},wcard(procMemUsage.dn,"memusage-sup"),lt(procMemUsage.Total,"{}"))'.format(
node_filter, min_memory_kb
)


def _proc_mem_usage(node_id, total_kb):
return [
{
"procMemUsage": {
"attributes": {
"dn": "topology/pod-1/node-{}/sys/procmem/memusage-sup".format(node_id),
"Modname": "sup",
"Total": str(total_kb),
}
}
}
]


def test_batch_at_boundary_issues_single_query(run_check, monkeypatch):
node_ids = [str(nid) for nid in range(101, 101 + BATCH_SIZE)] # exactly BATCH_SIZE nodes
fabric_nodes = _fx3_fabric_nodes(node_ids)
query = _batch_query(node_ids)

calls = []

def _mock_icurl(apitype, q, page=0, page_size=100000):
calls.append(q)
assert q == query
return []

monkeypatch.setattr(script, "icurl", _mock_icurl)

result = run_check(fabric_nodes=fabric_nodes)

assert len(calls) == 1
assert result.result == script.PASS


def test_batch_split_across_two_queries(run_check, monkeypatch):
# 25 affected nodes -> batch1 has 20 IDs, batch2 has the remaining 5.
node_ids = [str(nid) for nid in range(101, 126)]
fabric_nodes = _fx3_fabric_nodes(node_ids)
batch1_ids, batch2_ids = node_ids[:BATCH_SIZE], node_ids[BATCH_SIZE:]
query1, query2 = _batch_query(batch1_ids), _batch_query(batch2_ids)

# One low-memory node in each batch to confirm results from both queries are merged.
responses = {
query1: _proc_mem_usage(batch1_ids[0], 16000000),
query2: _proc_mem_usage(batch2_ids[-1], 16000000),
}
calls = []

def _mock_icurl(apitype, q, page=0, page_size=100000):
calls.append(q)
return responses[q]

monkeypatch.setattr(script, "icurl", _mock_icurl)

result = run_check(fabric_nodes=fabric_nodes)

assert sorted(calls) == sorted([query1, query2])
assert result.result == script.FAIL_O
expected_data = [
[batch1_ids[0], "leaf{}".format(batch1_ids[0]), "N9K-C93180YC-FX3", 16.0],
[batch2_ids[-1], "leaf{}".format(batch2_ids[-1]), "N9K-C93180YC-FX3", 16.0],
]
assert result.data == expected_data
Loading