From 3749cd618b2b7dfc4442de06dfa5c876f9639bc7 Mon Sep 17 00:00:00 2001
From: Michal Arbet <michal.arbet@ultimum.io>
Date: Wed, 29 Aug 2018 14:17:36 +0200
Subject: [PATCH] Fix async keyword for Python 3.7

In Python 3.7, async becomes a keyword, and therefore we need
to change variable async.

The passthru() previously had async and async_call, we just remove
the old parameter.

scciclient moved from async to do_async as parameter, so we use that.

Change-Id: I35cb34d9ba78186de88ff7b56ab89ee6e24db6e6
---
 driver-requirements.txt                       |  2 +-
 ironic/drivers/base.py                        | 35 ++++---------------
 ironic/drivers/modules/irmc/boot.py           |  8 ++---
 .../unit/drivers/modules/irmc/test_boot.py    |  8 ++---
 ironic/tests/unit/drivers/test_base.py        | 10 ------
 5 files changed, 16 insertions(+), 47 deletions(-)

diff --git a/driver-requirements.txt b/driver-requirements.txt
index e8cb3f36ae..0a0ade9827 100644
--- a/driver-requirements.txt
+++ b/driver-requirements.txt
@@ -8,7 +8,7 @@ proliantutils>=2.6.0
 pysnmp>=4.3.0,<5.0.0
 python-ironic-inspector-client>=1.5.0
 python-oneviewclient<3.0.0,>=2.5.2
-python-scciclient>=0.7.2
+python-scciclient>=0.8.0
 python-ilorest-library>=2.1.0
 hpOneView>=4.4.0
 UcsSdk==0.8.2.2
diff --git a/ironic/drivers/base.py b/ironic/drivers/base.py
index 1c6a376099..a4a9485a82 100644
--- a/ironic/drivers/base.py
+++ b/ironic/drivers/base.py
@@ -646,7 +646,7 @@ VendorMetadata = collections.namedtuple('VendorMetadata', ['method',
                                                            'metadata'])
 
 
-def _passthru(http_methods, method=None, async=None, async_call=None,
+def _passthru(http_methods, method=None, async_call=True,
               driver_passthru=False, description=None,
               attach=False, require_exclusive_lock=True):
     """A decorator for registering a function as a passthru function.
@@ -662,7 +662,6 @@ def _passthru(http_methods, method=None, async=None, async_call=None,
     :param http_methods: A list of supported HTTP methods by the vendor
                          function.
     :param method: an arbitrary string describing the action to be taken.
-    :param async: Deprecated, please use async_call instead.
     :param async_call: Boolean value. If True invoke the passthru function
                   asynchronously; if False, synchronously. If a passthru
                   function touches the BMC we strongly recommend it to
@@ -682,26 +681,6 @@ def _passthru(http_methods, method=None, async=None, async_call=None,
                                    for a synchronous passthru method. If False,
                                    don't lock the node. Defaults to True.
     """
-    # TODO(rloo): In Stein cycle, remove support for 'async' parameter.
-    #             The default value for 'async_call' should then be changed
-    #             to True.
-    if async_call is None:
-        if async is not None:
-            LOG.warning(
-                'The "async" parameter is deprecated, please use "async_call" '
-                'instead. The "async" parameter will be removed in the Stein '
-                'cycle.'
-            )
-            async_call = async
-        else:
-            async_call = True
-    else:
-        if async is not None:
-            raise TypeError(
-                "'async_call' and 'async' parameters cannot be used together. "
-                "Use 'async_call' instead of 'async' since 'async' is "
-                "deprecated and will be removed in the Stein cycle."
-            )
 
     def handle_passthru(func):
         api_method = method
@@ -737,17 +716,17 @@ def _passthru(http_methods, method=None, async=None, async_call=None,
     return handle_passthru
 
 
-def passthru(http_methods, method=None, async=None, description=None,
-             attach=False, require_exclusive_lock=True, async_call=None):
-    return _passthru(http_methods, method, async, async_call,
+def passthru(http_methods, method=None, async_call=True, description=None,
+             attach=False, require_exclusive_lock=True):
+    return _passthru(http_methods, method, async_call,
                      driver_passthru=False,
                      description=description, attach=attach,
                      require_exclusive_lock=require_exclusive_lock)
 
 
-def driver_passthru(http_methods, method=None, async=None, description=None,
-                    attach=False, async_call=None):
-    return _passthru(http_methods, method, async, async_call,
+def driver_passthru(http_methods, method=None, async_call=True,
+                    description=None, attach=False):
+    return _passthru(http_methods, method, async_call,
                      driver_passthru=True, description=description,
                      attach=attach)
 
diff --git a/ironic/drivers/modules/irmc/boot.py b/ironic/drivers/modules/irmc/boot.py
index 901a561b7e..c1e4738ee0 100644
--- a/ironic/drivers/modules/irmc/boot.py
+++ b/ironic/drivers/modules/irmc/boot.py
@@ -447,8 +447,8 @@ def _attach_virtual_cd(node, bootable_iso_filename):
             CONF.irmc.remote_image_user_name,
             CONF.irmc.remote_image_user_password)
 
-        irmc_client(cd_set_params, async=False)
-        irmc_client(scci.MOUNT_CD, async=False)
+        irmc_client(cd_set_params, do_async=False)
+        irmc_client(scci.MOUNT_CD, do_async=False)
 
     except scci.SCCIClientError as irmc_exception:
         LOG.exception("Error while inserting virtual cdrom "
@@ -503,8 +503,8 @@ def _attach_virtual_fd(node, floppy_image_filename):
             CONF.irmc.remote_image_user_name,
             CONF.irmc.remote_image_user_password)
 
-        irmc_client(fd_set_params, async=False)
-        irmc_client(scci.MOUNT_FD, async=False)
+        irmc_client(fd_set_params, do_async=False)
+        irmc_client(scci.MOUNT_FD, do_async=False)
 
     except scci.SCCIClientError as irmc_exception:
         LOG.exception("Error while inserting virtual floppy "
diff --git a/ironic/tests/unit/drivers/modules/irmc/test_boot.py b/ironic/tests/unit/drivers/modules/irmc/test_boot.py
index 452d0b7395..e1937a3c2d 100644
--- a/ironic/tests/unit/drivers/modules/irmc/test_boot.py
+++ b/ironic/tests/unit/drivers/modules/irmc/test_boot.py
@@ -726,8 +726,8 @@ class IRMCDeployPrivateMethodsTestCase(test_common.BaseIRMCTest):
                                        'admin',
                                        'admin0')
             irmc_client.assert_has_calls(
-                [mock.call(cd_set_params, async=False),
-                 mock.call(irmc_boot.scci.MOUNT_CD, async=False)])
+                [mock.call(cd_set_params, do_async=False),
+                 mock.call(irmc_boot.scci.MOUNT_CD, do_async=False)])
 
     @mock.patch.object(irmc_common, 'get_irmc_client', spec_set=True,
                        autospec=True)
@@ -805,8 +805,8 @@ class IRMCDeployPrivateMethodsTestCase(test_common.BaseIRMCTest):
                                        'admin',
                                        'admin0')
             irmc_client.assert_has_calls(
-                [mock.call(fd_set_params, async=False),
-                 mock.call(irmc_boot.scci.MOUNT_FD, async=False)])
+                [mock.call(fd_set_params, do_async=False),
+                 mock.call(irmc_boot.scci.MOUNT_FD, do_async=False)])
 
     @mock.patch.object(irmc_common, 'get_irmc_client', spec_set=True,
                        autospec=True)
diff --git a/ironic/tests/unit/drivers/test_base.py b/ironic/tests/unit/drivers/test_base.py
index d3f7367655..1ad38142ae 100644
--- a/ironic/tests/unit/drivers/test_base.py
+++ b/ironic/tests/unit/drivers/test_base.py
@@ -100,16 +100,6 @@ class PassthruDecoratorTestCase(base.TestCase):
         self.assertNotEqual(inst1.driver_routes['driver_noexception']['func'],
                             inst2.driver_routes['driver_noexception']['func'])
 
-    @mock.patch.object(driver_base.LOG, 'warning')
-    def test_old_async_warning(self, mock_log_warning):
-        driver_base.passthru(['POST'], async=True)
-        mock_log_warning.assert_called_once()
-
-    @mock.patch.object(driver_base.LOG, 'warning')
-    def test_new_async_call_without_warning(self, mock_log_warning):
-        driver_base.passthru(['POST'], async_call=True)
-        mock_log_warning.assert_not_called()
-
 
 class CleanStepDecoratorTestCase(base.TestCase):