Skip to content

Commit

Permalink
Remove --top constraints from config list commands. (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
digimaun authored Oct 1, 2020
1 parent f95484c commit ce1e83e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 63 deletions.
9 changes: 7 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Release History

**IoT Plug-and-Play updates**

* Regenerated runtime SDK for API version 2020-09-30
* GA release for `az iot pnp twin` command group
* Regenerated PnP runtime SDK to API version 2020-09-30
* All `az iot pnp` commands still remain under preview and are subject to change or deletion.

** IoT Hub updates**

* All configuration/edge deployment list operations no longer have a default top. By default all configuration entities will be returned.
Existing --top input should not be affected.


0.10.0
Expand Down
4 changes: 2 additions & 2 deletions azext_iot/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def load_arguments(self, _):
"top",
options_list=["--top"],
type=int,
help="Maximum number of configurations to return.",
help="Maximum number of configurations to return. By default all configurations are returned.",
)

with self.argument_context("iot edge") as context:
Expand Down Expand Up @@ -735,7 +735,7 @@ def load_arguments(self, _):
"top",
options_list=["--top"],
type=int,
help="Maximum number of deployments to return.",
help="Maximum number of deployments to return. By default all deployments are returned.",
)
context.argument(
"layered",
Expand Down
80 changes: 50 additions & 30 deletions azext_iot/operations/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,35 +246,51 @@ def _create_self_signed_cert(subject, valid_days, output_path=None):
return create_self_signed_certificate(subject, valid_days, output_path)


def update_iot_device_custom(instance, edge_enabled=None, status=None, status_reason=None,
auth_method=None, primary_thumbprint=None, secondary_thumbprint=None,
primary_key=None, secondary_key=None):
def update_iot_device_custom(
instance,
edge_enabled=None,
status=None,
status_reason=None,
auth_method=None,
primary_thumbprint=None,
secondary_thumbprint=None,
primary_key=None,
secondary_key=None,
):
if edge_enabled is not None:
instance['capabilities']['iotEdge'] = edge_enabled
instance["capabilities"]["iotEdge"] = edge_enabled
if status is not None:
instance['status'] = status
instance["status"] = status
if status_reason is not None:
instance['statusReason'] = status_reason
instance["statusReason"] = status_reason
if auth_method is not None:
if auth_method == DeviceAuthType.shared_private_key.name:
auth = 'sas'
if (primary_key and not secondary_key) or (not primary_key and secondary_key):
auth = "sas"
if (primary_key and not secondary_key) or (
not primary_key and secondary_key
):
raise CLIError("primary + secondary Key required with sas auth")
instance['authentication']['symmetricKey']['primaryKey'] = primary_key
instance['authentication']['symmetricKey']['secondaryKey'] = secondary_key
instance["authentication"]["symmetricKey"]["primaryKey"] = primary_key
instance["authentication"]["symmetricKey"]["secondaryKey"] = secondary_key
elif auth_method == DeviceAuthType.x509_thumbprint.name:
auth = 'selfSigned'
auth = "selfSigned"
if not any([primary_thumbprint, secondary_thumbprint]):
raise CLIError("primary or secondary Thumbprint required with selfSigned auth")
raise CLIError(
"primary or secondary Thumbprint required with selfSigned auth"
)
if primary_thumbprint:
instance['authentication']['x509Thumbprint']['primaryThumbprint'] = primary_thumbprint
instance["authentication"]["x509Thumbprint"][
"primaryThumbprint"
] = primary_thumbprint
if secondary_thumbprint:
instance['authentication']['x509Thumbprint']['secondaryThumbprint'] = secondary_thumbprint
instance["authentication"]["x509Thumbprint"][
"secondaryThumbprint"
] = secondary_thumbprint
elif auth_method == DeviceAuthType.x509_ca.name:
auth = 'certificateAuthority'
auth = "certificateAuthority"
else:
raise ValueError('Authorization method {} invalid.'.format(auth_method))
instance['authentication']['type'] = auth
raise ValueError("Authorization method {} invalid.".format(auth_method))
instance["authentication"]["type"] = auth
return instance


Expand All @@ -291,12 +307,13 @@ def iot_device_update(
try:
auth, pk, sk = _parse_auth(parameters)
updated_device = _assemble_device(
parameters['deviceId'],
auth, parameters['capabilities']['iotEdge'],
parameters["deviceId"],
auth,
parameters["capabilities"]["iotEdge"],
pk,
sk,
parameters['status'].lower(),
parameters.get('statusReason')
parameters["status"].lower(),
parameters.get("statusReason"),
)
etag = parameters.get("etag", None)
if etag:
Expand Down Expand Up @@ -1144,7 +1161,7 @@ def _iot_hub_configuration_show(target, config_id):


def iot_hub_configuration_list(
cmd, hub_name=None, top=10, resource_group_name=None, login=None
cmd, hub_name=None, top=None, resource_group_name=None, login=None
):
result = _iot_hub_configuration_list(
cmd,
Expand All @@ -1156,13 +1173,16 @@ def iot_hub_configuration_list(
filtered = [
c
for c in result
if (c["content"].get("deviceContent") or c["content"].get("moduleContent"))
if (
c["content"].get("deviceContent") is not None
or c["content"].get("moduleContent") is not None
)
]
return filtered[:top]
return filtered[:top] # list[:None] == list[:len(list)]


def iot_edge_deployment_list(
cmd, hub_name=None, top=10, resource_group_name=None, login=None
cmd, hub_name=None, top=None, resource_group_name=None, login=None
):
result = _iot_hub_configuration_list(
cmd,
Expand All @@ -1172,14 +1192,14 @@ def iot_edge_deployment_list(
login=login,
)

filtered = [c for c in result if c["content"].get("modulesContent")]
return filtered[:top]
filtered = [c for c in result if c["content"].get("modulesContent") is not None]
return filtered[:top] # list[:None] == list[:len(list)]


def _iot_hub_configuration_list(
cmd, hub_name=None, top=10, resource_group_name=None, login=None
cmd, hub_name=None, top=None, resource_group_name=None, login=None
):
top = _process_top(top, upper_limit=100)
top = _process_top(top)

discovery = IotHubDiscovery(cmd)
target = discovery.get_target(
Expand Down Expand Up @@ -1863,7 +1883,7 @@ def iot_c2d_message_receive(
login=None,
abandon=None,
complete=None,
reject=None
reject=None,
):
ack = None
ack_vals = [abandon, complete, reject]
Expand Down
24 changes: 0 additions & 24 deletions azext_iot/tests/iothub/configurations/test_iot_config_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,6 @@ def test_edge_deployments(self):
checks=config_list_check,
)

# Error top of -1 does not work with configurations
self.cmd(
"iot edge deployment list -n {} -g {} --top -1".format(LIVE_HUB, LIVE_RG),
expect_failure=True,
)

# Error max top of 100 with configurations
self.cmd(
"iot edge deployment list -n {} -g {} --top 101".format(LIVE_HUB, LIVE_RG),
expect_failure=True,
)

# Explicitly delete an edge deployment
self.cmd(
"iot edge deployment delete -d {} -n {} -g {}".format(
Expand Down Expand Up @@ -685,18 +673,6 @@ def test_device_configurations(self):
checks=config_list_check,
)

# Error top of -1 does not work with configurations
self.cmd(
"iot hub configuration list -n {} -g {} --top -1".format(LIVE_HUB, LIVE_RG),
expect_failure=True,
)

# Error max top of 100 with configurations
self.cmd(
"iot hub configuration list -n {} -g {} --top 101".format(LIVE_HUB, LIVE_RG),
expect_failure=True,
)

# Explicitly delete an ADM configuration
self.cmd(
"iot hub configuration delete -c {} -n {} -g {}".format(
Expand Down
18 changes: 13 additions & 5 deletions azext_iot/tests/iothub/configurations/test_iot_config_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def test_config_update_error(self, fixture_cmd, serviceclient_generic_error):


class TestConfigList:
@pytest.fixture(params=[10, 0, 20])
@pytest.fixture(params=[10, 0, 1000])
def service_client(self, mocked_response, fixture_ghcs, request):
result = []
size = request.param
Expand Down Expand Up @@ -711,7 +711,7 @@ def service_client(self, mocked_response, fixture_ghcs, request):
mocked_response.expected_size = size
yield mocked_response

@pytest.mark.parametrize("top", [1, 100])
@pytest.mark.parametrize("top", [1, 100, 1000, None])
def test_config_list(self, fixture_cmd, service_client, top):
result = subject.iot_hub_configuration_list(
cmd=fixture_cmd, hub_name=mock_target["entity"], top=top
Expand All @@ -722,9 +722,13 @@ def test_config_list(self, fixture_cmd, service_client, top):
assert len(result) == top or len(result) == service_client.expected_size * 2

list_request = service_client.calls[0].request
assert "top={}".format(top) in list_request.url

@pytest.mark.parametrize("top", [1, 10])
if top:
assert "top={}".format(top) in list_request.url
else:
assert not "top={}".format(top) in list_request.url

@pytest.mark.parametrize("top", [1, 100, 1000, None])
def test_deployment_list(self, fixture_cmd, service_client, top):
result = subject.iot_edge_deployment_list(
cmd=fixture_cmd, hub_name=mock_target["entity"], top=top
Expand All @@ -734,7 +738,11 @@ def test_deployment_list(self, fixture_cmd, service_client, top):
assert len(result) == top or len(result) == service_client.expected_size

list_request = service_client.calls[0].request
assert "top={}".format(top) in list_request.url

if top:
assert "top={}".format(top) in list_request.url
else:
assert not "top={}".format(top) in list_request.url

@pytest.mark.parametrize("top", [-1, 0, 101])
def test_config_list_invalid_args(self, fixture_cmd, top):
Expand Down

0 comments on commit ce1e83e

Please sign in to comment.