Skip to content

Commit b8ce15f

Browse files
authored
[hpc-cache] Bug fix, code refactoring and perfect test cases (Azure#2144)
* refactor HPC cache * modify the definition style of arguments
1 parent 8acc80f commit b8ce15f

File tree

10 files changed

+4835
-2424
lines changed

10 files changed

+4835
-2424
lines changed

src/hpc-cache/HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Release History
44
===============
55

6+
0.1.2
7+
++++++
8+
* Fix #13003: The command `az hpc-cache update` is modified to update only tags.
9+
* Fix #1997: Fix the bug when executing command `az hpc-cache nfs-storage-target update` without passing the parameter `--junction`.
10+
* Fix #14060: Improve the help description of parameter `--junction`.
11+
* The parameter `storage_account` supports passing in the name of storage account.
12+
613
0.1.1
714
++++++
815
* Remove line breaks from examples.

src/hpc-cache/README.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/hpc-cache/azext_hpc_cache/_help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050

5151
helps['hpc-cache update'] = """
5252
type: command
53-
short-summary: Create or update a Cache.
53+
short-summary: Update a Cache.
5454
examples:
5555
- name: Caches_Update
56-
text: az hpc-cache update --resource-group "scgroup" --name "sc1" --location "eastus" --cache-size-gb "3072" --subnet "/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Network/virtualNetworks/{virtual_network_name}/subnets/{subnet_name}" --sku-name "Standard_2G"
56+
text: az hpc-cache update --resource-group "scgroup" --name "sc1" --tags "key=val"
5757
"""
5858

5959
helps['hpc-cache delete'] = """

src/hpc-cache/azext_hpc_cache/_params.py

Lines changed: 46 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,123 +11,95 @@
1111
resource_group_name_type,
1212
get_location_type
1313
)
14-
from ._validators import process_container_resource, transfer_cache_name
14+
from ._validators import process_container_resource, JunctionAddAction, validate_storage_account_name_or_id
15+
from knack.arguments import CLIArgumentType
1516

17+
junction_type = CLIArgumentType(options_list=['--junction'],
18+
help='List of Cache namespace junctions to target for namespace associations.'
19+
'The sub parameters contains: '
20+
'(1) --namespace-path: Namespace path on a Cache for a Storage Target '
21+
'(2) --nfs-export: NFS export where targetPath exists '
22+
'(3) --target-path(Optional): Path in Storage Target to '
23+
'which namespacePath points',
24+
action=JunctionAddAction, nargs='+')
1625

17-
def load_arguments(self, _):
26+
storage_account_type = CLIArgumentType(options_list=['--storage-account'],
27+
help='Resource ID or Name of target storage account.',
28+
validator=validate_storage_account_name_or_id)
29+
30+
cache_name_type = CLIArgumentType(help='Name of Cache.')
31+
32+
storage_target_type = CLIArgumentType(help='Name of the Storage Target.')
1833

19-
with self.argument_context('hpc-cache skus list') as c:
20-
pass
2134

22-
with self.argument_context('hpc-cache usage-model list') as c:
23-
pass
35+
def load_arguments(self, _):
2436

2537
with self.argument_context('hpc-cache create') as c:
26-
c.argument('resource_group_name', resource_group_name_type)
27-
c.argument('name', help='Name of Cache.', required=True)
38+
c.argument('name', cache_name_type, required=True)
2839
c.argument('tags', tags_type)
2940
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=True)
3041
c.argument('cache_size_gb', help='The size of this Cache, in GB.', required=True)
3142
c.argument('subnet', help='Subnet used for the Cache.', required=True)
3243
c.argument('sku_name', help='SKU name for this Cache.', required=True)
3344

3445
with self.argument_context('hpc-cache update') as c:
35-
c.argument('resource_group_name', resource_group_name_type)
36-
c.argument('name', help='Name of Cache.')
46+
c.argument('name', cache_name_type)
3747
c.argument('tags', tags_type)
38-
c.argument('location', arg_type=get_location_type(self.cli_ctx))
39-
c.argument('cache_size_gb', help='The size of this Cache, in GB.')
40-
c.argument('subnet', help='Subnet used for the Cache.')
41-
c.argument('sku_name', help='SKU name for this Cache.')
42-
43-
with self.argument_context('hpc-cache delete') as c:
44-
c.argument('resource_group_name', resource_group_name_type)
45-
c.argument('name', help='Name of Cache.')
48+
c.argument('location', arg_type=get_location_type(self.cli_ctx), deprecate_info=c.deprecate(hide=True))
49+
c.argument('cache_size_gb', help='The size of this Cache, in GB.', deprecate_info=c.deprecate(hide=True))
50+
c.argument('subnet', help='Subnet used for the Cache.', deprecate_info=c.deprecate(hide=True))
51+
c.argument('sku_name', help='SKU name for this Cache.', deprecate_info=c.deprecate(hide=True))
4652

47-
with self.argument_context('hpc-cache show') as c:
48-
c.argument('resource_group_name', resource_group_name_type)
49-
c.argument('name', help='Name of Cache.')
53+
for item in ['delete', 'show', 'flush', 'start', 'stop', 'upgrade-firmware']:
54+
with self.argument_context('hpc-cache {}'.format(item)) as c:
55+
c.argument('name', cache_name_type)
5056

5157
with self.argument_context('hpc-cache wait') as c:
52-
c.argument('resource_group_name', resource_group_name_type)
53-
c.extra('name', help='Name of Cache.', validator=transfer_cache_name, required=True)
54-
c.ignore('cache_name')
55-
56-
with self.argument_context('hpc-cache list') as c:
57-
c.argument('resource_group_name', resource_group_name_type, required=False)
58-
59-
with self.argument_context('hpc-cache flush') as c:
60-
c.argument('resource_group_name', resource_group_name_type)
61-
c.argument('name', help='Name of Cache.')
62-
63-
with self.argument_context('hpc-cache start') as c:
64-
c.argument('resource_group_name', resource_group_name_type)
65-
c.argument('name', help='Name of Cache.')
66-
67-
with self.argument_context('hpc-cache stop') as c:
68-
c.argument('resource_group_name', resource_group_name_type)
69-
c.argument('name', help='Name of Cache.')
70-
71-
with self.argument_context('hpc-cache upgrade-firmware') as c:
72-
c.argument('resource_group_name', resource_group_name_type)
73-
c.argument('name', help='Name of Cache.')
58+
c.argument('cache_name', cache_name_type, options_list=['--name', '-n'], required=True)
7459

7560
with self.argument_context('hpc-cache blob-storage-target add') as c:
76-
c.argument('resource_group_name', resource_group_name_type)
77-
c.argument('cache_name', help='Name of Cache.')
78-
c.argument('name', help='Name of the Storage Target.')
61+
c.argument('cache_name', cache_name_type)
62+
c.argument('name', storage_target_type)
7963
c.argument('virtual_namespace_path', options_list=['--virtual-namespace-path', '-v'], required=True,
8064
help='Path to create for this storage target in the client-facing virtual filesystem.')
81-
c.extra('storage_account', options_list=['--storage-account'], help='Resource ID of target storage account.',
82-
required=True)
65+
c.extra('storage_account', storage_account_type, required=True)
8366
c.extra('container_name', options_list=['--container-name'], validator=process_container_resource,
8467
required=True, help='Name of target storage container.')
8568
c.ignore('clfs_target')
8669

8770
with self.argument_context('hpc-cache blob-storage-target update') as c:
88-
c.argument('resource_group_name', resource_group_name_type)
89-
c.argument('cache_name', help='Name of Cache.')
90-
c.argument('name', help='Name of the Storage Target.')
71+
c.argument('cache_name', cache_name_type)
72+
c.argument('name', storage_target_type)
9173
c.argument('virtual_namespace_path', options_list=['--virtual-namespace-path', '-v'],
9274
help='Path to create for this storage target in the client-facing virtual filesystem.')
93-
c.extra('storage_account', options_list=['--storage-account'],
94-
help='Resource ID of target storage account.')
75+
c.extra('storage_account', storage_account_type)
9576
c.extra('container_name', options_list=['--container-name'], validator=process_container_resource,
9677
help='Name of target storage container.')
9778
c.ignore('clfs_target')
9879

9980
with self.argument_context('hpc-cache storage-target remove') as c:
100-
c.argument('resource_group_name', resource_group_name_type)
101-
c.argument('cache_name', help='Name of Cache.')
102-
c.argument('name', help='Name of the Storage Target.')
81+
c.argument('cache_name', cache_name_type)
82+
c.argument('name', storage_target_type)
10383

10484
with self.argument_context('hpc-cache storage-target show') as c:
105-
c.argument('resource_group_name', resource_group_name_type)
106-
c.argument('cache_name', help='Name of Cache.')
107-
c.argument('name', help='Name of the Storage Target.')
85+
c.argument('cache_name', cache_name_type)
86+
c.argument('name', storage_target_type)
10887

10988
with self.argument_context('hpc-cache storage-target list') as c:
110-
c.argument('resource_group_name', resource_group_name_type)
111-
c.argument('cache_name', help='Name of Cache.')
89+
c.argument('cache_name', cache_name_type)
11290

11391
with self.argument_context('hpc-cache nfs-storage-target add') as c:
114-
c.argument('resource_group_name', resource_group_name_type)
115-
c.argument('cache_name', help='Name of Cache.')
116-
c.argument('name', help='Name of the Storage Target.')
117-
from ._validators import JunctionAddAction
118-
c.extra('junction', help='List of Cache namespace junctions to target for namespace associations.',
119-
action=JunctionAddAction, nargs='+', required=True)
92+
c.argument('cache_name', cache_name_type)
93+
c.argument('name', storage_target_type)
94+
95+
c.argument('junctions', junction_type, required=True)
12096
c.argument('nfs3_target', help='IP address or host name of an NFSv3 host (e.g., 10.0.44.44).', required=True)
12197
c.argument('nfs3_usage_model', help='Identifies the primary usage model to be used for this Storage Target.',
12298
required=True)
123-
c.ignore('junctions')
12499

125100
with self.argument_context('hpc-cache nfs-storage-target update') as c:
126-
c.argument('resource_group_name', resource_group_name_type)
127-
c.argument('cache_name', help='Name of Cache.')
128-
c.argument('name', help='Name of the Storage Target.')
129-
from ._validators import JunctionAddAction
130-
c.extra('junction', help='List of Cache namespace junctions to target for namespace associations.', action=JunctionAddAction, nargs='+')
101+
c.argument('cache_name', cache_name_type)
102+
c.argument('name', storage_target_type)
103+
c.argument('junctions', junction_type)
131104
c.argument('nfs3_target', help='IP address or host name of an NFSv3 host (e.g., 10.0.44.44).')
132105
c.argument('nfs3_usage_model', help='Identifies the primary usage model to be used for this Storage Target.')
133-
c.ignore('junctions')

src/hpc-cache/azext_hpc_cache/_validators.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
import argparse
66
from knack.util import CLIError
77

8-
# pylint: disable=unused-argument
9-
10-
11-
def transfer_cache_name(cmd, namespace):
12-
namespace.cache_name = namespace.name
13-
del namespace.name
14-
158

169
def process_container_resource(cmd, namespace):
1710
"""Processes the resource group parameter from the storage account and container name"""
1811
if not namespace.storage_account or not namespace.container_name:
1912
raise ValueError('usage error: Please specify --storage-account and --container-name for blob-storage-target')
20-
from msrestazure.tools import is_valid_resource_id
13+
from azure.mgmt.core.tools import is_valid_resource_id
2114
if not is_valid_resource_id(namespace.storage_account):
2215
raise ValueError('usage error: {} is not a valid resource id'.format(namespace.storage_account))
2316
namespace.clfs_target = '{}/blobServices/default/containers/{}'.format(
@@ -31,7 +24,6 @@ def process_container_resource(cmd, namespace):
3124
class JunctionAddAction(argparse._AppendAction):
3225
def __call__(self, parser, namespace, values, option_string=None):
3326
if not namespace.junctions:
34-
del namespace.junction
3527
namespace.junctions = []
3628
kwargs = {}
3729
for item in values:
@@ -48,3 +40,17 @@ def __call__(self, parser, namespace, values, option_string=None):
4840
if 'target-path' in kwargs:
4941
junction['targetPath'] = kwargs['target-path']
5042
namespace.junctions.append(junction)
43+
44+
45+
def validate_storage_account_name_or_id(cmd, namespace):
46+
if namespace.storage_account:
47+
from azure.mgmt.core.tools import resource_id, is_valid_resource_id
48+
from azure.cli.core.commands.client_factory import get_subscription_id
49+
if not is_valid_resource_id(namespace.storage_account):
50+
namespace.storage_account = resource_id(
51+
subscription=get_subscription_id(cmd.cli_ctx),
52+
resource_group=namespace.resource_group_name,
53+
namespace='Microsoft.Storage',
54+
type='storageAccounts',
55+
name=namespace.storage_account
56+
)

0 commit comments

Comments
 (0)