handle delayed AAD resources in deployments (#585)

This commit is contained in:
bmc-msft
2021-02-22 19:40:07 -05:00
committed by GitHub
parent e2e44ace8a
commit e7fe099f25
2 changed files with 43 additions and 11 deletions

View File

@ -384,6 +384,13 @@ class Client:
mode=DeploymentMode.incremental, template=template, parameters=params mode=DeploymentMode.incremental, template=template, parameters=params
) )
) )
count = 0
tries = 10
error: Optional[Exception] = None
while count < tries:
count += 1
try:
result = client.deployments.create_or_update( result = client.deployments.create_or_update(
self.resource_group, gen_guid(), deployment self.resource_group, gen_guid(), deployment
).result() ).result()
@ -394,6 +401,23 @@ class Client:
) )
sys.exit(1) sys.exit(1)
self.results["deploy"] = result.properties.outputs 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: def assign_scaleset_identity_role(self) -> None:
if self.upgrade: if self.upgrade:

View File

@ -235,6 +235,14 @@ def add_application_password(app_object_id: UUID) -> Tuple[str, str]:
return add_application_password_impl(app_object_id) return add_application_password_impl(app_object_id)
except GraphQueryError as err: except GraphQueryError as err:
error = err error = err
# 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) logging.warning("unable to create app password: %s", err.message)
time.sleep(wait_duration) time.sleep(wait_duration)
if error: if error: