Merge lp:~jseutter/landscape-client/invalid-integer into lp:~landscape/landscape-client/trunk

Proposed by Jerry Seutter
Status: Rejected
Rejected by: David Britton
Proposed branch: lp:~jseutter/landscape-client/invalid-integer
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 164 lines (+101/-7)
3 files modified
landscape/broker/config.py (+21/-5)
landscape/deployment.py (+20/-2)
landscape/tests/test_configuration.py (+60/-0)
To merge this branch: bzr merge lp:~jseutter/landscape-client/invalid-integer
Reviewer Review Type Date Requested Status
Geoff Teale (community) Approve
Landscape Pending
Review via email: mp+94057@code.launchpad.net

Description of the change

This branch addresses a bug caused by the exchange interval having an empty string in debconf. Trying to call landscape-config --exchange-interval "" resulted in a command line parse error. The fix changes the parsing to allow an empty string to be passed in, which causes the default setting to be used.

To post a comment you must log in.
Revision history for this message
Geoff Teale (tealeg) wrote :

+1 Looks good to me.

review: Approve

Unmerged revisions

458. By Jerry Seutter

Adding a missing docstring.

457. By Jerry Seutter

exchange-interval, urgent-exchange-interval and ping-interval now accept
the empty string on the command line.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/config.py'
2--- landscape/broker/config.py 2012-02-06 21:04:44 +0000
3+++ landscape/broker/config.py 2012-02-21 21:36:18 +0000
4@@ -63,18 +63,19 @@
5 parser.add_option("-k", "--ssl-public-key",
6 help="The public SSL key to verify the server. "
7 "Only used if the given URL is https.")
8- parser.add_option("--exchange-interval", default=15 * 60, type="int",
9- metavar="INTERVAL",
10+ parser.add_option("--exchange-interval", default=15 * 60,
11+ type="int_or_empty", metavar="INTERVAL",
12 help="The number of seconds between server "
13- "exchanges.")
14+ "exchanges.",
15+ action="callback", callback=self.int_or_empty)
16 parser.add_option("--urgent-exchange-interval", default=1 * 60,
17- type="int", metavar="INTERVAL",
18+ type="int_or_empty", metavar="INTERVAL",
19 help="The number of seconds between urgent server "
20 "exchanges.")
21 parser.add_option("--ping-url",
22 help="The URL to perform lightweight exchange "
23 "initiation with.")
24- parser.add_option("--ping-interval", default=30, type="int",
25+ parser.add_option("--ping-interval", default=30, type="int_or_empty",
26 metavar="INTERVAL",
27 help="The number of seconds between pings.")
28 parser.add_option("--http-proxy", metavar="URL",
29@@ -133,3 +134,18 @@
30
31 autodiscover = str(self.server_autodiscover).lower()
32 self.server_autodiscover = (autodiscover == "true")
33+
34+ if self.exchange_interval is "":
35+ self.exchange_interval = 15 * 60
36+ else:
37+ self.exchange_interval = int(self.exchange_interval)
38+
39+ if self.urgent_exchange_interval is "":
40+ self.urgent_exchange_interval = 1 * 60
41+ else:
42+ self.urgent_exchange_interval = int(self.urgent_exchange_interval)
43+
44+ if self.ping_interval is "":
45+ self.ping_interval = 30
46+ else:
47+ self.ping_interval = int(self.ping_interval)
48
49=== modified file 'landscape/deployment.py'
50--- landscape/deployment.py 2011-10-13 06:53:24 +0000
51+++ landscape/deployment.py 2012-02-21 21:36:18 +0000
52@@ -4,7 +4,8 @@
53 from logging import (getLevelName, getLogger,
54 FileHandler, StreamHandler, Formatter)
55
56-from optparse import OptionParser, SUPPRESS_HELP
57+from copy import copy
58+from optparse import OptionParser, Option, SUPPRESS_HELP
59 from ConfigParser import ConfigParser, NoSectionError
60
61 from landscape import VERSION
62@@ -30,6 +31,23 @@
63 handler.setFormatter(Formatter(format))
64
65
66+def check_int_or_empty(option, opt, value):
67+ """Validate the input of a int_or_empty parser type."""
68+ if value == '':
69+ return value
70+ try:
71+ return int(value)
72+ except ValueError:
73+ raise OptionValueError(
74+ "option %s: invalid integer value: %r" % (opt, value))
75+
76+
77+class OptionClass(Option):
78+ TYPES = Option.TYPES + ("int_or_empty",)
79+ TYPE_CHECKER = copy(Option.TYPE_CHECKER)
80+ TYPE_CHECKER["int_or_empty"] = check_int_or_empty
81+
82+
83 class BaseConfiguration(object):
84 """Base class for configuration implementations.
85
86@@ -230,7 +248,7 @@
87 landscape-related programs accept. These include
88 - C{config} (C{None})
89 """
90- parser = OptionParser(version=VERSION)
91+ parser = OptionParser(version=VERSION, option_class=OptionClass)
92 parser.add_option("-c", "--config", metavar="FILE",
93 help="Use config from this file (any command line "
94 "options override settings from the file) "
95
96=== modified file 'landscape/tests/test_configuration.py'
97--- landscape/tests/test_configuration.py 2012-02-02 02:49:13 +0000
98+++ landscape/tests/test_configuration.py 2012-02-21 21:36:18 +0000
99@@ -1631,6 +1631,66 @@
100 # care for this test. Mocker will ensure the tests
101 # we care about are done.
102
103+ def test_empty_exchange_interval(self):
104+ """
105+ Make sure an empty string can be used for the exchange interval.
106+ """
107+ # Make sure no sysvconfig modifications are attempted
108+ self.mocker.patch(SysVConfig)
109+ self.mocker.replay()
110+
111+ args = ["--silent", "--no-start",
112+ "--exchange-interval", "",]
113+ config = self.get_config(args)
114+ setup(config)
115+ self.assertEqual(config.exchange_interval, 15 * 60)
116+ self.assertConfigEqual(self.get_content(config),
117+ "[client]\n"
118+ "data_path = %s\n"
119+ "url = https://landscape.canonical.com/message-system\n"
120+ "server_autodiscover = False\n"
121+ % config.data_path)
122+
123+ def test_empty_urgent_exchange_interval(self):
124+ """
125+ Make sure an empty string can be used for the urgent exchange interval.
126+ """
127+ # Make sure no sysvconfig modifications are attempted
128+ self.mocker.patch(SysVConfig)
129+ self.mocker.replay()
130+
131+ args = ["--silent", "--no-start",
132+ "--urgent-exchange-interval", "",]
133+ config = self.get_config(args)
134+ setup(config)
135+ self.assertEqual(config.urgent_exchange_interval, 60)
136+ self.assertConfigEqual(self.get_content(config),
137+ "[client]\n"
138+ "data_path = %s\n"
139+ "url = https://landscape.canonical.com/message-system\n"
140+ "server_autodiscover = False\n"
141+ % config.data_path)
142+
143+ def test_empty_ping_interval(self):
144+ """
145+ Make sure an empty string can be used for the ping interval.
146+ """
147+ # Make sure no sysvconfig modifications are attempted
148+ self.mocker.patch(SysVConfig)
149+ self.mocker.replay()
150+
151+ args = ["--silent", "--no-start",
152+ "--ping-interval", "",]
153+ config = self.get_config(args)
154+ setup(config)
155+ self.assertEqual(config.ping_interval, 30)
156+ self.assertConfigEqual(self.get_content(config),
157+ "[client]\n"
158+ "data_path = %s\n"
159+ "url = https://landscape.canonical.com/message-system\n"
160+ "server_autodiscover = False\n"
161+ % config.data_path)
162+
163
164 class RegisterFunctionTest(LandscapeTest):
165

Subscribers

People subscribed via source and target branches

to all changes: