Skip to content
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

Issue/662 default storage class #745

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

fraugabel
Copy link
Contributor

fixed two bugs:

  1. make sure sonobuoy result file can be written
  2. cleanup test-pod at failure aswell, so the next run won't crash

Katharina Trentau added 9 commits September 9, 2024 13:31
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
Signed-off-by: Katharina Trentau <[email protected]>
@fraugabel fraugabel force-pushed the issue/662_default_storage_class branch from be2c002 to 7e9061a Compare September 9, 2024 11:33
Signed-off-by: Katharina Trentau <[email protected]>
Copy link
Member

@martinmo martinmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of review done, see inline comments.

Some general observations:

If the connection to the cluster fails, the script tries to continue anyway with the all the steps, which it shouldn't do.

The script still doesn't check if a provisioner such as cinder-csi is used.

@@ -1,8 +1,11 @@
aiohttp
click
fabric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fabric

This seems like a leftover from the rebase. The fabric dependency has been removed in main via 18a3dae.

Please regenerate the requirements.txt again afterwards.

kubernetes_asyncio
python-dateutil
PyYAML
openstacksdk
requests
tomli

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +84 to +90
def cleanup():
logger.debug(f"delete pod:{pod_name}")
api_response = k8s_api_instance.delete_namespaced_pod(pod_name, namespace)
logger.debug(f"delete pvc:{pvc_name}")
api_response = k8s_api_instance.delete_namespaced_persistent_volume_claim(
pvc_name, namespace
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please move the cleanup() function to the module level and use function arguments
  • The api_response is not checked. If that's intended, leave it out. But it might be better to check it and report to the user.
  • Also note that, during cleanup, exceptions could occur, which are currently not handled.

@@ -135,10 +143,9 @@ def check_default_persistentvolumeclaim_readwriteonce(k8s_api_instance, storage_
pod_info = json.loads(api_response.read().decode("utf-8"))
pod_status = pod_info["status"]["phase"]

# Check if pod is up and running:
# Check if pod is up and running: Default Retries 30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a comment here, I would suggest to replace the 30 literal in the while loop below with a module level constant (e.g., NUM_RETRIES = 30).

@@ -152,6 +159,7 @@ def check_default_persistentvolumeclaim_readwriteonce(k8s_api_instance, storage_
if pod_status != "Running":
raise SCSTestException(
"pod is not Running not able to setup test Enviornment",
cleanup(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. cleanup() will be immediately executed and the result, which is None, will be passed as an argument to the SCSTestException.

@@ -172,28 +180,24 @@ def check_default_persistentvolumeclaim_readwriteonce(k8s_api_instance, storage_
if pv["status"]["phase"] != "Bound":
raise SCSTestException(
"Not able to bind pv to pvc",
cleanup(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

return_code=41,
)

if "ReadWriteOnce" not in pv["spec"]["accessModes"]:
raise SCSTestException(
"access mode 'ReadWriteOnce' is not supported",
cleanup(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

api_response = k8s_api_instance.delete_namespaced_persistent_volume_claim(
pvc_name, namespace
)
cleanup()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are four places were a cleanup() call is inserted, but there should be one central place.

My suggestion would be to make use of the try ... finally construct, doing the cleanup in the finally block.

Or you could build a context manager that supports the with statement. An example of this can be found with the TestEnvironment class in the IaaS entropy check (usage).

Comment on lines +68 to +72
directory_path = os.path.dirname(f"./{test_name}.result.yaml")
os.makedirs(directory_path, exist_ok=True)

with open(f"./{test_name}.result.yaml", "w") as file:
yaml.dump(result_file, file)
with open(f"./{test_name}.result.yaml", "w") as file:
yaml.dump(result_file, file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still creates a file hierarchy replicating the absolute path to the script file, e.g. for me it creates:

/home/martinmorgenstern/workspace/scs/standards/Tests/home/martinmorgenstern/workspace/scs/standards/Tests/kaas/k8s-default-storage-class

The reason is that __file__ (which is the absolute path to the script) is used as the test_file_name argument passed to gen_sonobuoy_result_file and used without further processing.

In main(), you should use os.path.basename(__file__) to get only the script filename without the directories.

@@ -56,19 +56,17 @@ def setup_k8s_client(kubeconfigfile=None):


def gen_sonobuoy_result_file(error_n: int, error_msg: str, test_file_name: str):

test_name = test_file_name.replace(".py", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test_name = test_file_name.replace(".py", "")
test_name = test_file_name.removesuffix(".py")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants