From 9c064d888a673459a50b18513c7ab4e6112acf34 Mon Sep 17 00:00:00 2001 From: NITESH SINGH Date: Wed, 1 Apr 2026 18:24:29 +0530 Subject: [PATCH] fix(scenarios): fix network_chaos_ng variable shadowing and instance_count condition (#1219) Signed-off-by: NETIZEN-11 Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com> --- krkn/scenario_plugins/network_chaos_ng/models.py | 4 ++++ .../network_chaos_ng/network_chaos_ng_scenario_plugin.py | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/krkn/scenario_plugins/network_chaos_ng/models.py b/krkn/scenario_plugins/network_chaos_ng/models.py index aa923606..be48578e 100644 --- a/krkn/scenario_plugins/network_chaos_ng/models.py +++ b/krkn/scenario_plugins/network_chaos_ng/models.py @@ -56,6 +56,10 @@ class BaseNetworkChaosConfig: errors.append("wait_duration must be an int") if not isinstance(self.test_duration, int): errors.append("test_duration must be an int") + if not isinstance(self.instance_count, int): + errors.append("instance_count must be an int") + elif self.instance_count < 0: + errors.append("instance_count must be >= 0") return errors diff --git a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py index ce934534..eb1a5245 100644 --- a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py +++ b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# # Copyright 2025 The Krkn Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging import queue import random @@ -65,8 +68,8 @@ class NetworkChaosNgScenarioPlugin(AbstractScenarioPlugin): ) if ( - network_chaos_config.instance_count != 0 - and network_chaos_config.instance_count < len(targets) + network_chaos_config.instance_count > 0 + and len(targets) > network_chaos_config.instance_count ): targets = random.sample( targets, network_chaos_config.instance_count @@ -76,7 +79,7 @@ class NetworkChaosNgScenarioPlugin(AbstractScenarioPlugin): self.run_parallel(targets, network_chaos) else: self.run_serial(targets, network_chaos) - if len(config) > 1: + if len(scenario_config) > 1: logging.info( f"waiting {network_chaos_config.wait_duration} seconds before running the next " f"Network Chaos NG Module"