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
=== modified file 'landscape/broker/config.py'
--- landscape/broker/config.py 2012-02-06 21:04:44 +0000
+++ landscape/broker/config.py 2012-02-21 21:36:18 +0000
@@ -63,18 +63,19 @@
63 parser.add_option("-k", "--ssl-public-key",63 parser.add_option("-k", "--ssl-public-key",
64 help="The public SSL key to verify the server. "64 help="The public SSL key to verify the server. "
65 "Only used if the given URL is https.")65 "Only used if the given URL is https.")
66 parser.add_option("--exchange-interval", default=15 * 60, type="int",66 parser.add_option("--exchange-interval", default=15 * 60,
67 metavar="INTERVAL",67 type="int_or_empty", metavar="INTERVAL",
68 help="The number of seconds between server "68 help="The number of seconds between server "
69 "exchanges.")69 "exchanges.",
70 action="callback", callback=self.int_or_empty)
70 parser.add_option("--urgent-exchange-interval", default=1 * 60,71 parser.add_option("--urgent-exchange-interval", default=1 * 60,
71 type="int", metavar="INTERVAL",72 type="int_or_empty", metavar="INTERVAL",
72 help="The number of seconds between urgent server "73 help="The number of seconds between urgent server "
73 "exchanges.")74 "exchanges.")
74 parser.add_option("--ping-url",75 parser.add_option("--ping-url",
75 help="The URL to perform lightweight exchange "76 help="The URL to perform lightweight exchange "
76 "initiation with.")77 "initiation with.")
77 parser.add_option("--ping-interval", default=30, type="int",78 parser.add_option("--ping-interval", default=30, type="int_or_empty",
78 metavar="INTERVAL",79 metavar="INTERVAL",
79 help="The number of seconds between pings.")80 help="The number of seconds between pings.")
80 parser.add_option("--http-proxy", metavar="URL",81 parser.add_option("--http-proxy", metavar="URL",
@@ -133,3 +134,18 @@
133134
134 autodiscover = str(self.server_autodiscover).lower()135 autodiscover = str(self.server_autodiscover).lower()
135 self.server_autodiscover = (autodiscover == "true")136 self.server_autodiscover = (autodiscover == "true")
137
138 if self.exchange_interval is "":
139 self.exchange_interval = 15 * 60
140 else:
141 self.exchange_interval = int(self.exchange_interval)
142
143 if self.urgent_exchange_interval is "":
144 self.urgent_exchange_interval = 1 * 60
145 else:
146 self.urgent_exchange_interval = int(self.urgent_exchange_interval)
147
148 if self.ping_interval is "":
149 self.ping_interval = 30
150 else:
151 self.ping_interval = int(self.ping_interval)
136152
=== modified file 'landscape/deployment.py'
--- landscape/deployment.py 2011-10-13 06:53:24 +0000
+++ landscape/deployment.py 2012-02-21 21:36:18 +0000
@@ -4,7 +4,8 @@
4from logging import (getLevelName, getLogger,4from logging import (getLevelName, getLogger,
5 FileHandler, StreamHandler, Formatter)5 FileHandler, StreamHandler, Formatter)
66
7from optparse import OptionParser, SUPPRESS_HELP7from copy import copy
8from optparse import OptionParser, Option, SUPPRESS_HELP
8from ConfigParser import ConfigParser, NoSectionError9from ConfigParser import ConfigParser, NoSectionError
910
10from landscape import VERSION11from landscape import VERSION
@@ -30,6 +31,23 @@
30 handler.setFormatter(Formatter(format))31 handler.setFormatter(Formatter(format))
3132
3233
34def check_int_or_empty(option, opt, value):
35 """Validate the input of a int_or_empty parser type."""
36 if value == '':
37 return value
38 try:
39 return int(value)
40 except ValueError:
41 raise OptionValueError(
42 "option %s: invalid integer value: %r" % (opt, value))
43
44
45class OptionClass(Option):
46 TYPES = Option.TYPES + ("int_or_empty",)
47 TYPE_CHECKER = copy(Option.TYPE_CHECKER)
48 TYPE_CHECKER["int_or_empty"] = check_int_or_empty
49
50
33class BaseConfiguration(object):51class BaseConfiguration(object):
34 """Base class for configuration implementations.52 """Base class for configuration implementations.
3553
@@ -230,7 +248,7 @@
230 landscape-related programs accept. These include248 landscape-related programs accept. These include
231 - C{config} (C{None})249 - C{config} (C{None})
232 """250 """
233 parser = OptionParser(version=VERSION)251 parser = OptionParser(version=VERSION, option_class=OptionClass)
234 parser.add_option("-c", "--config", metavar="FILE",252 parser.add_option("-c", "--config", metavar="FILE",
235 help="Use config from this file (any command line "253 help="Use config from this file (any command line "
236 "options override settings from the file) "254 "options override settings from the file) "
237255
=== modified file 'landscape/tests/test_configuration.py'
--- landscape/tests/test_configuration.py 2012-02-02 02:49:13 +0000
+++ landscape/tests/test_configuration.py 2012-02-21 21:36:18 +0000
@@ -1631,6 +1631,66 @@
1631 # care for this test. Mocker will ensure the tests1631 # care for this test. Mocker will ensure the tests
1632 # we care about are done.1632 # we care about are done.
16331633
1634 def test_empty_exchange_interval(self):
1635 """
1636 Make sure an empty string can be used for the exchange interval.
1637 """
1638 # Make sure no sysvconfig modifications are attempted
1639 self.mocker.patch(SysVConfig)
1640 self.mocker.replay()
1641
1642 args = ["--silent", "--no-start",
1643 "--exchange-interval", "",]
1644 config = self.get_config(args)
1645 setup(config)
1646 self.assertEqual(config.exchange_interval, 15 * 60)
1647 self.assertConfigEqual(self.get_content(config),
1648 "[client]\n"
1649 "data_path = %s\n"
1650 "url = https://landscape.canonical.com/message-system\n"
1651 "server_autodiscover = False\n"
1652 % config.data_path)
1653
1654 def test_empty_urgent_exchange_interval(self):
1655 """
1656 Make sure an empty string can be used for the urgent exchange interval.
1657 """
1658 # Make sure no sysvconfig modifications are attempted
1659 self.mocker.patch(SysVConfig)
1660 self.mocker.replay()
1661
1662 args = ["--silent", "--no-start",
1663 "--urgent-exchange-interval", "",]
1664 config = self.get_config(args)
1665 setup(config)
1666 self.assertEqual(config.urgent_exchange_interval, 60)
1667 self.assertConfigEqual(self.get_content(config),
1668 "[client]\n"
1669 "data_path = %s\n"
1670 "url = https://landscape.canonical.com/message-system\n"
1671 "server_autodiscover = False\n"
1672 % config.data_path)
1673
1674 def test_empty_ping_interval(self):
1675 """
1676 Make sure an empty string can be used for the ping interval.
1677 """
1678 # Make sure no sysvconfig modifications are attempted
1679 self.mocker.patch(SysVConfig)
1680 self.mocker.replay()
1681
1682 args = ["--silent", "--no-start",
1683 "--ping-interval", "",]
1684 config = self.get_config(args)
1685 setup(config)
1686 self.assertEqual(config.ping_interval, 30)
1687 self.assertConfigEqual(self.get_content(config),
1688 "[client]\n"
1689 "data_path = %s\n"
1690 "url = https://landscape.canonical.com/message-system\n"
1691 "server_autodiscover = False\n"
1692 % config.data_path)
1693
16341694
1635class RegisterFunctionTest(LandscapeTest):1695class RegisterFunctionTest(LandscapeTest):
16361696

Subscribers

People subscribed via source and target branches

to all changes: