Skip to content

Add methods to CAS Management #129

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

Merged
merged 17 commits into from
Sep 6, 2022

Conversation

SilvestriStefano
Copy link
Contributor

@SilvestriStefano SilvestriStefano commented Aug 2, 2022

Hello,
I noticed that some methods are missing from the CAS Management service. I am thinking of adding the following for starters

  • list/create/delete sessions
  • load or unload a table
  • save a table
  • change scope of table

with related tests as well:

  • list/create/delete sessions
  • load or unload a table
  • save a table
  • change scope of table

Any suggestion/feedback is highly appreciated.

Question/curiosity: is there a reason why f-strings are not used?

Signed-off-by: Stefano Silvestri ssilvestri@olab-studio.com

@smlindauer
Copy link
Collaborator

Hey @SilvestriStefano,

We do not use f-strings since we still support users back to Python 3.5 and f-strings were introduced in Python 3.6.

I'm opening up the merge request to the git actions now, so those should begin to run momentarily.

If this is a WIP, would it be better to merge your updates into a new branch?

@SilvestriStefano
Copy link
Contributor Author

SilvestriStefano commented Aug 2, 2022

Hello,
I put the WIP tag because I haven't finished writing all the methods. I should have made a Draft pr, my bad.
If you prefer we can merge to a different branch.

@SilvestriStefano SilvestriStefano marked this pull request as draft August 2, 2022 12:31
@SilvestriStefano SilvestriStefano marked this pull request as ready for review September 1, 2022 14:18
@SilvestriStefano
Copy link
Contributor Author

SilvestriStefano commented Sep 1, 2022

Hi,
I have added all the functionality that I set out to do. I had to modify the upload_table() method because it was not working for me.

Originally, in the post request was written files={name: file} which I changed to files={'files':(name,file)}. I followed the instructions from the request documentation. I have also added an extra optional keyword argument which allows for more details to be passed in the body of the request.

I have not added a test method for the update_state_table() method as it is used and tested in other tests. Also I do not have permissions to promote or change state on tables in the Samples caslib. This means I would need to upload the table first in some other caslib and then change the state, which is exactly what I do in the test_upload_file() method.

@SilvestriStefano SilvestriStefano changed the title [WIP] - Add methods to CAS Management Add methods to CAS Management Sep 1, 2022
@smlindauer
Copy link
Collaborator

Hey @SilvestriStefano,

This looks great! I am in the process of reformatting the sasctl code base to fully follow PEP8 guidelines, so I made a number of comments in my review focused on those reformatting instances. The only logic change I suggested was with regards to adding a new function to handle the many key checks.

Thank you for creating the integration tests and their associated cassettes. I also noticed that cas_management is not subject to any unit tests, so I will add that to my to do list.

Copy link
Collaborator

@smlindauer smlindauer left a comment

Choose a reason for hiding this comment

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

Initial review

@@ -8,6 +8,10 @@

from .service import Service


from typing import Union, TextIO
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we shift this back up just below "import os" to minimize extra whitespace in the imports? And to clearly separate python built-in, external library, and sasctl-specific imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

"""
Returns a collection of sessions available on the CAS server.

Params
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Format Matching] Please use "Parameters" to match sasctl docstring format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad. It should be fixed now.

@@ -22,7 +26,125 @@ class CASManagement(Service):
list_servers, get_server, _, _ = Service._crud_funcs("/servers", "server")

@classmethod
def list_caslibs(cls, server, filter_=None):
def list_sessions(cls, qparams: dict = None, server: str = None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

change to query_params: more verbose variable names help with cognitive complexity and underscore instead of camelcase follows PEP8 S117 rule for variable naming convention

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


Params
------
queryParams : dict, optional
Copy link
Collaborator

Choose a reason for hiding this comment

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

query_params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"""
server = server or DEFAULT_SERVER

if qparams is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

query_params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if ("sourceTableName" not in qParam.keys()
and "quiet" not in qParam.keys()
and "removeAcs" not in qParam.keys()):
raise Exception(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use ValueError here instead of a general exception?

Copy link
Contributor Author

@SilvestriStefano SilvestriStefano Sep 2, 2022

Choose a reason for hiding this comment

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

done in the second helper function check_required_key

"Missing required query parameters `sourceTableName`, `quiet`, `removeAcs`"
)
else:
query = qParam
Copy link
Collaborator

Choose a reason for hiding this comment

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

query_params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

else:
raise ValueError(
"The only acceptable query parameters are %s and must be passed in a dictionary"
% (allowedQ)
Copy link
Collaborator

Choose a reason for hiding this comment

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

allowed_queries & unnecessary parentheses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

server : str, optional
Server where the `caslib` is registered.
Defaults to `cas-shared-default`.
qparams: dict, optional
Copy link
Collaborator

Choose a reason for hiding this comment

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

query_params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


from typing import Union, TextIO


DEFAULT_SERVER = "cas-shared-default"
DEFAULT_CASLIB = "casuser"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a classless function up here to handle the many key checks? Something like:

check_valid_keys(valid_keys, input_keys, parameter_name):
if not all(key in valid_keys for key in input_keys):
raise ValueError("The only acceptable values for %s are %s" % (parameter_name, valid_keys))

i.e. change

elif (
format_ == 'csv' and
not all(key in allowed_body_csv for key in input_keys)
):
raise ValueError(
"The parameters specific to a csv file are %s." % allowed_body_csv
)

to

elif format_ == "csv":
check_valid_keys(allowed_body_csv, input_keys, "csv parameters")

Copy link
Contributor Author

@SilvestriStefano SilvestriStefano Sep 2, 2022

Choose a reason for hiding this comment

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

As requested, I have added two functions that handles the many checks: one for checking that the keys entered are valid, and one that checks that required keys are being passed as inputs.

@SilvestriStefano
Copy link
Contributor Author

Hello @smlindauer,
I ll make all the suggested changes.

Thank you for reviewing.

@SilvestriStefano
Copy link
Contributor Author

I want to mention that I changed the DEFAULT_CASLIB value to Samples since casuser is not a valid caslib. The caslib associated to a user is CASUSER(user_id) were user_id is the id of the user (for example in my integration tests I have used CASUSER(X1064007) )

@smlindauer
Copy link
Collaborator

I want to mention that I changed the DEFAULT_CASLIB value to Samples since casuser is not a valid caslib. The caslib associated to a user is CASUSER(user_id) were user_id is the id of the user (for example in my integration tests I have used CASUSER(X1064007) )

Should we go with Samples or would Public make more sense? I believe Public and Samples are always created, but Public is more likely to contain CAS data that users would be using.

@SilvestriStefano
Copy link
Contributor Author

@smlindauer you are right. The "Public" caslib makes more sense as the default one. I made the change.

@smlindauer smlindauer merged commit a242abf into sassoftware:master Sep 6, 2022
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