Skip to content

Commit

Permalink
#451 backwards compatibility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Mar 11, 2022
1 parent d39acd0 commit b791e4d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
12 changes: 12 additions & 0 deletions libraries/cloudharness-common/cloudharness/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class ConfigurationCallException(Exception):

class ApplicationConfiguration(ApplicationConfig):

def __init__(self, *args, **kargs):
ApplicationConfig.__init__(self, *args, **kargs)
self.__conf = None

def is_auto_service(self) -> bool:
return self.harness.service.auto
Expand All @@ -36,6 +39,15 @@ def get_db_connection_string(self) -> str:
@property
def db_name(self) -> str:
return self.harness.database.name

@property
def conf(self):
"""
Legacy object
"""
if self.__conf is None:
self.__conf = ConfigObject(self.to_dict())
return self.__conf

@property
def image_name(self) -> str:
Expand Down
5 changes: 4 additions & 1 deletion libraries/cloudharness-common/tests/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def test_application_conf():
assert uut.is_sentry_enabled()

d2 = {'admin': {'pass': 'metacell', 'role': 'administrator', 'user': 'admin'}, 'client': {'id': 'rest-client', 'secret': '5678eb6e-9e2c-4ee5-bd54-34e7411339e8'}, 'enabled': True, 'harness': {'aliases': [], 'database': {'auto': True, 'mongo': {'image': 'mongo:5', 'ports': [{'name': 'http', 'port': 27017}]}, 'name': 'keycloak-postgres', 'neo4j': {'dbms_security_auth_enabled': 'false', 'image': 'neo4j:4.1.9', 'memory': {'heap': {'initial': '64M', 'max': '128M'}, 'pagecache': {'size': '64M'}, 'size': '256M'}, 'ports': [{'name': 'http', 'port': 7474}, {'name': 'bolt', 'port': 7687}]}, 'pass': 'password', 'postgres': {'image': 'postgres:10.4', 'initialdb': 'auth_db', 'ports': [{'name': 'http', 'port': 5432}]}, 'resources': {'limits': {'cpu': '1000m', 'memory': '2Gi'}, 'requests': {'cpu': '100m', 'memory': '512Mi'}}, 'size': '2Gi', 'type': 'postgres', 'user': 'user'}, 'dependencies': {'build': [], 'hard': [], 'soft': []}, 'deployment': {'auto': True, 'image': 'osb/accounts:3e02a15477b4696ed554e08cedf4109c67908cbe6b03331072b5b73e83b4fc2b', 'name': 'accounts', 'port': 8080, 'replicas': 1, 'resources': {'limits': {'cpu': '500m', 'memory': '1024Mi'}, 'requests': {'cpu': '10m', 'memory': '512Mi'}}}, 'domain': None, 'env': [{'name': 'KEYCLOAK_IMPORT', 'value': '/tmp/realm.json'}, {'name': 'KEYCLOAK_USER', 'value': 'admin'}, {'name': 'KEYCLOAK_PASSWORD', 'value': 'metacell'}, {'name': 'PROXY_ADDRESS_FORWARDING', 'value': 'true'}, {'name': 'DB_VENDOR', 'value': 'POSTGRES'}, {'name': 'DB_ADDR', 'value': 'keycloak-postgres'}, {'name': 'DB_DATABASE', 'value': 'auth_db'}, {'name': 'DB_USER', 'value': 'user'}, {'name': 'DB_PASSWORD', 'value': 'password'}, {'name': 'JAVA_OPTS', 'value': '-server -Xms64m -Xmx896m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED'}], 'name': 'accounts', 'readinessProbe': {'path': '/auth/realms/master'}, 'resources': [{'dst': '/tmp/realm.json', 'name': 'realm-config', 'src': 'realm.json'}], 'secrets': '', 'secured': False, 'service': {'auto': True, 'name': 'accounts', 'port': 8080}, 'subdomain': 'accounts', 'uri_role_mapping': [{'roles': ['administrator'], 'uri': '/*'}], 'use_services': []}, 'harvest': True, 'image': 'osb/accounts:latest', 'name': 'accounts', 'port': 8080, 'resources': {'limits': {'cpu': '500m', 'memory': '1024Mi'}, 'requests': {'cpu': '10m', 'memory': '512Mi'}}, 'task-images': {}, 'webclient': {'id': 'web-client', 'secret': '452952ae-922c-4766-b912-7b106271e34b'}}
ApplicationConfiguration.from_dict(d2)
uut = ApplicationConfiguration.from_dict(d2)
assert uut.conf
assert uut.conf.admin.role == 'administrator'
assert uut.conf["admin.role"] == 'administrator'

def test_get_configuration():
CloudharnessConfig.apps = {
Expand Down
4 changes: 2 additions & 2 deletions libraries/models/cloudharness_model/models/base_model_.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def to_dict(self):
result[humps.camelize(attr)] = result[attr]


if hasattr(self, "raw_dict"):
merged = dict(self.raw_dict)
if hasattr(self, "_raw_dict"):
merged = dict(self._raw_dict)
merged.update(result)
return merged
return result
Expand Down
1 change: 1 addition & 0 deletions libraries/models/test/test_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ def test_dict_behaviour():
u = user.to_dict()
assert u["first_name"] == "e"
assert u["firstName"] == "e"

5 changes: 4 additions & 1 deletion libraries/models/test/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def test_json_serialize():
assert v["name"] == cloned["name"]

values["apps"]["accounts"]["harness"] = ApplicationHarnessConfig(name="accounts2")
values["apps"]["accounts"]["other"] = "test"
v = HarnessMainConfig.from_dict(values)
assert v["apps"]["accounts"]["harness"]["name"] == "accounts2"
assert v["apps"]["accounts"]["other"] == "test"
dumped = json.dumps(v, cls=CloudHarnessJSONEncoder)
cloned = json.loads(dumped)
assert v["name"] == cloned["name"]
assert cloned["apps"]["accounts"]["harness"]["name"] == "accounts2"
assert cloned["apps"]["accounts"]["harness"]["name"] == "accounts2"
assert cloned["apps"]["accounts"]["other"] == "test"

0 comments on commit b791e4d

Please sign in to comment.