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

ensure config file is updated correctly #542

Merged
merged 3 commits into from
Jan 11, 2017
Merged

Conversation

hglkrijger
Copy link
Member

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

@patch('os.path.isfile')
def test_update_conf_file(self, _):
new_file = "\
DEVICE=eth0\n\
Copy link
Contributor

Choose a reason for hiding this comment

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

is this indentation intentional?

Copy link
Member Author

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]
Copy link
Contributor

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() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, thanks!

@hglkrijger hglkrijger merged commit 50690a1 into Azure:master Jan 11, 2017
@hglkrijger hglkrijger deleted the gh538 branch January 11, 2017 18:53
hglkrijger added a commit to hglkrijger/WALinuxAgent that referenced this pull request Jan 11, 2017
* ensure config file is updated correctly

* unit test fix

* correct ordering
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.

3 participants