Skip to content

Commit

Permalink
manifest-dev-tool update - Add '--use-short-url' option
Browse files Browse the repository at this point in the history
  • Loading branch information
Moshe Shahar committed Jan 5, 2021
1 parent 7e4d24e commit 39e1bfa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions manifesttool/dev_tool/actions/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def register_parser(parser: argparse.ArgumentParser,
'Must correspond to an existing component '
'name on target devices.'
)
if is_update_parser:
optional.add_argument(
'-u', '--use-short-url',
action='store_true',
help='Use a short candidate payload URL in the manifest.'
)
optional.add_argument(
'-m', '--sign-image',
action='store_true',
Expand Down
10 changes: 6 additions & 4 deletions manifesttool/dev_tool/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def update(
service_config: Path,
fw_version: str,
sign_image: bool,
component: str
component: str,
short_url: bool
):
config = load_service_config(service_config)

Expand All @@ -190,7 +191,7 @@ def update(
timestamp = time.strftime('%Y_%m_%d-%H_%M_%S')
logger.info('Uploading FW image %s', payload_path.as_posix())

fw_image_url, fw_image_id = api.fw_upload(
fw_image_url, short_image_url, fw_image_id = api.fw_upload(
fw_name='{timestamp}-{filename}'.format(
filename=payload_path.name,
timestamp=timestamp),
Expand All @@ -202,7 +203,7 @@ def update(
manifest_version=manifest_version,
vendor_data_path=vendor_data,
payload_path=payload_path,
payload_url=fw_image_url,
payload_url=short_image_url if short_url else fw_image_url,
priority=priority,
fw_version=fw_version,
sign_image=sign_image,
Expand Down Expand Up @@ -315,5 +316,6 @@ def entry_point(
service_config=cache_dir / defaults.CLOUD_CFG,
fw_version=fw_version,
sign_image=getattr(args, 'sign_image', False),
component=component_name
component=component_name,
short_url=hasattr(args, 'use_short_url') and args.use_short_url
)
12 changes: 7 additions & 5 deletions manifesttool/dev_tool/pelion/pelion.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _print_upload_progress(current: int, total: int):
'=' * count, increments, progress)
print(text, end='\n' if progress == 100 else '')

def fw_upload(self, fw_name: str, image: Path) -> Tuple[URL, ID]:
def fw_upload(self, fw_name: str, image: Path) -> Tuple[URL, str, ID]:
"""
Upload FW image
:param fw_name: update candidate image name as will appear on Pelion
Expand All @@ -146,9 +146,10 @@ def fw_upload(self, fw_name: str, image: Path) -> Tuple[URL, ID]:
if not chunk:
break
LOG.debug('FW upload job %s completed', job_id)
fw_image_url, fw_image_id = self._get_fw_image_meta(job_id)
fw_image_url, short_image_url, fw_image_id = \
self._get_fw_image_meta(job_id)
LOG.info('Uploaded FW image %s', fw_image_url)
return fw_image_url, fw_image_id
return fw_image_url, short_image_url, fw_image_id
except requests.HTTPError:
LOG.error('FW image upload failed')
raise
Expand All @@ -174,7 +175,7 @@ def _upload_image_chunk(self, chunk: bytes, job_id: ID):
)
response.raise_for_status()

def _get_fw_image_meta(self, job_id: ID) -> Tuple[URL, ID]:
def _get_fw_image_meta(self, job_id: ID) -> Tuple[URL, str, ID]:
"""
Helper function for extracting uploaded image URL and ID
:param job_id: upload job ID
Expand All @@ -190,7 +191,8 @@ def _get_fw_image_meta(self, job_id: ID) -> Tuple[URL, ID]:
headers=self._headers())
response.raise_for_status()
url = response.json()['datafile']
return url, image_id
short_url = response.json()['short_datafile']
return url, short_url, image_id

def _delete_upload_job(self, job_id: ID):
"""
Expand Down
5 changes: 4 additions & 1 deletion tests/dev_tool/test_dev_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ def mock_update_apis(
# FW image - get URL
requests_mock.get(
api_url(FW_IMAGE, id=firmware_image_id),
json={'datafile': 'https://my-fw.url.com'},
json={
'datafile': 'https://my-fw.url.com/fw_image.bin',
'short_datafile': '/fw/fw_image.bin',
},
status_code=http_status_code
)
# FW image - delete
Expand Down

0 comments on commit 39e1bfa

Please sign in to comment.