-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from stfc/Use_vm_personality_first
Use vm personality first
- Loading branch information
Showing
10 changed files
with
195 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import Dict | ||
|
||
from mashumaro import DataClassDictMixin | ||
from mashumaro.config import BaseConfig | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass | ||
class AqMetadata(DataClassDictMixin): | ||
""" | ||
Deserialised metadata that is set either on an Openstack image | ||
or a VM's metadata | ||
""" | ||
|
||
aq_archetype: str | ||
# Aq domain can hold either a domain or sandbox reference | ||
aq_domain: str | ||
|
||
aq_personality: str | ||
aq_os_version: str | ||
aq_os: str | ||
|
||
# pylint: disable=too-few-public-methods | ||
class Config(BaseConfig): | ||
""" | ||
Sets the aliases for the metadata keys | ||
""" | ||
|
||
aliases = { | ||
"aq_archetype": "AQ_ARCHETYPE", | ||
"aq_domain": "AQ_DOMAIN", | ||
"aq_personality": "AQ_PERSONALITY", | ||
"aq_os_version": "AQ_OSVERSION", | ||
"aq_os": "AQ_OS", | ||
} | ||
|
||
def override_from_vm_meta(self, vm_meta: Dict[str, str]): | ||
""" | ||
Overrides the values in the metadata with the values from the VM's | ||
metadata | ||
""" | ||
for attr, alias in self.Config.aliases.items(): | ||
if alias in vm_meta: | ||
setattr(self, attr, vm_meta[alias]) | ||
|
||
if "AQ_SANDBOX" in vm_meta: | ||
self.aq_domain = vm_meta["AQ_SANDBOX"] |
20 changes: 0 additions & 20 deletions
20
OpenStack-Rabbit-Consumer/rabbit_consumer/image_metadata.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import Dict | ||
|
||
import pytest | ||
|
||
from rabbit_consumer.aq_metadata import AqMetadata | ||
|
||
|
||
@pytest.fixture(name="image_metadata") | ||
def fixture_image_metadata() -> Dict[str, str]: | ||
""" | ||
Creates a dictionary with mock data | ||
which represents an example OpenStack image's metadata | ||
""" | ||
return { | ||
"AQ_ARCHETYPE": "archetype_mock", | ||
"AQ_DOMAIN": "domain_mock", | ||
"AQ_PERSONALITY": "personality_mock", | ||
"AQ_OS": "os_mock", | ||
"AQ_OSVERSION": "osversion_mock", | ||
} | ||
|
||
|
||
def test_aq_metadata_from_initial_dict(image_metadata): | ||
""" | ||
Tests creating an AQ metadata object from an initial dictionary | ||
""" | ||
returned = AqMetadata.from_dict(image_metadata) | ||
|
||
assert returned.aq_archetype == "archetype_mock" | ||
assert returned.aq_domain == "domain_mock" | ||
assert returned.aq_personality == "personality_mock" | ||
assert returned.aq_os == "os_mock" | ||
assert returned.aq_os_version == "osversion_mock" | ||
|
||
|
||
def test_aq_metadata_override_all(image_metadata): | ||
""" | ||
Tests overriding all values in an AQ metadata object | ||
""" | ||
returned = AqMetadata.from_dict(image_metadata) | ||
returned.override_from_vm_meta( | ||
{ | ||
"AQ_ARCHETYPE": "archetype_mock_override", | ||
"AQ_DOMAIN": "domain_mock_override", | ||
"AQ_PERSONALITY": "personality_mock_override", | ||
} | ||
) | ||
|
||
assert returned.aq_archetype == "archetype_mock_override" | ||
assert returned.aq_domain == "domain_mock_override" | ||
assert returned.aq_personality == "personality_mock_override" | ||
|
||
# Check the original values are still there | ||
assert returned.aq_os == "os_mock" | ||
assert returned.aq_os_version == "osversion_mock" | ||
|
||
|
||
def test_aq_metadata_override_sandbox(image_metadata): | ||
""" | ||
Tests overriding the sandbox value in an AQ metadata object | ||
maps correctly onto the domain value | ||
""" | ||
returned = AqMetadata.from_dict(image_metadata) | ||
returned.override_from_vm_meta( | ||
{ | ||
"AQ_SANDBOX": "sandbox_mock", | ||
} | ||
) | ||
# This should be the only value that has changed | ||
assert returned.aq_domain == "sandbox_mock" | ||
|
||
assert returned.aq_archetype == "archetype_mock" | ||
assert returned.aq_personality == "personality_mock" | ||
assert returned.aq_os == "os_mock" | ||
assert returned.aq_os_version == "osversion_mock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.1 | ||
2.3.0 |
Oops, something went wrong.