Regroup all session creation in util get_localAPI_session or APISession class. - #129
Regroup all session creation in util get_localAPI_session or APISession class.#129Ythogtha wants to merge 8 commits into
Conversation
0f82c30 to
be646e3
Compare
e1507b2 to
c0658d5
Compare
eae5e31 to
cee2b15
Compare
bc30ef6 to
1dfb701
Compare
cee2b15 to
4a333e5
Compare
Millefeuille42
left a comment
There was a problem hiding this comment.
All good for me except the remaining import util
bd3737d to
119cae3
Compare
d23fa61 to
8173b33
Compare
252789d to
d8ca026
Compare
e712aa5 to
fce2d13
Compare
8173b33 to
3c34049
Compare
3c34049 to
95a0211
Compare
…on class. New APISession class to handle lifecycle of the session, with context, or atexit handlers. Use various originator for xapi session creation, to differentiate where they are being created. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
Do not SMlog information when __del__ is called and the session has already been closed. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
… are set. SMlogs are set to LOG_DEBUG, except on failure to create a session. Fixed some less readable code: - lcache.py: import util on top instead of inside a method - util.py; removed double tempfile import Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
…out calls, privatise some APISession methods. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
Also fix some strings. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
…in cleanup.py Due to the rebase, some old-style session management appeared, this commit makes them use the new APISession. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
| api_session = util.timeout(5, util.APISession, "blktap-abort_linstor_gc") | ||
| session = api_session.session | ||
| try: | ||
| srs = util.get_linstor_srs_uuid(session) |
There was a problem hiding this comment.
| api_session = util.timeout(5, util.APISession, "blktap-abort_linstor_gc") | |
| session = api_session.session | |
| try: | |
| srs = util.get_linstor_srs_uuid(session) | |
| api_session = util.timeout(5, util.APISession, "SM-blktap2-abort-linstor-gc") | |
| try: | |
| srs = util.get_linstor_srs_uuid(api_session.session) |
Just to remove a temporary variable (and change session name to match other names and SM-blktap2 prefix). (:
There was a problem hiding this comment.
"SM-blktap2-abort-linstor-gc" is not applied in new commits.
| if self.session is None: | ||
| self.session = self.getSession() | ||
| self.sessionPrivate = True | ||
| self._api_session = util.APISession("SM-cleanup-XAPI") |
There was a problem hiding this comment.
I think we should standardize the names here. An "SMGC" prefix could match the existing logs. Or maybe "SM-GC" or just "GC". What do you think? @Ythogtha @Millefeuille42
There was a problem hiding this comment.
I'm goign for SM-GC, and looking at all APISession being opened as SM-{something}.
There was a problem hiding this comment.
Not fond of SM-GC even if more coherent with the rest, as GC related logs are identified as "SMGC" already.
Aug 4 07:29:34 r640-s1 SMGC: [2091943][MainThread] GC process exiting, no work left
If looking for anything GC related in the logs I know to check for "SMGC".
| # Everything was coalescable, remove the message | ||
| xapi_session.xenapi.SR.remove_from_sm_config(self.xapi.srRef, VDI.DB_GC_NO_SPACE) | ||
| xapi_session.xenapi.message.destroy(msg_id) | ||
| with util.APISession("GC-check_no_space") as xapi_session: |
There was a problem hiding this comment.
| with util.APISession("GC-check_no_space") as xapi_session: | |
| with util.APISession("XXX-check-no-space") as xapi_session: |
Suggested in a previous comment. 👀
But XXX because we must discuss about the prefix to use.
There was a problem hiding this comment.
check-no-space with "-" is not applied in new commits.
| )) | ||
| finally: | ||
| session.xenapi.session.logout() | ||
| with util.timeout(5), util.APISession("GC-coalescing") as session: |
Reworked some APISession originator for better consistency. Removed unuseful `session` intermediate variables. Reworked restevdis to avoid a huge indentation caused by APISession, by using a function. Adds a try/finally for session.logout() in util.py#sr_get_capability(). Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
fb254f1 to
c4d891b
Compare
Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
Millefeuille42
left a comment
There was a problem hiding this comment.
OK for me if and when all pending comments are resolved.
| def _init_executor_thread(self): | ||
| session = util.get_localAPI_session() | ||
| load = self.Load(session) | ||
| api_session = util.ApiSession("SM-linstorvhdutil") |
There was a problem hiding this comment.
I'd suggest to see if we can get automatically the file+function name in the session name, this will reduce maintenance in case of changes (see, for example it should be SM-linstorcowutil now) and also it would allow to not specify everytime the name of the sesion.
This is a suggestion but ain't blocking for me, could even be addressed in a separate PR.
There was a problem hiding this comment.
I prefer having an explicit session name; logs indicating a session aren't necessarily debug logs. They serve as a label that is human-readable and can be independent of the implementation. If we want to be more precise here, it would be SM-linstor-multi-cow-util here.
| class ApiSession(contextlib.AbstractContextManager): | ||
| session=None | ||
|
|
There was a problem hiding this comment.
Thinking about it, could it be interesting to define/override __call__ to login and return session? This would avoid the long and redundant api_session.session and reduce it to api_session().
Not sure if it's very clear and explicit when reading the code thought.
This is a non blocking comment, only putting it here to start a discussion.
There was a problem hiding this comment.
I guess we can have a card about that.
| <!-- Agent database query errors 150+ --> | ||
| <code> | ||
| <name>APISession</name> | ||
| <name>ApiSession</name> |
There was a problem hiding this comment.
@Nambrok For additional comment.
- I don't think we should change this field here (it would create a style inconsistent with the others below).
- IMHO We should specify this error code in the ApiSession class in the event of a connection failure to the XAPI.
| # Everything was coalescable, remove the message | ||
| xapi_session.xenapi.SR.remove_from_sm_config(self.xapi.srRef, VDI.DB_GC_NO_SPACE) | ||
| xapi_session.xenapi.message.destroy(msg_id) | ||
| with util.APISession("GC-check_no_space") as xapi_session: |
There was a problem hiding this comment.
check-no-space with "-" is not applied in new commits.
| api_session = util.timeout(5, util.APISession, "blktap-abort_linstor_gc") | ||
| session = api_session.session | ||
| try: | ||
| srs = util.get_linstor_srs_uuid(session) |
There was a problem hiding this comment.
"SM-blktap2-abort-linstor-gc" is not applied in new commits.
| class ApiSession(contextlib.AbstractContextManager): | ||
| session=None | ||
|
|
There was a problem hiding this comment.
I guess we can have a card about that.
New
APISessionclass to handle lifecycle of the session, with context, oratexithandlers.Use various originator for
xapisession creation, to differentiate where they are being created.APISessionusesget_localAPI_session()for session creation, so there is only one place for session creation, usingxenapi.login_with_password.get_localAPI_sessionshould be avoided and only remain inlcache.py.The session
originatoris shown on all logs messages pertaining to sessions, in SMlog, in the formatAPISession [{originator}] {message}.All login and logout messages starts with login or logout hence it is possible to count them to check if there is session leakage :