| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved | 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # | 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: | 10 # lowing conditions: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 # IN THE SOFTWARE. | 21 # IN THE SOFTWARE. |
| 22 # | 22 # |
| 23 | 23 |
| 24 from tests.unit import unittest | 24 from tests.unit import unittest |
| 25 from tests.unit import AWSMockServiceTestCase | 25 from tests.unit import AWSMockServiceTestCase |
| 26 | 26 |
| 27 from boto.ec2.securitygroup import SecurityGroup | 27 from boto.ec2.securitygroup import SecurityGroup |
| 28 from boto.rds import RDSConnection | 28 from boto.rds import RDSConnection |
| 29 from boto.rds.vpcsecuritygroupmembership import VPCSecurityGroupMembership | 29 from boto.rds.vpcsecuritygroupmembership import VPCSecurityGroupMembership |
| 30 from boto.rds.parametergroup import ParameterGroup | 30 from boto.rds.parametergroup import ParameterGroup |
| 31 from boto.rds.logfile import LogFile, LogFileObject |
| 31 | 32 |
| 33 import xml.sax.saxutils as saxutils |
| 32 | 34 |
| 33 class TestRDSConnection(AWSMockServiceTestCase): | 35 class TestRDSConnection(AWSMockServiceTestCase): |
| 34 connection_class = RDSConnection | 36 connection_class = RDSConnection |
| 35 | 37 |
| 36 def setUp(self): | 38 def setUp(self): |
| 37 super(TestRDSConnection, self).setUp() | 39 super(TestRDSConnection, self).setUp() |
| 38 | 40 |
| 39 def default_body(self): | 41 def default_body(self): |
| 40 return """ | 42 return """ |
| 41 <DescribeDBInstancesResponse> | 43 <DescribeDBInstancesResponse> |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 self.assertEqual(options.name, 'myoptiongroup') | 545 self.assertEqual(options.name, 'myoptiongroup') |
| 544 self.assertEqual(options.description, 'Test option group') | 546 self.assertEqual(options.description, 'Test option group') |
| 545 self.assertEqual(options.engine_name, 'oracle-se1') | 547 self.assertEqual(options.engine_name, 'oracle-se1') |
| 546 self.assertEqual(options.major_engine_version, '11.2') | 548 self.assertEqual(options.major_engine_version, '11.2') |
| 547 options = response[1] | 549 options = response[1] |
| 548 self.assertEqual(options.name, 'default:oracle-se1-11-2') | 550 self.assertEqual(options.name, 'default:oracle-se1-11-2') |
| 549 self.assertEqual(options.description, 'Default Option Group.') | 551 self.assertEqual(options.description, 'Default Option Group.') |
| 550 self.assertEqual(options.engine_name, 'oracle-se1') | 552 self.assertEqual(options.engine_name, 'oracle-se1') |
| 551 self.assertEqual(options.major_engine_version, '11.2') | 553 self.assertEqual(options.major_engine_version, '11.2') |
| 552 | 554 |
| 555 class TestRDSLogFile(AWSMockServiceTestCase): |
| 556 connection_class = RDSConnection |
| 557 |
| 558 def setUp(self): |
| 559 super(TestRDSLogFile, self).setUp() |
| 560 |
| 561 def default_body(self): |
| 562 return """ |
| 563 <DescribeDBLogFilesResponse xmlns="http://rds.amazonaws.com/doc/2013-02-
12/"> |
| 564 <DescribeDBLogFilesResult> |
| 565 <DescribeDBLogFiles> |
| 566 <DescribeDBLogFilesDetails> |
| 567 <LastWritten>1364403600000</LastWritten> |
| 568 <LogFileName>error/mysql-error-running.log</LogFileName> |
| 569 <Size>0</Size> |
| 570 </DescribeDBLogFilesDetails> |
| 571 <DescribeDBLogFilesDetails> |
| 572 <LastWritten>1364338800000</LastWritten> |
| 573 <LogFileName>error/mysql-error-running.log.0</LogFileName> |
| 574 <Size>0</Size> |
| 575 </DescribeDBLogFilesDetails> |
| 576 <DescribeDBLogFilesDetails> |
| 577 <LastWritten>1364342400000</LastWritten> |
| 578 <LogFileName>error/mysql-error-running.log.1</LogFileName> |
| 579 <Size>0</Size> |
| 580 </DescribeDBLogFilesDetails> |
| 581 <DescribeDBLogFilesDetails> |
| 582 <LastWritten>1364346000000</LastWritten> |
| 583 <LogFileName>error/mysql-error-running.log.2</LogFileName> |
| 584 <Size>0</Size> |
| 585 </DescribeDBLogFilesDetails> |
| 586 <DescribeDBLogFilesDetails> |
| 587 <LastWritten>1364349600000</LastWritten> |
| 588 <LogFileName>error/mysql-error-running.log.3</LogFileName> |
| 589 <Size>0</Size> |
| 590 </DescribeDBLogFilesDetails> |
| 591 <DescribeDBLogFilesDetails> |
| 592 <LastWritten>1364405700000</LastWritten> |
| 593 <LogFileName>error/mysql-error.log</LogFileName> |
| 594 <Size>0</Size> |
| 595 </DescribeDBLogFilesDetails> |
| 596 </DescribeDBLogFiles> |
| 597 </DescribeDBLogFilesResult> |
| 598 <ResponseMetadata> |
| 599 <RequestId>d70fb3b3-9704-11e2-a0db-871552e0ef19</RequestId> |
| 600 </ResponseMetadata> |
| 601 </DescribeDBLogFilesResponse> |
| 602 """ |
| 603 |
| 604 def test_get_all_logs_simple(self): |
| 605 self.set_http_response(status_code=200) |
| 606 response = self.service_connection.get_all_logs('db1') |
| 607 |
| 608 self.assert_request_parameters({ |
| 609 'Action': 'DescribeDBLogFiles', |
| 610 'DBInstanceIdentifier': 'db1', |
| 611 }, ignore_params_values=['Version']) |
| 612 |
| 613 self.assertEqual(len(response), 6) |
| 614 self.assertTrue(isinstance(response[0], LogFile)) |
| 615 self.assertEqual(response[0].log_filename, 'error/mysql-error-running.lo
g') |
| 616 self.assertEqual(response[0].last_written, '1364403600000') |
| 617 self.assertEqual(response[0].size, '0') |
| 618 |
| 619 def test_get_all_logs_filtered(self): |
| 620 self.set_http_response(status_code=200) |
| 621 response = self.service_connection.get_all_logs('db_instance_1', max_rec
ords=100, marker='error/mysql-error.log', file_size=2000000, filename_contains='
error', file_last_written=12345678) |
| 622 |
| 623 self.assert_request_parameters({ |
| 624 'Action': 'DescribeDBLogFiles', |
| 625 'DBInstanceIdentifier': 'db_instance_1', |
| 626 'MaxRecords': 100, |
| 627 'Marker': 'error/mysql-error.log', |
| 628 'FileSize': 2000000, |
| 629 'FilenameContains': 'error', |
| 630 'FileLastWritten': 12345678, |
| 631 }, ignore_params_values=['Version']) |
| 632 |
| 633 self.assertEqual(len(response), 6) |
| 634 self.assertTrue(isinstance(response[0], LogFile)) |
| 635 self.assertEqual(response[0].log_filename, 'error/mysql-error-running.lo
g') |
| 636 self.assertEqual(response[0].last_written, '1364403600000') |
| 637 self.assertEqual(response[0].size, '0') |
| 638 |
| 639 |
| 640 class TestRDSLogFileDownload(AWSMockServiceTestCase): |
| 641 connection_class = RDSConnection |
| 642 logfile_sample = """ |
| 643 ??2014-01-26 23:59:00.01 spid54 Microsoft SQL Server 2012 - 11.0.2100.60 (X
64) |
| 644 |
| 645 Feb 10 2012 19:39:15 |
| 646 |
| 647 Copyright (c) Microsoft Corporation |
| 648 |
| 649 Web Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack
1) (Hypervisor) |
| 650 |
| 651 |
| 652 |
| 653 2014-01-26 23:59:00.01 spid54 (c) Microsoft Corporation. |
| 654 |
| 655 2014-01-26 23:59:00.01 spid54 All rights reserved. |
| 656 |
| 657 2014-01-26 23:59:00.01 spid54 Server process ID is 2976. |
| 658 |
| 659 2014-01-26 23:59:00.01 spid54 System Manufacturer: 'Xen', System Model: 'HV
M domU'. |
| 660 |
| 661 2014-01-26 23:59:00.01 spid54 Authentication mode is MIXED. |
| 662 |
| 663 2014-01-26 23:59:00.01 spid54 Logging SQL Server messages in file 'D:\RDSDB
DATA\Log\ERROR'. |
| 664 |
| 665 2014-01-26 23:59:00.01 spid54 The service account is 'WORKGROUP\AMAZONA-NUQ
UUMV$'. This is an informational message; no user action is required. |
| 666 |
| 667 2014-01-26 23:59:00.01 spid54 The error log has been reinitialized. See the
previous log for older entries. |
| 668 |
| 669 2014-01-27 00:00:56.42 spid25s This instance of SQL Server has been using a
process ID of 2976 since 10/21/2013 2:16:50 AM (local) 10/21/2013 2:16:50 AM (UT
C). This is an informational message only; no user action is required. |
| 670 |
| 671 2014-01-27 09:35:15.43 spid71 I/O is frozen on database model. No user acti
on is required. However, if I/O is not resumed promptly, you could cancel the ba
ckup. |
| 672 |
| 673 2014-01-27 09:35:15.44 spid72 I/O is frozen on database msdb. No user actio
n is required. However, if I/O is not resumed promptly, you could cancel the bac
kup. |
| 674 |
| 675 2014-01-27 09:35:15.44 spid74 I/O is frozen on database rdsadmin. No user a
ction is required. However, if I/O is not resumed promptly, you could cancel the
backup. |
| 676 |
| 677 2014-01-27 09:35:15.44 spid73 I/O is frozen on database master. No user act
ion is required. However, if I/O is not resumed promptly, you could cancel the b
ackup. |
| 678 |
| 679 2014-01-27 09:35:25.57 spid73 I/O was resumed on database master. No user a
ction is required. |
| 680 |
| 681 2014-01-27 09:35:25.57 spid74 I/O was resumed on database rdsadmin. No user
action is required. |
| 682 |
| 683 2014-01-27 09:35:25.57 spid71 I/O was resumed on database model. No user ac
tion is required. |
| 684 |
| 685 2014-01-27 09:35:25.57 spid72 I/O was resumed on database msdb. No user act
ion is required. |
| 686 """ |
| 687 |
| 688 def setUp(self): |
| 689 super(TestRDSLogFileDownload, self).setUp() |
| 690 |
| 691 def default_body(self): |
| 692 return """ |
| 693 <DownloadDBLogFilePortionResponse xmlns="http://rds.amazonaws.com/doc/2013-09-09
/"> |
| 694 <DownloadDBLogFilePortionResult> |
| 695 <Marker>0:4485</Marker> |
| 696 <LogFileData>%s</LogFileData> |
| 697 <AdditionalDataPending>false</AdditionalDataPending> |
| 698 </DownloadDBLogFilePortionResult> |
| 699 <ResponseMetadata> |
| 700 <RequestId>27143615-87ae-11e3-acc9-fb64b157268e</RequestId> |
| 701 </ResponseMetadata> |
| 702 </DownloadDBLogFilePortionResponse> |
| 703 """ % self.logfile_sample |
| 704 |
| 705 def test_single_download(self): |
| 706 self.set_http_response(status_code=200) |
| 707 response = self.service_connection.get_log_file('db1', 'foo.log') |
| 708 |
| 709 self.assertTrue(isinstance(response, LogFileObject)) |
| 710 self.assertEqual(response.marker, '0:4485') |
| 711 self.assertEqual(response.dbinstance_id, 'db1') |
| 712 self.assertEqual(response.log_filename, 'foo.log') |
| 713 |
| 714 self.assertEqual(response.data, saxutils.unescape(self.logfile_sample)) |
| 715 |
| 716 self.assert_request_parameters({ |
| 717 'Action': 'DownloadDBLogFilePortion', |
| 718 'DBInstanceIdentifier': 'db1', |
| 719 'LogFileName': 'foo.log', |
| 720 }, ignore_params_values=['Version']) |
| 721 |
| 722 def test_multi_args(self): |
| 723 self.set_http_response(status_code=200) |
| 724 response = self.service_connection.get_log_file('db1', 'foo.log', marker
='0:4485', number_of_lines=10) |
| 725 |
| 726 self.assertTrue(isinstance(response, LogFileObject)) |
| 727 |
| 728 self.assert_request_parameters({ |
| 729 'Action': 'DownloadDBLogFilePortion', |
| 730 'DBInstanceIdentifier': 'db1', |
| 731 'Marker': '0:4485', |
| 732 'NumberOfLines': 10, |
| 733 'LogFileName': 'foo.log', |
| 734 }, ignore_params_values=['Version']) |
| 735 |
| 553 | 736 |
| 554 class TestRDSOptionGroupOptions(AWSMockServiceTestCase): | 737 class TestRDSOptionGroupOptions(AWSMockServiceTestCase): |
| 555 connection_class = RDSConnection | 738 connection_class = RDSConnection |
| 556 | 739 |
| 557 def setUp(self): | 740 def setUp(self): |
| 558 super(TestRDSOptionGroupOptions, self).setUp() | 741 super(TestRDSOptionGroupOptions, self).setUp() |
| 559 | 742 |
| 560 def default_body(self): | 743 def default_body(self): |
| 561 return """ | 744 return """ |
| 562 <DescribeOptionGroupOptionsResponse xmlns="http://rds.amazonaws.com/doc/
2013-05-15/"> | 745 <DescribeOptionGroupOptionsResponse xmlns="http://rds.amazonaws.com/doc/
2013-05-15/"> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 self.assertEqual(options.port_required, True) | 778 self.assertEqual(options.port_required, True) |
| 596 self.assertEqual(options.default_port, 1158) | 779 self.assertEqual(options.default_port, 1158) |
| 597 self.assertEqual(options.permanent, False) | 780 self.assertEqual(options.permanent, False) |
| 598 self.assertEqual(options.persistent, False) | 781 self.assertEqual(options.persistent, False) |
| 599 self.assertEqual(options.depends_on, []) | 782 self.assertEqual(options.depends_on, []) |
| 600 | 783 |
| 601 | 784 |
| 602 if __name__ == '__main__': | 785 if __name__ == '__main__': |
| 603 unittest.main() | 786 unittest.main() |
| 604 | 787 |
| OLD | NEW |