-
Notifications
You must be signed in to change notification settings - Fork 786
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
Changed add_token.py for issue #4526 #4546
Conversation
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.
Thanks a lot @ShrishtiKarkera! This is going in the right direction, and solves the issue at hand. However, there are things that can be improved, please have a look at the comments.
scripts/wrappers/add_token.py
Outdated
addr = str(ip) + ":" + str(port) + "/" + str(token) + "/" + str(check) | ||
if addr not in addr_set: | ||
print(f"microk8s join {ip}:{port}/{token}/{check}") | ||
addr_set.add(addr) |
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.
This is creating a set of IPs we have already "seen". However, the ask here is to simply avoid repeating the default_ip. It should be simpler if you simply check for ip == default_ip
in the for loop, right?
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.
Alright!
I was thinking if the there were duplicate ips in the all_ip list apart from default ip but its much simpler if the default ip is the only problem.
Thanks!
tests/unit/test_addtoken.py
Outdated
@mock.patch('builtins.print') | ||
@mock.patch('add_token.get_network_info', return_value=['10.23.53.54', ['10.23.53.54'], str(32)]) | ||
def test_add_token(self, addtoken, mock_print): | ||
# self.assertEqual(print_short('t', 'c'), 2) |
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.
is this leftover from debugging? do we need it?
tests/unit/test_addtoken.py
Outdated
from unittest import mock, TestCase | ||
from add_token import print_short | ||
|
||
class test_at(TestCase): |
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.
test classes are typically named with camel-case: TestSomething
. Please use a meaningful name for what we test here.
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.
My bad, test_at meant test_addtoken but I'll be more clearer.
Thanks
tests/unit/test_addtoken.py
Outdated
|
||
class test_at(TestCase): | ||
@mock.patch('builtins.print') | ||
@mock.patch('add_token.get_network_info', return_value=['10.23.53.54', ['10.23.53.54'], str(32)]) |
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.
let's be consistent and use '32'
as well, instead of str(32)
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.
Got it.
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.
Changed add_token.py to just check for the default_ip case.
Added another test case with multiple ip addresses.
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.
Looks nicer! Did a second pass
tests/unit/test_addtoken.py
Outdated
@mock.patch('add_token.get_network_info', return_value=['d_ip', ['ip1', 'ip2', 'd_ip'], '4']) | ||
def test_multiple(self, multiple, mock_print): | ||
print_short('t', 'c') | ||
mock_print.assert_called_with('microk8s join ip2:4/t/c') |
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.
this works, but does not tell the whole story. please make sure that you test all print invocations are as expected, not only the last one.
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.
Sure!
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 couldn't use the inbuilt assertion as it has a limit so I used capsys to check for all output lines.
Please let me know if anything else is required to be done.
tests/unit/test_addtoken.py
Outdated
all_outputs[0] == f"microk8s join d_ip:4/t/c" | ||
assert all_outputs[1] == f"microk8s join ip1:4/t/c" | ||
assert all_outputs[2] == f"microk8s join ip2:4/t/c" | ||
assert len(all_outputs) == 3 |
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.
this can be a single assert all_outputs == [cmd1, cmd2, cmd3]
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.
Okay
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.
Removed multiple assertions and added a single assert statement
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.
Checked for cla and lint
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.
checked for lint and cla
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.
checking for lint and cla try 2
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.
Lint passes, checking for cla
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.
checking for cla
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.
Final check
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.
Checked all tests
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.
Please rebase and cleanup the commit history, then we should be good to merge!
scripts/wrappers/join.py
Outdated
if "Address" in data: | ||
port = data["Address"].rsplit(":")[-1] | ||
except OSError: | ||
pass | ||
|
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.
this is unrelated to the changes of this PR, please revert
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.
Sure
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'm so sorry, I'll fix this
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.
Removed the join.py commit from the commit history
scripts/wrappers/join.py
Outdated
if "Address" in data: | ||
port = data["Address"].rsplit(":")[-1] | ||
except OSError: | ||
pass | ||
|
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'm so sorry, I'll fix this
tested with unittest (test_addtoken.py) tested with unittest (test_addtoken.py) changed and tested add_token.py canonical#4526 changed and tested add_token.py checked test_multiple for all outputs changed assertion in test_multiple() checked lint and cla checking for lint and cla checking for cla checking for cla checking for cla checking final checking final final push
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.
Squashed all commits into one
Summary
Changes
/microk8s/scripts/wrappers/add_token.py
Testing
The change was tested with a unittest in tests/unit/test_addtoken.py
Tested using mock print assertion with builtins.print
Possible Regressions
Checklist
Notes