Skip to content

Commit

Permalink
Process rules tests addition
Browse files Browse the repository at this point in the history
  • Loading branch information
jeniawhite committed May 19, 2022
1 parent 5f59493 commit 92bab7d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion JUSTFILE
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ gen-report:
allure generate tests/allure/results --clean -o tests/allure/reports && cp tests/allure/reports/history/* tests/allure/results/history/. && allure open tests/allure/reports

run-tests:
helm test cloudbeat-tests --namespace kube-system
helm test cloudbeat-tests --namespace kube-system --logs

build-load-run-tests: build-pytest-docker load-pytest-kind run-tests

prepare-local-helm-cluster: create-kind-cluster build-cloudbeat load-cloudbeat-image deploy-local-tests-helm
46 changes: 43 additions & 3 deletions tests/commonlib/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
from pathlib import Path
from munch import Munch, munchify
import time


def get_logs_from_stream(stream: str) -> list[Munch]:
Expand Down Expand Up @@ -100,14 +101,53 @@ def exec_command(container_name: str, command: str, param_value: str, resource:

current_resource = Path(resource)
if not current_resource.is_file():
raise Exception(f"File {resource} does not exist or mount missing.")
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 ':' ")
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")
raise Exception(
f"Command '{command}' still not implemented in test framework")

@staticmethod
def edit_process_file(container_name: str, dictionary, resource: str):
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.")

with current_resource.open() as f:
r_file = yaml.safe_load(f)

command = r_file["spec"]["containers"][0]["command"]
set_dict = dictionary.get("set", {})
unset_list = dictionary.get("unset", [])

for skey, svalue in set_dict.items():
if any(skey == x.split("=")[0] for x in command):
command = list(map(lambda x: x.replace(
x, skey + "=" + svalue) if skey == x.split("=")[0] else x, command))
else:
command.append(skey + "=" + svalue)

for uskey in unset_list:
command = [x for x in command if uskey != x.split("=")[0]]

r_file["spec"]["containers"][0]["command"] = command

with current_resource.open(mode="w") as f:
yaml.dump(r_file, f)

# Wait for process reboot
# TODO: Implement a more optimal way of waiting
time.sleep(60)

0 comments on commit 92bab7d

Please sign in to comment.