Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/user_docs/query_docs/IMAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ An `Image` has the following properties:
| `string` | "id", "uuid" | ID of the image |
| `string` (x) | "updated_at" | The timestamp when this image was last updated |
| `int` | "min_ram", "ram" | The minimum disk size in GB that is required to boot the image. |
| `int` | "min_disk", "disk" | The minimum amount of RAM in MB that is required to boot the image. |
| `string` | "name" | Name of the Image |
| `int` | "size" | The size of the image data, in bytes. |
| `string` | "status" | Image status |
| `int` | "min_disk", "disk" | The minimum amount of RAM in MB that is required to boot the image. |
| `string` | "name" | Name of the Image |
| `int` | "size" | The size of the image data, in bytes. |
| `string` | "status" | Image status |
| `string` | "owner", "tenant" | ID of the project which owns the image. Might be None i.e. for public images, which outputs in results as 'Not Found'. |
| `string` | "metadata" | Full metadata dictionary (as JSON-formatted string) |

(x) - These are UTC timestamps in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format
Any of these properties can be used for any of the API methods that takes a property - like `select`, `where`, `sort_by` etc
Expand All @@ -55,6 +57,7 @@ The following shared-common properties are listed below (as well as the Query ob
| Prop 1 | Prop 2 | Type | Maps | Documentation |
|--------|------------|-------------|-------------------------------|--------------------------|
| "id" | "image_id" | One-to-Many | `ImageQuery` to `ServerQuery` | [SERVERS.md](SERVERS.md) |
| "owner"| "id" | Many-to-One | `ImageQuery` to `ProjectQuery`| [PROJECTS.md](PROJECTS.md)


## Chaining to
Expand All @@ -63,6 +66,7 @@ Chaining from other `ImageQuery` requires passing `image_query` or any of the al
| From | Prop 1 | Prop 2 | Type | Documentation |
|---------------|--------|------------|-------------|--------------------------|
| `ServerQuery` | "id" | "image_id" | Many-to-One | [SERVERS.md](SERVERS.md) |
| `ProjectQuery`| "id" | "owner" | One-to-Many | [PROJECTS.md](PROJECTS.md)


## run() meta-parameters
Expand Down
3 changes: 3 additions & 0 deletions docs/user_docs/query_docs/PROJECTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The following shared-common properties are listed below (as well as the Query ob
| Prop 1 | Prop 2 | Type | Maps |
|--------|--------------|-------------|---------------------------------|
| "id" | "project_id" | One-to-Many | `ProjectQuery` to `ServerQuery` |
| "id" | "owner" | One-to-Many | `ProjectQuery` to `ServerQuery` |



## Chaining to
Expand All @@ -59,6 +61,7 @@ Chaining from other `ProjectQuery` requires passing `PROJECT_QUERY` or any alias
| From | Prop 1 | Prop 2 | Type | Documentation |
|---------------|--------------|--------|-------------|--------------------------|
| `ServerQuery` | "project_id" | "id" | Many-to-One | [SERVERS.md](SERVERS.md) |
| `ImageQuery` | "owner" | "id" | Many-to-One | [IMAGES.md](IMAGES.md)


## run() meta-parameters
Expand Down
8 changes: 8 additions & 0 deletions openstackquery/enums/props/image_properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from enum import auto

from openstackquery.enums.props.prop_enum import PropEnum
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
Expand All @@ -19,6 +21,8 @@ class ImageProperties(PropEnum):
IMAGE_NAME = auto()
IMAGE_SIZE = auto()
IMAGE_STATUS = auto()
IMAGE_OWNER = auto()
IMAGE_METADATA = auto()

@staticmethod
def _get_aliases():
Expand All @@ -35,6 +39,8 @@ def _get_aliases():
ImageProperties.IMAGE_NAME: ["name"],
ImageProperties.IMAGE_SIZE: ["size"],
ImageProperties.IMAGE_STATUS: ["status"],
ImageProperties.IMAGE_OWNER: ["owner", "tenant"],
ImageProperties.IMAGE_METADATA: ["metadata"],
}

@staticmethod
Expand All @@ -55,6 +61,8 @@ def get_prop_mapping(prop):
ImageProperties.IMAGE_NAME: lambda a: a["name"],
ImageProperties.IMAGE_SIZE: lambda a: a["size"],
ImageProperties.IMAGE_STATUS: lambda a: a["status"],
ImageProperties.IMAGE_OWNER: lambda a: a["metadata"]["owner_id"],
ImageProperties.IMAGE_METADATA: lambda a: json.dumps(a["metadata"]),
}
try:
return mapping[prop]
Expand Down
20 changes: 17 additions & 3 deletions openstackquery/mappings/image_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from openstackquery.aliases import QueryChainMappings
from openstackquery.enums.props.image_properties import ImageProperties
from openstackquery.enums.props.project_properties import ProjectProperties
from openstackquery.enums.props.server_properties import ServerProperties
from openstackquery.enums.query_presets import QueryPresets
from openstackquery.handlers.client_side_handler import ClientSideHandler
Expand All @@ -23,7 +24,10 @@ def get_chain_mappings() -> QueryChainMappings:
Return a dictionary containing property pairs mapped to query mappings.
This is used to define how to chain results from this query to other possible queries
"""
return {ImageProperties.IMAGE_ID: [ServerProperties.IMAGE_ID]}
return {
ImageProperties.IMAGE_ID: [ServerProperties.IMAGE_ID],
ImageProperties.IMAGE_OWNER: [ProjectProperties.PROJECT_ID],
}

@staticmethod
def get_runner_mapping() -> Type[ImageRunner]:
Expand Down Expand Up @@ -54,6 +58,7 @@ def get_server_side_handler() -> ServerSideHandler:
QueryPresets.EQUAL_TO: {
ImageProperties.IMAGE_NAME: lambda value: {"name": value},
ImageProperties.IMAGE_STATUS: lambda value: {"status": value},
ImageProperties.IMAGE_OWNER: lambda value: {"owner": value},
},
QueryPresets.ANY_IN: {
ImageProperties.IMAGE_NAME: lambda values: [
Expand All @@ -62,6 +67,9 @@ def get_server_side_handler() -> ServerSideHandler:
ImageProperties.IMAGE_STATUS: lambda values: [
{"status": value} for value in values
],
ImageProperties.IMAGE_OWNER: lambda values: [
{"owner": value} for value in values
],
},
QueryPresets.OLDER_THAN: {
ImageProperties.IMAGE_CREATION_DATE: lambda func=TimeUtils.convert_to_timestamp, **kwargs: {
Expand Down Expand Up @@ -127,8 +135,14 @@ def get_client_side_handler() -> ClientSideHandler:
QueryPresets.NOT_EQUAL_TO: ["*"],
QueryPresets.ANY_IN: ["*"],
QueryPresets.NOT_ANY_IN: ["*"],
QueryPresets.MATCHES_REGEX: [ImageProperties.IMAGE_NAME],
QueryPresets.NOT_MATCHES_REGEX: [ImageProperties.IMAGE_NAME],
QueryPresets.MATCHES_REGEX: [
ImageProperties.IMAGE_NAME,
ImageProperties.IMAGE_METADATA,
],
QueryPresets.NOT_MATCHES_REGEX: [
ImageProperties.IMAGE_NAME,
ImageProperties.IMAGE_METADATA,
],
QueryPresets.YOUNGER_THAN: date_prop_list,
QueryPresets.YOUNGER_THAN_OR_EQUAL_TO: date_prop_list,
QueryPresets.OLDER_THAN: date_prop_list,
Expand Down
8 changes: 7 additions & 1 deletion openstackquery/mappings/project_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Type

from openstackquery.aliases import QueryChainMappings
from openstackquery.enums.props.image_properties import ImageProperties
from openstackquery.enums.props.project_properties import ProjectProperties
from openstackquery.enums.props.server_properties import ServerProperties
from openstackquery.enums.query_presets import QueryPresets
Expand All @@ -22,7 +23,12 @@ def get_chain_mappings() -> QueryChainMappings:
Should return a dictionary containing property pairs mapped to query mappings.
This is used to define how to chain results from this query to other possible queries
"""
return {ProjectProperties.PROJECT_ID: [ServerProperties.PROJECT_ID]}
return {
ProjectProperties.PROJECT_ID: [
ServerProperties.PROJECT_ID,
ImageProperties.IMAGE_OWNER,
]
}

@staticmethod
def get_runner_mapping() -> Type[ProjectRunner]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="openstackquery",
version="1.3.0",
version="1.4.0",
author="STFC Cloud Team",
author_email="<cloud-support@stfc.ac.uk>",
description=DESCRIPTION,
Expand Down
6 changes: 5 additions & 1 deletion tests/enums/props/test_image_properties.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from unittest.mock import patch

import pytest

from openstackquery.enums.props.image_properties import ImageProperties
from openstackquery.exceptions.query_property_mapping_error import (
QueryPropertyMappingError,
)

from tests.mocks.mocked_props import MockProperties


Expand All @@ -30,6 +30,10 @@
(ImageProperties.IMAGE_NAME, ["image_name", "name"]),
(ImageProperties.IMAGE_SIZE, ["image_size", "size"]),
(ImageProperties.IMAGE_STATUS, ["image_status", "status"]),
(
ImageProperties.IMAGE_OWNER,
["image_owner", "owner", "tenant"],
),
],
)
def test_property_serialization(expected_prop, test_values, property_variant_generator):
Expand Down
10 changes: 8 additions & 2 deletions tests/mappings/test_image_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch

from openstackquery.enums.props.image_properties import ImageProperties
from openstackquery.enums.props.project_properties import ProjectProperties
from openstackquery.enums.props.server_properties import ServerProperties
from openstackquery.enums.query_presets import QueryPresets
from openstackquery.handlers.server_side_handler import ServerSideHandler
Expand Down Expand Up @@ -37,13 +38,14 @@ def test_server_side_handler_mappings_equal_to(server_side_test_mappings):
mappings = {
ImageProperties.IMAGE_NAME: "name",
ImageProperties.IMAGE_STATUS: "status",
ImageProperties.IMAGE_OWNER: "owner",
}

server_side_test_mappings(
ImageMapping,
QueryPresets.EQUAL_TO,
mappings,
test_case=(True, True),
test_case=(True, True, True),
)


Expand All @@ -59,11 +61,12 @@ def test_server_side_handler_mappings_any_in(server_side_any_in_mappings):
mappings = {
ImageProperties.IMAGE_NAME: "name",
ImageProperties.IMAGE_STATUS: "status",
ImageProperties.IMAGE_OWNER: "owner",
}
server_side_any_in_mappings(
ImageMapping,
mappings,
{"test1": "test1", "test2": "test2"},
{"test1": "test1", "test2": "test2", "test3": "test3"},
)


Expand Down Expand Up @@ -238,9 +241,11 @@ def test_client_side_handler(client_side_test_mappings):
QueryPresets.NOT_ANY_IN: ["*"],
QueryPresets.MATCHES_REGEX: [
ImageProperties.IMAGE_NAME,
ImageProperties.IMAGE_METADATA,
],
QueryPresets.NOT_MATCHES_REGEX: [
ImageProperties.IMAGE_NAME,
ImageProperties.IMAGE_METADATA,
],
QueryPresets.OLDER_THAN: date_prop_list,
QueryPresets.OLDER_THAN_OR_EQUAL_TO: date_prop_list,
Expand All @@ -260,6 +265,7 @@ def test_get_chain_mappings():
"""
expected_mappings = {
ImageProperties.IMAGE_ID: [ServerProperties.IMAGE_ID],
ImageProperties.IMAGE_OWNER: [ProjectProperties.PROJECT_ID],
}

assert set(ImageMapping.get_chain_mappings()) == set(expected_mappings)
8 changes: 7 additions & 1 deletion tests/mappings/test_project_mapping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from openstackquery.enums.props.image_properties import ImageProperties
from openstackquery.enums.props.project_properties import ProjectProperties
from openstackquery.enums.props.server_properties import ServerProperties
from openstackquery.enums.query_presets import QueryPresets
Expand Down Expand Up @@ -128,6 +129,11 @@ def test_get_chain_mappings():
"""
Tests get_chain_mapping outputs correctly
"""
expected_mappings = {ProjectProperties.PROJECT_ID: [ServerProperties.PROJECT_ID]}
expected_mappings = {
ProjectProperties.PROJECT_ID: [
ServerProperties.PROJECT_ID,
ImageProperties.IMAGE_OWNER,
]
}

assert set(ProjectMapping.get_chain_mappings()) == set(expected_mappings)