-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into small-reame-fix
- Loading branch information
Showing
18 changed files
with
508 additions
and
47 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,30 @@ | ||
""" | ||
This module provides kubernetes functionality based on original docker SDK python library. | ||
""" | ||
|
||
import docker | ||
|
||
|
||
class DockerWrapper: | ||
|
||
def __init__(self, config=None): | ||
if config.base_url != "": | ||
self.client = docker.DockerClient(base_url=config.base_url) | ||
else: | ||
self.client = docker.from_env() | ||
|
||
def exec_command(self, container_name: str, command: str, param_value: str, resource: str): | ||
""" | ||
This function retrieves container by name / id and executes (docker exec) command to container | ||
@param container_name: Container id or name | ||
@param command: String command to be executed (for docker exec) | ||
@param param_value: Command function parameter value to be updated | ||
@param resource: Path to resource file | ||
@return: Command output, if exists | ||
""" | ||
container = self.client.containers.get(container_id=container_name) | ||
command_f = f"{command} {param_value} {resource}" | ||
exit_code, output = container.exec_run(cmd=command_f) | ||
if exit_code > 0: | ||
return '' | ||
return output.decode().strip() |
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,82 @@ | ||
""" | ||
This module provides input / output manipulations on streams / files | ||
""" | ||
|
||
import os | ||
import io | ||
import json | ||
import yaml | ||
import shutil | ||
from pathlib import Path | ||
from munch import Munch | ||
|
||
|
||
def get_logs_from_stream(stream: str) -> list[Munch]: | ||
""" | ||
This function converts logs stream to list of Munch objects (dictionaries) | ||
@param stream: StringIO stream | ||
@return: List of Munch objects | ||
""" | ||
|
||
logs = io.StringIO(stream) | ||
result = [] | ||
# with open("pod_logs.log", 'a') as pod_log_file: | ||
# pod_log_file.writelines(logs) | ||
for log in logs: | ||
# current_log = log.split(sep="Z ")[1] | ||
if log and "bundles" in log: | ||
result.append(Munch(json.loads(log))) | ||
return result | ||
|
||
|
||
def get_k8s_yaml_objects(file_path: Path) -> list[str: dict]: | ||
""" | ||
This function loads yaml file, and returns the following list: | ||
[ {<k8s_kind> : {<k8s_metadata}}] | ||
:param file_path: YAML path | ||
:return: [ {<k8s_kind> : {<k8s_metadata}}] | ||
""" | ||
if not file_path: | ||
raise Exception(f'{file_path} is required') | ||
result_list = [] | ||
with file_path.open() as yaml_file: | ||
yaml_objects = yaml.safe_load_all(yaml_file) | ||
for yml_doc in yaml_objects: | ||
if yml_doc: | ||
doc = Munch(yml_doc) | ||
result_list.append({ | ||
doc.get('kind'): {key: value for key, value in doc.get('metadata').items() | ||
if key in ['name', 'namespace']} | ||
}) | ||
return result_list | ||
|
||
|
||
class FsClient: | ||
|
||
@staticmethod | ||
def exec_command(container_name: str, command: str, param_value: str, resource: str): | ||
""" | ||
This function executes os command | ||
@param container_name: Container node | ||
@param command: Linux command to be executed | ||
@param param_value: Value to be used in exec command | ||
@param resource: File / Resource path | ||
@return: None | ||
""" | ||
|
||
if container_name == '': | ||
raise Exception(f"Unknown {container_name} is sent") | ||
|
||
current_resource = Path(resource) | ||
if not current_resource.is_file(): | ||
raise Exception(f"File {resource} does not exist or mount missing.") | ||
|
||
if command == 'chmod': | ||
os.chmod(path=resource, mode=int(param_value)) | ||
elif command == 'chown': | ||
uid_gid = param_value.split(':') | ||
if len(uid_gid) != 2: | ||
raise Exception("User and group parameter shall be separated by ':' ") | ||
shutil.chown(path=resource, user=uid_gid[0], group=uid_gid[1]) | ||
else: | ||
raise Exception(f"Command '{command}' still not implemented in test framework") |
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 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
cloudbeat: | ||
deploy: true | ||
deploy: true | ||
|
||
testData: | ||
marker: ci_cloudbeat |
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,2 +1,5 @@ | ||
cloudbeat: | ||
deploy: false | ||
deploy: false | ||
|
||
testData: | ||
marker: rules |
Oops, something went wrong.