diff --git a/device-types/Nokia/7220-IXR-H3.yaml b/device-types/Nokia/7220-IXR-H3.yaml index d240cec354..274bfebbd3 100644 --- a/device-types/Nokia/7220-IXR-H3.yaml +++ b/device-types/Nokia/7220-IXR-H3.yaml @@ -7,6 +7,8 @@ u_height: 1 is_full_depth: true # 21.65" weight: 24.65 weight_unit: lb +front_image: true +rear_image: true comments: '[Datasheet](https://onestore.nokia.com/asset/210990)' console-ports: - name: Console diff --git a/elevation-images/Nokia/7220-IXR-H3.front.png b/elevation-images/Nokia/7220-IXR-H3.front.png new file mode 100644 index 0000000000..7bede2c7ac Binary files /dev/null and b/elevation-images/Nokia/7220-IXR-H3.front.png differ diff --git a/elevation-images/Nokia/7220-IXR-H3.rear.png b/elevation-images/Nokia/7220-IXR-H3.rear.png new file mode 100644 index 0000000000..e812e222c8 Binary files /dev/null and b/elevation-images/Nokia/7220-IXR-H3.rear.png differ diff --git a/schema/devicetype.json b/schema/devicetype.json index 5a7c1ac452..73d66cd325 100644 --- a/schema/devicetype.json +++ b/schema/devicetype.json @@ -47,6 +47,12 @@ "oz" ] }, + "front_image": { + "type": "boolean" + }, + "rear_image": { + "type": "boolean" + }, "subdevice_role": { "type": "string", "enum": [ diff --git a/tests/definitions_test.py b/tests/definitions_test.py index 1138e9b9ab..83c7d659cd 100644 --- a/tests/definitions_test.py +++ b/tests/definitions_test.py @@ -15,6 +15,10 @@ ('module-types', 'moduletype.json'), ) +IMAGE_FILETYPES = ( + 'bmp', 'gif', 'pjp', 'jpg', 'pjpeg', 'jpeg', 'jfif', 'png', 'tif', 'tiff', 'webp' +) + COMPONENT_TYPES = ( 'console-ports', 'console-server-ports', @@ -49,8 +53,24 @@ def _get_definition_files(): return ret +def _get_image_files(): + """ + Return a list of all image files within the specified path and manufacturer. + """ + ret = [] + + for f in sorted(glob.glob(f"elevation-images/*/*", recursive=True)): + # f = 'elevation-images/Nokia/nokia-7220-ixr-h3-front.png' + # f.split('/')[1] = Nokia + assert f.split('/')[2].split('.')[-1] in IMAGE_FILETYPES, f"Invalid file extension: {f}" + + ret.append((f.split('/')[1], f)) + + return ret + definition_files = _get_definition_files() +image_files = _get_image_files() known_slugs = set() @@ -133,4 +153,27 @@ def iterlist(var): elif isinstance(list_value, list): iterlist(list_value) + # Check for images if front_image or rear_image is True + if (definition.get('front_image') or definition.get('rear_image')): + manufacturer_images = [image for image in image_files if image[0] == file_path.split('/')[1]] + if not manufacturer_images: + pytest.fail(f'{file_path} has Front or Rear Image set to True but no images found for manufacturer', False) + + if(definition.get('front_image')): + devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'front'] + + if not devices: + pytest.fail(f'{file_path} has front_image set to True but no images found for device', False) + + for device_image in devices: + assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has front_image set to True but no images found for device' + if(definition.get('rear_image')): + devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'rear'] + + if not devices: + pytest.fail(f'{file_path} has rear_image set to True but no images found for device', False) + + for device_image in devices: + assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has rear_image set to True but no images found for device' + iterdict(definition)