forked from Kuadrant/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Kuadrant#361 from pehala/backend_reorg
Reorganize backend classes
- Loading branch information
Showing
11 changed files
with
100 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Module containing all the Backends""" | ||
|
||
from abc import abstractmethod | ||
|
||
from testsuite.gateway import Referencable | ||
from testsuite.lifecycle import LifecycleObject | ||
|
||
|
||
class Backend(LifecycleObject, Referencable): | ||
"""Backend (workload) deployed in Kubernetes""" | ||
|
||
@property | ||
@abstractmethod | ||
def url(self): | ||
"""Returns internal URL for this backend""" |
6 changes: 3 additions & 3 deletions
6
testsuite/openshift/httpbin.py → testsuite/backend/httpbin.py
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,69 @@ | ||
"""Mockserver implementation as Backend""" | ||
|
||
from testsuite.backend import Backend | ||
from testsuite.openshift import Selector | ||
from testsuite.openshift.client import OpenShiftClient | ||
from testsuite.openshift.deployment import Deployment, ContainerResources | ||
from testsuite.openshift.service import Service, ServicePort | ||
|
||
|
||
class MockserverBackend(Backend): | ||
"""Mockserver deployed as backend in Kubernetes""" | ||
|
||
PORT = 8080 | ||
|
||
def __init__(self, openshift: OpenShiftClient, name: str, label: str): | ||
self.openshift = openshift | ||
self.name = name | ||
self.label = label | ||
|
||
self.deployment = None | ||
self.service = None | ||
|
||
@property | ||
def reference(self): | ||
return { | ||
"group": "", | ||
"kind": "Service", | ||
"port": self.PORT, | ||
"name": self.name, | ||
"namespace": self.openshift.project, | ||
} | ||
|
||
@property | ||
def url(self): | ||
return f"{self.name}.{self.openshift.project}.svc.cluster.local" | ||
|
||
def commit(self): | ||
match_labels = {"app": self.label, "deployment": self.name} | ||
self.deployment = Deployment.create_instance( | ||
self.openshift, | ||
self.name, | ||
container_name="mockserver", | ||
image="quay.io/mganisin/mockserver:latest", | ||
ports={"api": 1080}, | ||
selector=Selector(matchLabels=match_labels), | ||
labels={"app": self.label}, | ||
resources=ContainerResources(limits_memory="2G"), | ||
lifecycle={"postStart": {"exec": {"command": ["/bin/sh", "init-mockserver"]}}}, | ||
) | ||
self.deployment.commit() | ||
self.deployment.wait_for_ready() | ||
|
||
self.service = Service.create_instance( | ||
self.openshift, | ||
self.name, | ||
selector=match_labels, | ||
ports=[ServicePort(name="1080-tcp", port=self.PORT, targetPort="api")], | ||
labels={"app": self.label}, | ||
) | ||
self.service.commit() | ||
|
||
def delete(self): | ||
with self.openshift.context: | ||
if self.service: | ||
self.service.delete() | ||
self.service = None | ||
if self.deployment: | ||
self.deployment.delete() | ||
self.deployment = None |
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
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 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