Skip to content

Commit

Permalink
Fix error when start simulator with setup option (#418)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
blackchoey authored Dec 16, 2019
1 parent d43febb commit 98c906b
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: python
python:
- "3.7"
- "3.6"
- "3.5"
- "3.4"
- "2.7"
install:
- pip install -r requirements_travis.txt
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion iotedgedev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 6 additions & 0 deletions iotedgedev/azurecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 20 additions & 4 deletions iotedgedev/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions iotedgedev/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion iotedgedev/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.0
current_version = 2.1.1
commit = True
tag = True

Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iotedgedev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py36, py37
envlist = py27, py36, py37, py38

#[travis]
#python =
Expand All @@ -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}

Expand Down
5 changes: 0 additions & 5 deletions vsts_ci/darwin/continuous-build-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion vsts_ci/linux/continuous-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions vsts_ci/win32/continuous-build-win32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 98c906b

Please sign in to comment.