Commit 0328b023 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

feat(tests): ECOC26-Add ZSM failure notification test and related scripts;...

feat(tests): ECOC26-Add ZSM failure notification test and related scripts; update KPI ranges and cleanup commands.
parent 6a467aa2
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -18,44 +18,45 @@
#
# Tests executed:
#   test_zsm_create_with_failure_notification
#      loads topology, creates KPI descriptor, creates L3NM + OPTICAL_CONNECTIVITY
#       services, starts hub/leaf received-power collectors, verifies KPI samples,
#     - loads topology, creates KPI descriptor, creates L3NM + OPTICAL_CONNECTIVITY
#       services, starts the selected leaf metric collector, verifies KPI samples,
#       builds ZSMCreateRequest with GENERATE_FAILURE_NOTIFICATION action, invokes
#       automation_client.ZSMCreate(), asserts response.
#
# Usage:
#   ./run_zsm_test.sh
#   ./run_zsm_fail_notify_test.sh

set -euo pipefail

NAMESPACE="tfs"
JOB_NAME="zsm-automation-test"
MANIFEST="$(dirname "$0")/zsm_test_job.yaml"
LOG_FILE="$(dirname "$0")/../logs/zsm_test_$(date '+%Y%m%d_%H%M').log"
LOG_FILE="$(dirname "$0")/../logs/zsm_test_leaf_$(date '+%Y%m%d_%H%M').log"
mkdir -p "$(dirname "${LOG_FILE}")"

# ── Clean up any previous run ────────────────────────────────────────────────
# Clean up any previous run.
if kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" &>/dev/null; then
    kubectl delete job "${JOB_NAME}" -n "${NAMESPACE}" --wait=true >>"${LOG_FILE}" 2>&1
fi

# ── Submit the Job ───────────────────────────────────────────────────────────
# Submit the Job.
kubectl apply -f "${MANIFEST}" >>"${LOG_FILE}" 2>&1

# ── Wait for the container to be Running (past ContainerCreating) ─────────────
# Wait for the container to be Running (past ContainerCreating).
until kubectl get pods -n "${NAMESPACE}" -l job-name="${JOB_NAME}" \
        --no-headers 2>/dev/null | grep -qE 'Running|Completed|Succeeded|Error'; do
    sleep 1
done

# ── Stream logs to file in the background as they are generated ──────────────
# Stream logs to file in the background as they are generated.
kubectl logs --follow -n "${NAMESPACE}" \
    -l job-name="${JOB_NAME}" \
    --tail=-1 \
    --pod-running-timeout=60s >>"${LOG_FILE}" 2>&1 &
LOGS_PID=$!

# ── Poll for job completion (Complete or Failed) ──────────────────────────────
for i in $(seq 1 60); do
# Poll for job completion (Complete or Failed).
for ((i = 1; i <= 60; i++)); do
    JOB_COND=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" \
        -o jsonpath='{.status.conditions[0].type}' 2>/dev/null || echo "")
    if [ "${JOB_COND}" = "Complete" ] || [ "${JOB_COND}" = "Failed" ]; then
@@ -64,19 +65,19 @@ for i in $(seq 1 60); do
    sleep 3
done

# ── Wait for the log streamer to flush and exit ───────────────────────────────
# Wait for the log streamer to flush and exit.
wait "${LOGS_PID}" 2>/dev/null || true

# ── Capture status, then immediately delete the Job and its Pod ───────────────
# Capture status, then immediately delete the Job and its Pod.
JOB_STATUS=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" \
    -o jsonpath='{.status.conditions[0].type}' 2>/dev/null || echo "Unknown")
kubectl delete job "${JOB_NAME}" -n "${NAMESPACE}" --wait=false >>"${LOG_FILE}" 2>&1 || true

# ── Report final status ──────────────────────────────────────────────────────
# Report final status.
if [ "${JOB_STATUS}" = "Complete" ]; then
    echo "[] Tests PASSED  full log: ${LOG_FILE}"
    echo "[OK] Tests PASSED - full log: ${LOG_FILE}"
    exit 0
else
    echo "[] Tests FAILED  full log: ${LOG_FILE}"
    echo "[FAIL] Tests FAILED - full log: ${LOG_FILE}"
    exit 1
fi
+2 −0
Original line number Diff line number Diff line
@@ -12,3 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# cmd to delete all log files in the logs directory
# find /home/cttc/tfs-ctrl/src/tests/ecoc26_pluggables/logs -type f -name '*.log' -delete
 No newline at end of file
+13 −15
Original line number Diff line number Diff line
@@ -21,21 +21,6 @@ via Kubernetes-injected environment variables — no mocks.
Each test is self-contained: it creates the pluggable it needs, verifies
the expected behaviour, and cleans up afterwards so that tests do not
depend on ordering or state left behind by earlier tests.

Test flow:
  1. test_ensure_topology              — load hub + leaf topology into Context
  2. test_nbi_post_hub_pluggable       — POST hub config via NBI (clean up)
  3. test_nbi_post_leaf_pluggable      — POST leaf config via NBI (clean up)
  4. test_nbi_post_without_config      — POST bare pluggable, no DSC (clean up)
  5. test_nbi_delete_pluggable         — DELETE pluggable (idempotent, 204×2)
  6. test_nbi_get_pluggable            — GET pluggable (200 → delete → 404)
  7. test_nbi_hub_group1_leaf_channel5 — group 1/channel 5 active, reset false
  8. test_nbi_hub_group2_leaf_channel7 — group 2/channel 7 active, reset false

A session-scoped ``netconf_reachable`` fixture probes TCP connectivity to
the real NETCONF routers (10.30.7.8:830, 10.30.7.7:830) and aborts the
session early when neither device is reachable.

"""

import logging
@@ -699,3 +684,16 @@ def test_nbi_hub_group2_leaf_channel7(netconf_reachable): # noqa: F811
    """Activate HUB DSC group 2 and LEAF channel-7, then reset all to false."""
    _run_selective_hub_leaf_flow(hub_group_id=2, leaf_channel=7)

# ----------------------------------------------------------------------------
# Test 9 — Reset to all-false HUB and LEAF configs (cleanup)
# ----------------------------------------------------------------------------

# def test_nbi_reset_all_false(netconf_reachable):  # noqa: F811
#     """Reset both HUB and LEAF to all-false configs, then delete pluggables.

#     This is a cleanup step to ensure that the devices are left in a known
#     state after the tests.  It pushes all-false payloads and verifies that
#     NBI GET returns 404 after deletion.
#     """
#     _reset_hub_to_all_false()
#     _reset_leaf_to_all_false()
+7 −7
Original line number Diff line number Diff line
@@ -61,11 +61,11 @@ def _parse_power_range(env_name, default_range):
_EXPECTED_RECEIVED_POWER_KPI_RANGES = {
    create_RECEIVED_POWER_hub_kpi_id_request().kpi_id.uuid: (
        "hub",
        _parse_power_range("ECOC26_HUB_RECEIVED_POWER_RANGE", (-80.0, -30.0)),
        _parse_power_range("ECOC26_HUB_RECEIVED_POWER_RANGE", (-24.0, 0.0)),
    ),
    create_RECEIVED_POWER_leaf_kpi_id_request().kpi_id.uuid: (
        "leaf",
        _parse_power_range("ECOC26_LEAF_RECEIVED_POWER_RANGE", (-30.0, 0.0)),
        _parse_power_range("ECOC26_LEAF_RECEIVED_POWER_RANGE", (-24.0, 0.0)),
    ),
}

@@ -75,11 +75,11 @@ _TOPOLOGY_UUID = "c76135e3-24a8-5e92-9bed-c3c9139359c8"
_EXPECTED_DEVICE_UUIDS = {ROUTER_HUB_DEVICE_UUID, ROUTER_LEAF_DEVICE_UUID}

_RECEIVED_POWER_KPIS = (
    (
        "hub",
        create_RECEIVED_POWER_hub_kpi_id_request,
        create_kpi_descriptor_RECEIVED_POWER_hub_request,
    ),
    # (
    #     "hub",
    #     create_RECEIVED_POWER_hub_kpi_id_request,
    #     create_kpi_descriptor_RECEIVED_POWER_hub_request,
    # ),
    (
        "leaf",
        create_RECEIVED_POWER_leaf_kpi_id_request,
+361 −0

File added.

Preview size limit exceeded, changes collapsed.