Skip to content

Commit

Permalink
Use regex module for bind path matching (#380)
Browse files Browse the repository at this point in the history
* Update re parsing engine to re2

* Add pyre2 as a dependency

* Remove re2 for simple mappings

* Revert array in bind for testing

* Add changes to cli

* Fix flake8 error

* Update test to look for existing subdir

* Fix flake error

* Remove 2nd folder check temporarily

* Install re2 headers

* Isolate failing step for prepro

* Try win2016

* Try win2022

* Debug

* Install dev dependency

* Preinstall pyre2

* Replace re2 with regex

* Test

* Test

* Update tests and version flag

* Update to prod version

* Revert test pipeline changes
  • Loading branch information
marianan authored Mar 17, 2022
1 parent 9fc0674 commit 3348cad
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

[![PyPI version](https://badge.fury.io/py/iotedgehubdev.svg)](https://badge.fury.io/py/iotedgehubdev)

## 0.14.11 - 2022-03-01
## 0.14.13 - 2022-03-16
* Update regex match module

## 0.14.12 - 2022-03-01
* Update Python support to 3.9

## 0.14.11 - 2022-02-10
Expand Down
2 changes: 1 addition & 1 deletion iotedgehubdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
pkg_resources.declare_namespace(__name__)

__author__ = 'Microsoft Corporation'
__version__ = '0.14.12'
__version__ = '0.14.13'
__AIkey__ = '95b20d64-f54f-4de3-8ad5-165a75a6c6fe'
__production__ = 'iotedgehubdev'
4 changes: 2 additions & 2 deletions iotedgehubdev/compose_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

import os
import re
import regex

from jsonpath_rw import parse

Expand Down Expand Up @@ -187,7 +187,7 @@ def service_parser_volumes(create_options_details):
# Binds should be in the format [source:]destination[:mode]
# Windows format and LCOW format are more strict than Linux format due to colons in Windows paths,
# so match with them first
match = re.match(EdgeConstants.MOUNT_WIN_REGEX, bind) or re.match(EdgeConstants.MOUNT_LCOW_REGEX, bind)
match = regex.match(EdgeConstants.MOUNT_WIN_REGEX, bind) or regex.match(EdgeConstants.MOUNT_LCOW_REGEX, bind)
if match is not None:
source = match.group('source') or ''
target = match.group('destination')
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docker-compose==1.29.1
pytest
pyinstaller==4.2
urllib3>=1.26.4
regex
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from setuptools import find_packages, setup

VERSION = '0.14.12'
VERSION = '0.14.13'
# If we have source, validate that our version numbers match
# This should prevent uploading releases with mismatched versions.
try:
Expand Down
12 changes: 8 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,22 @@ def test_cli_start_with_create_options_for_bind(runner):
shutil.copy(deployment_json_file_path, config_file_path)

if get_docker_os_type() == "windows":
update_file_content(config_file_path, '/usr:/home/moduleuser/test',
r'C:\\\\\\\\Users:C:/moduleuser/test')
update_file_content(config_file_path, '/usr:/home/moduleuser/usr',
r'C:\\\\\\\\Windows\\\\\\\\System32:C:/moduleuser/System32')
update_file_content(config_file_path, '/run:/home/moduleuser/run',
r'C:\\\\\\\\Windows\\\\\\\\System:C:/moduleuser/System')

cli_setup(runner)
cli_start_with_deployment(runner, config_file_path)

wait_verify_docker_output(['docker', 'logs', 'edgeHubDev'], ['Opened link'])
wait_verify_docker_output(['docker', 'logs', 'tempSensor'], ['Sending message'])
if get_docker_os_type() == "windows":
wait_verify_docker_output('echo dir | docker exec -i -w c:/moduleuser/test/ tempSensor cmd', ['Public'], True)
wait_verify_docker_output('echo dir | docker exec -i -w c:/moduleuser/System32/ tempSensor cmd', ['Public'], True)
wait_verify_docker_output('echo dir | docker exec -i -w c:/moduleuser/System/ tempSensor cmd', ['Public'], True)
else:
wait_verify_docker_output(['docker', 'exec', 'tempSensor', 'ls', '/home/moduleuser/test'], ["share"])
wait_verify_docker_output(['docker', 'exec', 'tempSensor', 'ls', '/home/moduleuser/usr'], ["share"])
wait_verify_docker_output(['docker', 'exec', 'tempSensor', 'ls', '/home/moduleuser/run'], ["docker"])
finally:
shutil.rmtree(temp_config_folder, ignore_errors=True)
result = cli_stop(runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0",
"createOptions": "{\"HostConfig\":{\"Binds\":[\"/usr:/home/moduleuser/test\"]}}"
"createOptions": "{\"HostConfig\":{\"Binds\":[\"/usr:/home/moduleuser/usr\",\"/run:/home/moduleuser/run\"]}}"
}
}
}
Expand Down

0 comments on commit 3348cad

Please sign in to comment.