def test_cli(tmp_path):
    c_source = tmp_path / 'update_default_resources.c'
    cache_dir = tmp_path / defaults.BASE_PATH.as_posix()
    dev_cfg = cache_dir / defaults.DEV_CFG
    cert = cache_dir / defaults.UPDATE_PUBLIC_KEY_CERT
    key = cache_dir / defaults.UPDATE_PRIVATE_KEY
    api_cfg = cache_dir / defaults.CLOUD_CFG

    dummy_access_key = '456321789541515'
    dummy_api_url = 'https://i.am.tired.of.writing.tests.com'

    cmd = ['--debug', 'init']

    with conftest.working_directory(tmp_path):
        assert 0 == dev_tool.entry_point(cmd)

    assert not api_cfg.is_file()

    dev_cfg_digest = digest_file(dev_cfg)
    c_source_digest = digest_file(c_source)
    cert_digest = digest_file(cert)
    key_digest = digest_file(key)

    cmd = [
        'init', '--access-key', dummy_access_key, '--api-url', dummy_api_url
    ]

    with conftest.working_directory(tmp_path):
        assert 0 == dev_tool.entry_point(
            cmd + ['--api-url', 'https://some.url.pelion.com'])

    assert c_source_digest != digest_file(c_source)
    assert cert_digest != digest_file(cert)
    assert key_digest != digest_file(key)
    assert dev_cfg_digest != digest_file(dev_cfg)
    assert api_cfg.is_file()

    with conftest.working_directory(tmp_path):
        assert 0 == dev_tool.entry_point(cmd + ['--force'])

    assert c_source_digest != digest_file(c_source)
    assert cert_digest != digest_file(cert)
    assert key_digest != digest_file(key)
    assert dev_cfg_digest != digest_file(dev_cfg)

    with api_cfg.open('rb') as fh:
        api_cfg_data = yaml.safe_load(fh)
    assert dummy_access_key == api_cfg_data['access_key']
    assert dummy_api_url == api_cfg_data['host']
def test_cli_developer(happy_day_data, action):

    dev_cfg = happy_day_data['tmp_path'] / defaults.DEV_CFG
    generate_developer_config(
        key_file=happy_day_data['key_file'],
        certificate_file=happy_day_data['certificate_file'],
        config=dev_cfg,
        do_overwrite=True)

    output_manifest = happy_day_data['tmp_path'] / 'manifest.bin'
    cmd = ['--debug'] + action + [
        '--priority',
        '100500',
        '--output',
        output_manifest.as_posix(),
        '--cache-dir',
        happy_day_data['tmp_path'].as_posix(),
        '--payload-url',
        'https://arm.com/foo.bin?id=67567565576857',
        '--payload-path',
        happy_day_data['delta_file'].as_posix(),
        '--vendor-data',
        dev_cfg.as_posix(),
    ]

    if not any(['v1' in x for x in action]):
        cmd.extend(['--fw-version', '100.500.0'])

    with conftest.working_directory(happy_day_data['tmp_path']):
        assert 0 == dev_tool.entry_point(cmd)
Beispiel #3
0
def _common(happy_day_data, action, payload_path):
    cmd = ['--debug'] + action + [
        '--cache-dir', happy_day_data['tmp_path'].as_posix(), '--payload-path',
        payload_path.as_posix(), '--vendor-data',
        happy_day_data['dev_cfg'].as_posix(), '--wait-for-completion',
        '--timeout', '10', '--device-id', '1234'
    ]
    if '-fw-version' not in action and \
        '--fw-migrate-ver' not in action:
        if action[0] == 'update-v1':
            cmd.extend(['--fw-version', '100500'])
        else:
            cmd.extend(['--fw-version', '100.500.666'])

    with conftest.working_directory(happy_day_data['tmp_path']):
        return dev_tool.entry_point(cmd)
def test_cli_developer(happy_day_data, action):

    dev_cfg = happy_day_data['tmp_path'] / defaults.DEV_CFG
    payload_path = happy_day_data['fw_file'].as_posix()
    if '--combined-image' in action:
        generate_package(happy_day_data)
        payload_path = happy_day_data['package_data']['out_file_name']
    elif '-r' in action:
        payload_path = happy_day_data['delta_file'].as_posix()
    class_id = uuid.uuid4()
    vendor_id = uuid.uuid4()
    generate_developer_config(key_file=happy_day_data['key_file'],
                              cert_file=happy_day_data['certificate_file'],
                              config=dev_cfg,
                              class_id=class_id,
                              vendor_id=vendor_id)

    output_manifest = happy_day_data['tmp_path'] / 'manifest.bin'
    cmd = ['--debug'] + action + [
        '--priority',
        '100500',
        '--output',
        output_manifest.as_posix(),
        '--cache-dir',
        happy_day_data['tmp_path'].as_posix(),
        '--payload-url',
        'https://pelion.com/foo.bin?id=67567565576857',
        '--payload-path',
        payload_path,
        '--vendor-data',
        dev_cfg.as_posix(),
    ]

    if '-fw-version' not in action and \
        '--fw-migrate-ver' not in action:
        if action[0] == 'create-v1':
            cmd.extend(['--fw-version', '100500'])
        else:
            cmd.extend(['--fw-version', '100.500.666'])

    with conftest.working_directory(happy_day_data['tmp_path']):
        assert 0 == dev_tool.entry_point(cmd)