# Path: dcos_launch/util.py
# class DeploymentError(Exception):
#     pass


import contextlib
import copy
import logging
import re
import requests
import retrying
from azure.common.credentials import ServicePrincipalCredentials
from azure.common.exceptions import CloudError
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource.resources.v2016_02_01 import ResourceManagementClient
from azure.mgmt.resource.resources.v2016_02_01.models import (DeploymentMode,
                                                              DeploymentProperties,
                                                              ResourceGroup)
from azure.monitor import MonitorClient
from dcos_launch.util import DeploymentError
from dcos_test_utils.helpers import Host
        Azure will not register a template instantly after deployment, so
        CloudError must be expected as retried. Once the ops are retrieved, this
        loops through all operations in the group's only deployment
        if any operations are still in progress, then this function will sleep
        once all operations are complete, if there any failures, those will be
        printed to the log stream
        """
        log.info('Waiting for deployment to finish')

        def azure_failure_report():
            deploy_ops = self.azure_wrapper.rmc.deployment_operations.list(
                    self.group_name, DEPLOYMENT_NAME.format(self.group_name))
            failures = [(op.properties.status_code, op.properties.status_message) for op
                        in deploy_ops if op.properties.provisioning_state == 'Failed']
            for failure in failures:
                log.error('Deployment operation failed! {}: {}'.format(*failure))

        @retrying.retry(
            wait_fixed=60 * 1000, stop_max_delay=timeout * 1000,
            retry_on_result=lambda res: res is False,
            retry_on_exception=lambda ex: isinstance(ex, CloudError))
        def check_deployment_operations():
            deploy_state = self.get_deployment_state()

            if deploy_state == 'Succeeded':
                return True

            elif deploy_state == 'Failed':
                log.info('Deployment failed. Checking deployment operations.')
                azure_failure_report()

# Path: dcos_launch/util.py
# class DeploymentError(Exception):
#     pass


# Path: dcos_launch/platforms/arm.py
import contextlib
import copy
import logging
import re
import requests
import retrying
from azure.common.credentials import ServicePrincipalCredentials
from azure.common.exceptions import CloudError
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource.resources.v2016_02_01 import ResourceManagementClient
from azure.mgmt.resource.resources.v2016_02_01.models import (DeploymentMode,
                                                              DeploymentProperties,
                                                              ResourceGroup)
from azure.monitor import MonitorClient
from dcos_launch.util import DeploymentError
from dcos_test_utils.helpers import Host

        Azure will not register a template instantly after deployment, so
        CloudError must be expected as retried. Once the ops are retrieved, this
        loops through all operations in the group's only deployment
        if any operations are still in progress, then this function will sleep
        once all operations are complete, if there any failures, those will be
        printed to the log stream
        """
        log.info('Waiting for deployment to finish')

        def azure_failure_report():
            deploy_ops = self.azure_wrapper.rmc.deployment_operations.list(
                    self.group_name, DEPLOYMENT_NAME.format(self.group_name))
            failures = [(op.properties.status_code, op.properties.status_message) for op
                        in deploy_ops if op.properties.provisioning_state == 'Failed']
            for failure in failures:
                log.error('Deployment operation failed! {}: {}'.format(*failure))

        @retrying.retry(
            wait_fixed=60 * 1000, stop_max_delay=timeout * 1000,
            retry_on_result=lambda res: res is False,
            retry_on_exception=lambda ex: isinstance(ex, CloudError))
        def check_deployment_operations():
            deploy_state = self.get_deployment_state()

            if deploy_state == 'Succeeded':
                return True

            elif deploy_state == 'Failed':
                log.info('Deployment failed. Checking deployment operations.')
                azure_failure_report()

                raise DeploymentError('Azure Deployment Failed!')