From 77ef9316bdad6c1ed66f79dc205d7b3358a712b9 Mon Sep 17 00:00:00 2001 From: Pascal Hakim Date: Sat, 8 Feb 2014 17:51:09 +1100 Subject: [PATCH] Finished implementation of RDS's DescribeDBLogFiles --- boto/rds/__init__.py | 42 ++++++++++++++++++++++++------- tests/unit/rds/test_connection.py | 16 +++++++----- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/boto/rds/__init__.py b/boto/rds/__init__.py index edf6237a1a..99d6b2e0fa 100644 --- a/boto/rds/__init__.py +++ b/boto/rds/__init__.py @@ -1076,23 +1076,47 @@ def get_all_dbsnapshots(self, snapshot_id=None, instance_id=None, return self.get_list('DescribeDBSnapshots', params, [('DBSnapshot', DBSnapshot)]) - def get_all_logs(self, dbinstance_id=None): + def get_all_logs(self, dbinstance_id, max_records=None, marker=None, file_size=None, filename_contains=None, file_last_written=None): """ Get all log files :type instance_id: str - :param instance_id: The identifier of a DBInstance. If provided, - only the :class:`boto.rds.logfile.LogFile` related - to that instance will be returned. If not - provided, all logfiles will be returned. + :param instance_id: The identifier of a DBInstance. + + :type max_records: int + :param max_records: Number of log file names to return. + + :type marker: str + :param marker: The marker provided by a previous request. + + :file_size: int + :param file_size: Filter results to files large than this size in bytes. + + :filename_contains: str + :param filename_contains: Filter results to files with filename containing this string + + :file_last_written: int + :param file_last_written: Filter results to files written after this time (POSIX timestamp) :rtype: list :return: A list of :class:`boto.rds.logfile.LogFile` """ - params = {} - if dbinstance_id: - params['DBInstanceIdentifier'] = dbinstance_id - params['MaxRecords'] = 26 + params = {'DBInstanceIdentifier': dbinstance_id} + + if file_size: + params['FileSize'] = file_size + + if filename_contains: + params['FilenameContains'] = filename_contains + + if file_last_written: + params['FileLastWritten'] = file_last_written + + if marker: + params['Marker'] = marker + + if max_records: + params['MaxRecords'] = max_records return self.get_list('DescribeDBLogFiles', params, [('DescribeDBLogFilesDetails',LogFile)]) diff --git a/tests/unit/rds/test_connection.py b/tests/unit/rds/test_connection.py index 48afc9e044..d925ef47b7 100644 --- a/tests/unit/rds/test_connection.py +++ b/tests/unit/rds/test_connection.py @@ -599,13 +599,13 @@ def default_body(self): """ - def test_get_all_logs(self): + def test_get_all_logs_simple(self): self.set_http_response(status_code=200) - response = self.service_connection.get_all_logs() + response = self.service_connection.get_all_logs('db1') self.assert_request_parameters({ 'Action': 'DescribeDBLogFiles', - 'MaxRecords': 26, + 'DBInstanceIdentifier': 'db1', }, ignore_params_values=['Version']) self.assertEqual(len(response), 6) @@ -614,14 +614,18 @@ def test_get_all_logs(self): self.assertEqual(response[0].last_written, '1364403600000') self.assertEqual(response[0].size, '0') - def test_get_all_logs_single(self): + def test_get_all_logs_filtered(self): self.set_http_response(status_code=200) - response = self.service_connection.get_all_logs('db_instance_1') + response = self.service_connection.get_all_logs('db_instance_1', max_records=100, marker='error/mysql-error.log', file_size=2000000, filename_contains='error', file_last_written=12345678) self.assert_request_parameters({ 'Action': 'DescribeDBLogFiles', 'DBInstanceIdentifier': 'db_instance_1', - 'MaxRecords': 26, + 'MaxRecords': 100, + 'Marker': 'error/mysql-error.log', + 'FileSize': 2000000, + 'FilenameContains': 'error', + 'FileLastWritten': 12345678, }, ignore_params_values=['Version']) self.assertEqual(len(response), 6)