Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable couldn't be all digital for SECURE_ID #169

Open
hanhsuan opened this issue Dec 3, 2023 · 6 comments
Open

Environment variable couldn't be all digital for SECURE_ID #169

hanhsuan opened this issue Dec 3, 2023 · 6 comments

Comments

@hanhsuan
Copy link
Contributor

hanhsuan commented Dec 3, 2023

This might be the limitation of subprocess, the error log as below while the SECURE_ID is a valid HEX string 123456.

Traceback (most recent call last):
  File "/usr/local/bin/testflinger-device-connector", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/cmd.py", line 60, in main
    raise SystemExit(args.func(args))
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/devices/__init__.py", line 194, in runtest
    raise e
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/devices/__init__.py", line 190, in runtest
    exitcode = testflinger_device_connectors.run_test_cmds(
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/__init__.py", line 373, in run_test_cmds
    return _run_test_cmds_str(cmds, config, env)
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/__init__.py", line 487, in _run_test_cmds_str
    result = runcmd("./tf_cmd_script", env)
  File "/usr/local/lib/python3.10/dist-packages/testflinger_device_connectors/__init__.py", line 332, in runcmd
    with subprocess.Popen(
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1783, in _execute_child
    env_list.append(k + b'=' + os.fsencode(v))
  File "/usr/lib/python3.10/os.py", line 811, in fsencode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int

The reason is env_list.append(k + b'=' + os.fsencode(v)) will use os.fsencode to encode the environment variables and check the data type should be string.

def fsencode(filename):
        """Encode filename (an os.PathLike, bytes, or str) to the filesystem
        encoding with 'surrogateescape' error handler, return bytes unchanged.
        On Windows, use 'strict' error handler if the file system encoding is
        'mbcs' (which is the default encoding).
        """
        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, str):
            return filename.encode(encoding, errors)
        else:
            return filename

It could change this line to

env = {x: str(y) for x, y in env.items() if y }

to solve this problem.

Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CERTTF-266.

This message was autogenerated

Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CERTTF-267.

This message was autogenerated

@plars
Copy link
Collaborator

plars commented Dec 4, 2023

It should already be string data though, right? It's the value for an env var. I'm curious why you are trying to assign binary data to it?

Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CERTTF-268.

This message was autogenerated

@hanhsuan
Copy link
Contributor Author

hanhsuan commented Dec 5, 2023

I'm not. The 123456 is assigned to HEXR_DEVICE_SECURE_ID in the configuration file for device-connector and I think it is converted to int by python itself.

Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CERTTF-269.

This message was autogenerated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants