Coverage for watcher/decision_engine/scope/baremetal.py: 81%
32 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2018 ZTE Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
17from watcher.decision_engine.scope import base
20class BaremetalScope(base.BaseScope):
21 """Baremetal Audit Scope Handler"""
23 def __init__(self, scope, config, osc=None):
24 super(BaremetalScope, self).__init__(scope, config)
25 self._osc = osc
27 def exclude_resources(self, resources, **kwargs):
28 nodes_to_exclude = kwargs.get('nodes')
29 for resource in resources:
30 if 'ironic_nodes' in resource: 30 ↛ 29line 30 didn't jump to line 29 because the condition on line 30 was always true
31 nodes_to_exclude.extend(
32 [node['uuid'] for node
33 in resource['ironic_nodes']])
35 def remove_nodes_from_model(self, nodes_to_exclude, cluster_model):
36 for node_uuid in nodes_to_exclude:
37 node = cluster_model.get_node_by_uuid(node_uuid)
38 cluster_model.remove_node(node)
40 def get_scoped_model(self, cluster_model):
41 """Leave only nodes and instances proposed in the audit scope"""
42 if not cluster_model: 42 ↛ 43line 42 didn't jump to line 43 because the condition on line 42 was never true
43 return None
45 nodes_to_exclude = []
46 baremetal_scope = []
48 if not self.scope: 48 ↛ 49line 48 didn't jump to line 49 because the condition on line 48 was never true
49 return cluster_model
51 for scope in self.scope: 51 ↛ 56line 51 didn't jump to line 56 because the loop on line 51 didn't complete
52 baremetal_scope = scope.get('baremetal')
53 if baremetal_scope: 53 ↛ 51line 53 didn't jump to line 51 because the condition on line 53 was always true
54 break
56 if not baremetal_scope: 56 ↛ 57line 56 didn't jump to line 57 because the condition on line 56 was never true
57 return cluster_model
59 for rule in baremetal_scope:
60 if 'exclude' in rule: 60 ↛ 59line 60 didn't jump to line 59 because the condition on line 60 was always true
61 self.exclude_resources(
62 rule['exclude'], nodes=nodes_to_exclude)
64 self.remove_nodes_from_model(nodes_to_exclude, cluster_model)
66 return cluster_model