Class: RHC::Rest::Mock::MockRestApplication

Inherits:
Application show all
Includes:
Helpers
Defined in:
lib/rhc/rest/mock.rb

Instance Method Summary collapse

Methods included from Helpers

#challenge, #credentials_for, #define_exceptional_test_on_wizard, #empty_domains, #empty_keys, #empty_response_list, #example_allows_gear_sizes?, #example_allows_members?, #expect_authorization, #mock_alias_links, #mock_alias_response, #mock_api_with_authorizations, #mock_app_links, #mock_cart_links, #mock_cartridge_response, #mock_client_links, #mock_date_1, #mock_domain_links, #mock_gear_groups_response, #mock_href, #mock_key_links, #mock_pass, #mock_real_client_links, #mock_response_links, #mock_uri, #mock_user, #mock_user_auth, #mock_user_links, #new_authorization, #new_domain, #simple_carts, #simple_user, #stub_add_authorization, #stub_add_key, #stub_add_key_error, #stub_api, #stub_api_request, #stub_api_v12, #stub_application_cartridges, #stub_authorizations, #stub_create_domain, #stub_delete_authorization, #stub_delete_authorizations, #stub_mock_ssh_keys, #stub_no_domains, #stub_no_keys, #stub_one_application, #stub_one_domain, #stub_one_key, #stub_relative_application, #stub_simple_carts, #stub_update_key, #stub_user

Methods inherited from Application

#<=>, #deployment_activations, #domain, #find_alias, #find_cartridge, #find_cartridges, #find_environment_variable, #find_environment_variables, #gear_info, #gear_ssh_url, #gears, #host, #scalable?, #scalable_carts, #ssh_string, #supports_add_cartridge_with_env_vars?, #supports_add_cartridge_with_gear_size?, #threaddump

Methods included from RHC::Rest::Membership

#compact_members, #delete_members, included, #leave, #members, #owner, #supports_members?, #supports_update_members?, #update_members

Methods inherited from Base

#add_message, #has_param?, #link_href, #links, #rest_method, #supports?

Methods included from AttributesClass

#define_attr, #model_name

Methods included from Attributes

#attribute, #attributes, #attributes=, #clear_attribute

Constructor Details

#initialize(client, name, type, domain, scale = nil, gear_profile = 'default', initial_git_url = nil, environment_variables = nil) ⇒ MockRestApplication

Returns a new instance of MockRestApplication.



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/rhc/rest/mock.rb', line 756

def initialize(client, name, type, domain, scale=nil, gear_profile='default', initial_git_url=nil, environment_variables=nil)
  super({}, client)
  @name = name
  @domain = domain
  @cartridges = []
  @creation_time = Date.new(2000, 1, 1).strftime('%Y-%m-%dT%H:%M:%S%z')
  @uuid = fakeuuid
  @initial_git_url = initial_git_url
  @git_url = "git:fake.foo/git/#{@name}.git"
  @app_url = "https://#{@name}-#{@domain.name}.fake.foo/"
  @ssh_url = "ssh://#{@uuid}@127.0.0.1"
  @aliases = []
  @environment_variables = environment_variables || []
  @gear_profile = gear_profile
  @auto_deploy = true
  @keep_deployments = 1
  if scale
    @scalable = true
  end
  self.attributes = {:links => mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0')), :messages => []}
  self.gear_count = 5
  types = Array(type)
  cart = add_cartridge(types.first, false) if types.first
  if scale
    cart.supported_scales_to = (cart.scales_to = -1)
    cart.supported_scales_from = (cart.scales_from = 2)
    cart.current_scale = 2
    cart.scales_with = "haproxy-1.4"
    prox = add_cartridge('haproxy-1.4')
    prox.collocated_with = [types.first]
  end
  types.drop(1).each{ |c| add_cartridge(c, false) }
  @framework = types.first
end

Instance Method Details

#add_alias(app_alias) ⇒ Object



857
858
859
# File 'lib/rhc/rest/mock.rb', line 857

def add_alias(app_alias)
  @aliases << MockRestAlias.new(@client, app_alias)
end

#add_cartridge(cart, embedded = true, environment_variables = nil) ⇒ Object



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'lib/rhc/rest/mock.rb', line 795

def add_cartridge(cart, embedded=true, environment_variables=nil)
  name, url =
    if cart.is_a? String
      [cart, nil]
    elsif cart.respond_to? :[]
      [cart[:name] || cart['name'], cart[:url] || cart['url']]
    elsif RHC::Rest::Cartridge === cart
      [cart.name, cart.url]
    end

  type = embedded ? "embedded" : "standalone"
  c = MockRestCartridge.new(client, name, type, self)
  if url
    c.url = url
    c.name = c.url_basename
  end
  #set_environment_variables(environment_variables)
  c.properties << {'name' => 'prop1', 'value' => 'value1', 'description' => 'description1' }
  @cartridges << c
  c.messages << "Cartridge added with properties"
  c
end

#add_member(member) ⇒ Object



893
894
895
896
# File 'lib/rhc/rest/mock.rb', line 893

def add_member(member)
  (@members ||= []) << member
  self
end

#aliasesObject



865
866
867
# File 'lib/rhc/rest/mock.rb', line 865

def aliases
  @aliases
end

#auto_deployObject



902
903
904
# File 'lib/rhc/rest/mock.rb', line 902

def auto_deploy
  @auto_deploy || false
end

#cartridgesObject



833
834
835
# File 'lib/rhc/rest/mock.rb', line 833

def cartridges
  @cartridges
end

#configure(options = {}) ⇒ Object



898
899
900
# File 'lib/rhc/rest/mock.rb', line 898

def configure(options={})
  options.each {|key,value| self.instance_variable_set("@#{key.to_s}", value)}
end

#deploymentsObject



910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'lib/rhc/rest/mock.rb', line 910

def deployments
  base_time1 = Time.local(2000,1,1,1,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time2 = Time.local(2000,1,1,2,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time3 = Time.local(2000,1,1,3,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time4 = Time.local(2000,1,1,4,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time5 = Time.local(2000,1,1,5,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time6 = Time.local(2000,1,1,6,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  [
    MockRestDeployment.new(self, '0000001', 'master', '0000001', nil, false, base_time1, false, [base_time1]),
    MockRestDeployment.new(self, '0000002', 'master', '0000002', nil, false, base_time2, false, [base_time2, base_time6]),
    MockRestDeployment.new(self, '0000003', 'master', '0000003', nil, false, base_time3, false, [base_time3, base_time5]),
    MockRestDeployment.new(self, '0000004', 'master', '0000004', nil, false, base_time4, false, [base_time4]),
    MockRestDeployment.new(self, '0000005', 'master', '0000005', nil, false, base_time5, false, [base_time5]),
  ]
end

#destroyObject



791
792
793
# File 'lib/rhc/rest/mock.rb', line 791

def destroy
  @domain.applications.delete self
end

#environment_variablesObject



869
870
871
872
873
874
875
# File 'lib/rhc/rest/mock.rb', line 869

def environment_variables
  if supports? "LIST_ENVIRONMENT_VARIABLES"
    @environment_variables || []
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end

#fakeuuidObject



752
753
754
# File 'lib/rhc/rest/mock.rb', line 752

def fakeuuid
  "fakeuuidfortests#{@name}"
end

#gear_groupsObject



822
823
824
825
826
827
828
829
830
831
# File 'lib/rhc/rest/mock.rb', line 822

def gear_groups
  # we don't have heavy interaction with gear groups yet so keep this simple
  @gear_groups ||= begin
    if @scalable
      cartridges.map{ |c| MockRestGearGroup.new(client, [c.name], c.current_scale) if c.name != 'haproxy-1.4' }.compact
    else
      [MockRestGearGroup.new(client, cartridges.map{ |c| {'name' => c.name} }, 1)]
    end
  end
end

#idObject



818
819
820
# File 'lib/rhc/rest/mock.rb', line 818

def id
  @uuid || attributes['uuid'] || attributes['id']
end

#keep_deploymentsObject



906
907
908
# File 'lib/rhc/rest/mock.rb', line 906

def keep_deployments
  @keep_deployments
end

#reloadObject



849
850
851
# File 'lib/rhc/rest/mock.rb', line 849

def reload
  @app
end

#remove_alias(app_alias) ⇒ Object



861
862
863
# File 'lib/rhc/rest/mock.rb', line 861

def remove_alias(app_alias)
  @aliases.delete_if {|x| x.id == app_alias}
end

#restartObject



845
846
847
# File 'lib/rhc/rest/mock.rb', line 845

def restart
  @app
end

#set_environment_variables(env_vars = []) ⇒ Object



877
878
879
880
881
882
883
# File 'lib/rhc/rest/mock.rb', line 877

def set_environment_variables(env_vars=[])
  if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
    environment_variables.concat env_vars
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end

#startObject



837
838
839
# File 'lib/rhc/rest/mock.rb', line 837

def start
  @app
end

#stop(*args) ⇒ Object



841
842
843
# File 'lib/rhc/rest/mock.rb', line 841

def stop(*args)
  @app
end

#tidyObject



853
854
855
# File 'lib/rhc/rest/mock.rb', line 853

def tidy
  @app
end

#unset_environment_variables(env_vars = []) ⇒ Object



885
886
887
888
889
890
891
# File 'lib/rhc/rest/mock.rb', line 885

def unset_environment_variables(env_vars=[])
  if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
    env_vars.each { |item| environment_variables.delete_if { |env_var| env_var.name == item } }
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end