-
Notifications
You must be signed in to change notification settings - Fork 371
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
ensure config file is updated correctly #542
Conversation
@patch('os.path.isfile') | ||
def test_update_conf_file(self, _): | ||
new_file = "\ | ||
DEVICE=eth0\n\ |
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 indentation intentional?
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.
yes.. whitespace is not stripped when provided to the patch.
@@ -140,9 +140,9 @@ def update_conf_file(path, line_start, val, chk_err=False): | |||
if not os.path.isfile(path) and chk_err: | |||
raise IOError("Can't find config file:{0}".format(path)) | |||
conf = read_file(path).split('\n') | |||
conf = [x for x in conf if not x.startswith(line_start)] | |||
conf = [x for x in conf if not x.startswith(line_start) and x is not None and len(x) > 0] |
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.
shouldn't 'x is not None' come before x.startswith() ?
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.
yep, thanks!
* ensure config file is updated correctly * unit test fix * correct ordering
In
fileutil.update_conf_file
we do not append a final newline, which can cause values to become unreadable. Also, when updating a value, we can potentially add multiple newline characters. This change addresses both cases./cc @brendandixon @jinhyunr