Skip to content

Commit

Permalink
containerapp containerapp job add tests (#6598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedygre authored Aug 7, 2023
1 parent 01d85ec commit 050fdd9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Upcoming
* 'az containerapp job start': update start execution payload format to exlude template property from API version 2023-05-01 onwards
* 'az containerapp service': add support for creation and deletion of MariaDB
* 'az containerapp create/list': support --environment-type parameter
* 'az containerapp logs show': fix raising error for response status code is not OK

0.3.36
++++++
Expand Down
1 change: 0 additions & 1 deletion src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def create(self, no_registry=False):
resource_group_name=self.resource_group.name,
image=self.image,
managed_env=self.env.get_rid(),
target_port=self.target_port,
registry_server=None if no_registry else self.registry_server,
registry_pass=None if no_registry else self.registry_pass,
registry_user=None if no_registry else self.registry_user,
Expand Down
14 changes: 7 additions & 7 deletions src/containerapp/azext_containerapp/containerapp_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def validate_arguments(self):
validate_create(self.get_argument_registry_identity(), self.get_argument_registry_pass(), self.get_argument_registry_user(), self.get_argument_registry_server(), self.get_argument_no_wait())
validate_revision_suffix(self.get_argument_revision_suffix())

def construct_containerapp(self):
def construct_payload(self):
if self.get_argument_registry_identity() and not is_registry_msi_system(self.get_argument_registry_identity()):
logger.info("Creating an acrpull role assignment for the registry identity")
create_acrpull_role_assignment(self.cmd, self.get_argument_registry_server(), self.get_argument_registry_identity(), skip_error=True)
Expand Down Expand Up @@ -545,7 +545,7 @@ def construct_containerapp(self):
else:
set_managed_identity(self.cmd, self.get_argument_resource_group_name(), self.containerapp_def, user_assigned=[self.get_argument_registry_identity()])

def create_containerapp(self):
def create(self):
try:
r = self.client.create_or_update(
cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name(), container_app_envelope=self.containerapp_def,
Expand All @@ -555,7 +555,7 @@ def create_containerapp(self):
except Exception as e:
handle_raw_exception(e)

def construct_containerapp_for_post_process(self, r):
def construct_for_post_process(self, r):
if is_registry_msi_system(self.get_argument_registry_identity()):
while r["properties"]["provisioningState"] == "InProgress":
r = self.client.show(self.cmd, self.get_argument_resource_group_name(), self.get_argument_name())
Expand All @@ -573,9 +573,9 @@ def construct_containerapp_for_post_process(self, r):
registries_def["identity"] = self.get_argument_registry_identity()
safe_set(self.containerapp_def, "properties", "configuration", "registries", value=[registries_def])

def post_process_containerapp(self, r):
def post_process(self, r):
if is_registry_msi_system(self.get_argument_registry_identity()):
r = self.create_containerapp()
r = self.create()

if "properties" in r and "provisioningState" in r["properties"] and r["properties"]["provisioningState"].lower() == "waiting" and not self.get_argument_no_wait():
not self.get_argument_disable_warnings() and logger.warning('Containerapp creation in progress. Please monitor the creation using `az containerapp show -n {} -g {}`'.format(self.get_argument_name(), self.get_argument_resource_group_name()))
Expand Down Expand Up @@ -734,8 +734,8 @@ def __init__(
):
super().__init__(cmd, client, raw_parameters, models)

def construct_containerapp(self):
super().construct_containerapp()
def construct_payload(self):
super().construct_payload()
self.set_up_extended_location()

def set_up_extended_location(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def post_process(self, r):
if "properties" in r and "provisioningState" in r["properties"] and r["properties"]["provisioningState"].lower() == "waiting" and not self.get_argument_no_wait():
not self.get_argument_disable_warnings() and logger.warning('Containerapp job creation in progress. Please monitor the creation using `az containerapp job show -n {} -g {}`'.format(self.get_argument_name, self.get_argument_resource_group_name()))

return r

def construct_payload(self):
if self.get_argument_registry_identity() and not is_registry_msi_system(self.get_argument_registry_identity()):
logger.info("Creating an acrpull role assignment for the registry identity")
Expand Down
10 changes: 5 additions & 5 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ def create_containerapp(cmd,
containerapp_create_decorator.register_provider(CONTAINER_APPS_RP)
containerapp_create_decorator.validate_arguments()

containerapp_create_decorator.construct_containerapp()
r = containerapp_create_decorator.create_containerapp()
containerapp_create_decorator.construct_containerapp_for_post_process(r)
r = containerapp_create_decorator.post_process_containerapp(r)
containerapp_create_decorator.construct_payload()
r = containerapp_create_decorator.create()
containerapp_create_decorator.construct_for_post_process(r)
r = containerapp_create_decorator.post_process(r)
return r


Expand Down Expand Up @@ -3804,7 +3804,7 @@ def stream_containerapp_logs(cmd, resource_group_name, name, container=None, rev
headers=headers)

if not resp.ok:
ValidationError(f"Got bad status from the logstream API: {resp.status_code}")
raise ValidationError(f"Got bad status from the logstream API: {resp.status_code}")

for line in resp.iter_lines():
if line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def test_containerapp_manualjob_crudoperations_e2e(self, resource_group):
self.assertTrue(len(jobs_list) == 1)

# update the Container App Job resource
self.cmd("az containerapp job update --resource-group {} --name {} --replica-timeout 300 --replica-retry-limit 1 --image mcr.microsoft.com/k8se/quickstart-jobs:latest --cpu '0.5' --memory '1.0Gi'".format(resource_group, job))
self.cmd("az containerapp job update --resource-group {} --name {} --replica-timeout 300 --replica-retry-limit 1 --image mcr.microsoft.com/k8se/quickstart-jobs:latest --cpu '0.5' --memory '1.0Gi'".format(resource_group, job), checks=[
JMESPathCheck('name', job),
JMESPathCheck('properties.configuration.replicaTimeout', 300),
JMESPathCheck('properties.configuration.replicaRetryLimit', 1),
JMESPathCheck('properties.configuration.triggerType', "manual", case_sensitive=False),
JMESPathCheck('properties.template.containers[0].image', "mcr.microsoft.com/k8se/quickstart-jobs:latest"),
JMESPathCheck('properties.template.containers[0].resources.cpu', "0.5"),
JMESPathCheck('properties.template.containers[0].resources.memory', "1Gi"),
])

# verify the updated Container App Job resource
self.cmd("az containerapp job show --resource-group {} --name {}".format(resource_group, job), checks=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,23 @@ def test_containerappjob_create_with_yaml(self, resource_group):
containerappjob_file_name = f"{self._testMethodName}_containerappjob.yml"

write_test_file(containerappjob_file_name, containerappjob_yaml_text)
self.cmd(f'containerapp job create -n {job} -g {resource_group} --environment {env} --yaml {containerappjob_file_name}')
self.cmd(f'containerapp job create -n {job} -g {resource_group} --environment {env} --yaml {containerappjob_file_name}', checks=[
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.configuration.triggerType", "Manual", case_sensitive=False),
JMESPathCheck('properties.configuration.replicaTimeout', 100),
JMESPathCheck('properties.configuration.replicaRetryLimit', 1),
JMESPathCheck('properties.template.containers[0].image', "mcr.microsoft.com/k8se/quickstart-jobs:latest"),
JMESPathCheck('properties.template.containers[0].resources.cpu', "0.5"),
JMESPathCheck('properties.template.containers[0].resources.memory', "1Gi"),
JMESPathCheck('identity.type', "UserAssigned"),
JMESPathCheck('properties.template.volumes[0].storageType', 'AzureFile'),
JMESPathCheck('properties.template.volumes[0].storageName', share),
JMESPathCheck('properties.template.volumes[0].name', 'azure-files-volume'),
JMESPathCheck('properties.template.volumes[0].mountOptions', 'uid=999,gid=999'),
JMESPathCheck('properties.template.containers[0].volumeMounts[0].subPath', 'sub'),
JMESPathCheck('properties.template.containers[0].volumeMounts[0].mountPath', '/mnt/data'),
JMESPathCheck('properties.template.containers[0].volumeMounts[0].volumeName', 'azure-files-volume')
])

self.cmd(f'containerapp job show -g {resource_group} -n {job}', checks=[
JMESPathCheck("properties.provisioningState", "Succeeded"),
Expand Down

0 comments on commit 050fdd9

Please sign in to comment.