fix(scenarios): fix network_chaos_ng variable shadowing and instance_count condition (#1219)

Signed-off-by: NETIZEN-11 <niteshkumar121411@gmail.com>
Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com>
This commit is contained in:
NITESH SINGH
2026-04-01 08:54:29 -04:00
committed by GitHub
co-authored by Paige Patton
parent b3e9ea1c3b
commit 9c064d888a
2 changed files with 10 additions and 3 deletions
@@ -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
@@ -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"