diff options
| author | Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> | 2025-08-19 11:04:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-19 11:04:38 +0200 |
| commit | 3bfcf335c5f16a6c814710b01f38342c40f85a8d (patch) | |
| tree | efa1d64693f8851c31b6b1851967fb9e9d6cd2b2 /python | |
| parent | 96fb2848e61cc5de677d9e6ad7f5c55ae397a698 (diff) | |
| parent | 69cd4845861c88285ab496339f19103dec7a32b6 (diff) | |
| download | vyos-1x-3bfcf335c5f16a6c814710b01f38342c40f85a8d.tar.gz vyos-1x-3bfcf335c5f16a6c814710b01f38342c40f85a8d.zip | |
Merge branch 'current' into T7678
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/component_version.py | 10 | ||||
| -rw-r--r-- | python/vyos/utils/file.py | 36 | ||||
| -rw-r--r-- | python/vyos/vpp/config_resource_checks/resource_defaults.py | 2 | ||||
| -rw-r--r-- | python/vyos/vpp/config_verify.py | 34 |
4 files changed, 77 insertions, 5 deletions
diff --git a/python/vyos/component_version.py b/python/vyos/component_version.py index 136bd36e8..13fb8333f 100644 --- a/python/vyos/component_version.py +++ b/python/vyos/component_version.py @@ -209,6 +209,16 @@ def version_info_prune_component(x: VersionInfo, y: VersionInfo) -> VersionInfo: x.component = {k: v for k, v in x.component.items() if k in y.component} +def add_system_version_string(config_str: str = None) -> str: + """Wrap config string with system version and return string.""" + version_info = version_info_from_system() + if config_str is not None: + version_info.update_config_body(config_str) + version_info.update_footer() + + return version_info.write_string() + + def add_system_version(config_str: str = None, out_file: str = None): """Wrap config string with system version and write to out_file. diff --git a/python/vyos/utils/file.py b/python/vyos/utils/file.py index 1e2de2b39..c363b5bdc 100644 --- a/python/vyos/utils/file.py +++ b/python/vyos/utils/file.py @@ -14,6 +14,9 @@ # License along with this library. If not, see <http://www.gnu.org/licenses/>. import os +import tempfile +from contextlib import contextmanager + from vyos.utils.permission import chown def makedir(path, user=None, group=None): @@ -185,3 +188,36 @@ def wait_for_file_write_complete(file_path, pre_hook=None, timeout=None, sleep_i """ Waits for a process to close a file after opening it in write mode. """ wait_for_inotify(file_path, event_type='IN_CLOSE_WRITE', pre_hook=pre_hook, timeout=timeout, sleep_interval=sleep_interval) + +def copy_chown(source, target): + import shutil + import stat + + shutil.copy2(source, target) + st = os.stat(source) + os.chown(target, st[stat.ST_UID], st[stat.ST_GID]) + + +@contextmanager +def write_file_atomic(file_path, mode='w'): + with open(file_path, mode) as _: + pass + temp_file = tempfile.NamedTemporaryFile( + delete=False, dir=os.path.dirname(file_path) + ) + if os.path.exists(file_path): + copy_chown(file_path, temp_file.name) + + file = open(temp_file.name, mode) + try: + yield file + finally: + file.flush() + os.fsync(file.fileno()) + file.close() + os.replace(temp_file.name, file_path) + if os.path.exists(temp_file.name): + try: + os.unlink(temp_file.name) + except Exception: + pass diff --git a/python/vyos/vpp/config_resource_checks/resource_defaults.py b/python/vyos/vpp/config_resource_checks/resource_defaults.py index 797b45701..d8316fcaf 100644 --- a/python/vyos/vpp/config_resource_checks/resource_defaults.py +++ b/python/vyos/vpp/config_resource_checks/resource_defaults.py @@ -31,7 +31,7 @@ default_resource_map = { # Default size of buffers transferred via netlink 'netlink_rx_buffer_size': 212992, # Default amount of memory allocated for VPP stats segment usage - 'statseg_heap_size': '96M', + 'statseg_heap_size': '128M', # Minimal amount of memory required to start VPP 'min_memory': '8G', # Minimal number of physical CPU cores required to start VPP diff --git a/python/vyos/vpp/config_verify.py b/python/vyos/vpp/config_verify.py index 9c56c8b95..c6f43e340 100644 --- a/python/vyos/vpp/config_verify.py +++ b/python/vyos/vpp/config_verify.py @@ -215,8 +215,8 @@ def verify_vpp_memory(config: dict): main_heap_size = mem_checks.memory_main_heap(config['settings']) main_heap_page_size = mem_checks.main_heap_page_size(config['settings']) - if main_heap_size < 51 << 20: - raise ConfigError('The main heap size must be greater than or equal to 51M') + if main_heap_size < 1 << 30: + raise ConfigError('The main heap size must be greater than or equal to 1G') readable_heap_page = bytes_to_human_memory(main_heap_page_size, 'K') @@ -367,8 +367,8 @@ def verify_vpp_statseg_size(settings: dict): statseg_size = mem_checks.statseg_size(settings) if 'size' in settings.get('statseg'): - if statseg_size < 1 << 20: - raise ConfigError('The statseg size must be greater than or equal to 1M') + if statseg_size < 128 << 20: + raise ConfigError('The statseg size must be greater than or equal to 128M') if 'page_size' in settings['statseg']: statseg_page_size = mem_checks.statseg_page_size(settings) @@ -390,3 +390,29 @@ def verify_vpp_interfaces_dpdk_num_queues(qtype: str, num_queues: int, workers: f'The number of {qtype} queues cannot be greater than the number of configured VPP workers: ' f'workers: {workers}, queues: {num_queues}' ) + + +def verify_routes_count(settings: dict, workers: int): + """ + Maximum routes count depending on main heap size, + statistics segment size and workers + """ + counters = 2 # 2 counters for each route + bytes = 16 # each counter consumes 16 bytes + statseg_scale = 2 + statseg_size = settings['statseg']['size'] + statseg_size_in_bytes = human_memory_to_bytes(statseg_size) + main_heap = settings['memory']['main_heap_size'] + main_heap_in_gb = human_memory_to_bytes(main_heap) >> 30 + + formula = (workers + 1) * counters * bytes * statseg_scale + routes_count_statseg = statseg_size_in_bytes / formula + routes_count_statseg = round(routes_count_statseg / 1_000_000, 2) + routes_count_mh = main_heap_in_gb * 2 + routes_count_min = min(routes_count_statseg, routes_count_mh) + Warning( + f'NOTE: Current dataplane capacity (estimated): {routes_count_min} M IPv4 routes. ' + 'Exceeding these values will lead to a dataplane out-of-memory condition and a crash. ' + 'Extensive use of features like ACLs, NAT and others may reduce the numbers above. ' + 'Please read the documentation for details: https://docs.vyos.io/' + ) |
