-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move CSI attach detach test and rewrite script in Python #412
base: main
Are you sure you want to change the base?
Conversation
9e1bd29
to
4464115
Compare
4464115
to
ab2ae37
Compare
101c9a7
to
10e0296
Compare
10e0296
to
514b28f
Compare
9d8e600
to
5652571
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add unit tests for the functions at csi.py
p99 = disk_number * 99 // 100 | ||
return p50, p90, p99, disk_number | ||
|
||
def create_statefulset(namespace, replicas, storage_class): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be inside of KubernetesClient
. Therefore, we can re-use it other scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm debating this because lots of spec define here are solely used in this test so not sure if it's worth putting in KubernetesClient. That's why I have a get_app_client() so at least I can re-use the client
def log_duration(description, start_time, log_file): | ||
"""Log the time duration of an operation.""" | ||
end_time = datetime.now() | ||
duration = int((end_time - start_time).total_seconds()) | ||
with open(log_file, "a") as f: | ||
f.write(f"{description}: {duration}\n") | ||
print(f"{description}: {duration}s") | ||
|
||
def wait_for_condition(check_function, target, comparison="gte", interval=1): | ||
"""Wait for a condition using a given check function.""" | ||
while True: | ||
current_list = check_function() | ||
current = len(current_list) | ||
print(f"Current: {current}, Target: {target}") | ||
if (comparison == "gte" and current >= target) or (comparison == "lte" and current <= target): | ||
return current | ||
time.sleep(interval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- These functions could be in some utils file
- Add to the
wait_for_condition
description what thecheck_function
should return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean util file under csi
folder? I don't think these are useful for other folders like clusterloader2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They might still be useful for other tests in the future. Note: this is not critical. Feel free to address it in another PR.
end_time = datetime.now() | ||
duration = int((end_time - start_time).total_seconds()) | ||
with open(log_file, "a") as f: | ||
f.write(f"{description}: {duration}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets put quotes ("") in the key and value or add a validation to check if the description does not contains :
, what would break the parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description and duration are passed inside the test only though. I don't think that check is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but someone can change the description in the future and don't notice that it breaks this logic
ed79eb6
to
0632933
Compare
25de0d8
to
1c1be6f
Compare
|
||
ns = self.client.create_namespace(name) | ||
self.assertEqual(ns.metadata.name, mock_read_namespace.return_value.metadata.name) | ||
mock_read_namespace.assert_called_once_with(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of it, assert that the "kubernetes.client.CoreV1Api.create_namespace" was not called
self.assertEqual(len(returned_pods), len(expected_pods)) | ||
self.assertEqual(returned_pods, expected_pods) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: you can replace those with only self.assertCountEqual(expected_pods, returned_pods)
Summary