Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FileShare commands. #84

Merged
merged 9 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests.
  • Loading branch information
Haroon Feisal committed May 3, 2022
commit 02eec4d2740ee842a4068119f5cc7d3283181d0a
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@
"accountKey": None,
"accessMode": None,
"shareName": None
}
}
10 changes: 7 additions & 3 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
RegistryInfo as RegistryInfoModel,
AzureCredentials as AzureCredentialsModel,
SourceControl as SourceControlModel,
ManagedServiceIdentity as ManagedServiceIdentityModel)
ManagedServiceIdentity as ManagedServiceIdentityModel,
AzureFileProperties as AzureFilePropertiesModel)
from ._utils import (_validate_subscription_registered, _get_location_from_resource_group, _ensure_location_allowed,
parse_secret_flags, store_as_secret_and_return_secret_ref, parse_env_var_flags,
_generate_log_analytics_if_not_provided, _get_existing_secrets, _convert_object_from_snake_to_camel_case,
Expand Down Expand Up @@ -2211,6 +2212,7 @@ def show_storage(cmd, name, storage_name, resource_group_name):
except CLIError as e:
handle_raw_exception(e)


def list_storage(cmd, name, resource_group_name):
_validate_subscription_registered(cmd, "Microsoft.App")

Expand All @@ -2219,9 +2221,10 @@ def list_storage(cmd, name, resource_group_name):
except CLIError as e:
handle_raw_exception(e)

def create_or_update_storage(cmd, storage_name, resource_group_name, name, account_name, share_name, account_key, access_mode, type="AzureFile", no_wait=False):

def create_or_update_storage(cmd, storage_name, resource_group_name, name, account_name, share_name, account_key, access_mode, type="AzureFile", no_wait=False): # pylint: disable=redefined-builtin
_validate_subscription_registered(cmd, "Microsoft.App")
from ._models import AzureFileProperties as AzureFilePropertiesModel

if type.lower() != "azurefile":
raise ValidationError("Only AzureFile type is supported at this time.")

Expand All @@ -2240,6 +2243,7 @@ def create_or_update_storage(cmd, storage_name, resource_group_name, name, accou
except CLIError as e:
handle_raw_exception(e)


def remove_storage(cmd, storage_name, name, resource_group_name, no_wait=False):
_validate_subscription_registered(cmd, "Microsoft.App")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,44 @@ def test_containerapp_identity_user(self, resource_group):
self.cmd('containerapp identity show -g {} -n {}'.format(resource_group, ca_name), checks=[
JMESPathCheck('type', 'None'),
])


@live_only()
class ContainerappEnvStorageTests(ScenarioTest):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_env_storage(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
storage_name = self.create_random_name(prefix='storage', length=24)
shares_name = self.create_random_name(prefix='share', length=24)

self.cmd('containerapp env create -g {} -n {}'.format(resource_group, env_name))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

while containerapp_env["properties"]["provisioningState"].lower() == "waiting":
time.sleep(5)
containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

self.cmd('storage account create -g {} -n {} --kind StorageV2 --sku Standard_ZRS --enable-large-file-share'.format(resource_group, storage_name))
self.cmd('storage share-rm create -g {} -n {} --storage-account {} --access-tier "TransactionOptimized" --quota 1024'.format(resource_group, shares_name, storage_name))

storage_keys = self.cmd('az storage account keys list -g {} -n {}'.format(resource_group, storage_name)).get_output_in_json()[0]

self.cmd('containerapp env storage set -g {} -n {} --storage-name {} --account-name {} --account-key {} --access-mode ReadOnly --share-name {}'.format(resource_group, env_name, storage_name, storage_name, storage_keys["value"], shares_name), checks=[
JMESPathCheck('name', storage_name),
])

self.cmd('containerapp env storage show -g {} -n {} --storage-name {}'.format(resource_group, env_name, storage_name), checks=[
JMESPathCheck('name', storage_name),
])

self.cmd('containerapp env storage list -g {} -n {}'.format(resource_group, env_name), checks=[
JMESPathCheck('[0].name', storage_name),
])

self.cmd('containerapp env storage remove -g {} -n {} --storage-name {} --yes'.format(resource_group, env_name, storage_name))

self.cmd('containerapp env storage list -g {} -n {}'.format(resource_group, env_name), checks=[
JMESPathCheck('length(@)', 0),
])