Merge lp:~tealeg/landscape-client/prevent-overwriting-config into lp:~landscape/landscape-client/trunk

Proposed by Geoff Teale
Status: Merged
Approved by: Geoff Teale
Approved revision: 721
Merged at revision: 720
Proposed branch: lp:~tealeg/landscape-client/prevent-overwriting-config
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 75 lines (+22/-1)
3 files modified
landscape/deployment.py (+2/-1)
landscape/tests/test_configuration.py (+3/-0)
landscape/tests/test_deployment.py (+17/-0)
To merge this branch: bzr merge lp:~tealeg/landscape-client/prevent-overwriting-config
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Alberto Donato (community) Approve
Review via email: mp+184261@code.launchpad.net

Commit message

This branch modifies the write method of
landscape.deployment.BaseConfiguration to ensure that valid
configuration values that existed in the file prior to modification
are retained even if they match defaults.

Description of the change

This branch modifies the write method of landscape.deployment.BaseConfiguration to ensure that valid configuration values that existed in the file prior to modification are retained even if they match defaults.

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

Great, +1!

review: Approve
Revision history for this message
Chris Glass (tribaal) wrote :

Nice! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/deployment.py'
2--- landscape/deployment.py 2013-08-14 07:57:30 +0000
3+++ landscape/deployment.py 2013-09-06 10:09:33 +0000
4@@ -224,7 +224,8 @@
5 all_options.update(self._set_options)
6 for name, value in all_options.items():
7 if name != "config" and name not in self.unsaved_options:
8- if value == self._command_line_defaults.get(name):
9+ if (value == self._command_line_defaults.get(name) and
10+ name not in self._config_file_options):
11 config_parser.remove_option(self.config_section, name)
12 else:
13 config_parser.set(self.config_section, name, value)
14
15=== modified file 'landscape/tests/test_configuration.py'
16--- landscape/tests/test_configuration.py 2013-06-18 07:51:50 +0000
17+++ landscape/tests/test_configuration.py 2013-09-06 10:09:33 +0000
18@@ -749,6 +749,7 @@
19 computer_title = rex
20 data_path = %s
21 account_name = account
22+url = https://landscape.canonical.com/message-system
23 """ % config.data_path)
24
25 def test_silent_setup_no_register(self):
26@@ -765,6 +766,7 @@
27 self.assertConfigEqual(self.get_content(config), """\
28 [client]
29 data_path = %s
30+url = https://landscape.canonical.com/message-system
31 """ % config.data_path)
32
33 def test_silent_setup_no_register_with_default_preseed_params(self):
34@@ -801,6 +803,7 @@
35 "account_name = \n"
36 "computer_title = \n"
37 "https_proxy = \n"
38+ "url = https://landscape.canonical.com/message-system\n"
39 % config.data_path)
40
41 def test_silent_setup_without_computer_title(self):
42
43=== modified file 'landscape/tests/test_deployment.py'
44--- landscape/tests/test_deployment.py 2013-08-14 07:57:30 +0000
45+++ landscape/tests/test_deployment.py 2013-09-06 10:09:33 +0000
46@@ -175,12 +175,29 @@
47 "[client]\nlog_level = warning\n")
48
49 def test_dont_write_default_options(self):
50+ """
51+ Don't write options to the file if they exactly match the default and
52+ didn't already exist in the file.
53+ """
54 self.write_config_file(log_level="debug")
55 self.config.log_level = "info"
56 self.config.write()
57 data = open(self.config_filename).read()
58 self.assertConfigEqual(data, "[client]")
59
60+ def test_do_write_preexisting_default_options(self):
61+ """
62+ If the value of an option matches the default, but the option was
63+ already written in the file, then write it back to the file.
64+ """
65+ config = "[client]\nlog_level = info\n"
66+ config_filename = self.makeFile(config)
67+ self.config.load_configuration_file(config_filename)
68+ self.config.log_level = "info"
69+ self.config.write()
70+ data = open(config_filename).read()
71+ self.assertConfigEqual(data, "[client]\nlog_level = info\n")
72+
73 def test_dont_delete_explicitly_set_default_options(self):
74 """
75 If the user explicitly sets a configuration option to its default

Subscribers

People subscribed via source and target branches

to all changes: