Skip to content

Commit e1ca149

Browse files
author
Frederick Ross
committed
Fixed Stanza.submit to take a dict, not a string.
Added a test for it (and removed an unnecessary restart in the test suite). Updated CHANGELOG.
1 parent a7e61b5 commit e1ca149

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.0
44

5+
* Stanza.submit now takes a dictionary of key/value pairs specifying the stanza instead of a raw string.
56
* Namespace handling has changed subtly. Code that depends on namespace handling in detail may break.
67
* Added User.role_entities to return a list of the actual entity objects for the
78
roles of a user. User.roles still returns a list of the role names.

splunklib/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,11 +1680,11 @@ class Stanza(Entity):
16801680
def submit(self, stanza):
16811681
"""Populates a stanza in a given configuration file. #FRED? Thought KV pairs would be what you provide, not a single name.
16821682
1683-
:param stanza: The name of the stanza.
1684-
:type stanza: ``string``
1685-
:return: The new :class:`Stanza` object.
1683+
:param stanza: A dictionary of key/value pairs to set in this stanza.
1684+
:type stanza: ``dict``
1685+
:return: The :class:`Stanza` object this method is called on.
16861686
"""
1687-
self.service.request(self.path, method="POST", body=stanza)
1687+
self.service.post(self.path, **stanza)
16881688
return self
16891689

16901690
def __len__(self):

tests/test_conf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def setUp(self):
5050

5151
def tearDown(self):
5252
self.service.apps.delete(self.app_name)
53+
self.clear_restart_message()
5354

5455
def test_confs(self):
5556
confs = self.app_service.confs
@@ -83,6 +84,14 @@ def test_confs(self):
8384
self.assertEqual(len(stanza), 1)
8485
self.assertTrue(key in stanza)
8586

87+
values = {testlib.tmpname(): testlib.tmpname(),
88+
testlib.tmpname(): testlib.tmpname()}
89+
stanza.submit(values)
90+
stanza.refresh()
91+
for key, value in values.iteritems():
92+
self.assertTrue(key in stanza)
93+
self.assertEqual(value, stanza[key])
94+
8695
count = len(conf)
8796
conf.delete(stanza_name)
8897
self.assertFalse(stanza_name in conf)

0 commit comments

Comments
 (0)