summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2017-01-19 08:26:54 -0500
committerSean Dague <sean@dague.net>2017-01-19 09:11:14 -0500
commit20ab477eaeb6ca438fcb78edeb53a54169222ea1 (patch)
tree707deee48d2998b2bfb6a97d829b5c9d75423c45
parentde7019bd28c486aa93b7aeedcb6249c393b8ddee (diff)
add setlc_raw to the cli
This allows the devstack_localrc command from grenade be ported to dsconf. Change-Id: Iea8e826205ad402d0cf6fd6688860171b6f0a391
Notes
Notes (review): Code-Review+2: Sean Dague <sean@dague.net> Workflow+1: Sean Dague <sean@dague.net> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 19 Jan 2017 20:25:58 +0000 Reviewed-on: https://review.openstack.org/422619 Project: openstack/devstack-tools Branch: refs/heads/master
-rw-r--r--devstack/cmd.py12
-rw-r--r--devstack/dsconf.py4
-rw-r--r--devstack/tests/test_localconf_set_local.py23
3 files changed, 36 insertions, 3 deletions
diff --git a/devstack/cmd.py b/devstack/cmd.py
index 5e54219..837866b 100644
--- a/devstack/cmd.py
+++ b/devstack/cmd.py
@@ -46,6 +46,10 @@ def setlc(local_conf, args):
46 local_conf.set_local(args.name, args.value) 46 local_conf.set_local(args.name, args.value)
47 47
48 48
49def setlc_raw(local_conf, args):
50 local_conf.set_raw(" ".join(args.items))
51
52
49def setlc_conf(local_conf, args): 53def setlc_conf(local_conf, args):
50 local_conf.set(args.group, args.conf, args.section, args.name, args.value) 54 local_conf.set(args.group, args.conf, args.section, args.name, args.value)
51 55
@@ -115,8 +119,14 @@ def parse_args(argv):
115 parser_setlc.add_argument('name') 119 parser_setlc.add_argument('name')
116 parser_setlc.add_argument('value') 120 parser_setlc.add_argument('value')
117 121
122 parser_setlc_raw = subparsers.add_parser(
123 'setlc_raw', help='set raw line at the end of localrc in local.conf')
124 parser_setlc_raw.set_defaults(func=setlc_raw)
125 parser_setlc_raw.add_argument('local_conf')
126 parser_setlc_raw.add_argument('items', nargs="+")
127
118 parser_setlc_conf = subparsers.add_parser( 128 parser_setlc_conf = subparsers.add_parser(
119 'setlc_conf', help='set variable in localrc of local.conf') 129 'setlc_conf', help='set variable in ini section of local.conf')
120 parser_setlc_conf.set_defaults(func=setlc_conf) 130 parser_setlc_conf.set_defaults(func=setlc_conf)
121 parser_setlc_conf.add_argument('local_conf') 131 parser_setlc_conf.add_argument('local_conf')
122 parser_setlc_conf.add_argument('group') 132 parser_setlc_conf.add_argument('group')
diff --git a/devstack/dsconf.py b/devstack/dsconf.py
index 06d7f76..253d812 100644
--- a/devstack/dsconf.py
+++ b/devstack/dsconf.py
@@ -233,11 +233,11 @@ class LocalConf(object):
233 if not os.path.exists(self.fname): 233 if not os.path.exists(self.fname):
234 with open(self.fname, "w+") as writer: 234 with open(self.fname, "w+") as writer:
235 writer.write("[[local|localrc]]\n") 235 writer.write("[[local|localrc]]\n")
236 writer.write("%s" % line) 236 writer.write("%s\n" % line.lstrip())
237 return 237 return
238 238
239 def _do_set(writer, no_line): 239 def _do_set(writer, no_line):
240 writer.write("%s" % line) 240 writer.write("%s\n" % line.lstrip())
241 self._at_insert_point_local(line, _do_set) 241 self._at_insert_point_local(line, _do_set)
242 242
243 def _at_insert_point(self, group, conf, section, name, func): 243 def _at_insert_point(self, group, conf, section, name, func):
diff --git a/devstack/tests/test_localconf_set_local.py b/devstack/tests/test_localconf_set_local.py
index a5049e7..daf6c59 100644
--- a/devstack/tests/test_localconf_set_local.py
+++ b/devstack/tests/test_localconf_set_local.py
@@ -62,6 +62,21 @@ global_physnet_mtu=1450
62compute = auto 62compute = auto
63""" 63"""
64 64
65RESULT3 = """
66[[local|localrc]]
67a=b
68c=d
69f=1
70enable_plugin foo http://foo branch
71enable_plugin bar http://foo branch
72[[post-config|$NEUTRON_CONF]]
73[DEFAULT]
74global_physnet_mtu=1450
75[[post-config|$NOVA_CONF]]
76[upgrade_levels]
77compute = auto
78"""
79
65 80
66class TestLcSet(testtools.TestCase): 81class TestLcSet(testtools.TestCase):
67 82
@@ -85,3 +100,11 @@ class TestLcSet(testtools.TestCase):
85 with open(self._path) as f: 100 with open(self._path) as f:
86 content = f.read() 101 content = f.read()
87 self.assertEqual(content, RESULT2) 102 self.assertEqual(content, RESULT2)
103
104 def test_set_raw(self):
105 conf = dsconf.LocalConf(self._path)
106 conf.set_local_raw("enable_plugin foo http://foo branch")
107 conf.set_local_raw("enable_plugin bar http://foo branch")
108 with open(self._path) as f:
109 content = f.read()
110 self.assertEqual(content, RESULT3)