Skip to content

Commit

Permalink
fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Azarh authored and Alex Azarh committed Nov 27, 2016
1 parent cc82a79 commit b35cf96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
Empty file removed package/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def prepare_connectivity(self,
:param cloudshell.cp.azure.models.azure_cloud_provider_resource_model.AzureCloudProviderResourceModel cloud_provider_model:cloud provider
:return:
"""
async_operations = [] # list of AzureOperationPoller
reservation_id = reservation.reservation_id
group_name = str(reservation_id)
subnet_name = group_name
Expand All @@ -78,8 +77,9 @@ def prepare_connectivity(self,

# 2+3. create storage account and keypairs (async)
pool = ThreadPool()
pool.apply_async(self._create_storage_and_keypairs,
(logger, storage_client, storage_account_name, group_name, cloud_provider_model, tags))
storage_res = pool.apply_async(self._create_storage_and_keypairs,
(logger, storage_client, storage_account_name, group_name, cloud_provider_model,
tags))

logger.info("Retrieving MGMT vNet from resource group {} by tag {}={}".format(
cloud_provider_model.management_group_name,
Expand Down Expand Up @@ -119,6 +119,7 @@ def prepare_connectivity(self,
tags=tags)

logger.info("Creating NSG management rules...")
# 5. Set rules on NSG ti create a sandbox
self._create_management_rules(
group_name=group_name,
management_vnet=management_vnet,
Expand All @@ -129,16 +130,7 @@ def prepare_connectivity(self,
cidr = self._extract_cidr(request)
logger.info("Received CIDR {0} from server".format(cidr))

# 5. Create a subnet
self._create_subnet(cidr=cidr,
cloud_provider_model=cloud_provider_model,
logger=logger,
network_client=network_client,
network_security_group=network_security_group,
sandbox_vnet=sandbox_vnet,
subnet_name=subnet_name)

# 6. Attach the NSG to the subnet
# 6. Create a subnet with NSG
self._create_subnet(cidr=cidr,
cloud_provider_model=cloud_provider_model,
logger=logger,
Expand All @@ -150,6 +142,7 @@ def prepare_connectivity(self,
# wait for all async operations
pool.close()
pool.join()
storage_res.get(timeout=900) # will wait for 15 min and raise exception if storage account creation failed

action_result.storage_name = storage_account_name
action_result.subnet_name = subnet_name
Expand All @@ -158,6 +151,7 @@ def prepare_connectivity(self,

def _create_storage_and_keypairs(self, logger, storage_client, storage_account_name, group_name,
cloud_provider_model, tags):

# 2. Create a storage account
logger.info("Creating a storage account {0} .".format(storage_account_name))
self.storage_service.create_storage_account(storage_client=storage_client,
Expand All @@ -172,6 +166,8 @@ def _create_storage_and_keypairs(self, logger, storage_client, storage_account_n
storage_account_name=storage_account_name,
storage_client=storage_client)

return True

def _wait_on_operations(self, async_operations, logger):
logger.info("Waiting for async create operations to be done... {}".format(async_operations))
for operation_poller in async_operations:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import uuid
from unittest import TestCase
import mock

import jsonpickle
import mock
from mock import MagicMock, Mock

from cloudshell.cp.azure.common.deploy_data_holder import DeployDataHolder
from cloudshell.cp.azure.common.exceptions.virtual_network_not_found_exception import VirtualNetworkNotFoundException
from cloudshell.cp.azure.domain.services.security_group import SecurityGroupService

from tests.helpers.test_helper import TestHelper

from cloudshell.cp.azure.domain.services.key_pair import KeyPairService

from cloudshell.cp.azure.domain.services.tags import TagService

from cloudshell.cp.azure.domain.services.network_service import NetworkService

from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService

from cloudshell.cp.azure.domain.services.security_group import SecurityGroupService
from cloudshell.cp.azure.domain.services.storage_service import StorageService

from cloudshell.cp.azure.domain.services.tags import TagService
from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService
from cloudshell.cp.azure.domain.vm_management.operations.prepare_connectivity_operation import \
PrepareConnectivityOperation
from mock import MagicMock, Mock
from tests.helpers.test_helper import TestHelper


class TestPrepareConnectivity(TestCase):
Expand Down Expand Up @@ -98,21 +89,18 @@ def test_prepare_connectivity(self, operation_helper_class):
network_client.network_security_groups.create_or_update.assert_called_once()

def test_extract_cidr_throws_error(self):
action = MagicMock()

self.assertRaises(ValueError,
self.prepare_connectivity_operation._extract_cidr,
action)

action = Mock()
att = Mock()
att.attributeName = 'Network'
att.attributeValue = ''
action.customActionAttributes = [att]

request = Mock()
request.actions = [action]

self.assertRaises(ValueError,
self.prepare_connectivity_operation._extract_cidr,
action)
request)

def test_prepare_connectivity_throes_exception_on_unavailable_VNETs(self):
# Arrange
Expand Down

0 comments on commit b35cf96

Please sign in to comment.