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

added autoRefresh option for regular login (non-websocket connections) #34

Merged
merged 20 commits into from
Dec 27, 2018

Conversation

kprav33n
Copy link
Contributor

This should resolve #16

@kprav33n
Copy link
Contributor Author

Thanks for the contribution. We'll also have to address the CI issues identified circleci, travis-ci, and codacy before we can merge this PR.

@codecov
Copy link

codecov bot commented Dec 24, 2018

Codecov Report

Merging #34 into master will increase coverage by 2.18%.
The diff coverage is 78.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
+ Coverage   65.15%   67.34%   +2.18%     
==========================================
  Files           8        8              
  Lines         924     1087     +163     
==========================================
+ Hits          602      732     +130     
- Misses        322      355      +33
Impacted Files Coverage Δ
pyaci/core.py 72.76% <78.03%> (+1.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b43fe90...f335c39. Read the comment docs.

@toravir
Copy link

toravir commented Dec 25, 2018

Fixes both #16 and #17 - and addressed the first set of code review comments.

@toravir
Copy link

toravir commented Dec 25, 2018

@kprav33n pls review the websocket auto refresh and test code. autoRefresh param during Login() controls both autoRefresh of Login Sessions AND subscriptions - if we need different knobs for both separately, can do it too - my guess is that single knob is simple.

Copy link
Contributor Author

@kprav33n kprav33n left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Some minor style issues suggested. We can take care of some now, and others later.

pyaci/core.py Outdated

#Web Socket Statuses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
#Web Socket Statuses
# Web Socket Statuses

pyaci/core.py Outdated

#Web Socket Statuses
WS_OPENING = 'Websocket Opening...'
WS_OPEN = 'Websocket Open.'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
WS_OPEN = 'Websocket Open.'
WS_OPENED = 'Websocket Opened.'

pyaci/core.py Outdated

#Web Socket Statuses
WS_OPENING = 'Websocket Opening...'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
WS_OPENING = 'Websocket Opening...'
WS_OPENING = 'Websocket Opening.'

pyaci/core.py Outdated
self._autoRefresh = False
self._autoRefreshThread = None
self._login = {}
self._autotest = False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not thrilled to have test specific handling in the product code. We'll leave this for now, and discuss later how to remove it.

if 'APIC-cookie' in self._rootApi()._session.cookies :
token = self._rootApi()._session.cookies['APIC-cookie']
else:
raise Exception('APIC-cookie NOT found.. Make sure you have logged in.')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should have specific exceptions/errors thrown instead of the blanket Exception. We can handle this later.

pyaci/core.py Outdated
@@ -698,12 +731,102 @@ def _spawnChildFromAttributes(self, className, **attributes):
return self._spawnChildFromRn(className, rn)


class autoRefreshThread(threading.Thread):
def __init__(self, rootApi):
super(autoRefreshThread, self).__init__()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
super(autoRefreshThread, self).__init__()
super(AutoRefreshThread, self).__init__()

pyaci/core.py Outdated

def run(self):
logger.debug('arThread: Starting up...')
REFRESH_BEFORE = 60 #approx - this many seconds before expiry, do refresh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
REFRESH_BEFORE = 60 #approx - this many seconds before expiry, do refresh
REFRESH_BEFORE = 60 # approx - this many seconds before expiry, do refresh

pyaci/core.py Outdated
def run(self):
logger.debug('arThread: Starting up...')
REFRESH_BEFORE = 60 #approx - this many seconds before expiry, do refresh
CHECK_INTERVAL = 10 #how long to sleep before waking to check
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
CHECK_INTERVAL = 10 #how long to sleep before waking to check
CHECK_INTERVAL = 10 # how long to sleep before waking to check

pyaci/core.py Outdated
logger.debug('arThread: Starting up...')
REFRESH_BEFORE = 60 #approx - this many seconds before expiry, do refresh
CHECK_INTERVAL = 10 #how long to sleep before waking to check
WS_REFRESH_INT = 40 #approx - this many seconds before subscription refresh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
WS_REFRESH_INT = 40 #approx - this many seconds before subscription refresh
WS_REFRESH_INT = 40 # approx - this many seconds before subscription refresh

pyaci/core.py Outdated
int(doc['imdata']['aaaLogin']['@refreshTimeoutSeconds'])
logger.debug(root._login)
if root._autoRefresh:
arThread = autoRefreshThread(root)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
arThread = autoRefreshThread(root)
arThread = AutoRefreshThread(root)

@toravir
Copy link

toravir commented Dec 26, 2018

@kprav33n addressed code review comments - removed the knob for testing in the production code by restructuring the code.

only thing to discuss and do later is: exceptions from pyaci
another todo is for a way to run all CI, codacy, codecov tests locally (before the commit)

@kprav33n
Copy link
Contributor Author

Thank you for meticulously taking care of all review comments. Appreciate the contribution. Merged.

@kprav33n kprav33n merged commit c462454 into datacenter:master Dec 27, 2018
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.

Provide an API to configure automatic session token refresh
2 participants