Skip to content

Commit

Permalink
Fix stuff after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-baillargeon committed Apr 25, 2024
1 parent 50b3638 commit c3bde10
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions anta/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import resource
from collections import defaultdict
from collections import defaultdict
from typing import TYPE_CHECKING

from anta import GITHUB_SUGGESTION
Expand All @@ -19,8 +18,6 @@
from anta.tools import Catchtime, cprofile

if TYPE_CHECKING:
from anta.catalog import AntaCatalog, AntaTestDefinition
from anta.device import AntaDevice
from anta.catalog import AntaCatalog, AntaTestDefinition
from anta.device import AntaDevice
from anta.inventory import AntaInventory
Expand All @@ -31,31 +28,6 @@
DEFAULT_NOFILE = 16384


def adjust_rlimit_nofile() -> tuple[int, int]:
"""Adjust the maximum number of open file descriptors for the ANTA process.
The limit is set to the lower of the current hard limit and the value of the ANTA_NOFILE environment variable.
If the `ANTA_NOFILE` environment variable is not set or is invalid, `DEFAULT_NOFILE` is used.
Returns
-------
tuple[int, int]: The new soft and hard limits for open file descriptors.
"""
try:
nofile = int(os.environ.get("ANTA_NOFILE", DEFAULT_NOFILE))
except ValueError as exception:
logger.warning("The ANTA_NOFILE environment variable value is invalid: %s\nDefault to %s.", exc_to_str(exception), DEFAULT_NOFILE)
nofile = DEFAULT_NOFILE

limits = resource.getrlimit(resource.RLIMIT_NOFILE)
logger.debug("Initial limit numbers for open file descriptors for the current ANTA process: Soft Limit: %s | Hard Limit: %s", limits[0], limits[1])
nofile = nofile if limits[1] > nofile else limits[1]
logger.debug("Setting soft limit for open file descriptors for the current ANTA process to %s", nofile)
resource.setrlimit(resource.RLIMIT_NOFILE, (nofile, limits[1]))
return resource.getrlimit(resource.RLIMIT_NOFILE)


def adjust_rlimit_nofile() -> tuple[int, int]:
"""Adjust the maximum number of open file descriptors for the ANTA process.
Expand Down Expand Up @@ -211,9 +183,6 @@ async def main( # noqa: PLR0913
devices: Devices on which to run tests. None means all devices. These may come from the `--device / -d` CLI option in NRFU.
tests: Tests to run against devices. None means all tests. These may come from the `--test / -t` CLI option in NRFU.
tags: Tags to filter devices from the inventory. These may come from the `--tags` CLI option in NRFU.
devices: Devices on which to run tests. None means all devices. These may come from the `--device / -d` CLI option in NRFU.
tests: Tests to run against devices. None means all tests. These may come from the `--test / -t` CLI option in NRFU.
tags: Tags to filter devices from the inventory. These may come from the `--tags` CLI option in NRFU.
established_only: Include only established device(s).
dry_run: Build the list of coroutine to run and stop before test execution.
"""
Expand Down Expand Up @@ -252,22 +221,6 @@ async def main( # noqa: PLR0913

logger.info(run_info)

if catalog.final_tests_count > limits[0]:
logger.warning(
"The number of concurrent tests is higher than the open file descriptors limit for this ANTA process.\n"
"Errors may occur while running the tests.\n"
"Please consult the ANTA FAQ."
)
run_info = (
"--- ANTA NRFU Run Information ---\n"
f"Number of devices: {len(inventory)} ({len(selected_inventory)} established)\n"
f"Total number of selected tests: {catalog.final_tests_count}\n"
f"Maximum number of open file descriptors for the current ANTA process: {limits[0]}\n"
"---------------------------------"
)

logger.info(run_info)

if catalog.final_tests_count > limits[0]:
logger.warning(
"The number of concurrent tests is higher than the open file descriptors limit for this ANTA process.\n"
Expand Down Expand Up @@ -308,14 +261,7 @@ async def main( # noqa: PLR0913
test_results = await asyncio.gather(*coros)
for r in test_results:
manager.add(r)
logger.info("Running ANTA tests...")
test_results = await asyncio.gather(*coros)
for r in test_results:
manager.add(r)

logger.info("Running ANTA tests completed in %s", run_t.time)

log_cache_statistics(selected_inventory.devices)
logger.info("Running ANTA tests completed in %s", run_t.time)

log_cache_statistics(selected_inventory.devices)

0 comments on commit c3bde10

Please sign in to comment.