Modify threshold policy to support multiple constraints
[optf/has.git] / conductor / conductor / tests / unit / solver / optimizer / constraints / test_threshold.py
1 #
2 # -------------------------------------------------------------------------
3 #   Copyright (C) 2020 Wipro Limited.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # -------------------------------------------------------------------------
18 #
19
20 import json
21 import unittest
22 from conductor.solver.optimizer.constraints.threshold import Threshold
23 from conductor.solver.optimizer.decision_path import DecisionPath
24 from conductor.solver.request.demand import Demand
25
26
27 class TestThreshold(unittest.TestCase):
28
29     def test_solve(self):
30
31         candidates_file = './conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json'
32         candidates = json.loads(open(candidates_file).read())
33
34         properties = {'evaluate':
35                           [{'attribute': 'latency', 'threshold': 30, 'operator': 'lte'},
36                            {'attribute': 'exp_data_rate_ul', 'threshold': 70, 'operator': 'gte'}]}
37
38         threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0,
39                                   _properties=properties)
40
41         decision_path = DecisionPath()
42         decision_path.current_demand = Demand('URLLC')
43
44         self.assertEqual(candidates, threshold_obj.solve(decision_path, candidates, None))
45
46         properties = {'evaluate':
47                           [{'attribute': 'latency', 'threshold': 10, 'operator': 'lte'},
48                            {'attribute': 'exp_data_rate_ul', 'threshold': 120, 'operator': 'gte'}]}
49
50         threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0,
51                                   _properties=properties)
52
53         self.assertEqual([], threshold_obj.solve(decision_path, candidates, None))
54
55
56 if __name__ == "__main__":
57     unittest.main()