summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDileep Ranganathan <dileep.ranganathan@intel.com>2018-03-19 08:26:42 -0700
committerDileep Ranganathan <dileep.ranganathan@intel.com>2018-03-25 12:36:18 -0700
commit784505a1ff2aa94fab7c2eb8c754fcba8b6049a7 (patch)
treee8b1d795b5c8fce108094edb6cffe91f010f8156
parentf559ed62d76b90c28c874c2efee7c9bbb67bba87 (diff)
Implemented match all operator for HPA
Implemented match all operator for list inputs. For eg: InstructionSetExetensions which checks for a input set of requirements in the available capability list. Change-Id: I3784ae2f85309236f790a0d6a5927ab3ec535b97 Issue-ID: OPTFRA-181 Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
-rw-r--r--conductor/conductor/data/plugins/inventory_provider/hpa_utils.py48
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/test_hpa_utils.py65
2 files changed, 113 insertions, 0 deletions
diff --git a/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py
new file mode 100644
index 0000000..6ed622c
--- /dev/null
+++ b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# -------------------------------------------------------------------------
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+
+'''Utility functions for
+ Hardware Platform Awareness (HPA) constraint plugin'''
+
+# python imports
+
+# Conductor imports
+
+# Third-party library imports
+from oslo_log import log
+
+LOG = log.getLogger(__name__)
+
+
+def match_all_operator(big_list, small_list):
+ '''
+ Match ALL operator for HPA
+ Check if smaller list is a subset of bigger list
+ :param big_list: bigger list
+ :param small_list: smaller list
+ :return: True or False
+ '''
+ if not big_list or not small_list:
+ return False
+
+ big_set = set(big_list)
+ small_set = set(small_list)
+
+ return small_set.issubset(big_set)
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_hpa_utils.py b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_hpa_utils.py
new file mode 100644
index 0000000..f5e36c9
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_hpa_utils.py
@@ -0,0 +1,65 @@
+#
+# -------------------------------------------------------------------------
+# 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.data.plugins.inventory_provider import hpa_utils
+
+
+class TestHPAUtils(unittest.TestCase):
+
+ def test_match_all_operator(self):
+ self.assertEqual(False, hpa_utils.match_all_operator(None, None))
+ self.assertEqual(False, hpa_utils.match_all_operator([], None))
+ self.assertEqual(False, hpa_utils.match_all_operator(None, []))
+ self.assertEqual(False, hpa_utils.match_all_operator([], []))
+
+ big_list = ['aes', 'sse', 'avx', 'smt']
+ small_list = ['avx', 'aes']
+ self.assertEqual(True,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+ big_list = ['aes', 'sse', 'avx', 'smt']
+ small_list = ['avx', 'pcmulqdq']
+ self.assertEqual(False,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+ big_list = ['aes', 'sse', 'avx', 'smt']
+ small_list = ['aes', 'sse', 'avx', 'smt']
+ self.assertEqual(True,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+ big_list = ['aes', 'sse', 'avx', 'smt']
+ small_list = ['smt']
+ self.assertEqual(True,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+ big_list = ['aes']
+ small_list = ['smt']
+ self.assertEqual(False,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+ # check the order of elements
+ big_list = ['aes', 'sse', 'avx', 'smt']
+ small_list = sorted(big_list)
+ self.assertEqual(True,
+ hpa_utils.match_all_operator(big_list, small_list))
+
+
+if __name__ == "__main__":
+ unittest.main()