Skip to content

Commit

Permalink
ensure mode match (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyschulman authored Apr 20, 2023
1 parent 4b1be35 commit f219bdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions netcam_aioeos/vlans/eos_check_switchports.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------------------------------------------------------
# System Imports
# -----------------------------------------------------------------------------

from typing import cast

# -----------------------------------------------------------------------------
# Public Imports
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -82,7 +88,7 @@ async def eos_check_switchports(
for check in switchport_checks.checks:
result = SwitchportCheckResult(device=device, check=check)

expd_status = check.expected_results
expd_status = cast(SwitchportCheck.ExpectSwitchport, check.expected_results)

if_name = check.check_id()

Expand All @@ -94,7 +100,15 @@ async def eos_check_switchports(
results.append(result.measure())
continue

# ensure the expected port mode matches before calling the specific
# mode check. if there is a mismatch, then fail now.

msrd_swpinfo = msrd_port["switchportInfo"]
if expd_status.switchport_mode != (msrd_mdoe := msrd_swpinfo["mode"]):
result.measurement = SwitchportCheckResult.Measurement()
result.measurement.switchport_mode = msrd_mdoe
results.append(result.measure())
continue

# verify the expected switchport mode (access / trunk)
(
Expand Down Expand Up @@ -135,9 +149,8 @@ def _check_trunk_switchport(
These checks include matching on the native-vlan and trunk-allowed-vlans.
"""

expd: SwitchportCheck.ExpectTrunk = result.check.expected_results
expd = cast(SwitchportCheck.ExpectTrunk, result.check.expected_results)
msrd = result.measurement = SwitchportCheckResult.MeasuredTrunk()

msrd.switchport_mode = msrd_status["mode"]
msrd.native_vlan = msrd_status["trunkingNativeVlanId"]

Expand Down Expand Up @@ -165,6 +178,7 @@ def on_mismatch(_field, _expd_v, _msrd_v):
return

_msrd_v_set = parse_istrange(_msrd_v)

_expd_v_set = set(expd_allowed_vids)
_info = dict()
if _missing := _expd_v_set - _msrd_v_set:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "netcam-aioeos"
version = "0.6.2"
version = "0.6.3"
description = "NetCAD/CAM - Arista EOS/eAPI asyncio driver"
readme = "README.md"
authors = ["Jeremy Schulman"]
Expand Down

0 comments on commit f219bdb

Please sign in to comment.