Skip to content

Commit

Permalink
Merge pull request #24 from ARMmbed/manifest-tool-200
Browse files Browse the repository at this point in the history
Manifest-tool 2.0.0 support
  • Loading branch information
janisimonen authored Sep 18, 2020
2 parents 5eddd59 + b063893 commit fcf3685
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ pytest dev-client-tests.py -k test_03_get_resource
```

### Running the update test
Before running the update test case create an authentication certificate with [manifest-tool's init](https://www.pelion.com/docs/device-management/current/updating-firmware/setting-up.html) command and [compile your update image](https://www.pelion.com/docs/device-management/current/updating-firmware/preparing-images.html).
Update test uses the same manifest-tool to create the actual manifest for update campaign.
Running the update test provide mandatory update image path and optional manifest-tool init path arguments at startup:
Before running the update test case create an authentication certificate with [manifest-dev-tool init](https://www.pelion.com/docs/device-management/current/updating-firmware/setting-up.html) command and [compile your update image](https://www.pelion.com/docs/device-management/current/updating-firmware/preparing-images.html).
Update test uses the same manifest-dev-tool to create the actual manifest for update campaign.
Running the update test provide mandatory update image path and optional manifest-dev-tool init path arguments at startup:
- `--update_bin=/home/user/mbed-cloud-client-example_update.bin` absolute path for the update image
- `--manifest_tool=/home/user/mbed-os-example-pelion` absolute path where manifest-tool init is executed - defaults to current working directory
- `--manifest_tool=/home/user/mbed-os-example-pelion` absolute path where manifest-dev-tool init is executed - defaults to current working directory

If you want to leave the firmware image, manifest and campaign to your account after the test, add `--no_cleanup` startup argument.
New manifest-tool 2.0.0 supports two different versions of manifest schemas. Update test's manifest creation defaults to 'v1' manifest version, but you can set the version e.g to 'v3' by the `--manifest_version=v3` startup argument.
Supported versions at the moment are 'v1' and 'v3'.


### Results output
Expand Down
4 changes: 3 additions & 1 deletion pelion_test_lib/fixtures/cloud_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def update_device(cloud, client, request):
"""
binary_path = request.config.getoption('update_bin', None)
manifest_tool_path = request.config.getoption('manifest_tool')
manifest_version = request.config.getoption('manifest_version', 'v1')
no_cleanup = request.config.getoption('no_cleanup', False)
delta_manifest = request.config.getoption('delta_manifest', None)
local_bin = request.config.getoption('local_binary', None)
Expand Down Expand Up @@ -142,7 +143,8 @@ def update_device(cloud, client, request):
manifest_file = manifest_tool.create_manifest(path=manifest_tool_path,
firmware_url=fw_image['datafile'],
update_image_path=binary_path,
delta_manifest=delta_manifest)
delta_manifest=delta_manifest,
manifest_version=manifest_version)
assert manifest_file is not None, 'Manifest file was not created'

manifest = cloud.update.upload_firmware_manifest(manifest_file, expected_status_code=201).json()
Expand Down
23 changes: 16 additions & 7 deletions pelion_test_lib/tools/manifest_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

BINARIES = 'bin'
MANIFEST_TOOL = 'manifest-tool'
MANIFEST_DEV_TOOL = 'manifest-dev-tool'
UPDATE_DEFAULT_RESOURCES = 'update_default_resources.c'
SETTINGS_FILE = '.manifest_tool.json'

Expand All @@ -36,20 +37,20 @@ def init(working_path, vendor_domain=None, model_name=None):
:param model_name: "product model identifier"
:return: Path to update_default_resources.c path if it was created. Else None
"""
log.debug('manifest-tool init - START')
log.debug('{} init - START'.format(MANIFEST_DEV_TOOL))
if vendor_domain is None:
vendor_domain = '{}.com'.format(uuid.uuid4().hex)
if model_name is None:
model_name = uuid.uuid4().hex
command = [MANIFEST_TOOL, 'init', '-d', vendor_domain, '-m', model_name, '-q', '-f']
command = [MANIFEST_DEV_TOOL, 'init', '-d', vendor_domain, '-m', model_name, '-q', '-f']
log.debug(command)
p = subprocess.Popen(command, cwd=working_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if stdout:
log.debug(stdout)
if stderr:
log.warning(stderr)
log.debug('manifest-tool init - DONE')
log.debug('{} init - DONE'.format(MANIFEST_DEV_TOOL))
f = os.path.join(os.sep, working_path, UPDATE_DEFAULT_RESOURCES)
if os.path.isfile(f):
log.debug('Path to update_default_resources.c: {}'.format(f))
Expand All @@ -58,25 +59,33 @@ def init(working_path, vendor_domain=None, model_name=None):
return None


def create_manifest(path, firmware_url, update_image_path, output='output.manifest', delta_manifest=None):
def create_manifest(path, firmware_url, update_image_path, output='output.manifest', delta_manifest=None,
manifest_version='v1'):
"""
Create a manifest file
:param path: Manifest-tool path
:param firmware_url: URL to firmware image
:param update_image_path: Path to local update image
:param output: Manifest file name
:param delta_manifest: File name of the json input file generated by delta-tool in case of delta update
:param manifest_version: Version for created manifest, either 'v1' or 'v3'
:returns: Path to a manifest file on success. Otherwise None.
:raises: OSError if invalid or inaccessible file name or path.
ValueError if Popen is called with invalid arguments.
"""
log.info('Creating manifest for update campaign with manifest-tool...')
log.debug('manifest-tool create - START')
log.debug('{} create - START'.format(MANIFEST_DEV_TOOL))
path = os.path.abspath(path)
# remove file if it exists
if os.path.isfile(output):
os.remove(output)
cmd = [MANIFEST_TOOL, 'create', '-u', firmware_url, '-o', output]
if manifest_version == 'v1':
cmd = [MANIFEST_DEV_TOOL, 'create-v1', '-u', firmware_url, '-o', output]
elif manifest_version == 'v3':
cmd = [MANIFEST_DEV_TOOL, 'create', '-u', firmware_url, '-o', output, '--sign-image']
else:
log.error('Only "v1" and "v3" manifest version are supported!')
return None
if delta_manifest:
log.debug('Specifying delta payload')
cmd.append('-i')
Expand All @@ -93,7 +102,7 @@ def create_manifest(path, firmware_url, update_image_path, output='output.manife
log.debug(stdout)
if stderr:
log.warning(stderr)
log.debug('manifest-tool create - DONE')
log.debug('{} create - DONE'.format(MANIFEST_DEV_TOOL))
# return path to manifest file
f = os.path.join(os.sep, path, output)
if os.path.isfile(f):
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
manifest-tool == 1.5.2
mbed-ls
pytest
manifest-tool==2.0.0
mbed-ls==1.7.*
pytest==6.0.*
pytest-html
pyserial
requests
requests==2.24.0
ws4py
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def pytest_addoption(parser):
help='set true if given update_bin is a delta image')
parser.addoption('--local_binary', action='store', help='local linux client binary path')
parser.addoption('--use_one_apikey', action='store_true', default=False, help='do not create temp api key')
parser.addoption('--manifest_version', action='store', default='v1', help='manifest template version')


def pytest_report_teststatus(report):
Expand Down

0 comments on commit fcf3685

Please sign in to comment.