Add NSSI candidate
[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         # test 1
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         # test 2
47         properties = {'evaluate':
48                           [{'attribute': 'latency', 'threshold': 10, 'operator': 'lte'},
49                            {'attribute': 'exp_data_rate_ul', 'threshold': 120, 'operator': 'gte'}]}
50
51         threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0,
52                                   _properties=properties)
53
54         self.assertEqual([], threshold_obj.solve(decision_path, candidates, None))
55
56         # test 3
57         properties = {'evaluate':
58                           [{'attribute': 'latency', 'threshold': 10, 'operator': 'lte'},
59                            {'attribute': 'area_traffic_cap', 'threshold': 120, 'operator': 'gte'}]}
60
61         threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0,
62                                   _properties=properties)
63
64         self.assertEqual([], threshold_obj.solve(decision_path, candidates, None))
65
66
67 if __name__ == "__main__":
68     unittest.main()