aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/wrapper/start.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/onaptests/steps/wrapper/start.py')
-rw-r--r--src/onaptests/steps/wrapper/start.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/onaptests/steps/wrapper/start.py b/src/onaptests/steps/wrapper/start.py
new file mode 100644
index 0000000..18ba5df
--- /dev/null
+++ b/src/onaptests/steps/wrapper/start.py
@@ -0,0 +1,64 @@
+"""Start simulators via simulators' API."""
+from typing import Union, Optional, Dict
+import requests
+from onaptests.steps.base import BaseStep
+from onaptests.utils.exceptions import TestConfigurationException
+
+class SimulatorStartStep(BaseStep):
+ """Basic operations on a docker container."""
+
+ def __init__(self, # pylint: disable=R0913
+ cleanup: bool = False,
+ https: bool = False,
+ host: str = None,
+ port: Union[int, str] = None,
+ endpoint: Optional[str] = "",
+ method: str = "GET",
+ data: Dict = None) -> None:
+ """Prepare request data and details.
+
+ Arguments:
+ cleanup (bool):
+ determines if cleanup action should be called.
+ Defaults to False.
+ https (bool): use https or http. Defaults to False.
+ host (str): IP or hostname. Defaults to None.
+ port (Union[int, str]): port number. Defaults to None.
+ endpoint (str):
+ additional endpoint if applicable.
+ Defautls to "".
+ method (str):
+ GET or POST strings, case insensitive.
+ Defaults tp GET.
+ data (Dict):
+ parameters, that request's post() or get() takes, besides url.
+ For example, {"json": {}, ...}. Defaults to None.
+ """
+ if not host and not port:
+ raise TestConfigurationException("Provide host and/or port.")
+
+ super().__init__(cleanup=cleanup)
+
+ default_port = "443" if https else "80"
+ protocol = "https" if https else "http"
+ endpoint = endpoint[1:] if endpoint.startswith("/") else endpoint
+
+ self.method = method
+ self.data = data if data else {}
+ self.url = f"{protocol}://{host}:{port or default_port}/{endpoint}"
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Send commands to the simulator application."
+
+ @property
+ def component(self) -> str:
+ """Component name."""
+ return "Environment"
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ """Send a start command to the simulator application."""
+ super().execute()
+ requests.request(self.method.upper(), self.url, **self.data)