Skip to content

Commit

Permalink
Add sleep() in Azure e2e to allow for deleteOperation propagation (#288)
Browse files Browse the repository at this point in the history
* Add sleep() in Azure e2e to allow for deleteOperation propagation

Signed-off-by: Theo Giovanna <[email protected]>

* Update Azure version in Azure's mocks

Signed-off-by: Theo Giovanna <[email protected]>

* Use LROPoller done() instead of sleep()

Signed-off-by: Theo Giovanna <[email protected]>

* Update pip in github action

Signed-off-by: Theo Giovanna <[email protected]>

* Install crypto package ahead of time

Signed-off-by: Theo Giovanna <[email protected]>
  • Loading branch information
giovannt0 authored Mar 31, 2021
1 parent c49875a commit dc580ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/install_test_setup_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Update PIP and install crypto package
run: python -m pip install -U pip && pip install cryptography
- name: Install wheel
run: pip install wheel
- name: Install dependencies through setup.py
Expand Down
6 changes: 5 additions & 1 deletion tests/providers/azure/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def testDiskCopyToOtherZone(self):
# permit same-name disks in different regions.
operation = self.az.compute.compute_client.disks.begin_delete(
disk_copy.resource_group_name, disk_copy.name)
operation.wait()
# Delete operation takes some time to propagate within Azure, which in
# some cases causes the next test to fail. Therefore we have to wait for
# completion.
while not operation.done():
sleep(5)

@typing.no_type_check
def testStartVm(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/providers/azure/internal/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def testCreateDiskFromSnapshotUri(self,
@mock.patch('libcloudforensics.providers.azure.internal.compute.AZCompute.GetInstance')
@mock.patch('libcloudforensics.providers.azure.internal.compute.AZCompute._GetInstanceType')
@mock.patch('libcloudforensics.providers.azure.internal.network.AZNetwork.CreateNetworkInterface')
@mock.patch('azure.mgmt.compute.v2020_06_01.operations._virtual_machines_operations.VirtualMachinesOperations.begin_create_or_update')
@mock.patch('azure.mgmt.compute.v2020_12_01.operations._virtual_machines_operations.VirtualMachinesOperations.begin_create_or_update')
@typing.no_type_check
def testGetOrCreateAnalysisVm(self,
mock_vm,
Expand Down Expand Up @@ -262,7 +262,7 @@ def testGetOrCreateAnalysisVm(self,
self.assertEqual('fake-analysis-vm-name', vm.name)
self.assertTrue(created)

@mock.patch('azure.mgmt.compute.v2020_06_01.operations._virtual_machine_sizes_operations.VirtualMachineSizesOperations.list')
@mock.patch('azure.mgmt.compute.v2020_12_01.operations._virtual_machine_sizes_operations.VirtualMachineSizesOperations.list')
@typing.no_type_check
def testListVMSizes(self, mock_list):
"""Test that instance types are correctly listed."""
Expand Down Expand Up @@ -292,7 +292,7 @@ class AZVirtualMachineTest(unittest.TestCase):
# pylint: disable=line-too-long

@mock.patch('libcloudforensics.providers.azure.internal.compute.AZCompute.ListDisks')
@mock.patch('azure.mgmt.compute.v2020_06_01.operations._virtual_machines_operations.VirtualMachinesOperations.get')
@mock.patch('azure.mgmt.compute.v2020_12_01.operations._virtual_machines_operations.VirtualMachinesOperations.get')
@typing.no_type_check
def testGetBootDisk(self, mock_get_vm, mock_list_disk):
"""Test that the boot disk from an instance is retrieved."""
Expand Down Expand Up @@ -321,7 +321,7 @@ def testGetDisk(self, mock_list_disk):
'Microsoft.Compute/type/fake-vm-name', str(error.exception))

@mock.patch('libcloudforensics.providers.azure.internal.compute.AZCompute.ListDisks')
@mock.patch('azure.mgmt.compute.v2020_06_01.operations._virtual_machines_operations.VirtualMachinesOperations.get')
@mock.patch('azure.mgmt.compute.v2020_12_01.operations._virtual_machines_operations.VirtualMachinesOperations.get')
@typing.no_type_check
def testListDisks(self, mock_get_vm, mock_list_disk):
"""Test that disks from an instance are correctly listed."""
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/azure/internal/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class AZStorageTest(unittest.TestCase):
"""Test Azure storage class."""
# pylint: disable=line-too-long

@mock.patch('azure.mgmt.storage.v2019_06_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
@mock.patch('azure.mgmt.storage.v2019_06_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
@mock.patch('azure.mgmt.storage.v2021_01_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
@mock.patch('azure.mgmt.storage.v2021_01_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
@typing.no_type_check
def testCreateStorageAccount(self, mock_create, mock_list_keys):
"""Test that a storage account is created and its information retrieved"""
Expand Down

0 comments on commit dc580ca

Please sign in to comment.