From ce1e83e557516cb222984e00ecacf64250ab0f55 Mon Sep 17 00:00:00 2001 From: Paymaun Date: Thu, 1 Oct 2020 11:02:21 -0700 Subject: [PATCH] Remove --top constraints from config list commands. (#257) --- HISTORY.rst | 9 ++- azext_iot/_params.py | 4 +- azext_iot/operations/hub.py | 80 ++++++++++++------- .../configurations/test_iot_config_int.py | 24 ------ .../configurations/test_iot_config_unit.py | 18 +++-- 5 files changed, 72 insertions(+), 63 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index f543888c6..81cef2e1c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 diff --git a/azext_iot/_params.py b/azext_iot/_params.py index 93765b831..f3194a86a 100644 --- a/azext_iot/_params.py +++ b/azext_iot/_params.py @@ -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: @@ -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", diff --git a/azext_iot/operations/hub.py b/azext_iot/operations/hub.py index 52e72a3f4..9c24cd036 100644 --- a/azext_iot/operations/hub.py +++ b/azext_iot/operations/hub.py @@ -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 @@ -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: @@ -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, @@ -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, @@ -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( @@ -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] diff --git a/azext_iot/tests/iothub/configurations/test_iot_config_int.py b/azext_iot/tests/iothub/configurations/test_iot_config_int.py index 65b18f1c5..68aba4382 100644 --- a/azext_iot/tests/iothub/configurations/test_iot_config_int.py +++ b/azext_iot/tests/iothub/configurations/test_iot_config_int.py @@ -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( @@ -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( diff --git a/azext_iot/tests/iothub/configurations/test_iot_config_unit.py b/azext_iot/tests/iothub/configurations/test_iot_config_unit.py index 8d9a9606c..e681bccaf 100644 --- a/azext_iot/tests/iothub/configurations/test_iot_config_unit.py +++ b/azext_iot/tests/iothub/configurations/test_iot_config_unit.py @@ -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 @@ -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 @@ -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 @@ -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):