Update to Alpine 3.14
[functest.git] / functest / tests / unit / utils / test_functest_utils.py
index 4ec2058..1fab8f1 100644 (file)
@@ -82,7 +82,7 @@ class FunctestUtilsTesting(unittest.TestCase):
     def _get_environ(self, var, *args):  # pylint: disable=unused-argument
         if var == 'INSTALLER_TYPE':
             return self.installer
-        elif var == 'DEPLOY_SCENARIO':
+        if var == 'DEPLOY_SCENARIO':
             return self.scenario
         return var
 
@@ -100,10 +100,10 @@ class FunctestUtilsTesting(unittest.TestCase):
                            mock.mock_open()) as mopen:
             stream = six.BytesIO()
             stream.write(self.cmd_readline().encode("utf-8"))
-            mock_obj2 = mock.Mock()
-            attrs = {'stdout': stream, 'wait.return_value': 1}
-            mock_obj2.configure_mock(**attrs)
-            mock_subproc_open.return_value = mock_obj2
+            attrs = {
+                'return_value.__enter__.return_value.stdout': stream,
+                'return_value.__enter__.return_value.wait.return_value': 1}
+            mock_subproc_open.configure_mock(**attrs)
             resp = functest_utils.execute_command(
                 self.cmd, info=True, error_msg=self.error_msg, verbose=True,
                 output_file=self.output_file)
@@ -121,10 +121,10 @@ class FunctestUtilsTesting(unittest.TestCase):
                            mock.mock_open()) as mopen:
             stream = six.BytesIO()
             stream.write(self.cmd_readline().encode("utf-8"))
-            mock_obj2 = mock.Mock()
-            attrs = {'stdout': stream, 'wait.return_value': 0}
-            mock_obj2.configure_mock(**attrs)
-            mock_subproc_open.return_value = mock_obj2
+            attrs = {
+                'return_value.__enter__.return_value.stdout': stream,
+                'return_value.__enter__.return_value.wait.return_value': 0}
+            mock_subproc_open.configure_mock(**attrs)
             resp = functest_utils.execute_command(
                 self.cmd, info=True, error_msg=self.error_msg, verbose=True,
                 output_file=self.output_file)
@@ -140,10 +140,10 @@ class FunctestUtilsTesting(unittest.TestCase):
                 as mock_subproc_open:
             stream = six.BytesIO()
             stream.write(self.cmd_readline().encode("utf-8"))
-            mock_obj2 = mock.Mock()
-            attrs = {'stdout': stream, 'wait.return_value': 0}
-            mock_obj2.configure_mock(**attrs)
-            mock_subproc_open.return_value = mock_obj2
+            attrs = {
+                'return_value.__enter__.return_value.stdout': stream,
+                'return_value.__enter__.return_value.wait.return_value': 0}
+            mock_subproc_open.configure_mock(**attrs)
             resp = functest_utils.execute_command(
                 self.cmd, info=False, error_msg="", verbose=False,
                 output_file=None)
@@ -154,12 +154,13 @@ class FunctestUtilsTesting(unittest.TestCase):
         # pylint: disable=unused-argument
         with mock.patch('functest.utils.functest_utils.subprocess.Popen') \
                 as mock_subproc_open:
+            attrs = {}
             stream = six.BytesIO()
             stream.write(self.cmd_readline().encode("utf-8"))
-            mock_obj2 = mock.Mock()
-            attrs = {'stdout': stream, 'wait.return_value': 1}
-            mock_obj2.configure_mock(**attrs)
-            mock_subproc_open.return_value = mock_obj2
+            attrs = {
+                'return_value.__enter__.return_value.stdout': stream,
+                'return_value.__enter__.return_value.wait.return_value': 1}
+            mock_subproc_open.configure_mock(**attrs)
             resp = functest_utils.execute_command(
                 self.cmd, info=False, error_msg="", verbose=False,
                 output_file=None)
@@ -308,6 +309,30 @@ class FunctestUtilsTesting(unittest.TestCase):
             cloud), "Stein")
         args[0].assert_called_once_with(cloud)
 
+    @mock.patch('functest.utils.functest_utils.get_nova_version',
+                return_value=(2, 78))
+    def test_openstack_version12(self, *args):
+        cloud = mock.Mock()
+        self.assertEqual(functest_utils.get_openstack_version(
+            cloud), "Train")
+        args[0].assert_called_once_with(cloud)
+
+    @mock.patch('functest.utils.functest_utils.get_nova_version',
+                return_value=(2, 87))
+    def test_openstack_version13(self, *args):
+        cloud = mock.Mock()
+        self.assertEqual(functest_utils.get_openstack_version(
+            cloud), "Ussuri")
+        args[0].assert_called_once_with(cloud)
+
+    @mock.patch('functest.utils.functest_utils.get_nova_version',
+                return_value=(2, 88))
+    def test_openstack_version14(self, *args):
+        cloud = mock.Mock()
+        self.assertEqual(functest_utils.get_openstack_version(
+            cloud), "Wallaby")
+        args[0].assert_called_once_with(cloud)
+
     @mock.patch('functest.utils.functest_utils.get_nova_version',
                 return_value=None)
     def test_openstack_version_exc(self, *args):
@@ -322,7 +347,7 @@ class FunctestUtilsTesting(unittest.TestCase):
         self.assertEqual(
             functest_utils.convert_dict_to_ini({"a": "b"}), "a:b")
         value = functest_utils.convert_dict_to_ini({"a": "b", "c": "d"})
-        self.assertTrue(value == "a:b,c:d" or value == "c:d,a:b")
+        self.assertTrue(value in ('a:b,c:d', 'c:d,a:b'))
         with self.assertRaises(AssertionError):
             functest_utils.convert_list_to_ini("")