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
=== modified file 'landscape/deployment.py'
--- landscape/deployment.py 2013-08-14 07:57:30 +0000
+++ landscape/deployment.py 2013-09-06 10:09:33 +0000
@@ -224,7 +224,8 @@
224 all_options.update(self._set_options)224 all_options.update(self._set_options)
225 for name, value in all_options.items():225 for name, value in all_options.items():
226 if name != "config" and name not in self.unsaved_options:226 if name != "config" and name not in self.unsaved_options:
227 if value == self._command_line_defaults.get(name):227 if (value == self._command_line_defaults.get(name) and
228 name not in self._config_file_options):
228 config_parser.remove_option(self.config_section, name)229 config_parser.remove_option(self.config_section, name)
229 else:230 else:
230 config_parser.set(self.config_section, name, value)231 config_parser.set(self.config_section, name, value)
231232
=== modified file 'landscape/tests/test_configuration.py'
--- landscape/tests/test_configuration.py 2013-06-18 07:51:50 +0000
+++ landscape/tests/test_configuration.py 2013-09-06 10:09:33 +0000
@@ -749,6 +749,7 @@
749computer_title = rex749computer_title = rex
750data_path = %s750data_path = %s
751account_name = account751account_name = account
752url = https://landscape.canonical.com/message-system
752""" % config.data_path)753""" % config.data_path)
753754
754 def test_silent_setup_no_register(self):755 def test_silent_setup_no_register(self):
@@ -765,6 +766,7 @@
765 self.assertConfigEqual(self.get_content(config), """\766 self.assertConfigEqual(self.get_content(config), """\
766[client]767[client]
767data_path = %s768data_path = %s
769url = https://landscape.canonical.com/message-system
768""" % config.data_path)770""" % config.data_path)
769771
770 def test_silent_setup_no_register_with_default_preseed_params(self):772 def test_silent_setup_no_register_with_default_preseed_params(self):
@@ -801,6 +803,7 @@
801 "account_name = \n"803 "account_name = \n"
802 "computer_title = \n"804 "computer_title = \n"
803 "https_proxy = \n"805 "https_proxy = \n"
806 "url = https://landscape.canonical.com/message-system\n"
804 % config.data_path)807 % config.data_path)
805808
806 def test_silent_setup_without_computer_title(self):809 def test_silent_setup_without_computer_title(self):
807810
=== modified file 'landscape/tests/test_deployment.py'
--- landscape/tests/test_deployment.py 2013-08-14 07:57:30 +0000
+++ landscape/tests/test_deployment.py 2013-09-06 10:09:33 +0000
@@ -175,12 +175,29 @@
175 "[client]\nlog_level = warning\n")175 "[client]\nlog_level = warning\n")
176176
177 def test_dont_write_default_options(self):177 def test_dont_write_default_options(self):
178 """
179 Don't write options to the file if they exactly match the default and
180 didn't already exist in the file.
181 """
178 self.write_config_file(log_level="debug")182 self.write_config_file(log_level="debug")
179 self.config.log_level = "info"183 self.config.log_level = "info"
180 self.config.write()184 self.config.write()
181 data = open(self.config_filename).read()185 data = open(self.config_filename).read()
182 self.assertConfigEqual(data, "[client]")186 self.assertConfigEqual(data, "[client]")
183187
188 def test_do_write_preexisting_default_options(self):
189 """
190 If the value of an option matches the default, but the option was
191 already written in the file, then write it back to the file.
192 """
193 config = "[client]\nlog_level = info\n"
194 config_filename = self.makeFile(config)
195 self.config.load_configuration_file(config_filename)
196 self.config.log_level = "info"
197 self.config.write()
198 data = open(config_filename).read()
199 self.assertConfigEqual(data, "[client]\nlog_level = info\n")
200
184 def test_dont_delete_explicitly_set_default_options(self):201 def test_dont_delete_explicitly_set_default_options(self):
185 """202 """
186 If the user explicitly sets a configuration option to its default203 If the user explicitly sets a configuration option to its default

Subscribers

People subscribed via source and target branches

to all changes: