From 98c906bb621fe7c1eaf47442435d423198e3536a Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Mon, 16 Dec 2019 13:25:19 +0800 Subject: [PATCH] Fix error when start simulator with setup option (#418) * Fix error when start simulator with --setup option * Bump version to 2.1.1 * Install fixed version of Azure CLI IoT extension * Do not support 3.8 due to Azure CLI IoT extension incompatible --- .travis.yml | 3 +-- CHANGELOG.md | 5 +++++ iotedgedev/__init__.py | 2 +- iotedgedev/azurecli.py | 6 ++++++ iotedgedev/cli.py | 24 ++++++++++++++++++---- iotedgedev/constants.py | 1 + iotedgedev/simulator.py | 2 +- setup.cfg | 2 +- setup.py | 6 ++++-- tests/test_iotedgedev.py | 2 +- tests/test_simulator.py | 10 +++++++++ tox.ini | 4 ++-- vsts_ci/darwin/continuous-build-darwin.yml | 5 ----- vsts_ci/linux/continuous-build-linux.yml | 1 - vsts_ci/win32/continuous-build-win32.yml | 4 ---- 15 files changed, 53 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index de711b21..8a2ba4a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: python python: + - "3.7" - "3.6" - - "3.5" - - "3.4" - "2.7" install: - pip install -r requirements_travis.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index f291c15c..9d693001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this project since 0.82.0 will be documented in this file. +## [2.1.1] - 2019-12-11 +### Changed +- Fix getconfig fails if template contains a placeholder that is not enclosed in quotes.[[#414](https://github.com/Azure/iotedgedev/issues/414)] +- Fix wrong instruction to `iotedgedev iothub setup` with extra flags.[[#417](https://github.com/Azure/iotedgedev/issues/417)] + ## [2.1.0] - 2019-10-28 ### Added - Validate schema of deployment template and generated deployment manifest in `genconfig` command diff --git a/iotedgedev/__init__.py b/iotedgedev/__init__.py index d5d4303b..f97d25ce 100644 --- a/iotedgedev/__init__.py +++ b/iotedgedev/__init__.py @@ -4,5 +4,5 @@ __author__ = 'Microsoft Corporation' __email__ = 'vsciet@microsoft.com' -__version__ = '2.1.0' +__version__ = '2.1.1' __AIkey__ = '95b20d64-f54f-4de3-8ad5-165a75a6c6fe' diff --git a/iotedgedev/azurecli.py b/iotedgedev/azurecli.py index 14c7ba08..45afc6ca 100644 --- a/iotedgedev/azurecli.py +++ b/iotedgedev/azurecli.py @@ -209,6 +209,12 @@ def add_extension(self, name): "--yes"], f("Error while adding extension {name}."), suppress_output=True) + def add_extension_with_source(self, source_url): + return self.invoke_az_cli_outproc(["extension", "add", "--source", source_url, + "--yes"], + f("Error while add extension from source {source_url}."), + suppress_output=True) + def extension_exists(self, name): return self.invoke_az_cli_outproc(["extension", "show", "--name", name, "--output", "table"], f("Error while checking for extension {name}."), suppress_output=True) diff --git a/iotedgedev/cli.py b/iotedgedev/cli.py index d10a8085..5a2fa003 100644 --- a/iotedgedev/cli.py +++ b/iotedgedev/cli.py @@ -10,6 +10,7 @@ from fstrings import f from .azurecli import AzureCli +from .constants import Constants from .decorators import add_module_options, with_telemetry from .dockercls import Docker from .edge import Edge @@ -223,6 +224,7 @@ def push(ctx, do_deploy, no_build, template_file, platform): help="Specify the deployment manifest file") @with_telemetry def deploy(manifest_file): + ensure_azure_cli_iot_ext() edge = Edge(envvars, output, azure_cli) edge.deploy(manifest_file) @@ -341,12 +343,16 @@ def setup_simulator(gateway_host, iothub_connection_string): default=53000, show_default=True, help="Port of the service for sending message.") +@click.option("--iothub-connection-string", + "-c", + help="Set Azure IoT Hub connection string when setup IoT Edge simulator. Note: Use double quotes when supplying this input.", + required=False) @with_telemetry -def start_simulator(setup, solution, build, manifest_file, platform, verbose, inputs, port): +def start_simulator(setup, solution, build, manifest_file, platform, verbose, inputs, port, iothub_connection_string): sim = Simulator(envvars, output) if setup: - sim.setup(socket.getfqdn()) + sim.setup(socket.getfqdn(), iothub_connection_string) if solution or not inputs: sim.start_solution(manifest_file, platform, verbose, build) @@ -400,6 +406,7 @@ def modulecred(local, output_file): help="Specify number of seconds to monitor for messages") @with_telemetry def monitor(timeout): + ensure_azure_cli_iot_ext() utility = Utility(envvars, output) ih = IoTHub(envvars, utility, output, azure_cli) ih.monitor_events(timeout) @@ -408,6 +415,16 @@ def monitor(timeout): main.add_command(monitor) +def ensure_azure_cli_iot_ext(): + if not azure_cli.extension_exists("azure-cli-iot-ext"): + try: + # Install fixed version of Azure CLI IoT extension + azure_cli.add_extension_with_source(Constants.azure_cli_iot_ext_source_url) + except Exception: + # Fall back to install latest Azure CLI IoT extension when fail + azure_cli.add_extension("azure-cli-iot-ext") + + def validate_option(ctx, param, value): global default_subscriptionId global azure_cli_processing_complete @@ -467,8 +484,7 @@ def validate_option(ctx, param, value): if param.name == "iothub_name": output.param("IOT HUB", value, f("Setting IoT Hub to '{value}'..."), azure_cli_processing_complete) envvars.IOTHUB_NAME = value - if not azure_cli.extension_exists("azure-cli-iot-ext"): - azure_cli.add_extension("azure-cli-iot-ext") + ensure_azure_cli_iot_ext() if not azure_cli.iothub_exists(value, envvars.RESOURCE_GROUP_NAME): # check if the active subscription already contains a free IoT Hub # if yes ask if the user wants to create an S1 diff --git a/iotedgedev/constants.py b/iotedgedev/constants.py index d8fe2f01..9873d3ab 100644 --- a/iotedgedev/constants.py +++ b/iotedgedev/constants.py @@ -9,3 +9,4 @@ class Constants: moduledir_placeholder_pattern = r'\${MODULEDIR<(.+)>(\..+)?}' deployment_template_schema_url = "http://json.schemastore.org/azure-iot-edge-deployment-template-2.0" deployment_manifest_schema_url = "http://json.schemastore.org/azure-iot-edge-deployment-2.0" + azure_cli_iot_ext_source_url = "https://github.com/Azure/azure-iot-cli-extension/releases/download/v0.8.6/azure_cli_iot_ext-0.8.6-py2.py3-none-any.whl" diff --git a/iotedgedev/simulator.py b/iotedgedev/simulator.py index 45e60d7d..1be84967 100644 --- a/iotedgedev/simulator.py +++ b/iotedgedev/simulator.py @@ -14,7 +14,7 @@ def __init__(self, envvars, output): self.output = output self.utility = Utility(self.envvars, self.output) - def setup(self, gateway_host, iothub_connection_string): + def setup(self, gateway_host, iothub_connection_string=""): self.output.header("Setting Up IoT Edge Simulator") self.envvars.verify_envvar_has_val("DEVICE_CONNECTION_STRING", self.envvars.DEVICE_CONNECTION_STRING) diff --git a/setup.cfg b/setup.cfg index c47886be..39c1c59c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.0 +current_version = 2.1.1 commit = True tag = True diff --git a/setup.py b/setup.py index 0070e514..f71285cd 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def run(self): setup( name='iotedgedev', - version='2.1.0', + version='2.1.1', description='The Azure IoT Edge Dev Tool greatly simplifies the IoT Edge development process by automating many routine manual tasks, such as building, deploying, pushing modules and configuring the IoT Edge Runtime.', long_description='See https://github.com/azure/iotedgedev for usage instructions.', author='Microsoft Corporation', @@ -76,6 +76,7 @@ def run(self): license='MIT license', zip_safe=False, keywords='azure iot edge dev tool', + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <3.8', classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Intended Audience :: Developers', @@ -84,7 +85,8 @@ def run(self): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6' + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7' ], test_suite='tests', tests_require=test_requirements, diff --git a/tests/test_iotedgedev.py b/tests/test_iotedgedev.py index cc0de5aa..ad84075c 100644 --- a/tests/test_iotedgedev.py +++ b/tests/test_iotedgedev.py @@ -217,7 +217,7 @@ def test_deploy_modules(): result = runner_invoke(['deploy']) assert 'DEPLOYMENT COMPLETE' in result.output - assert 'ERROR' not in result.output + assert 'ERROR' not in result.output.replace('ERROR: Error while checking for extension', '') @pytest.fixture diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 29db7e84..1ee0e4aa 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -93,6 +93,16 @@ def test_start_solution(capfd): assert 'IoT Edge Simulator has been started in solution mode.' in out +@pytest.mark.skipif(get_docker_os_type() == 'windows', reason='Simulator does not support windows container') +def test_start_solution_with_setup(capfd): + result = runner_invoke(['simulator', 'start', '--setup', '-s', '-b', '-f', 'deployment.template.json']) + out, err = capfd.readouterr() + + assert 'Setup IoT Edge Simulator successfully.' in result.output + assert 'BUILD COMPLETE' in result.output + assert 'IoT Edge Simulator has been started in solution mode.' in out + + @pytest.mark.skipif(get_docker_os_type() == 'windows', reason='Simulator does not support windows container') def test_monitor(capfd): try: diff --git a/tox.ini b/tox.ini index a3137bfd..0ba729d2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py36, py37 +envlist = py27, py36, py37, py38 #[travis] #python = @@ -15,7 +15,7 @@ envlist = py27, py36, py37 deps = pytest -rrequirements_dev.txt -commands = pytest -s -v +commands = pytest -s -v {posargs} #setenv = # PYTHONPATH = {toxinidir} diff --git a/vsts_ci/darwin/continuous-build-darwin.yml b/vsts_ci/darwin/continuous-build-darwin.yml index d69273b5..edd47dd1 100644 --- a/vsts_ci/darwin/continuous-build-darwin.yml +++ b/vsts_ci/darwin/continuous-build-darwin.yml @@ -28,11 +28,6 @@ steps: yo --version displayName: "Install Yeoman and Azure IoT Edge Node.js module generator packages" - - powershell: | - az extension add --name azure-cli-iot-ext - az --version - displayName: "Install Azure Cli iot extension" - - script: | pip install --upgrade pip pip install --upgrade tox diff --git a/vsts_ci/linux/continuous-build-linux.yml b/vsts_ci/linux/continuous-build-linux.yml index 5bad6bd0..eeccfbe6 100644 --- a/vsts_ci/linux/continuous-build-linux.yml +++ b/vsts_ci/linux/continuous-build-linux.yml @@ -18,7 +18,6 @@ steps: pip install --upgrade pip pip install --upgrade tox sudo npm i -g iothub-explorer - az extension add --name azure-cli-iot-ext az --version displayName: "Update and install required tools" diff --git a/vsts_ci/win32/continuous-build-win32.yml b/vsts_ci/win32/continuous-build-win32.yml index eba5dfa6..653c079d 100644 --- a/vsts_ci/win32/continuous-build-win32.yml +++ b/vsts_ci/win32/continuous-build-win32.yml @@ -13,10 +13,6 @@ steps: npm i -g iothub-explorer yo generator-azure-iot-edge-module displayName: "Install IoT Hub explorer, Yeoman and Azure IoT Edge Node.js module generator packages" - - pwsh: | - az extension add --name azure-cli-iot-ext - displayName: "Install Azure CLI IoT Extension" - - pwsh: | pip install tox tox -e "$(TOXENV)"