-
-
Notifications
You must be signed in to change notification settings - Fork 782
Fix st2 login and st2 whoami commands to work #3211
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
Conversation
|
@Mierdin I'm a bit confused about this - it seems like it should have never worked, or am I missing something? |
|
Edit: So it seems like the problem is that only ConfigParser instance in Python 3 works like a dict (https://docs.python.org/3/library/configparser.html#module-configparser), but not one available in Python 2 (https://docs.python.org/2/library/configparser.html). Did you happen to test it with Python 3 locally (I used Python 2.7 which is the version we officially support)? We don't fully support Python 3 yet and if anything, we should use the approach which works on both versions where possible :) |
|
Hrm, this is all very strange. FWIW I was not using Python 3 - my dev box runs 2.7.6. I'll dig into this today and see if I can't get it straightened out. Apologies if I'm over-relying on |
No problem, sometimes it's hard to find the balance what to mock and what to not in the unit tests.
It looks like this could also happen if you have Afaik, none of our packages and components rely and use that package, but having this package installed locally would cause this behavior. |
The previous version of these tests were a bit too reliant on mock, so this approach instead works with as few mocks as possible. Naturally, we have to keep the mock for the st2 API interactions, but these tests run the `st2 login` and `st2 whoami` commands using real config files, as opposed to a mocked ConfigParser. Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Codecov Report
@@ Coverage Diff @@
## master #3211 +/- ##
==========================================
- Coverage 77.8% 77.63% -0.17%
==========================================
Files 433 433
Lines 22415 22414 -1
==========================================
- Hits 17439 17400 -39
- Misses 4976 5014 +38
Continue to review full report at Codecov.
|
|
So....after looking into this a bit more, here's my working theory. It's true that the built-in Looks like this does get installed in the virtualenv when running So, this explains why it was working before the move to using the Now, regarding the errors that came up once #3194 was merged, I'm guessing this is because All that said, the changes you made to auth.py are definitely better, and my mocks were clearly wrong as they were built to mimic the wrong I re-did all of the unit tests for this in ea4c121 and onward; hopefully they'll help protect from this a bit better. |
|
Yes, I also agree with your assessment :) And yeah, it's a bit nasty that dev dependencies can interfere with things in suck a sneaky manner... |
|
|
||
| class TestLoginUncaughtException(TestLoginBase): | ||
|
|
||
| CONFIG_FILE = '/tmp/logintest.cfg' |
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.
Might be a bit safer to use a random temporary path (e.g. mkstemp), besides that, LGTM.
|
It appears e2e tests failed because this branch doesn't contain packs.download fix / changes (the tests are passing on master). I've merged latest master into this branch, this should fix it. |
…o fix_st2_login_command
st2client/tests/unit/test_auth.py
Outdated
| import requests | ||
| import argparse | ||
| import logging | ||
| from cStringIO import StringIO |
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 style / import ordering thing - we tend to put stdlib imports at the top then followed by 3rd party package imports then followed by local components imports.
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 follow the same standard, and I know better. Need to figure out why my editor didn't catch this
st2client/tests/unit/test_auth.py
Outdated
| import requests | ||
| import argparse | ||
| import logging | ||
| from cStringIO import StringIO |
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.
For cross version compatibility it would be better to use six.StringIO (yeah, this one shouldn't cause issues :D)
|
|
||
| DOTST2_PATH = os.path.expanduser('~/.st2/') | ||
|
|
||
| def __init__(self, *args, **kwargs): |
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 using kwargs, it would be a bit more readable to just directly declare arguments in the constructor signature.
|
@Mierdin when you get a chance can you please have a look and approve it (I forgot I opened it and the PR hasn't been approved yet so I can't merge it :))? |
otherwise it will be re-used when multiple class inherit from this base class which is undesired since we always want to start with a clean state.
|
It looks like I was also able to replace |
|
Some of the e2e tests failure appear to be related to intermediate upstream / networking issues. |
Mierdin
left a comment
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.
Nice, thanks for the improvements! LGTM
|
@Kami I re-ran the e2e test and it passed. Not sure why Codecov is throwing a fit though. |
Randomly noticed it's not working while testing it - https://gist.github.com/Kami/f03360208e2e8599f42d3152df054842
It looks like the problem is that code tries to work with the
ConfigParserobject as a dictionary, butConfigParserobject doesn't behave and support dictionary-like access notation.Edit: Looked at the tests and it looks like they didn't catch this issue because the hide it because they mock
ConfigParserinstance. I know that's not always possible, but we should try to avoid mocking as much as possible because many times we end up mocking too much and we actually end up testing mocks and not the actual code...TODO