Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
handle delayed AAD resources in deployments (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Feb 23, 2021
1 parent e2e44ac commit e7fe099
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
44 changes: 34 additions & 10 deletions src/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,40 @@ def deploy_template(self) -> None:
mode=DeploymentMode.incremental, template=template, parameters=params
)
)
result = client.deployments.create_or_update(
self.resource_group, gen_guid(), deployment
).result()
if result.properties.provisioning_state != "Succeeded":
logger.error(
"error deploying: %s",
json.dumps(result.as_dict(), indent=4, sort_keys=True),
)
sys.exit(1)
self.results["deploy"] = result.properties.outputs
count = 0
tries = 10
error: Optional[Exception] = None
while count < tries:
count += 1

try:
result = client.deployments.create_or_update(
self.resource_group, gen_guid(), deployment
).result()
if result.properties.provisioning_state != "Succeeded":
logger.error(
"error deploying: %s",
json.dumps(result.as_dict(), indent=4, sort_keys=True),
)
sys.exit(1)
self.results["deploy"] = result.properties.outputs
return
except Exception as err:
error = err
as_repr = repr(err)
# Modeled after Azure-CLI. See:
# https://github.com/Azure/azure-cli/blob/
# 3a2f6009cff788fde3b0170823c9129f187b2812/src/azure-cli-core/
# azure/cli/core/commands/arm.py#L1086
if (
"PrincipalNotFound" in as_repr
and "does not exist in the directory" in as_repr
):
logging.info("application principal not available in AAD yet")
if error:
raise error
else:
raise Exception("unknown error deploying")

def assign_scaleset_identity_role(self) -> None:
if self.upgrade:
Expand Down
10 changes: 9 additions & 1 deletion src/deployment/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,15 @@ def add_application_password(app_object_id: UUID) -> Tuple[str, str]:
return add_application_password_impl(app_object_id)
except GraphQueryError as err:
error = err
logging.warning("unable to create app password: %s", err.message)
# modeled after AZ-CLI's handling of missing application
# See: https://github.com/Azure/azure-cli/blob/
# e015d5bcba0c2d21dc42189daa43dc1eb82d2485/src/azure-cli/
# azure/cli/command_modules/util/tests/
# latest/test_rest.py#L191-L192
if "Request_ResourceNotFound" in repr(err):
logging.info("app unavailable in AAD, unable to create password yet")
else:
logging.warning("unable to create app password: %s", err.message)
time.sleep(wait_duration)
if error:
raise error
Expand Down

0 comments on commit e7fe099

Please sign in to comment.