Skip to content

Commit b1845dc

Browse files
authored
issue 384 - error on empty peer container (#397)
* checking if config has peers Signed-off-by: haim-kermany <[email protected]> * using query_not_executed instead of exception Signed-off-by: haim-kermany <[email protected]> * 1. create QueryAnswer for good format 2. handle expected_not_executed on every scheme run Signed-off-by: haim-kermany <[email protected]> * returning scan-dir-test-scheme.yaml Signed-off-by: haim-kermany <[email protected]> Signed-off-by: haim-kermany <[email protected]>
1 parent 076dd7d commit b1845dc

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

nca/NetworkConfig/NetworkConfigQuery.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def execute_and_compute_output_in_required_format(self, cmd_line_flag=False):
6262
and bool indicator if the query was not executed
6363
:rtype: int, Union[dict, str], bool
6464
"""
65+
for config in self.get_configs():
66+
if not config.peer_container.get_num_peers():
67+
error_msg = f'Error: Network configuration \'{config.name}\' does not have any peers. Can not run Query'
68+
query_answer = QueryAnswer(output_result=error_msg, query_not_executed=True)
69+
return query_answer.numerical_result, self._handle_output(query_answer), query_answer.query_not_executed
6570
query_answer = self.execute(cmd_line_flag)
6671
if self.output_config.outputFormat not in self.get_supported_output_formats():
6772
return query_answer.numerical_result, '', query_answer.query_not_executed
@@ -95,6 +100,10 @@ def execute(self, cmd_line_flag):
95100
def get_configs_names(self):
96101
raise NotImplementedError
97102

103+
@abstractmethod
104+
def get_configs(self):
105+
raise NotImplementedError
106+
98107

99108
class NetworkConfigQuery(BaseNetworkQuery):
100109
"""
@@ -115,6 +124,13 @@ def get_configs_names(self):
115124
"""
116125
return [self.config.name]
117126

127+
def get_configs(self):
128+
"""
129+
returns the config
130+
:rtype: list[NetworksConfig]
131+
"""
132+
return [self.config]
133+
118134
@staticmethod
119135
def get_query_type():
120136
return QueryType.SingleConfigQuery
@@ -750,6 +766,13 @@ def get_configs_names(self):
750766
"""
751767
return [self.name1, self.name2]
752768

769+
def get_configs(self):
770+
"""
771+
returns list of the query's configs
772+
:rtype: list[NetworksConfig]
773+
"""
774+
return [self.config1, self.config2]
775+
753776
@staticmethod
754777
def get_query_type():
755778
return QueryType.ComparisonToBaseConfigQuery

nca/SchemeRunner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,13 @@ def run_queries(self, query_array):
198198
if res != expected:
199199
self.warning(f'Unexpected result for query {query_name}: Expected {expected}, got {res}\n', query)
200200
self.global_res += 1
201-
if 'expectedNotExecuted' in query:
202-
expected_not_executed = query['expectedNotExecuted']
203-
if not_executed != expected_not_executed:
204-
self.warning(f'{query_name} was not executed {not_executed} times. '
205-
f'Although, expected to not be executed {expected_not_executed} times')
206-
self.global_res += 1
201+
expected_not_executed = query.get('expectedNotExecuted', 0)
202+
if not_executed != expected_not_executed:
203+
msg = f'{query_name} was not executed {not_executed} times.'
204+
if 'expectedNotExecuted' in query:
205+
msg = msg + f' Although, expected to not be executed {expected_not_executed} times'
206+
self.warning(msg)
207+
self.global_res += 1
207208
if comparing_err != 0:
208209
self.warning(f'Unexpected output comparing result for query {query_name} ')
209210
self.global_res += 1

tests/istio_testcases/scan-dir-test-scheme.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ networkConfigList:
1010
queries:
1111
- name: test-query
1212
connectivityMap:
13-
- test
13+
- test
14+
expectedNotExecuted: 1

0 commit comments

Comments
 (0)