Commit 044626eb authored by Antonio Terceiro's avatar Antonio Terceiro
Browse files

lava_dispatcher_host: reject mappings with empty device_info

For example, if by mistake you add a mapping for {"board_id": None},
then *all* devices will match. We don't want that.
parent a77ee642
......@@ -30,6 +30,7 @@ def get_mapping_path(job_id):
def add_device_container_mapping(
job_id, device_info, container, container_type="lxc", logging_info={}
data = {
"device_info": device_info,
"container": container,
......@@ -48,6 +49,15 @@ def add_device_container_mapping(
def validate_device_info(device_info):
if not device_info:
raise ValueError("Addind mapping for empty device info: %r" % device_info)
if not any(device_info.values()):
raise ValueError(
"Addind mapping for device info with empty keys: %r" % device_info
def share_device_with_container(options, setup_logger=None):
data = find_mapping(options)
if not data:
......@@ -89,10 +99,13 @@ def find_mapping(options):
def match_mapping(device_info, options):
matched = False
for k, v in device_info.items():
if k in options and v and getattr(options, k) != v:
return False
return True
matched = True
return matched
def share_device_with_container_lxc(container, node):
......@@ -48,6 +48,16 @@ def test_add_mapping_without_job_dir(tmpdir):
assert os.path.exists(tmpdir / "1" / "usbmap.yaml")
def test_device_info_required(mocker):
with pytest.raises(ValueError):
add_device_container_mapping("1", {}, "mycontainer")
def test_device_info_keys_required(mocker):
with pytest.raises(ValueError):
add_device_container_mapping("1", {"serial_number": None}, "mycontainer")
def test_simple_share_device_with_container(mocker):
check_call = mocker.patch("subprocess.check_call")
add_device_container_mapping("1", {"serial_number": "1234567890"}, "mycontainer")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment