Skip to content

Commit 7eaed6d

Browse files
committed
fix(scenarios): fix network_chaos_ng variable shadowing and instance_count condition
Signed-off-by: NETIZEN-11 <niteshkumar121411@gmail.com>
1 parent ef50aa8 commit 7eaed6d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

krkn/scenario_plugins/network_chaos_ng/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def validate(self) -> list[str]:
5656
errors.append("wait_duration must be an int")
5757
if not isinstance(self.test_duration, int):
5858
errors.append("test_duration must be an int")
59+
if not isinstance(self.instance_count, int):
60+
errors.append("instance_count must be an int")
61+
elif self.instance_count < 0:
62+
errors.append("instance_count must be >= 0")
5963
return errors
6064

6165

krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
#
13
# Copyright 2025 The Krkn Authors
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,6 +13,7 @@
1113
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1214
# See the License for the specific language governing permissions and
1315
# limitations under the License.
16+
1417
import logging
1518
import queue
1619
import random
@@ -65,8 +68,8 @@ def run(
6568
)
6669

6770
if (
68-
network_chaos_config.instance_count != 0
69-
and network_chaos_config.instance_count < len(targets)
71+
network_chaos_config.instance_count > 0
72+
and len(targets) > network_chaos_config.instance_count
7073
):
7174
targets = random.sample(
7275
targets, network_chaos_config.instance_count
@@ -76,7 +79,7 @@ def run(
7679
self.run_parallel(targets, network_chaos)
7780
else:
7881
self.run_serial(targets, network_chaos)
79-
if len(config) > 1:
82+
if len(scenario_config) > 1:
8083
logging.info(
8184
f"waiting {network_chaos_config.wait_duration} seconds before running the next "
8285
f"Network Chaos NG Module"

0 commit comments

Comments
 (0)