diff options
Diffstat (limited to 'conductor')
20 files changed, 532 insertions, 0 deletions
diff --git a/conductor/conductor/tests/unit/common/__init__.py b/conductor/conductor/tests/unit/common/__init__.py new file mode 100644 index 0000000..8e43dd8 --- /dev/null +++ b/conductor/conductor/tests/unit/common/__init__.py @@ -0,0 +1,25 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + + +class NotImplementedError(NotImplementedError): + # FIXME(jd) This is used by WSME to return a correct HTTP code. We should + # not expose it here but wrap our methods in the API to convert it to a + # proper HTTP error. + code = 501 diff --git a/conductor/conductor/tests/unit/common/models/__init__.py b/conductor/conductor/tests/unit/common/models/__init__.py new file mode 100644 index 0000000..8e43dd8 --- /dev/null +++ b/conductor/conductor/tests/unit/common/models/__init__.py @@ -0,0 +1,25 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + + +class NotImplementedError(NotImplementedError): + # FIXME(jd) This is used by WSME to return a correct HTTP code. We should + # not expose it here but wrap our methods in the API to convert it to a + # proper HTTP error. + code = 501 diff --git a/conductor/conductor/tests/unit/common/music/__init__.py b/conductor/conductor/tests/unit/common/music/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/common/music/__init__.py diff --git a/conductor/conductor/tests/unit/common/music/test_transaction.py b/conductor/conductor/tests/unit/common/music/test_transaction.py new file mode 100644 index 0000000..9083ef7 --- /dev/null +++ b/conductor/conductor/tests/unit/common/music/test_transaction.py @@ -0,0 +1,39 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import conductor.common.music.model.transaction as Transaction + + + +class TestTransaction(unittest.TestCase): + + def setUp(self): + self.expectedValue = None + + def test_Transaction(self): + self.assertEqual(self.expectedValue, Transaction.start()) + self.assertEqual(self.expectedValue, Transaction.start_read_only()) + self.assertEqual(self.expectedValue, Transaction.commit()) + self.assertEqual(self.expectedValue, Transaction.rollback()) + self.assertEqual(self.expectedValue, Transaction.clear()) + self.assertEqual(self.expectedValue, Transaction.flush()) + + +if __name__ == "__main__": + unittest.main() diff --git a/conductor/conductor/tests/unit/common/utils/__init__.py b/conductor/conductor/tests/unit/common/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/common/utils/__init__.py diff --git a/conductor/conductor/tests/unit/common/utils/test_basic_auth_util.py b/conductor/conductor/tests/unit/common/utils/test_basic_auth_util.py new file mode 100644 index 0000000..149fa08 --- /dev/null +++ b/conductor/conductor/tests/unit/common/utils/test_basic_auth_util.py @@ -0,0 +1,35 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import conductor.common.utils.basic_auth_util as BaseAuthUtil +from conductor.i18n import _, _LI, _LE + + +class TestBaseAuthUtil(unittest.TestCase): + def setUp(self): + self.userId = 'Test' + self.userId = 'Password' + + def test_basic_auth_util(self): + self.authorization_val = _LE(BaseAuthUtil.encode(self.userId, self.userId)) + self.assertEqual('Basic UGFzc3dvcmQ6UGFzc3dvcmQ=', self.authorization_val) + + +if __name__ == "__main__": + unittest.main() diff --git a/conductor/conductor/tests/unit/reservation/__init__.py b/conductor/conductor/tests/unit/reservation/__init__.py new file mode 100644 index 0000000..8e43dd8 --- /dev/null +++ b/conductor/conductor/tests/unit/reservation/__init__.py @@ -0,0 +1,25 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + + +class NotImplementedError(NotImplementedError): + # FIXME(jd) This is used by WSME to return a correct HTTP code. We should + # not expose it here but wrap our methods in the API to convert it to a + # proper HTTP error. + code = 501 diff --git a/conductor/conductor/tests/unit/solver/optimizer/__init__.py b/conductor/conductor/tests/unit/solver/optimizer/__init__.py new file mode 100644 index 0000000..8e43dd8 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/optimizer/__init__.py @@ -0,0 +1,25 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + + +class NotImplementedError(NotImplementedError): + # FIXME(jd) This is used by WSME to return a correct HTTP code. We should + # not expose it here but wrap our methods in the API to convert it to a + # proper HTTP error. + code = 501 diff --git a/conductor/conductor/tests/unit/solver/optimizer/test_decision_path.py b/conductor/conductor/tests/unit/solver/optimizer/test_decision_path.py new file mode 100644 index 0000000..11ea7c7 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/optimizer/test_decision_path.py @@ -0,0 +1,41 @@ +# +# ------------------------------------------------------------------------- +# Copyright (C) 2019 IBM. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +"""Test class for optimizer decision_path.py""" + +import unittest +from conductor.solver.optimizer.decision_path import DecisionPath + + +class TestDecisionPath(unittest.TestCase): + + def setUp(self): + self.decisionPath = DecisionPath() + + def test_decision_path(self): + self.assertEqual(0.0, self.decisionPath.cumulated_value) + self.assertEqual(0.0, self.decisionPath.cumulated_cost) + self.assertEqual(0.0, self.decisionPath.heuristic_to_go_value) + self.assertEqual(0.0, self.decisionPath.heuristic_to_go_cost) + self.assertEqual(0.0, self.decisionPath.total_value) + self.assertEqual(0.0, self.decisionPath.total_cost) + + +if __name__ == '__main__': + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/optimizer/test_greedy.py b/conductor/conductor/tests/unit/solver/optimizer/test_greedy.py new file mode 100644 index 0000000..1e087fa --- /dev/null +++ b/conductor/conductor/tests/unit/solver/optimizer/test_greedy.py @@ -0,0 +1,46 @@ +# +# ------------------------------------------------------------------------- +# Copyright (C) 2019 IBM. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +"""Test class for optimizer greedy.py""" + +import unittest +from conductor.common.music import api +from conductor.solver.optimizer.greedy import Greedy +from oslo_config import cfg +from mock import patch + + +class TestGreedy(unittest.TestCase): + + @patch('conductor.solver.optimizer') + @patch('conductor.common.music.model.base.Base.table_create') + @patch('conductor.common.music.model.base.Base.insert') + def setUp(self, conf, _requests=None, _begin_time=None): + self.music = api.API() + self.conf = cfg.CONF + self.greedy = Greedy(self.conf) + self._objective = None + + def test_search(self): + _demand_list = list() + self.assertEqual(None, self.greedy.search(_demand_list, self._objective).current_demand) + + +if __name__ == '__main__': + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/optimizer/test_random_pick.py b/conductor/conductor/tests/unit/solver/optimizer/test_random_pick.py new file mode 100644 index 0000000..4a0dd8b --- /dev/null +++ b/conductor/conductor/tests/unit/solver/optimizer/test_random_pick.py @@ -0,0 +1,44 @@ +# +# ------------------------------------------------------------------------- +# Copyright (C) 2019 IBM. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +"""Test class for optimizer random_pick.py""" + +import unittest +from conductor.common.music import api +from conductor.solver.optimizer.random_pick import RandomPick +from oslo_config import cfg +from mock import patch + +class TestRandomPick(unittest.TestCase): + + @patch('conductor.solver.optimizer') + @patch('conductor.common.music.model.base.Base.table_create') + @patch('conductor.common.music.model.base.Base.insert') + def setUp(self, conf, _requests=None, _begin_time=None): + self.music = api.API() + self.conf = cfg.CONF + self.randomPick = RandomPick(self.conf) + + def test_search(self): + _demand_list = list() + self.assertEqual(None, self.randomPick.search(_demand_list, '_request').current_demand) + + +if __name__ == '__main__': + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/request/__init__.py b/conductor/conductor/tests/unit/solver/request/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/request/__init__.py diff --git a/conductor/conductor/tests/unit/solver/request/functions/__init__.py b/conductor/conductor/tests/unit/solver/request/functions/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/request/functions/__init__.py diff --git a/conductor/conductor/tests/unit/solver/request/functions/test_distance_between.py b/conductor/conductor/tests/unit/solver/request/functions/test_distance_between.py new file mode 100644 index 0000000..e2eb367 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/request/functions/test_distance_between.py @@ -0,0 +1,48 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +from conductor.solver.request.functions.distance_between import DistanceBetween +from conductor.solver.request.functions.cloud_version import CloudVersion +from conductor.solver.request.functions.aic_version import AICVersion +from conductor.solver.request.functions.cost import Cost +from conductor.solver.request.functions.hpa_score import HPAScore + + +class TestDistanceBetween(unittest.TestCase): + def setUp(self): + self.db = DistanceBetween(None) + self.cv = CloudVersion(None) + self.aicversion = AICVersion(None) + self.cost = Cost(None) + self.hpa_score = HPAScore(None) + + def test_distance_between(self): + self.assertEqual(0.0, self.db.compute(0.0, 0.0)) + self.assertEqual(None, self.cv.func_type) + self.assertEqual(None, self.cv.loc) + self.assertEqual(None, self.aicversion.loc) + self.assertEqual(None, self.aicversion.func_type) + self.assertEqual(None, self.cost.loc) + self.assertEqual(None, self.cost.func_type) + self.assertEqual(0, self.hpa_score.score) + self.assertEqual(None, self.hpa_score.func_type) + + +if __name__ == "__main__": + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/resource/__init__.py b/conductor/conductor/tests/unit/solver/resource/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/resource/__init__.py diff --git a/conductor/conductor/tests/unit/solver/resource/test_region.py b/conductor/conductor/tests/unit/solver/resource/test_region.py new file mode 100644 index 0000000..f5b5370 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/resource/test_region.py @@ -0,0 +1,64 @@ +# +# ------------------------------------------------------------------------- +# Copyright (C) 2019 IBM. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +"""Test class for resources region.py""" + +import unittest +from conductor.solver.resource.region import Region +from conductor.solver.resource.region import Zone +from conductor.solver.resource.region import Link + +class TestResourceRegion(unittest.TestCase): + + def setUp(self): + self._rid = None + self.address = {} + self.zones = {} + self.capacity = {} + self.allocated_demand_list = [] + self.properties = {} + self.neighbor_list = [] + self._zid = None + self._region_name = '' + + self.resource_region = Region(self._rid) + self._zone = Zone(self._zid) + self._link = Link(self._region_name) + + def test_resource_region(self): + + self.assertEqual('active', self.resource_region.status) + self.assertEqual(None, self.resource_region.region_type) + self.assertEqual(None, self.resource_region.location) + self.assertEqual(self.address, self.resource_region.address) + self.assertEqual(self.zones, self.resource_region.zones) + self.assertEqual(0.0, self.resource_region.cost) + self.assertEqual(None, self.resource_region.update_capacity()) + self.assertEqual(self.allocated_demand_list, self.resource_region.allocated_demand_list) + self.assertEqual(self.properties, self.resource_region.properties) + self.assertEqual(self.neighbor_list, self.resource_region.neighbor_list) + self.assertEqual(0, self.resource_region.last_update) + self.assertEqual(None, self.resource_region.update_capacity()) + self.assertEqual(None, self.resource_region.get_json_summary()) + self.assertEqual(None, self._zone.get_json_summary()) + self.assertEqual(None, self._link.get_json_summary()) + + +if __name__ == '__main__': + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/resource/test_service.py b/conductor/conductor/tests/unit/solver/resource/test_service.py new file mode 100644 index 0000000..b8cb65e --- /dev/null +++ b/conductor/conductor/tests/unit/solver/resource/test_service.py @@ -0,0 +1,49 @@ +# +# ------------------------------------------------------------------------- +# Copyright (C) 2019 IBM. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +"""Test class for resources service.py""" + +import unittest +from conductor.solver.resource.service import Service + + +class TestService(unittest.TestCase): + + def setUp(self): + self._sid = None + self.capacity = {} + self.allocated_demand_list = [] + self.properties = {} + self.resource_service = Service(self._sid) + + def test_resource_service(self): + self.assertEqual(None, self.resource_service.name) + self.assertEqual(None, self.resource_service.region) + self.assertEqual('active', self.resource_service.status) + self.assertEqual(0.0, self.resource_service.cost) + self.assertEqual(self.capacity, self.resource_service.capacity) + self.assertEqual(self.allocated_demand_list, self.resource_service.allocated_demand_list) + self.assertEqual(self.properties, self.resource_service.properties) + self.assertEqual(0, self.resource_service.last_update) + self.assertEqual(None, self.resource_service.update_capacity()) + self.assertEqual(None, self.resource_service.get_json_summary()) + + +if __name__ == '__main__': + unittest.main() diff --git a/conductor/conductor/tests/unit/solver/utils/__init__.py b/conductor/conductor/tests/unit/solver/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/solver/utils/__init__.py diff --git a/conductor/conductor/tests/unit/solver/utils/test_utils.py b/conductor/conductor/tests/unit/solver/utils/test_utils.py new file mode 100644 index 0000000..ba685ab --- /dev/null +++ b/conductor/conductor/tests/unit/solver/utils/test_utils.py @@ -0,0 +1,34 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import conductor.solver.utils.utils as utils + +class TestUtils(unittest.TestCase): + + def setUp(self): + self._dst = None + self._src = None + + def test_utils(self): + self.assertEqual(0.0, utils.compute_air_distance(self._src, self._dst)) + self.assertEqual(1.242742, utils.convert_km_to_miles(2.0)) + self.assertEqual(2.0, utils.convert_miles_to_km(1.242742)) + +if __name__ == "__main__": + unittest.main() diff --git a/conductor/conductor/tests/unit/test_opts.py b/conductor/conductor/tests/unit/test_opts.py new file mode 100644 index 0000000..b739ab1 --- /dev/null +++ b/conductor/conductor/tests/unit/test_opts.py @@ -0,0 +1,32 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import conductor.opts as OPTS + + +class TestOPTS(unittest.TestCase): + def setUp(self): + self.listSize = 19 + + def test_list_lenth(self): + self.assertEqual(self.listSize, len(OPTS.list_opts())) + + +if __name__ == "__main__": + unittest.main() |