Added decribe_option_groups and delete_option_group support
This commit is contained in:
		
							parent
							
								
									40db44f2cd
								
							
						
					
					
						commit
						503d46d36a
					
				| @ -3,6 +3,7 @@ from __future__ import unicode_literals | ||||
| import copy | ||||
| 
 | ||||
| import boto.rds2 | ||||
| import json | ||||
| from jinja2 import Template | ||||
| 
 | ||||
| from moto.cloudformation.exceptions import UnformattedGetAttTemplateException | ||||
| @ -462,6 +463,40 @@ class RDS2Backend(BaseBackend): | ||||
|         self.option_groups[option_group_id] = option_group | ||||
|         return option_group | ||||
| 
 | ||||
|     def delete_option_group(self, option_group_name): | ||||
|         if option_group_name in self.option_groups: | ||||
|             return self.option_groups.pop(option_group_name) | ||||
|         else: | ||||
|             raise RDSClientError('OptionGroupNotFoundFault', 'Specified OptionGroupName: {} not found.'.format(option_group_name)) | ||||
| 
 | ||||
|     def describe_option_groups(self, option_group_kwargs): | ||||
|         option_group_list = [] | ||||
| 
 | ||||
|         if option_group_kwargs['marker']: | ||||
|             marker = option_group_kwargs['marker'] | ||||
|         else: | ||||
|             marker = 0 | ||||
|         if option_group_kwargs['max_records']: | ||||
|             max_records = option_group_kwargs['max_records'] | ||||
|         else: | ||||
|             max_records = 100 | ||||
| 
 | ||||
|         for option_group_name, option_group in self.option_groups.items(): | ||||
|             if option_group_kwargs['name'] and option_group.name != option_group_kwargs['name']: | ||||
|                 continue | ||||
|             elif option_group_kwargs['engine_name'] and \ | ||||
|                     option_group.engine_name != option_group_kwargs['engine_name']: | ||||
|                 continue | ||||
|             elif option_group_kwargs['major_engine_version'] and \ | ||||
|                     option_group.major_engine_version != option_group_kwargs['major_engine_version']: | ||||
|                 continue | ||||
|             else: | ||||
|                 option_group_list.append(option_group) | ||||
|         if not len(option_group_list): | ||||
|             raise RDSClientError('OptionGroupNotFoundFault', | ||||
|                                  'Specified OptionGroupName: {} not found.'.format(option_group_kwargs['name'])) | ||||
|         return option_group_list[marker:max_records+marker] | ||||
| 
 | ||||
| 
 | ||||
| class OptionGroup(object): | ||||
|     def __init__(self, name, engine_name, major_engine_version, description=None): | ||||
|  | ||||
| @ -164,6 +164,21 @@ class RDS2Response(BaseResponse): | ||||
|         template = self.response_template(CREATE_OPTION_GROUP_TEMPLATE) | ||||
|         return template.render(option_group=option_group) | ||||
| 
 | ||||
|     def delete_option_group(self): | ||||
|         kwargs = self._get_option_group_kwargs() | ||||
|         option_group = self.backend.delete_option_group(kwargs['name']) | ||||
|         template = self.response_template(DELETE_OPTION_GROUP_TEMPLATE) | ||||
|         return template.render(option_group=option_group) | ||||
| 
 | ||||
|     def describe_option_groups(self): | ||||
|         kwargs = self._get_option_group_kwargs() | ||||
|         kwargs['max_records'] = self._get_param('MaxRecords') | ||||
|         kwargs['marker'] = self._get_param('Marker') | ||||
|         option_groups = self.backend.describe_option_groups(kwargs) | ||||
|         template = self.response_template(DESCRIBE_OPTION_GROUP_TEMPLATE) | ||||
|         return template.render(option_groups=option_groups) | ||||
| 
 | ||||
| 
 | ||||
| CREATE_DATABASE_TEMPLATE = """{ | ||||
|   "CreateDBInstanceResponse": { | ||||
|     "CreateDBInstanceResult": { | ||||
| @ -287,3 +302,20 @@ CREATE_OPTION_GROUP_TEMPLATE = """{ | ||||
|         } | ||||
|     } | ||||
| }""" | ||||
| 
 | ||||
| DELETE_OPTION_GROUP_TEMPLATE = \ | ||||
|     """{"DeleteOptionGroupResponse": {"ResponseMetadata": {"RequestId": "e2590367-9fa2-11e4-99cf-55e92d41c60e"}}}""" | ||||
| 
 | ||||
| DESCRIBE_OPTION_GROUP_TEMPLATE = \ | ||||
|     """{"DescribeOptionGroupsResponse": { | ||||
|           "DescribeOptionGroupsResult": { | ||||
|             "Marker": null, | ||||
|             "OptionGroupsList": [ | ||||
|             {%- for option_group in option_groups -%} | ||||
|                 {%- if loop.index != 1 -%},{%- endif -%} | ||||
|                 {{ option_group.to_json() }} | ||||
|             {%- endfor -%} | ||||
|             ]}, | ||||
|             "ResponseMetadata": {"RequestId": "4caf445d-9fbc-11e4-87ea-a31c60ed2e36"} | ||||
|         }}""" | ||||
| 
 | ||||
|  | ||||
| @ -91,6 +91,36 @@ def test_create_option_group_empty_description(): | ||||
|     conn.create_option_group.when.called_with('test', 'postgres', '9.3', '').should.throw(BotoServerError) | ||||
| 
 | ||||
| 
 | ||||
| @mock_rds2 | ||||
| def test_describe_option_group(): | ||||
|     conn = boto.rds2.connect_to_region("us-west-2") | ||||
|     conn.create_option_group('test', 'postgres', '9.3', 'test option group') | ||||
|     option_groups = conn.describe_option_groups('test') | ||||
|     option_groups['DescribeOptionGroupsResponse']['DescribeOptionGroupsResult']['OptionGroupsList'][0]['OptionGroupName'].should.equal('test') | ||||
| 
 | ||||
| @mock_rds2 | ||||
| def test_describe_non_existant_option_group(): | ||||
|     conn = boto.rds2.connect_to_region("us-west-2") | ||||
|     conn.describe_option_groups.when.called_with("not-a-option-group").should.throw(BotoServerError) | ||||
| 
 | ||||
| 
 | ||||
| @mock_rds2 | ||||
| def test_delete_option_group(): | ||||
|     conn = boto.rds2.connect_to_region("us-west-2") | ||||
|     conn.create_option_group('test', 'postgres', '9.3', 'test option group') | ||||
|     option_groups = conn.describe_option_groups('test') | ||||
|     option_groups['DescribeOptionGroupsResponse']['DescribeOptionGroupsResult']['OptionGroupsList'][0]['OptionGroupName'].should.equal('test') | ||||
|     conn.delete_option_group('test') | ||||
|     conn.describe_option_groups.when.called_with('test').should.throw(BotoServerError) | ||||
| 
 | ||||
| 
 | ||||
| @mock_rds2 | ||||
| def test_delete_non_existant_option_group(): | ||||
|     conn = boto.rds2.connect_to_region("us-west-2") | ||||
|     conn.delete_option_group.when.called_with('non-existant').should.throw(BotoServerError) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| #@disable_on_py3() | ||||
| #@mock_rds2 | ||||
| #def test_delete_database(): | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user