Class: Fog::AWS::RDS::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::RDS::Mock
- Defined in:
- lib/fog/aws/rds.rb,
lib/fog/aws/requests/rds/create_db_instance.rb,
lib/fog/aws/requests/rds/create_db_snapshot.rb,
lib/fog/aws/requests/rds/delete_db_instance.rb,
lib/fog/aws/requests/rds/delete_db_snapshot.rb,
lib/fog/aws/requests/rds/modify_db_instance.rb,
lib/fog/aws/requests/rds/reboot_db_instance.rb,
lib/fog/aws/requests/rds/describe_db_instances.rb,
lib/fog/aws/requests/rds/describe_db_snapshots.rb,
lib/fog/aws/requests/rds/describe_db_parameters.rb,
lib/fog/aws/requests/rds/create_db_security_group.rb,
lib/fog/aws/requests/rds/delete_db_security_group.rb,
lib/fog/aws/requests/rds/create_db_parameter_group.rb,
lib/fog/aws/requests/rds/delete_db_parameter_group.rb,
lib/fog/aws/requests/rds/modify_db_parameter_group.rb,
lib/fog/aws/requests/rds/describe_db_engine_versions.rb,
lib/fog/aws/requests/rds/describe_db_security_groups.rb,
lib/fog/aws/requests/rds/describe_db_parameter_groups.rb,
lib/fog/aws/requests/rds/describe_db_reserved_instances.rb,
lib/fog/aws/requests/rds/create_db_instance_read_replica.rb,
lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb,
lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb,
lib/fog/aws/requests/rds/restore_db_instance_from_db_snapshot.rb,
lib/fog/aws/requests/rds/restore_db_instance_to_point_in_time.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorize_db_security_group_ingress(name, opts = {}) ⇒ Object
- #create_db_instance(db_name, options = {}) ⇒ Object
- #create_db_instance_read_replica(instance_identifier, source_identifier, options = {}) ⇒ Object
- #create_db_parameter_group(group_name, group_family, description) ⇒ Object
- #create_db_security_group(name, description = name) ⇒ Object
- #create_db_snapshot(identifier, name) ⇒ Object
- #data ⇒ Object
- #delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) ⇒ Object
- #delete_db_parameter_group(group_name) ⇒ Object
- #delete_db_security_group(name, description = name) ⇒ Object
- #delete_db_snapshot(group_name) ⇒ Object
- #describe_db_engine_versions(opts = {}) ⇒ Object
- #describe_db_instances(identifier = nil, opts = {}) ⇒ Object
- #describe_db_parameter_groups(name = nil, opts = {}) ⇒ Object
- #describe_db_parameters(name, opts = {}) ⇒ Object
- #describe_db_reserved_instances(identifier = nil, opts = {}) ⇒ Object
- #describe_db_security_group(opts = {}) ⇒ Object
- #describe_db_snapshots(opts = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #modify_db_instance(db_name, apply_immediately, options = {}) ⇒ Object
- #modify_db_parameter_group(group_name, parameters) ⇒ Object
- #reboot_db_instance(instance_identifier) ⇒ Object
- #reset_data ⇒ Object
- #restore_db_instance_from_db_snapshot(snapshot_id, db_id, options = {}) ⇒ Object
- #restore_db_instance_to_point_in_time(source_db_name, target_db_name, opts = {}) ⇒ Object
- #revoke_db_security_group_ingress(name, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fog/aws/rds.rb', line 75 def initialize(={}) @aws_access_key_id = [:aws_access_key_id] @region = [:region] || 'us-east-1' unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region) raise ArgumentError, "Unknown region: #{@region.inspect}" end end |
Class Method Details
.data ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/aws/rds.rb', line 60 def self.data @data ||= Hash.new do |hash, region| owner_id = Fog::AWS::Mock.owner_id hash[region] = Hash.new do |region_hash, key| region_hash[key] = { :servers => {} } end end end |
.reset ⇒ Object
71 72 73 |
# File 'lib/fog/aws/rds.rb', line 71 def self.reset @data = nil end |
Instance Method Details
#authorize_db_security_group_ingress(name, opts = {}) ⇒ Object
35 36 37 |
# File 'lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb', line 35 def (name, opts = {}) Fog::Mock.not_implemented end |
#create_db_instance(db_name, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fog/aws/requests/rds/create_db_instance.rb', line 49 def create_db_instance(db_name, ={}) response = Excon::Response.new if self.data[:servers] and self.data[:servers][db_name] # I don't know how to raise an exception that contains the excon data #response.status = 400 #response.body = { # 'Code' => 'DBInstanceAlreadyExists', # 'Message' => "DB Instance already exists" #} #return response raise Fog::AWS::RDS::IdentifierTaken.new("DBInstanceAlreadyExists #{response.body.to_s}") end # These are the required parameters according to the API required_params = %w{AllocatedStorage DBInstanceClass Engine MasterUserPassword MasterUsername } required_params.each do |key| unless .has_key?(key) and [key] and ![key].to_s.empty? #response.status = 400 #response.body = { # 'Code' => 'MissingParameter', # 'Message' => "The request must contain the parameter #{key}" #} #return response raise Fog::AWS::RDS::NotFound.new("The request must contain the parameter #{key}") end end data = { "DBInstanceIdentifier"=> db_name, "DBName" => ["DBName"], "created_at" => nil, "AutoMinorVersionUpgrade"=>true, "Endpoint"=>{}, "ReadReplicaDBInstanceIdentifiers"=>[], "PreferredMaintenanceWindow"=>"mon:04:30-mon:05:00", "Engine"=> ["Engine"], "EngineVersion"=> ["EngineVersion"] || "5.1.57", "PendingModifiedValues"=>{"MasterUserPassword"=>"****"}, # This clears when is available "MultiAZ"=>false, "MasterUsername"=> ["MasterUsername"], "DBInstanceClass"=> ["DBInstanceClass"], "DBInstanceStatus"=>"creating", "BackupRetentionPeriod"=> ["BackupRetentionPeriod"] || 1, "AllocatedStorage"=> ["AllocatedStorage"], "DBParameterGroups"=> # I think groups shoul be in the self.data method [{"DBParameterGroupName"=>"default.mysql5.1", "ParameterApplyStatus"=>"in-sync"}], "DBSecurityGroups"=> [{"Status"=>"active", "DBSecurityGroupName"=>"default"}], "LicenseModel"=>"general-public-license", "PreferredBackupWindow"=>"08:00-08:30" } self.data[:servers][db_name] = data response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "CreateDBInstanceResult"=> {"DBInstance"=> data} } response.status = 200 # This values aren't showed at creating time but at available time self.data[:servers][db_name]["created_at"] = Time.now response end |
#create_db_instance_read_replica(instance_identifier, source_identifier, options = {}) ⇒ Object
35 36 37 |
# File 'lib/fog/aws/requests/rds/create_db_instance_read_replica.rb', line 35 def create_db_instance_read_replica(instance_identifier, source_identifier, ={}) Fog::Mock.not_implemented end |
#create_db_parameter_group(group_name, group_family, description) ⇒ Object
34 35 36 |
# File 'lib/fog/aws/requests/rds/create_db_parameter_group.rb', line 34 def create_db_parameter_group(group_name, group_family, description) Fog::Mock.not_implemented end |
#create_db_security_group(name, description = name) ⇒ Object
29 30 31 |
# File 'lib/fog/aws/requests/rds/create_db_security_group.rb', line 29 def create_db_security_group(name, description = name) Fog::Mock.not_implemented end |
#create_db_snapshot(identifier, name) ⇒ Object
29 30 31 |
# File 'lib/fog/aws/requests/rds/create_db_snapshot.rb', line 29 def create_db_snapshot(identifier, name) Fog::Mock.not_implemented end |
#data ⇒ Object
87 88 89 |
# File 'lib/fog/aws/rds.rb', line 87 def data self.class.data[@region][@aws_access_key_id] end |
#delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/aws/requests/rds/delete_db_instance.rb', line 33 def delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) response = Excon::Response.new unless skip_snapshot # I don't know how to mock snapshot_identifier Fog::Logger.warning("snapshot_identifier is not mocked [light_black](#{caller.first})[/]") end if server_set = self.data[:servers].delete(identifier) response.status = 200 response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "DeleteDBInstanceResult" => { "DBInstance" => server_set } } response else raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found") end end |
#delete_db_parameter_group(group_name) ⇒ Object
29 30 31 |
# File 'lib/fog/aws/requests/rds/delete_db_parameter_group.rb', line 29 def delete_db_parameter_group(group_name) Fog::Mock.not_implemented end |
#delete_db_security_group(name, description = name) ⇒ Object
27 28 29 |
# File 'lib/fog/aws/requests/rds/delete_db_security_group.rb', line 27 def delete_db_security_group(name, description = name) Fog::Mock.not_implemented end |
#delete_db_snapshot(group_name) ⇒ Object
29 30 31 |
# File 'lib/fog/aws/requests/rds/delete_db_snapshot.rb', line 29 def delete_db_snapshot(group_name) Fog::Mock.not_implemented end |
#describe_db_engine_versions(opts = {}) ⇒ Object
27 28 29 |
# File 'lib/fog/aws/requests/rds/describe_db_engine_versions.rb', line 27 def describe_db_engine_versions(opts={}) Fog::Mock.not_implemented end |
#describe_db_instances(identifier = nil, opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/aws/requests/rds/describe_db_instances.rb', line 35 def describe_db_instances(identifier=nil, opts={}) response = Excon::Response.new server_set = [] if identifier if server = self.data[:servers][identifier] server_set << server else raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found") end else server_set = self.data[:servers].values end server_set.each do |server| case server["DBInstanceStatus"] when "creating" if Time.now - server['created_at'] >= Fog::Mock.delay * 2 region = "us-east-1" server["DBInstanceStatus"] = "available" server["availability_zone"] = region + 'a' server["Endpoint"] = {"Port"=>3306, "Address"=> Fog::AWS::Mock.rds_address(server["DBInstanceIdentifier"],region) } server["PendingModifiedValues"] = {} end when "rebooting" # it applies pending modified values if server["PendingModifiedValues"] server.merge!(server["PendingModifiedValues"]) server["PendingModifiedValues"] = {} server["DBInstanceStatus"] = 'available' end end end response.status = 200 response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "DescribeDBInstancesResult" => { "DBInstances" => server_set } } response end |
#describe_db_parameter_groups(name = nil, opts = {}) ⇒ Object
38 39 40 |
# File 'lib/fog/aws/requests/rds/describe_db_parameter_groups.rb', line 38 def describe_db_parameter_groups(name=nil, opts={}) Fog::Mock.not_implemented end |
#describe_db_parameters(name, opts = {}) ⇒ Object
39 40 41 |
# File 'lib/fog/aws/requests/rds/describe_db_parameters.rb', line 39 def describe_db_parameters(name, opts={}) Fog::Mock.not_implemented end |
#describe_db_reserved_instances(identifier = nil, opts = {}) ⇒ Object
35 36 37 |
# File 'lib/fog/aws/requests/rds/describe_db_reserved_instances.rb', line 35 def describe_db_reserved_instances(identifier=nil, opts={}) Fog::Mock.not_implemented end |
#describe_db_security_group(opts = {}) ⇒ Object
31 32 33 |
# File 'lib/fog/aws/requests/rds/describe_db_security_groups.rb', line 31 def describe_db_security_group(opts={}) Fog::Mock.not_implemented end |
#describe_db_snapshots(opts = {}) ⇒ Object
35 36 37 |
# File 'lib/fog/aws/requests/rds/describe_db_snapshots.rb', line 35 def describe_db_snapshots(opts={}) Fog::Mock.not_implemented end |
#modify_db_instance(db_name, apply_immediately, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fog/aws/requests/rds/modify_db_instance.rb', line 47 def modify_db_instance(db_name, apply_immediately, ={}) response = Excon::Response.new if server = self.data[:servers][db_name] if server["DBInstanceStatus"] != "available" raise Fog::AWS::RDS::NotFound.new("DBInstance #{db_name} not available for modification") else # TODO verify the params options # if apply_immediately is false, all the options go to pending_modified_values and then apply and clear after either # a reboot or the maintainance window if apply_immediately modified_server = server.merge() else modified_server = server["PendingModifiedValues"].merge!() # it appends end response.status = 200 response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "ModifyDBInstanceResult" => { "DBInstance" => modified_server } } response end else raise Fog::AWS::RDS::NotFound.new("DBInstance #{db_name} not found") end end |
#modify_db_parameter_group(group_name, parameters) ⇒ Object
48 49 50 |
# File 'lib/fog/aws/requests/rds/modify_db_parameter_group.rb', line 48 def modify_db_parameter_group(group_name, parameters) Fog::Mock.not_implemented end |
#reboot_db_instance(instance_identifier) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/aws/requests/rds/reboot_db_instance.rb', line 27 def reboot_db_instance(instance_identifier) response = Excon::Response.new if server = self.data[:servers][instance_identifier] if server["DBInstanceStatus"] != "available" raise Fog::AWS::RDS::NotFound.new("DBInstance #{db_name} not available for rebooting") else server["DBInstanceStatus"] = 'rebooting' response.status = 200 response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "RebootDBInstanceResult" => { "DBInstance" => server } } response end else raise Fog::AWS::RDS::NotFound.new("DBInstance #{db_name} not found") end end |
#reset_data ⇒ Object
91 92 93 |
# File 'lib/fog/aws/rds.rb', line 91 def reset_data self.class.data[@region].delete(@aws_access_key_id) end |
#restore_db_instance_from_db_snapshot(snapshot_id, db_id, options = {}) ⇒ Object
26 27 28 |
# File 'lib/fog/aws/requests/rds/restore_db_instance_from_db_snapshot.rb', line 26 def restore_db_instance_from_db_snapshot(snapshot_id, db_id, ={}) Fog::Mock.not_implemented end |
#restore_db_instance_to_point_in_time(source_db_name, target_db_name, opts = {}) ⇒ Object
26 27 28 |
# File 'lib/fog/aws/requests/rds/restore_db_instance_to_point_in_time.rb', line 26 def restore_db_instance_to_point_in_time(source_db_name, target_db_name, opts={}) Fog::Mock.not_implemented end |
#revoke_db_security_group_ingress(name, opts = {}) ⇒ Object
35 36 37 |
# File 'lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb', line 35 def revoke_db_security_group_ingress(name, opts = {}) Fog::Mock.not_implemented end |