Skip to content

Commit 0d05ca4

Browse files
committed
Merge pull request influxdata#294 from roman-vynar/more-funcs
Added drop_retention_policy()
2 parents da0eb9a + 5dfecd1 commit 0d05ca4

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

influxdb/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,20 @@ def alter_retention_policy(self, name, database=None,
548548

549549
self.query(query_string)
550550

551+
def drop_retention_policy(self, name, database=None):
552+
"""Drop an existing retention policy for a database.
553+
554+
:param name: the name of the retention policy to drop
555+
:type name: str
556+
:param database: the database for which the retention policy is
557+
dropped. Defaults to current client's database
558+
:type database: str
559+
"""
560+
query_string = (
561+
"DROP RETENTION POLICY {0} ON {1}"
562+
).format(name, database or self._database)
563+
self.query(query_string)
564+
551565
def get_list_retention_policies(self, database=None):
552566
"""Get the list of retention policies for a database.
553567

influxdb/tests/client_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,27 @@ def test_alter_retention_policy_invalid(self):
632632
with _mocked_session(cli, 'get', 400):
633633
self.cli.alter_retention_policy('somename', 'db')
634634

635+
def test_drop_retention_policy(self):
636+
example_response = '{"results":[{}]}'
637+
638+
with requests_mock.Mocker() as m:
639+
m.register_uri(
640+
requests_mock.GET,
641+
"http://localhost:8086/query",
642+
text=example_response
643+
)
644+
self.cli.drop_retention_policy('somename', 'db')
645+
self.assertEqual(
646+
m.last_request.qs['q'][0],
647+
'drop retention policy somename on db'
648+
)
649+
650+
@raises(Exception)
651+
def test_drop_retention_policy_fails(self):
652+
cli = InfluxDBClient('host', 8086, 'username', 'password')
653+
with _mocked_session(cli, 'delete', 401):
654+
cli.drop_retention_policy('default', 'db')
655+
635656
def test_get_list_retention_policies(self):
636657
example_response = \
637658
'{"results": [{"series": [{"values": [["fsfdsdf", "24h0m0s", 2]],'\

influxdb/tests/server_tests/client_test_with_server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,27 @@ def test_alter_retention_policy_invalid(self):
604604
rsp
605605
)
606606

607+
def test_drop_retention_policy(self):
608+
self.cli.create_retention_policy('somename', '1d', 1)
609+
610+
# Test drop retention
611+
self.cli.drop_retention_policy('somename', 'db')
612+
rsp = self.cli.get_list_retention_policies()
613+
self.assertEqual(
614+
[{'duration': '0', 'default': True,
615+
'replicaN': 1, 'name': 'default'}],
616+
rsp
617+
)
618+
619+
def test_drop_retention_policy_default(self):
620+
# Test drop default retention
621+
with self.assertRaises(InfluxDBClientError) as ctx:
622+
self.cli.drop_retention_policy('default', 'db')
623+
624+
self.assertEqual(400, ctx.exception.code)
625+
self.assertIn('{"error":"error parsing query: found DEFAULT, expected POLICY',
626+
ctx.exception.content)
627+
607628
def test_issue_143(self):
608629
pt = partial(point, 'a_serie_name', timestamp='2015-03-30T16:16:37Z')
609630
pts = [

0 commit comments

Comments
 (0)