Browse Source

add setlc_raw to the cli

This allows the devstack_localrc command from grenade be ported to
dsconf.

Change-Id: Iea8e826205ad402d0cf6fd6688860171b6f0a391
Sean Dague 2 years ago
parent
commit
20ab477eae
3 changed files with 36 additions and 3 deletions
  1. 11
    1
      devstack/cmd.py
  2. 2
    2
      devstack/dsconf.py
  3. 23
    0
      devstack/tests/test_localconf_set_local.py

+ 11
- 1
devstack/cmd.py View File

@@ -46,6 +46,10 @@ def setlc(local_conf, args):
46 46
     local_conf.set_local(args.name, args.value)
47 47
 
48 48
 
49
+def setlc_raw(local_conf, args):
50
+    local_conf.set_raw(" ".join(args.items))
51
+
52
+
49 53
 def setlc_conf(local_conf, args):
50 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 119
     parser_setlc.add_argument('name')
116 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 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 130
     parser_setlc_conf.set_defaults(func=setlc_conf)
121 131
     parser_setlc_conf.add_argument('local_conf')
122 132
     parser_setlc_conf.add_argument('group')

+ 2
- 2
devstack/dsconf.py View File

@@ -233,11 +233,11 @@ class LocalConf(object):
233 233
         if not os.path.exists(self.fname):
234 234
             with open(self.fname, "w+") as writer:
235 235
                 writer.write("[[local|localrc]]\n")
236
-                writer.write("%s" % line)
236
+                writer.write("%s\n" % line.lstrip())
237 237
                 return
238 238
 
239 239
         def _do_set(writer, no_line):
240
-            writer.write("%s" % line)
240
+            writer.write("%s\n" % line.lstrip())
241 241
         self._at_insert_point_local(line, _do_set)
242 242
 
243 243
     def _at_insert_point(self, group, conf, section, name, func):

+ 23
- 0
devstack/tests/test_localconf_set_local.py View File

@@ -62,6 +62,21 @@ global_physnet_mtu=1450
62 62
 compute = auto
63 63
 """
64 64
 
65
+RESULT3 = """
66
+[[local|localrc]]
67
+a=b
68
+c=d
69
+f=1
70
+enable_plugin foo http://foo branch
71
+enable_plugin bar http://foo branch
72
+[[post-config|$NEUTRON_CONF]]
73
+[DEFAULT]
74
+global_physnet_mtu=1450
75
+[[post-config|$NOVA_CONF]]
76
+[upgrade_levels]
77
+compute = auto
78
+"""
79
+
65 80
 
66 81
 class TestLcSet(testtools.TestCase):
67 82
 
@@ -85,3 +100,11 @@ class TestLcSet(testtools.TestCase):
85 100
         with open(self._path) as f:
86 101
             content = f.read()
87 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)

Loading…
Cancel
Save