You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/11/03 22:38:36 UTC

[libcloud] branch understand-ai-intelligent-retry updated (d2138f9 -> 5c59095)

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a change to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git.


    from d2138f9  Add changelog entries.
     new bf147dc  Update the function logic so we don't use open "while True" statement, also make retry-after a float so we can use lower value than 1 second in the tests to speed them up.
     new 8940a66  Add a test case for successful retry scenario where we successfuly retry on second attempt which we previously didn't have.
     new bfda9fc  Fix lint violations.
     add 4e76d31  Fix Minio homepage links in the docs
     add 7633f49  Fix Minio website from the driver
     add 847ae39  Merge pull request #1604 from fedepad/docs/fix-minio-links
     add f793f02  setup.py: Fix invalid python_requires
     add ee4ca96  Merge branch 'py-req' of https://github.com/mgorny/libcloud into mgorny-py-req
     add dae3a62  Add changelog entry.
     add 3ce42e9  Upgrade tox to 3.24.4.
     add 5e8d12d  Remove cron jobs
     add bfbf38d  Merge truk
     add 6a83430  Add disabled property to image: #1614
     add f510631  Add disabled property to flavor: #1614
     add d2d028b  revert change
     add 5976ea5  Update changelog: #1614
     add 97247b0  Merge pull request #1615 from micafer/ost_disabled_images
     add bcfec62  Specify lower timeout for integration tests job.
     add 754f2b4  Fix NSOne DNS Provider
     add 4048faa  Merge branch 'fix/nsone-create-record' of https://github.com/karantan/libcloud into karantan-fix/nsone-create-record
     add e06fb47  Add changelog entry.
     add 120cdb1  Update cloudsigma driver
     add 42c6780  Merge branch 'cloudsigma-updates' of https://github.com/dimgal1/libcloud into dimgal1-cloudsigma-updates
     add 051f243  Add changelog entry for #1558.
     add 8e60da0  Implements #1611
     add c2364ac  Fix typo
     add 04ba707  Merge pull request #1612 from micafer/fix_1611
     add 07fc284  Add changelog entry.
     add c84b341  EC2: Add support for gp3 and io2 volumes
     add 495052a  Merge branch 'trunk' of https://github.com/palashgandhi/libcloud into trunk
     add bed982a  Add changelog entry for #1596.
     add 8147b1c  Fix: #1575
     add 8a2c0d2  Merge branch 'fix-session-timeout' of https://github.com/dimgal1/libcloud into dimgal1-fix-session-timeout
     add 21ae20e  Add changelog entry for #1576.
     add 32653fe  Add additional test cases for asserting that timeout argument is correctly passed to the underlying requests send() method.
     add 044d990  Reduce timeout.
     add ac00b5b  Optimized 'iterate_container_objects' by filtering the objects before creating the iterator
     add 1500242  removed a call to _filter_listed_container_objects
     add e7f525b  Merge branch 'get_objects_with_prefix' of https://github.com/Ido-Levi/libcloud into Ido-Levi-get_objects_with_prefix
     add c1f2d86  Add changelog entry for #1584.
     add 53e5cf4  Add additional assertion.
     add 9580e2f  Update cryptography version used for tests.
     add b08e67a  Implements #1585
     add c9f9fb2  update changelog
     add cf63133  Merge branch 'trunk' into volume_quota
     add 78bf5f0  Merge pull request #1586 from micafer/volume_quota
     add 443d4d0  Upgrade paramiko used for tests to fix a failing tests due to bug in paramiko / cryptography dependency.
     add 9e676e2  Allow default connection timeout to be easily overriden using a module constant (e.g. for tests or similar).
     add f8b0b8b  Specify timeout for container getting ready and ensure container is always killed / stopped on exit.
     add 24c4685  Decrease container ready timeout, update message we wait for - it looks like Docker image behavior has changed.
     add 26fbcfd  Merge pull request #1616 from Kami/integration_tests_fixes
     add b49bbd3  Also try running unit tests under Python 3.10 on CI.
     add e15f0e6  Update tox config.
     add 15bd841  Use latest version of pytest under Python >= 3.6 since it contains a bug fix for running under Python 3.10.
     add 9273a34  Use newer version of cryptography under Python >= 3.6.
     add 24ef735  Update setup.py classifiers metadata and indicate we also support Python 3.10.
     add fcc0d72  Update setUpClass method in the Azure integration tests class to clean up any stray / left over resources from previous runs.
     add f98e814  Test the change.
     add 3717570  Make sure we pass GITHUB_ env variables to the tox run.
     add 5bc982f  Update code per PR feedback, test the change again.
     add 049ac90  Use latest version of pytest for integration tests, use tee-sys functionality so produced output is printed to console in real time and also on success and not just on failure.
     add 784b67c  Fix bug in the clean up code.
     add 0b42b1c  Add additional print and assert.
     add 7b06167  Remove testing changes.
     add 139feb3  Include additional tags.
     add 14027fc  Use try / finally.
     add d31e3ee  Use larger chunk size to speed up the tests.
     add 106383c  Make sure value is an int, use valid prefix.
     add bbcaa27  Update more tests to use less chunks to speed up all tests which previously used 1 byte chunk size.
     add a3f5297  Add additional assert.
     add 5a2ee7c  Reduce workflow timeout now that we have substantially sped up the tests.
     add b973182  Pass -rsx flag to pytest to report reason for skipped tests.
     add d695dbf  Merge pull request #1617 from Kami/itests_cleanup_step
     add faf718a  Use less chunks to speed up the test.
     add 6008a84  Use utf-8 encoding to decode byte string, print sample response to make debugging easier.
     add 97f7005  Add additional logging.
     add 23963b2  Test a change to see why task which works locally is failing on CI.
     add 40abc24  Update workflow.
     add 155e6d6  Test a change.
     add 6eef7a5  Try using jsonnet which should work under Python 3.
     add c8553fd  Remove testing change.
     add 5166da9  Update pricing data file.
     add efde7b4  Add Openstack Application Credential Support
     add a7539d2  Merge branch 'openstappcred' of https://github.com/ic-hep/libcloud into ic-hep-openstappcred
     add 5800c7c  Add changelog entry for #1598.
     add 81c6bd8  Fix small issue detected by pylint.
     add 7beffe1  Update codecov dependency.
     add 611d831  Add workaround for paramiko debug logging when LIBCLOUD_DEBUG is enabled.
     add 8717428  Update Google authentication class so we don't try to retry failed requests when retrying is enabled globally (either via module level constant or via environment variable value) when performing credentials check on driver intialization.
     add 4e2eace  Add workaround for paramiko debug logging when LIBCLOUD_DEBUG is enabled.
     add 9ad6f42  Fix formatting.
     add 8ee39db  Merge branch 'trunk' into google_auth_improvements
     add a474c68  Update type annotation.
     add 0b8b223  Update Google Auth class so we don't try to contact GCE metadata server when determining credentials type in case of oAuth 2 / installed app credentials are used.
     add e7adf14  Update minimum version of requests dependency we require as part of install_requires in setup.py to 2.26.0 when running under Python >= 3.6.
     add 4d25b24  Run dist install + dist install wheels checks on CI for multiple Python versions.
     add 29218a8  Fold it into a single job to reduce number of parallel jobs and speed things up.
     add 636dc14  Add missing file.
     add fb5486a  Fix small issue detected by pylint.
     add 1b66d83  Fix typo.
     add 3a69dff  Also run dist checks under Python 3.10.
     add 77a8d65  Update dist check.
     add 592abbf  Print python version.
     add 464c459  Move the assignment to make race less likely to occur.
     add 71f4f1f  Add a new CI job which runs on daily basis and verifies Libcloud can be installed from pip using all the supported versions.
     add 6a5eafc  Add skip duplicates pre job to CodeQL workflow.
     add eb655e4  Add job timeouts to all the jobs.
     add 819d285  Remove testing changes.
     add 7f61280  Try pinning docutils to see if it fixes new build failure which just started happening today.
     add 7ed2b02  Re-regenerate supported providers tables.
     add f1d82ee  Merge pull request #1619 from Kami/requests_changes
     add fecad4c  Merge branch 'trunk' into google_auth_improvements
     add 25b06f6  Merge pull request #1621 from Kami/google_auth_improvements
     add 6e5afd4  Increase timeout.
     add 7b82354  Try a fix for RTD build failure.
     add c766c04  Try upgrading to the latest version of sphinx.
     add feda19f  Move file in docs subdirectory.
     add 6ab9b10  Revert "Move file in docs subdirectory."
     add c475387  Remove change / workaround which should not be needed anymore now that we are running latest version of sphinx.
     add 856abc9  Update latest test and dev deps to latest versions.
     add fe3291b  Fix various lint violations and add some ignore pragmas for false positives.
     add dd26aa4  Also upgrade to the latest version of mypy.
     add 1b0f036  Update test requirements.
     add 04637ee  Remove subtree module to work around bug.
     add 842e2bf  Squashed '.github/actions/skip-duplicate-actions/' content from commit f75dd656
     add 12aba11  Merge commit '842e2bf2169a888ff20e6c7ba209a82ca3fd8f21' as '.github/actions/skip-duplicate-actions'
     add b299f5a  Add comment on how to update subtree.
     add dd9810f  Fix Python 3.5 compatibility.
     add 8756b68  Use a submodule instead of subtree.
     add 361e22e  Merge pull request #1622 from Kami/deps_update
     add 2f9d9d2  fix typos
     add 6d44bb3  add ex_auth_cache parameter to OpenStack drivers for caching of authentication tokens and reuse across processes
     add 532aa1f  OpenStack authentication token cache example
     add 46454a3  add upgrade note for exception message change in  libcloud/common/openstack_identity.py:691
     add 583cbca  Add changelog entry for #1557.
     new 5c59095  Merge branch 'trunk' into understand-ai-intelligent-retry

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/actions/skip-duplicate-actions             |     2 +-
 .github/workflows/codeql-analysis.yml              |    25 +
 .github/workflows/install_test.yml                 |    42 +
 .github/workflows/integration-tests.yml            |     3 +-
 .github/workflows/main.yml                         |    23 +-
 .github/workflows/publish_pricing_to_s3.yml        |     3 +-
 CHANGES.rst                                        |   103 +
 MANIFEST.in                                        |     1 +
 contrib/scrape-ec2-prices.py                       |    15 +-
 docs/compute/_supported_methods_block_storage.rst  |     2 +-
 .../_supported_methods_key_pair_management.rst     |     2 +-
 docs/compute/_supported_methods_main.rst           |     2 +-
 docs/compute/drivers/openstack.rst                 |    23 +-
 .../compute/create_ibm_sce_windows_node.py         |     2 +-
 docs/examples/compute/gandi/create_node.py         |     2 +-
 docs/examples/compute/gridscale/create_node.py     |     2 +-
 docs/examples/compute/gridscale/deploy_node.py     |     2 +-
 docs/examples/compute/openstack/auth_cache.py      |    18 +
 docs/examples/compute/ovh/attach_volume.py         |     2 +-
 docs/examples/compute/ovh/create_node.py           |     2 +-
 docs/storage/_supported_methods_cdn.rst            |     2 +-
 docs/storage/_supported_methods_main.rst           |     2 +-
 docs/storage/_supported_providers.rst              |     2 +-
 docs/upgrade_notes.rst                             |    10 +
 integration/storage/base.py                        |    67 +-
 integration/storage/test_azure_blobs.py            |    37 +-
 integration/storage/test_minio.py                  |     2 +-
 libcloud/__init__.py                               |    10 +-
 libcloud/backup/drivers/gce.py                     |     2 +-
 libcloud/common/base.py                            |    14 +-
 libcloud/common/cloudsigma.py                      |   258 +-
 libcloud/common/exceptions.py                      |     2 +-
 libcloud/common/gandi.py                           |     4 +-
 libcloud/common/google.py                          |    23 +-
 libcloud/common/openstack.py                       |    41 +-
 libcloud/common/openstack_identity.py              |   518 +-
 libcloud/compute/drivers/azure.py                  |     2 +-
 libcloud/compute/drivers/azure_arm.py              |     3 +-
 libcloud/compute/drivers/cloudsigma.py             |   315 +-
 libcloud/compute/drivers/ec2.py                    |    21 +-
 libcloud/compute/drivers/gandi.py                  |     2 +-
 libcloud/compute/drivers/gce.py                    |     8 +-
 libcloud/compute/drivers/openstack.py              |    88 +-
 libcloud/compute/drivers/softlayer.py              |     2 +-
 libcloud/compute/drivers/vcloud.py                 |     8 +-
 libcloud/container/drivers/gke.py                  |     2 +-
 libcloud/data/pricing.json                         | 98244 ++++++++++---------
 libcloud/dns/drivers/nsone.py                      |    21 +-
 libcloud/http.py                                   |    11 +-
 libcloud/storage/drivers/azure_blobs.py            |     1 +
 libcloud/storage/drivers/local.py                  |    11 +-
 libcloud/storage/drivers/minio.py                  |     2 +-
 libcloud/test/common/test_google.py                |    10 +
 libcloud/test/common/test_openstack_identity.py    |   188 +-
 .../fixtures/cloudsigma_2_0/drives_resize.json     |     2 +-
 .../fixtures/cloudsigma_2_0/keypairs_get.json      |    12 +
 .../fixtures/cloudsigma_2_0/keypairs_import.json   |    16 +
 .../fixtures/cloudsigma_2_0/keypairs_list.json     |    33 +
 .../compute/fixtures/cloudsigma_2_0/libdrives.json |     2 +-
 .../fixtures/cloudsigma_2_0/servers_clone.json     |     4 +-
 .../cloudsigma_2_0/servers_create_with_vlan.json   |     4 +-
 .../cloudsigma_2_0/servers_detail_mixed_state.json |     4 +-
 .../fixtures/cloudsigma_2_0/servers_get.json       |   108 +
 .../fixtures/openstack/_v3__auth_unauthorized.json |     1 +
 .../fixtures/openstack_v1.1/_flavors_detail.json   |     2 +-
 .../openstack_v1.1/_v3_0__volume_quota.json        |    55 +
 libcloud/test/compute/test_cloudsigma_v1_0.py      |     2 +-
 libcloud/test/compute/test_cloudsigma_v2_0.py      |    91 +-
 libcloud/test/compute/test_cloudwatt.py            |    11 +
 libcloud/test/compute/test_ec2.py                  |     6 +-
 libcloud/test/compute/test_openstack.py            |   105 +-
 libcloud/test/compute/test_rackspace.py            |     2 +-
 .../nsone/create_record_already_exists.json        |     3 +
 .../dns/fixtures/nsone/create_record_success.json  |    24 +
 .../nsone/create_record_zone_not_found.json        |     3 +
 libcloud/test/dns/test_base.py                     |     3 +-
 libcloud/test/dns/test_nsone.py                    |    66 +-
 libcloud/test/storage/test_local.py                |     5 +
 libcloud/test/test_connection.py                   |    49 +
 libcloud/test/test_http.py                         |    36 +-
 libcloud/utils/connection.py                       |     7 +-
 libcloud/utils/misc.py                             |    20 +-
 libcloud/utils/retry.py                            |    42 +-
 requirements-rtd.txt                               |     2 +
 requirements-tests.txt                             |    29 +-
 .../{check_file_names.sh => dist_install_check.sh} |    32 +-
 ...k_file_names.sh => dist_wheel_install_check.sh} |    33 +-
 setup.py                                           |    16 +-
 tox.ini                                            |   175 +-
 89 files changed, 52550 insertions(+), 48664 deletions(-)
 create mode 100644 .github/workflows/install_test.yml
 create mode 100644 docs/examples/compute/openstack/auth_cache.py
 create mode 100644 libcloud/test/compute/fixtures/cloudsigma_2_0/keypairs_get.json
 create mode 100644 libcloud/test/compute/fixtures/cloudsigma_2_0/keypairs_import.json
 create mode 100644 libcloud/test/compute/fixtures/cloudsigma_2_0/keypairs_list.json
 create mode 100644 libcloud/test/compute/fixtures/cloudsigma_2_0/servers_get.json
 create mode 100644 libcloud/test/compute/fixtures/openstack/_v3__auth_unauthorized.json
 create mode 100644 libcloud/test/compute/fixtures/openstack_v1.1/_v3_0__volume_quota.json
 create mode 100644 libcloud/test/dns/fixtures/nsone/create_record_already_exists.json
 create mode 100644 libcloud/test/dns/fixtures/nsone/create_record_success.json
 create mode 100644 libcloud/test/dns/fixtures/nsone/create_record_zone_not_found.json
 create mode 100644 requirements-rtd.txt
 copy scripts/{check_file_names.sh => dist_install_check.sh} (59%)
 copy scripts/{check_file_names.sh => dist_wheel_install_check.sh} (57%)

[libcloud] 01/04: Update the function logic so we don't use open "while True" statement, also make retry-after a float so we can use lower value than 1 second in the tests to speed them up.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit bf147dc6418531074ec5ba1266af49af9aaf85fd
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Nov 3 22:05:47 2021 +0100

    Update the function logic so we don't use open "while True" statement,
    also make retry-after a float so we can use lower value than 1 second in
    the tests to speed them up.
---
 libcloud/common/exceptions.py |  2 +-
 libcloud/utils/retry.py       | 17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/libcloud/common/exceptions.py b/libcloud/common/exceptions.py
index e9f12b5..b27e6e9 100644
--- a/libcloud/common/exceptions.py
+++ b/libcloud/common/exceptions.py
@@ -56,7 +56,7 @@ class RateLimitReachedError(BaseHTTPError):
                                                     self.message,
                                                     headers)
         if self.headers is not None:
-            self.retry_after = int(self.headers.get('retry-after', 0))
+            self.retry_after = float(self.headers.get('retry-after', 0))
         else:
             self.retry_after = 0
 
diff --git a/libcloud/utils/retry.py b/libcloud/utils/retry.py
index c45db86..a112318 100644
--- a/libcloud/utils/retry.py
+++ b/libcloud/utils/retry.py
@@ -93,17 +93,15 @@ class MinimalRetry:
         def retry_loop(*args, **kwargs):
             current_delay = self.retry_delay
             end = datetime.now() + timedelta(seconds=self.timeout)
+            last_exc = None
 
-            while True:
+            while datetime.now() < end:
                 try:
                     return transform_ssl_error(func, *args, **kwargs)
                 except Exception as exc:
-                    if isinstance(exc, RateLimitReachedError):
-                        if datetime.now() >= end:
-                            # We have exhausted retry timeout so we abort
-                            # retrying
-                            raise
+                    last_exc = exc
 
+                    if isinstance(exc, RateLimitReachedError):
                         _logger.debug("You are being rate limited, backing off...")
 
                         # NOTE: Retry after defaults to 0 in the
@@ -117,13 +115,12 @@ class MinimalRetry:
                         # Reset retries if we're told to wait due to rate
                         # limiting
                         current_delay = self.retry_delay
-                    elif datetime.now() >= end:
-                        raise
                     elif self.should_retry(exc):
                         time.sleep(current_delay)
                         current_delay *= self.backoff
-                    else:
-                        raise
+
+            if last_exc and datetime.now() >= end:
+                raise last_exc
 
         return retry_loop
 

[libcloud] 03/04: Fix lint violations.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit bfda9fc09527b8b8adb2c0d33462da9eee8ef537
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Nov 3 22:20:05 2021 +0100

    Fix lint violations.
---
 libcloud/utils/misc.py  | 16 ++++++++--------
 libcloud/utils/retry.py | 26 +++++++++++++++++---------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/libcloud/utils/misc.py b/libcloud/utils/misc.py
index 747d55c..3932015 100644
--- a/libcloud/utils/misc.py
+++ b/libcloud/utils/misc.py
@@ -22,9 +22,12 @@ from libcloud.common.providers import get_driver as _get_driver
 from libcloud.common.providers import set_driver as _set_driver
 # Imported for backward compatibility
 # noinspection PyProtectedMember
-from libcloud.utils.retry import (Retry,
-                                  DEFAULT_DELAY, DEFAULT_TIMEOUT, DEFAULT_BACKOFF,
-                                  TRANSIENT_SSL_ERROR, TransientSSLError)
+from libcloud.utils.retry import Retry  # flake8: noqa
+from libcloud.utils.retry import DEFAULT_DELAY  # noqa: F401
+from libcloud.utils.retry import DEFAULT_TIMEOUT  # noqa: F401
+from libcloud.utils.retry import DEFAULT_BACKOFF  # noqa: F401
+from libcloud.utils.retry import TRANSIENT_SSL_ERROR  # noqa: F401
+from libcloud.utils.retry import TransientSSLError  # noqa: F401
 
 
 __all__ = [
@@ -51,8 +54,8 @@ def find(l, predicate):
 # been moved to "libcloud.common.providers" module
 get_driver = _get_driver
 set_driver = _set_driver
-# Note: This is an alias for backward-compatibility for a function which has been
-# moved to "libcloud.util.retry" module
+# Note: This is an alias for backward-compatibility for a function which has
+# been moved to "libcloud.util.retry" module
 retry = Retry
 
 
@@ -254,6 +257,3 @@ class ReprMixin(object):
 
     def __str__(self):
         return str(self.__repr__())
-
-
-
diff --git a/libcloud/utils/retry.py b/libcloud/utils/retry.py
index baa6c73..af77572 100644
--- a/libcloud/utils/retry.py
+++ b/libcloud/utils/retry.py
@@ -53,7 +53,9 @@ class MinimalRetry:
     def __init__(self, retry_delay=DEFAULT_DELAY,
                  timeout=DEFAULT_TIMEOUT, backoff=DEFAULT_BACKOFF):
         """
-        Wrapper around retrying that helps to handle common transient exceptions.
+        Wrapper around retrying that helps to handle common transient
+        exceptions.
+
         This minimalistic version only retries SSL errors and rate limiting.
 
         :param retry_delay: retry delay between the attempts.
@@ -102,7 +104,8 @@ class MinimalRetry:
                     last_exc = exc
 
                     if isinstance(exc, RateLimitReachedError):
-                        _logger.debug("You are being rate limited, backing off...")
+                        _logger.debug("You are being rate limited, backing "
+                                      "off...")
 
                         # NOTE: Retry after defaults to 0 in the
                         # RateLimitReachedError class so we a use more
@@ -130,11 +133,15 @@ class MinimalRetry:
 class Retry(MinimalRetry):
 
     def __init__(self, retry_exceptions=RETRY_EXCEPTIONS,
-                 retry_delay=DEFAULT_DELAY, timeout=DEFAULT_TIMEOUT, backoff=DEFAULT_BACKOFF):
+                 retry_delay=DEFAULT_DELAY, timeout=DEFAULT_TIMEOUT,
+                 backoff=DEFAULT_BACKOFF):
         """
-        Wrapper around retrying that helps to handle common transient exceptions.
-        This version retries the errors that `libcloud.utils.retry:MinimalRetry` retries
-        and all errors of the exception types that are given.
+        Wrapper around retrying that helps to handle common transient
+        exceptions.
+
+        This version retries the errors that
+        `libcloud.utils.retry:MinimalRetry` retries and all errors of the
+        exception types that are given.
 
         :param retry_exceptions: types of exceptions to retry on.
         :param retry_delay: retry delay between the attempts.
@@ -143,15 +150,16 @@ class Retry(MinimalRetry):
 
         :Example:
 
-        retry_request = Retry(retry_exceptions=(httplib.NotConnected,), timeout=1, retry_delay=1, backoff=1)
+        retry_request = Retry(retry_exceptions=(httplib.NotConnected,),
+                              timeout=1, retry_delay=1, backoff=1)
         retry_request(self.connection.request)()
         """
 
-        super().__init__(retry_delay=retry_delay, timeout=timeout, backoff=backoff)
+        super().__init__(retry_delay=retry_delay, timeout=timeout,
+                         backoff=backoff)
         if retry_exceptions is None:
             retry_exceptions = RETRY_EXCEPTIONS
         self.retry_exceptions = retry_exceptions
 
     def should_retry(self, exception):
         return type(exception) in self.retry_exceptions
-

[libcloud] 02/04: Add a test case for successful retry scenario where we successfuly retry on second attempt which we previously didn't have.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit 8940a66353ced059091bdc935291378f73711eaa
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Nov 3 22:10:02 2021 +0100

    Add a test case for successful retry scenario where we successfuly retry
    on second attempt which we previously didn't have.
---
 libcloud/test/test_connection.py | 27 +++++++++++++++++++++++++++
 libcloud/utils/retry.py          |  3 +--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libcloud/test/test_connection.py b/libcloud/test/test_connection.py
index 2848426..42ec975 100644
--- a/libcloud/test/test_connection.py
+++ b/libcloud/test/test_connection.py
@@ -470,6 +470,33 @@ class ConnectionClassTestCase(unittest.TestCase):
             self.assertEqual(mock_connect.call_count, 2,
                             'Retry logic failed')
 
+    def test_retry_rate_limit_error_success_on_second_attempt(self):
+        con = Connection()
+        con.connection = Mock()
+        connect_method = 'libcloud.common.base.Connection.request'
+
+        self.retry_counter = 0
+
+        def mock_connect_side_effect(*args, **kwargs):
+            self.retry_counter += 1
+
+            if self.retry_counter < 2:
+                headers = {'retry-after': 0.2}
+                raise RateLimitReachedError(headers=headers)
+
+            return 'success'
+
+        with patch(connect_method) as mock_connect:
+            mock_connect.__name__ = 'mock_connect'
+            mock_connect.side_effect = mock_connect_side_effect
+            retry_request = Retry(timeout=0.6, retry_delay=0.1,
+                                  backoff=1)
+            result = retry_request(con.request)(action='/')
+            self.assertEqual(result, "success")
+
+            self.assertEqual(mock_connect.call_count, 2,
+                            'Retry logic failed')
+
 
 class CertificateConnectionClassTestCase(unittest.TestCase):
     def setUp(self):
diff --git a/libcloud/utils/retry.py b/libcloud/utils/retry.py
index a112318..baa6c73 100644
--- a/libcloud/utils/retry.py
+++ b/libcloud/utils/retry.py
@@ -119,8 +119,7 @@ class MinimalRetry:
                         time.sleep(current_delay)
                         current_delay *= self.backoff
 
-            if last_exc and datetime.now() >= end:
-                raise last_exc
+            raise last_exc
 
         return retry_loop
 

[libcloud] 04/04: Merge branch 'trunk' into understand-ai-intelligent-retry

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit 5c590956d7223ff914579a714dc3d1312c1fae67
Merge: bfda9fc 583cbca
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Nov 3 22:21:09 2021 +0100

    Merge branch 'trunk' into understand-ai-intelligent-retry

 .github/actions/skip-duplicate-actions             |     2 +-
 .github/workflows/codeql-analysis.yml              |    25 +
 .github/workflows/install_test.yml                 |    42 +
 .github/workflows/integration-tests.yml            |     3 +-
 .github/workflows/main.yml                         |    23 +-
 .github/workflows/publish_pricing_to_s3.yml        |     3 +-
 CHANGES.rst                                        |   103 +
 MANIFEST.in                                        |     1 +
 contrib/scrape-ec2-prices.py                       |    15 +-
 docs/compute/_supported_methods_block_storage.rst  |     2 +-
 .../_supported_methods_key_pair_management.rst     |     2 +-
 docs/compute/_supported_methods_main.rst           |     2 +-
 docs/compute/drivers/openstack.rst                 |    23 +-
 .../compute/create_ibm_sce_windows_node.py         |     2 +-
 docs/examples/compute/gandi/create_node.py         |     2 +-
 docs/examples/compute/gridscale/create_node.py     |     2 +-
 docs/examples/compute/gridscale/deploy_node.py     |     2 +-
 docs/examples/compute/openstack/auth_cache.py      |    18 +
 docs/examples/compute/ovh/attach_volume.py         |     2 +-
 docs/examples/compute/ovh/create_node.py           |     2 +-
 docs/storage/_supported_methods_cdn.rst            |     2 +-
 docs/storage/_supported_methods_main.rst           |     2 +-
 docs/storage/_supported_providers.rst              |     2 +-
 docs/upgrade_notes.rst                             |    10 +
 integration/storage/base.py                        |    67 +-
 integration/storage/test_azure_blobs.py            |    37 +-
 integration/storage/test_minio.py                  |     2 +-
 libcloud/__init__.py                               |    10 +-
 libcloud/backup/drivers/gce.py                     |     2 +-
 libcloud/common/base.py                            |    14 +-
 libcloud/common/cloudsigma.py                      |   258 +-
 libcloud/common/gandi.py                           |     4 +-
 libcloud/common/google.py                          |    23 +-
 libcloud/common/openstack.py                       |    41 +-
 libcloud/common/openstack_identity.py              |   518 +-
 libcloud/compute/drivers/azure.py                  |     2 +-
 libcloud/compute/drivers/azure_arm.py              |     3 +-
 libcloud/compute/drivers/cloudsigma.py             |   315 +-
 libcloud/compute/drivers/ec2.py                    |    21 +-
 libcloud/compute/drivers/gandi.py                  |     2 +-
 libcloud/compute/drivers/gce.py                    |     8 +-
 libcloud/compute/drivers/openstack.py              |    88 +-
 libcloud/compute/drivers/softlayer.py              |     2 +-
 libcloud/compute/drivers/vcloud.py                 |     8 +-
 libcloud/container/drivers/gke.py                  |     2 +-
 libcloud/data/pricing.json                         | 98244 ++++++++++---------
 libcloud/dns/drivers/nsone.py                      |    21 +-
 libcloud/http.py                                   |    11 +-
 libcloud/storage/drivers/azure_blobs.py            |     1 +
 libcloud/storage/drivers/local.py                  |    11 +-
 libcloud/storage/drivers/minio.py                  |     2 +-
 libcloud/test/common/test_google.py                |    10 +
 libcloud/test/common/test_openstack_identity.py    |   188 +-
 .../fixtures/cloudsigma_2_0/drives_resize.json     |     2 +-
 .../fixtures/cloudsigma_2_0/keypairs_get.json      |    12 +
 .../fixtures/cloudsigma_2_0/keypairs_import.json   |    16 +
 .../fixtures/cloudsigma_2_0/keypairs_list.json     |    33 +
 .../compute/fixtures/cloudsigma_2_0/libdrives.json |     2 +-
 .../fixtures/cloudsigma_2_0/servers_clone.json     |     4 +-
 .../cloudsigma_2_0/servers_create_with_vlan.json   |     4 +-
 .../cloudsigma_2_0/servers_detail_mixed_state.json |     4 +-
 .../fixtures/cloudsigma_2_0/servers_get.json       |   108 +
 .../fixtures/openstack/_v3__auth_unauthorized.json |     1 +
 .../fixtures/openstack_v1.1/_flavors_detail.json   |     2 +-
 .../openstack_v1.1/_v3_0__volume_quota.json        |    55 +
 libcloud/test/compute/test_cloudsigma_v1_0.py      |     2 +-
 libcloud/test/compute/test_cloudsigma_v2_0.py      |    91 +-
 libcloud/test/compute/test_cloudwatt.py            |    11 +
 libcloud/test/compute/test_ec2.py                  |     6 +-
 libcloud/test/compute/test_openstack.py            |   105 +-
 libcloud/test/compute/test_rackspace.py            |     2 +-
 .../nsone/create_record_already_exists.json        |     3 +
 .../dns/fixtures/nsone/create_record_success.json  |    24 +
 .../nsone/create_record_zone_not_found.json        |     3 +
 libcloud/test/dns/test_base.py                     |     3 +-
 libcloud/test/dns/test_nsone.py                    |    66 +-
 libcloud/test/storage/test_local.py                |     5 +
 libcloud/test/test_connection.py                   |    22 +
 libcloud/test/test_http.py                         |    36 +-
 libcloud/utils/connection.py                       |     7 +-
 libcloud/utils/misc.py                             |     4 +-
 requirements-rtd.txt                               |     2 +
 requirements-tests.txt                             |    29 +-
 scripts/dist_install_check.sh                      |    40 +
 scripts/dist_wheel_install_check.sh                |    41 +
 setup.py                                           |    16 +-
 tox.ini                                            |   175 +-
 87 files changed, 52533 insertions(+), 48610 deletions(-)

diff --cc CHANGES.rst
index 1940e47,df16244..c2c8d6f
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@@ -7,19 -7,50 +7,63 @@@ Changes in Apache Libcloud 3.3.2 (in de
  Common
  ~~~~~~
  
+ - Fix how we set HTTP request timeout on the underlying requests session
+   object. requests library has changed how timeout is set so our old
+   code had no affect.
+ 
+   (GITHUB-1575, GITHUB-1576)
+   [Dimitris Galanis - @dimgal1]
+ 
+ - Update setup.py metadata and indicate we also support Python 3.10.
+ 
+ - [Google] Update Google authentication code so so we don't try to contact
+   GCE metadata server when determining auth credentials type when oAuth 2.0 /
+   installed app type of credentials are used.
+ 
+   (GITHUB-1591, GITHUB-1621)
+ 
+   Reported by Veith Röthlingshöfer - @RunOrVeith.
+ 
+ - [Google] Update Google authentication code so we don't try to retry failed
+   request when trying to determine if GCE metadata server is available when
+   retrying is enabled globally (either via module level constant or via
+   environment variable value).
+ 
+   This will speed up scenarios when trying is enabled globally, but GCE
+   metadata server is not available and different type of credentials are used
+   (e.g. oAuth 2).
+ 
+   (GITHUB-1591, GITHUB-1621)
+ 
+   Reported by Veith Röthlingshöfer - @RunOrVeith.
+ 
+ - Update minimum ``requests`` version we require as part for install_requires
+   in setup.py to ``2.26.0`` when using Python >= 3.6.
+ 
+   This was done to avoid licensing issue with transitive dependency
+   (``chardet``).
+ 
+   NOTE: requests ``>=2.25.1`` will be used when using Python 3.5 since 2.26.0
+   doesn't support Python 3.5 anymore.
+ 
+   For more context, see https://github.com/psf/requests/pull/5797.
+   (GITHUB-1594)
+ 
+   Reported by Jarek Potiuk - @potiuk.
+ 
 +- Update HTTP connection and request retry code to be more flexible so user
 +  can specify and utilize custom retry logic which can be configured via
 +  connection retryCls attribute
 +  (``driver.connection.retryCls = MyRetryClass``).
 +
 +  (GITHUB-1558)
 +  [Veith Röthlingshöfer - @RunOrVeith]
 +
 +- HTTP connection and request retry logic has been updated so we still respect
 +  ``timeout`` argument when retrying requests due to rate limit being reached
 +  errors. Previously, we would try to retry indefinitely on
 +  ``RateLimitReachedError`` exceptions.
 +
  Storage
  ~~~~~~~
  
diff --cc libcloud/utils/misc.py
index 3932015,8088c9c..17433d0
--- a/libcloud/utils/misc.py
+++ b/libcloud/utils/misc.py
@@@ -44,9 -42,29 +44,9 @@@ __all__ = 
      'ReprMixin'
  ]
  
 -# Error message which indicates a transient SSL error upon which request
 -# can be retried
 -TRANSIENT_SSL_ERROR = 'The read operation timed out'
 -
 -
 -class TransientSSLError(ssl.SSLError):
 -    """Represent transient SSL errors, e.g. timeouts"""
 -    pass
 -
 -
 -# Constants used by the ``retry`` decorator
 -DEFAULT_TIMEOUT = 30  # default retry timeout
 -DEFAULT_DELAY = 1  # default sleep delay used in each iterator
 -DEFAULT_BACKOFF = 1  # retry backup multiplier
 -RETRY_EXCEPTIONS = (RateLimitReachedError, socket.error, socket.gaierror,
 -                    httplib.NotConnected, httplib.ImproperConnectionState,
 -                    TransientSSLError)
 -
  
- def find(l, predicate):
-     results = [x for x in l if predicate(x)]
+ def find(value, predicate):
+     results = [x for x in value if predicate(x)]
      return results[0] if len(results) > 0 else None