Added test for _get_instance_vhd() retries. 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/b50f0b33 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b50f0b33 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b50f0b33 Branch: refs/heads/trunk Commit: b50f0b33e1de12ccdb961d59ec82c7dbfcb4ea6a Parents: ffce9f9 Author: Lucas Di Pentima <[email protected]> Authored: Tue Oct 31 12:36:06 2017 -0300 Committer: Quentin Pradet <[email protected]> Committed: Mon Nov 6 19:01:13 2017 +0400 ---------------------------------------------------------------------- libcloud/test/compute/test_azure_arm.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/b50f0b33/libcloud/test/compute/test_azure_arm.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_azure_arm.py b/libcloud/test/compute/test_azure_arm.py index 3367125..a32917d 100644 --- a/libcloud/test/compute/test_azure_arm.py +++ b/libcloud/test/compute/test_azure_arm.py @@ -21,6 +21,7 @@ from datetime import datetime import mock from libcloud.common.exceptions import BaseHTTPError +from libcloud.common.types import LibcloudError from libcloud.compute.base import (NodeLocation, NodeSize, VolumeSnapshot, StorageVolume) from libcloud.compute.drivers.azure_arm import AzureImage, NodeAuthPassword @@ -491,6 +492,21 @@ class AzureNodeDriverTests(LibcloudTestCase): ex_storage_account='sga1') self.assertEqual(vhd_url, 'https://sga1.blob.core.chinacloudapi.cn/vhds/test1-os_0.vhd') + def test_get_instance_vhd__retries_ten_times(self): + with mock.patch.object(self.driver, '_ex_delete_old_vhd') as m: + # 10 retries are OK + m.side_effect = [False] * 9 + [True] + vhd_url = self.driver._get_instance_vhd(name='test1', + ex_resource_group='000000', + ex_storage_account='sga1') + self.assertEqual(vhd_url, 'https://sga1.blob.core.windows.net/vhds/test1-os_9.vhd') + # Fail on the 11th + m.side_effect = [False] * 10 + [True] + with self.assertRaises(LibcloudError): + self.driver._get_instance_vhd(name='test1', + ex_resource_group='000000', + ex_storage_account='sga1') + class AzureMockHttp(MockHttp): fixtures = ComputeFileFixtures('azure_arm')
