~ubuntu-branches/ubuntu/vivid/landscape-client/vivid

« back to all changes in this revision

Viewing changes to debian/patches/sysinfo-ignore-nonexistent-config.diff

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2014-11-20 21:03:56 UTC
  • mfrom: (1.1.34)
  • Revision ID: package-import@ubuntu.com-20141120210356-bdl520tpnxddxtm0
Tags: 14.11-0ubuntu1
* New upstream version:
  - Fix regression occurring when performing Landscape-driven release
    upgrades (LP: #1389686)
  - Fix regression occurring when switching the client between different
    Landscape servers (LP #376134)
  - Support reporting QEMU virtualization (LP: #1374501)
  - Bump Juju integration message format (LP: #1369635, LP: #1362506)
  - Drop provisioning registration message (LP: #1362506)
  - Drop cloud registration message (LP: #1342646)
  - Fix handling broken packages (LP: #1326940)
  - Add new Swift usage message type (LP: #1320236)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--- a/landscape/__init__.py
2
 
+++ b/landscape/__init__.py
3
 
@@ -1,5 +1,5 @@
4
 
 DEBIAN_REVISION = ""
5
 
-UPSTREAM_VERSION = "13.10+bzr73"
6
 
+UPSTREAM_VERSION = "14.01"
7
 
 VERSION = "%s%s" % (UPSTREAM_VERSION, DEBIAN_REVISION)
8
 
 
9
 
 # The "server-api" field of outgoing messages will be set to this value, and
10
 
--- a/landscape/broker/config.py
11
 
+++ b/landscape/broker/config.py
12
 
@@ -79,7 +79,7 @@
13
 
         """Get the path to the message store."""
14
 
         return os.path.join(self.data_path, "messages")
15
 
 
16
 
-    def load(self, args, accept_nonexistent_config=False):
17
 
+    def load(self, args):
18
 
         """
19
 
         Load options from command line arguments and a config file.
20
 
 
21
 
@@ -87,8 +87,7 @@
22
 
         C{http_proxy} and C{https_proxy} environment variables based on
23
 
         that config data.
24
 
         """
25
 
-        super(BrokerConfiguration, self).load(
26
 
-            args, accept_nonexistent_config=accept_nonexistent_config)
27
 
+        super(BrokerConfiguration, self).load(args)
28
 
         if self.http_proxy:
29
 
             os.environ["http_proxy"] = self.http_proxy
30
 
         elif self._original_http_proxy:
31
 
--- a/landscape/deployment.py
32
 
+++ b/landscape/deployment.py
33
 
@@ -148,18 +148,24 @@
34
 
         """
35
 
         self.load(self._command_line_args)
36
 
 
37
 
-    def load(self, args, accept_nonexistent_config=False):
38
 
+    def load(self, args, accept_nonexistent_default_config=False):
39
 
         """
40
 
         Load configuration data from command line arguments and a config file.
41
 
 
42
 
+        @param accept_nonexistent_default_config: If True, don't complain if
43
 
+            default configuration files aren't found
44
 
+
45
 
         @raise: A SystemExit if the arguments are bad.
46
 
+
47
 
         """
48
 
         self.load_command_line(args)
49
 
 
50
 
         if self.config:
51
 
             config_filenames = [self.config]
52
 
+            allow_missing = False
53
 
         else:
54
 
             config_filenames = self.default_config_filenames
55
 
+            allow_missing = accept_nonexistent_default_config
56
 
         # Parse configuration file, if found.
57
 
         for config_filename in config_filenames:
58
 
             if (os.path.isfile(config_filename)
59
 
@@ -169,7 +175,7 @@
60
 
                 break
61
 
 
62
 
         else:
63
 
-            if not accept_nonexistent_config:
64
 
+            if not allow_missing:
65
 
                 if len(config_filenames) == 1:
66
 
                     message = (
67
 
                         "error: config file %s can't be read" %
68
 
@@ -402,12 +408,11 @@
69
 
 
70
 
         return parser
71
 
 
72
 
-    def load(self, args, accept_nonexistent_config=False):
73
 
+    def load(self, args):
74
 
         """
75
 
         Load configuration data from command line arguments and a config file.
76
 
         """
77
 
-        super(Configuration, self).load(
78
 
-            args, accept_nonexistent_config=accept_nonexistent_config)
79
 
+        super(Configuration, self).load(args)
80
 
 
81
 
         if not isinstance(self.server_autodiscover, bool):
82
 
             autodiscover = str(self.server_autodiscover).lower()
83
 
--- a/landscape/sysinfo/deployment.py
84
 
+++ b/landscape/sysinfo/deployment.py
85
 
@@ -100,7 +100,9 @@
86
 
     if sysinfo is None:
87
 
         sysinfo = SysInfoPluginRegistry()
88
 
     config = SysInfoConfiguration()
89
 
-    config.load(args)
90
 
+    # landscape-sysinfo needs to work where there's no
91
 
+    # /etc/landscape/client.conf See lp:1293990
92
 
+    config.load(args, accept_nonexistent_default_config=True)
93
 
     for plugin in config.get_plugins():
94
 
         sysinfo.add(plugin)
95
 
 
96
 
--- a/landscape/sysinfo/tests/test_deployment.py
97
 
+++ b/landscape/sysinfo/tests/test_deployment.py
98
 
@@ -5,6 +5,8 @@
99
 
 
100
 
 from twisted.internet.defer import Deferred
101
 
 
102
 
+from landscape.lib.fs import create_file
103
 
+
104
 
 from landscape.sysinfo.deployment import (
105
 
     SysInfoConfiguration, ALL_PLUGINS, run, setup_logging,
106
 
     get_landscape_log_directory)
107
 
@@ -49,9 +51,7 @@
108
 
 
109
 
     def test_config_file(self):
110
 
         filename = self.makeFile()
111
 
-        f = open(filename, "w")
112
 
-        f.write("[sysinfo]\nsysinfo_plugins = TestPlugin\n")
113
 
-        f.close()
114
 
+        create_file(filename, "[sysinfo]\nsysinfo_plugins = TestPlugin\n")
115
 
         self.configuration.load(["--config", filename, "-d", self.makeDir()])
116
 
         plugins = self.configuration.get_plugins()
117
 
         self.assertEqual(len(plugins), 1)
118
 
@@ -155,6 +155,17 @@
119
 
 
120
 
         return result.addCallback(check_result)
121
 
 
122
 
+    def test_missing_config_file(self):
123
 
+        """The process doesn't fail if there is no config file."""
124
 
+        # Existing revert in tearDown will handle undoing this
125
 
+        SysInfoConfiguration.default_config_filenames = []
126
 
+        result = run([])
127
 
+
128
 
+        def check_result(result):
129
 
+            self.assertIn("System load", self.stdout.getvalue())
130
 
+
131
 
+        return result.addCallback(check_result)
132
 
+
133
 
     def test_plugins_called_after_reactor_starts(self):
134
 
         """
135
 
         Plugins are invoked after the reactor has started, so that they can
136
 
--- a/landscape/tests/test_deployment.py
137
 
+++ b/landscape/tests/test_deployment.py
138
 
@@ -4,7 +4,10 @@
139
 
 from StringIO import StringIO
140
 
 from textwrap import dedent
141
 
 
142
 
-from landscape.deployment import Configuration, get_versioned_persist
143
 
+from landscape.lib.fs import read_file, create_file
144
 
+
145
 
+from landscape.deployment import (
146
 
+    BaseConfiguration, Configuration, get_versioned_persist)
147
 
 from landscape.manager.config import ManagerConfiguration
148
 
 
149
 
 from landscape.tests.helpers import LandscapeTest, LogKeeperHelper
150
 
@@ -21,6 +24,37 @@
151
 
         return parser
152
 
 
153
 
 
154
 
+class BaseConfigurationTest(LandscapeTest):
155
 
+
156
 
+    def test_load_not_found_default_accept_missing(self):
157
 
+        """
158
 
+        C{config.load} doesn't exit the process if the default config file
159
 
+        is not found and C{accept_nonexistent_default_config} is C{True}.
160
 
+        """
161
 
+        class MyConfiguration(BaseConfiguration):
162
 
+            default_config_filenames = ["/not/here"]
163
 
+
164
 
+        config = MyConfiguration()
165
 
+        result = config.load([], accept_nonexistent_default_config=True)
166
 
+        self.assertIs(result, None)
167
 
+
168
 
+    def test_load_not_found_accept_missing(self):
169
 
+        """
170
 
+        C{config.load} exits the process if the specified config file
171
 
+        is not found and C{accept_nonexistent_default_config} is C{True}.
172
 
+        """
173
 
+        class MyConfiguration(BaseConfiguration):
174
 
+            default_config_filenames = []
175
 
+
176
 
+        config = MyConfiguration()
177
 
+        filename = "/not/here"
178
 
+        error = self.assertRaises(
179
 
+            SystemExit, config.load, ["--config", filename],
180
 
+            accept_nonexistent_default_config=True)
181
 
+        self.assertEqual(
182
 
+            "error: config file %s can't be read" % filename, str(error))
183
 
+
184
 
+
185
 
 class ConfigurationTest(LandscapeTest):
186
 
 
187
 
     helpers = [LogKeeperHelper]
188
 
@@ -160,7 +194,7 @@
189
 
         self.write_config_file(log_level="debug")
190
 
         self.config.log_level = "warning"
191
 
         self.config.write()
192
 
-        data = open(self.config_filename).read()
193
 
+        data = read_file(self.config_filename)
194
 
         self.assertConfigEqual(data, "[client]\nlog_level = warning")
195
 
 
196
 
     def test_write_configuration_with_section(self):
197
 
@@ -168,7 +202,7 @@
198
 
         self.write_config_file(section_name="babble", whatever="yay")
199
 
         self.config.whatever = "boo"
200
 
         self.config.write()
201
 
-        data = open(self.config_filename).read()
202
 
+        data = read_file(self.config_filename)
203
 
         self.assertConfigEqual(data, "[babble]\nwhatever = boo")
204
 
 
205
 
     def test_write_unrelated_configuration_back(self):
206
 
@@ -183,7 +217,7 @@
207
 
         self.config.load_configuration_file(config_filename)
208
 
         self.config.whatever = "boo"
209
 
         self.config.write()
210
 
-        data = open(config_filename).read()
211
 
+        data = read_file(config_filename)
212
 
         self.assertConfigEqual(
213
 
             data,
214
 
             "[babble]\nwhatever = boo\n\n[goojy]\nunrelated = yes")
215
 
@@ -195,9 +229,8 @@
216
 
         self.config.load([])
217
 
         self.config.log_level = "warning"
218
 
         self.config.write()
219
 
-        data = open(self.config_filename).read()
220
 
-        self.assertConfigEqual(data,
221
 
-            "[client]\nlog_level = warning\n")
222
 
+        data = read_file(self.config_filename)
223
 
+        self.assertConfigEqual(data, "[client]\nlog_level = warning\n")
224
 
 
225
 
     def test_write_empty_list_values_instead_of_double_quotes(self):
226
 
         """
227
 
@@ -209,7 +242,7 @@
228
 
         self.config.load([])
229
 
         self.config.include_manager_plugins = ""
230
 
         self.config.write()
231
 
-        data = open(self.config_filename).read()
232
 
+        data = read_file(self.config_filename)
233
 
         self.assertConfigEqual(data, "[client]\ninclude_manager_plugins = \n")
234
 
 
235
 
     def test_dont_write_config_specified_default_options(self):
236
 
@@ -220,7 +253,7 @@
237
 
         self.write_config_file(log_level="debug")
238
 
         self.config.log_level = "info"
239
 
         self.config.write()
240
 
-        data = open(self.config_filename).read()
241
 
+        data = read_file(self.config_filename)
242
 
         self.assertConfigEqual(data, "[client]")
243
 
 
244
 
     def test_dont_write_unspecified_default_options(self):
245
 
@@ -231,7 +264,7 @@
246
 
         self.write_config_file()
247
 
         self.config.log_level = "info"
248
 
         self.config.write()
249
 
-        data = open(self.config_filename).read()
250
 
+        data = read_file(self.config_filename)
251
 
         self.assertConfigEqual(data, "[client]")
252
 
 
253
 
     def test_dont_write_client_section_default_options(self):
254
 
@@ -242,7 +275,7 @@
255
 
         self.write_config_file(log_level="debug")
256
 
         self.config.log_level = "info"
257
 
         self.config.write()
258
 
-        data = open(self.config_filename).read()
259
 
+        data = read_file(self.config_filename)
260
 
         self.assertConfigEqual(data, "[client]")
261
 
 
262
 
     def test_do_write_preexisting_default_options(self):
263
 
@@ -255,7 +288,7 @@
264
 
         self.config.load_configuration_file(config_filename)
265
 
         self.config.log_level = "info"
266
 
         self.config.write()
267
 
-        data = open(config_filename).read()
268
 
+        data = read_file(config_filename)
269
 
         self.assertConfigEqual(data, "[client]\nlog_level = info\n")
270
 
 
271
 
     def test_dont_delete_explicitly_set_default_options(self):
272
 
@@ -266,21 +299,21 @@
273
 
         """
274
 
         self.write_config_file(log_level="info")
275
 
         self.config.write()
276
 
-        data = open(self.config_filename).read()
277
 
+        data = read_file(self.config_filename)
278
 
         self.assertConfigEqual(data, "[client]\nlog_level = info")
279
 
 
280
 
     def test_dont_write_config_option(self):
281
 
         self.write_config_file()
282
 
         self.config.config = self.config_filename
283
 
         self.config.write()
284
 
-        data = open(self.config_filename).read()
285
 
+        data = read_file(self.config_filename)
286
 
         self.assertConfigEqual(data, "[client]")
287
 
 
288
 
     def test_write_command_line_options(self):
289
 
         self.write_config_file()
290
 
         self.config.load(["--log-level", "warning"])
291
 
         self.config.write()
292
 
-        data = open(self.config_filename).read()
293
 
+        data = read_file(self.config_filename)
294
 
         self.assertConfigEqual(data, "[client]\nlog_level = warning\n")
295
 
 
296
 
     def test_write_command_line_precedence(self):
297
 
@@ -289,7 +322,7 @@
298
 
         self.write_config_file(log_level="debug")
299
 
         self.config.load(["--log-level", "warning"])
300
 
         self.config.write()
301
 
-        data = open(self.config_filename).read()
302
 
+        data = read_file(self.config_filename)
303
 
         self.assertConfigEqual(data, "[client]\nlog_level = warning\n")
304
 
 
305
 
     def test_write_manually_set_precedence(self):
306
 
@@ -299,17 +332,16 @@
307
 
         self.config.load(["--log-level", "warning"])
308
 
         self.config.log_level = "error"
309
 
         self.config.write()
310
 
-        data = open(self.config_filename).read()
311
 
+        data = read_file(self.config_filename)
312
 
         self.assertConfigEqual(data, "[client]\nlog_level = error\n")
313
 
 
314
 
     def test_write_to_given_config_file(self):
315
 
-        filename = self.makeFile()
316
 
+        filename = self.makeFile(content="")
317
 
         self.config.load(
318
 
-            ["--log-level", "warning", "--config", filename],
319
 
-            accept_nonexistent_config=True)
320
 
+            ["--log-level", "warning", "--config", filename])
321
 
         self.config.log_level = "error"
322
 
         self.config.write()
323
 
-        data = open(filename).read()
324
 
+        data = read_file(filename)
325
 
         self.assertConfigEqual(data, "[client]\nlog_level = error\n")
326
 
 
327
 
     def test_comments_are_maintained(self):
328
 
@@ -322,7 +354,7 @@
329
 
         self.config.load_configuration_file(filename)
330
 
         self.config.log_level = "error"
331
 
         self.config.write()
332
 
-        new_config = open(filename).read()
333
 
+        new_config = read_file(filename)
334
 
         self.assertConfigEqual(
335
 
             new_config,
336
 
             "[client]\n# Comment 1\nlog_level = error\n#Comment 2\n")
337
 
@@ -383,7 +415,7 @@
338
 
         """
339
 
         filename = self.makeFile("[client]\nhello = world1\n")
340
 
         self.config.load(["--config", filename])
341
 
-        open(filename, "w").write("[client]\nhello = world2\n")
342
 
+        create_file(filename, "[client]\nhello = world2\n")
343
 
         self.config.reload()
344
 
         self.assertEqual(self.config.hello, "world2")
345
 
 
346
 
@@ -459,8 +491,8 @@
347
 
 
348
 
     def test_url_option(self):
349
 
         """Ensure options.url option can be read by parse_args."""
350
 
-        options = self.parser.parse_args(["--url",
351
 
-                                       "http://mylandscape/message-system"])[0]
352
 
+        options = self.parser.parse_args(
353
 
+            ["--url", "http://mylandscape/message-system"])[0]
354
 
         self.assertEqual(options.url, "http://mylandscape/message-system")
355
 
 
356
 
     def test_url_default(self):
357
 
@@ -470,8 +502,8 @@
358
 
 
359
 
     def test_ping_url_option(self):
360
 
         """Ensure options.ping_url option can be read by parse_args."""
361
 
-        options = self.parser.parse_args(["--ping-url",
362
 
-                                       "http://mylandscape/ping"])[0]
363
 
+        options = self.parser.parse_args(
364
 
+            ["--ping-url", "http://mylandscape/ping"])[0]
365
 
         self.assertEqual(options.ping_url, "http://mylandscape/ping")
366
 
 
367
 
     def test_ping_url_default(self):
368
 
@@ -482,8 +514,8 @@
369
 
 
370
 
     def test_ssl_public_key_option(self):
371
 
         """Ensure options.ssl_public_key option can be read by parse_args."""
372
 
-        options = self.parser.parse_args(["--ssl-public-key",
373
 
-                                       "/tmp/somekeyfile.ssl"])[0]
374
 
+        options = self.parser.parse_args(
375
 
+            ["--ssl-public-key", "/tmp/somekeyfile.ssl"])[0]
376
 
         self.assertEqual(options.ssl_public_key, "/tmp/somekeyfile.ssl")
377
 
 
378
 
     def test_ssl_public_key_default(self):
379
 
@@ -508,8 +540,9 @@
380
 
         Ensure options.autodiscover_srv_query_string option can be read by
381
 
         parse_args.
382
 
         """
383
 
-        options = self.parser.parse_args(["--autodiscover-srv-query-string",
384
 
-                                       "_tcp._landscape.someotherdomain"])[0]
385
 
+        options = self.parser.parse_args(
386
 
+            ["--autodiscover-srv-query-string",
387
 
+             "_tcp._landscape.someotherdomain"])[0]
388
 
         self.assertEqual(options.autodiscover_srv_query_string,
389
 
                          "_tcp._landscape.someotherdomain")
390
 
 
391
 
@@ -527,8 +560,8 @@
392
 
         Ensure options.autodiscover_a_query_string option can be read by
393
 
         parse_args.
394
 
         """
395
 
-        options = self.parser.parse_args(["--autodiscover-a-query-string",
396
 
-                                       "customname.mydomain"])[0]
397
 
+        options = self.parser.parse_args(
398
 
+            ["--autodiscover-a-query-string", "customname.mydomain"])[0]
399
 
         self.assertEqual(options.autodiscover_a_query_string,
400
 
                          "customname.mydomain")
401
 
 
402
 
@@ -543,8 +576,8 @@
403
 
 
404
 
     def test_log_file_option(self):
405
 
         """Ensure options.log_dir option can be read by parse_args."""
406
 
-        options = self.parser.parse_args(["--log-dir",
407
 
-                                       "/var/log/my-awesome-log"])[0]
408
 
+        options = self.parser.parse_args(
409
 
+            ["--log-dir", "/var/log/my-awesome-log"])[0]
410
 
         self.assertEqual(options.log_dir, "/var/log/my-awesome-log")
411
 
 
412
 
     def test_log_level_default(self):