Limit number of tries to create alternate VHD blob names. Signed-off-by: Quentin Pradet <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ffce9f97 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ffce9f97 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ffce9f97 Branch: refs/heads/trunk Commit: ffce9f97946382c7eda10e5c3929f7cf01687c8e Parents: 152a5e0 Author: Peter Amstutz <[email protected]> Authored: Thu Oct 19 16:22:19 2017 -0400 Committer: Quentin Pradet <[email protected]> Committed: Mon Nov 6 19:01:13 2017 +0400 ---------------------------------------------------------------------- libcloud/compute/drivers/azure_arm.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/ffce9f97/libcloud/compute/drivers/azure_arm.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py index c59d9d7..fcc9ef3 100644 --- a/libcloud/compute/drivers/azure_arm.py +++ b/libcloud/compute/drivers/azure_arm.py @@ -2076,7 +2076,8 @@ class AzureNodeDriver(NodeDriver): def _get_instance_vhd(self, name, ex_resource_group, ex_storage_account, ex_blob_container="vhds"): n = 0 - while True: + errors = [] + while n < 10: try: instance_vhd = "https://%s.blob%s" \ "/%s/%s-os_%i.vhd" \ @@ -2086,11 +2087,15 @@ class AzureNodeDriver(NodeDriver): name, n) if self._ex_delete_old_vhd(ex_resource_group, instance_vhd): - # We were able to remove it or it doesn't exist. + # We were able to remove it or it doesn't exist, + # so we can use it. return instance_vhd - except LibcloudError: - pass + except LibcloudError as lce: + errors.append(str(lce)) n += 1 + raise LibcloudError("Unable to find a name for a VHD to use for " + "instance in 10 tries, errors were:\n - %s" % + ("\n - ".join(errors))) def _split_blob_uri(uri):
