-
Notifications
You must be signed in to change notification settings - Fork 1
NetworkPlugin update: adding url collector arg and test enhancements #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
413c594
05fd9bd
99ceb7a
be29312
a714789
a5105f7
9267683
4b4733f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ############################################################################### | ||
| # | ||
| # MIT License | ||
| # | ||
| # Copyright (c) 2025 Advanced Micro Devices, Inc. | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in all | ||
| # copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
| # | ||
| ############################################################################### | ||
|
|
||
| from typing import Literal, Optional | ||
|
|
||
| from nodescraper.models import CollectorArgs | ||
|
|
||
|
|
||
| class NetworkCollectorArgs(CollectorArgs): | ||
| url: Optional[str] = None | ||
| netprobe: Optional[Literal["ping", "wget", "curl"]] = None | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,10 @@ | |
| from typing import Dict, List, Optional, Tuple | ||
|
|
||
| from nodescraper.base import InBandDataCollector | ||
| from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus | ||
| from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily | ||
| from nodescraper.models import TaskResult | ||
|
|
||
| from .collector_args import NetworkCollectorArgs | ||
| from .networkdata import ( | ||
| BroadcomNicDevice, | ||
| BroadcomNicQos, | ||
|
|
@@ -55,7 +56,7 @@ | |
| ) | ||
|
|
||
|
|
||
| class NetworkCollector(InBandDataCollector[NetworkDataModel, None]): | ||
| class NetworkCollector(InBandDataCollector[NetworkDataModel, NetworkCollectorArgs]): | ||
| """Collect network configuration details using ip command""" | ||
|
|
||
| DATA_MODEL = NetworkDataModel | ||
|
|
@@ -64,6 +65,9 @@ class NetworkCollector(InBandDataCollector[NetworkDataModel, None]): | |
| CMD_RULE = "ip rule show" | ||
| CMD_NEIGHBOR = "ip neighbor show" | ||
| CMD_ETHTOOL_TEMPLATE = "ethtool {interface}" | ||
| CMD_PING = "ping" | ||
| CMD_WGET = "wget" | ||
| CMD_CURL = "curl" | ||
|
|
||
| # LLDP commands | ||
| CMD_LLDPCLI_NEIGHBOR = "lldpcli show neighbor" | ||
|
|
@@ -1669,12 +1673,59 @@ def _collect_pensando_nic_info( | |
| uncollected_commands, | ||
| ) | ||
|
|
||
| def _check_network_connectivity(self, cmd: str, url: str) -> bool: | ||
| """Check network connectivity using specified command. | ||
|
|
||
| Args: | ||
| cmd: Command to use for connectivity check (ping, wget, or curl) | ||
| url: URL or hostname to check | ||
|
|
||
| Returns: | ||
| bool: True if network is accessible, False otherwise | ||
| """ | ||
| if cmd not in {"ping", "wget", "curl"}: | ||
| raise ValueError( | ||
| f"Invalid network probe command: '{cmd}'. " | ||
| f"Valid options are: 'ping', 'wget', 'curl'" | ||
| ) | ||
|
|
||
| # Determine ping options based on OS | ||
| ping_option = "-c 1" if self.system_info.os_family == OSFamily.LINUX else "-n 1" | ||
|
|
||
| # Build command based on cmd parameter using class constants | ||
| if cmd == "ping": | ||
| result = self._run_sut_cmd(f"{self.CMD_PING} {url} {ping_option}") | ||
| elif cmd == "wget": | ||
| result = self._run_sut_cmd(f"{self.CMD_WGET} {url}") | ||
| else: # curl | ||
| result = self._run_sut_cmd(f"{self.CMD_CURL} {url}") | ||
|
|
||
| if result.exit_code == 0: | ||
| self._log_event( | ||
| category=EventCategory.NETWORK, | ||
| description="System networking is up", | ||
| data={"url": url, "accessible": result.exit_code == 0}, | ||
| priority=EventPriority.INFO, | ||
|
Comment on lines
+1706
to
+1708
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. description=f"Network connectivity check successful: {cmd} to {url} succeeded", |
||
| ) | ||
| else: | ||
| self._log_event( | ||
| category=EventCategory.NETWORK, | ||
| description=f"{cmd} to {url} failed!", | ||
| data={"url": url, "not accessible": result.exit_code == 0}, | ||
| priority=EventPriority.ERROR, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this: console_log=True |
||
| ) | ||
|
|
||
| return result.exit_code == 0 | ||
|
|
||
| def collect_data( | ||
| self, | ||
| args=None, | ||
| args: Optional[NetworkCollectorArgs] = None, | ||
| ) -> Tuple[TaskResult, Optional[NetworkDataModel]]: | ||
| """Collect network configuration from the system. | ||
|
|
||
| Args: | ||
| args: Optional NetworkCollectorArgs with URL for network connectivity check | ||
|
|
||
| Returns: | ||
| Tuple[TaskResult, Optional[NetworkDataModel]]: tuple containing the task result | ||
| and an instance of NetworkDataModel or None if collection failed. | ||
|
|
@@ -1695,6 +1746,23 @@ def collect_data( | |
| pensando_rdma_statistics: List[PensandoNicRdmaStatistics] = [] | ||
| pensando_version_host_software: Optional[PensandoNicVersionHostSoftware] = None | ||
| pensando_version_firmware: List[PensandoNicVersionFirmware] = [] | ||
| network_accessible: Optional[bool] = None | ||
|
|
||
| # Check network connectivity if URL is provided | ||
| if args and args.url: | ||
jaspals3123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cmd = args.netprobe if args.netprobe else "ping" | ||
| try: | ||
| network_accessible = self._check_network_connectivity(cmd, args.url) | ||
| except ValueError as e: | ||
| self._log_event( | ||
| category=EventCategory.NETWORK, | ||
| description=str(e), | ||
| data={"netprobe": cmd, "url": args.url}, | ||
| priority=EventPriority.ERROR, | ||
| console_log=True, | ||
| ) | ||
| # Set network_accessible to None since we couldn't check | ||
| network_accessible = None | ||
|
|
||
| # Collect interface/address information | ||
| res_addr = self._run_sut_cmd(self.CMD_ADDR) | ||
|
|
@@ -1823,6 +1891,7 @@ def collect_data( | |
| pensando_nic_rdma_statistics=pensando_rdma_statistics, | ||
| pensando_nic_version_host_software=pensando_version_host_software, | ||
| pensando_nic_version_firmware=pensando_version_firmware, | ||
| accessible=network_accessible, | ||
| ) | ||
| self.result.status = ExecutionStatus.OK | ||
| return self.result, network_data | ||
Uh oh!
There was an error while loading. Please reload this page.