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_team_links, #mock_teams_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, #uuid

Methods included from RHC::Rest::Membership

#compact_members, #default_member_role, #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.



832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/rhc/rest/mock.rb', line 832

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



941
942
943
# File 'lib/rhc/rest/mock.rb', line 941

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

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



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'lib/rhc/rest/mock.rb', line 871

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



983
984
985
986
987
# File 'lib/rhc/rest/mock.rb', line 983

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

#aliasesObject



949
950
951
# File 'lib/rhc/rest/mock.rb', line 949

def aliases
  @aliases
end

#auto_deployObject



993
994
995
# File 'lib/rhc/rest/mock.rb', line 993

def auto_deploy
  @auto_deploy || false
end

#cartridgesObject



909
910
911
# File 'lib/rhc/rest/mock.rb', line 909

def cartridges
  @cartridges
end

#configure(options = {}) ⇒ Object



989
990
991
# File 'lib/rhc/rest/mock.rb', line 989

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

#deploymentsObject



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/rhc/rest/mock.rb', line 1001

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



867
868
869
# File 'lib/rhc/rest/mock.rb', line 867

def destroy
  @domain.applications.delete self
end

#environment_variablesObject



953
954
955
956
957
958
959
# File 'lib/rhc/rest/mock.rb', line 953

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

#fakeuuidObject



828
829
830
# File 'lib/rhc/rest/mock.rb', line 828

def fakeuuid
  "fakeuuidfortests#{@name}"
end

#gear_groupsObject



898
899
900
901
902
903
904
905
906
907
# File 'lib/rhc/rest/mock.rb', line 898

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



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

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

#init_membersObject



977
978
979
980
981
# File 'lib/rhc/rest/mock.rb', line 977

def init_members
  @members ||= []
  attributes['members'] ||= []
  self
end

#keep_deploymentsObject



997
998
999
# File 'lib/rhc/rest/mock.rb', line 997

def keep_deployments
  @keep_deployments
end

#reloadObject



925
926
927
# File 'lib/rhc/rest/mock.rb', line 925

def reload
  @app
end

#remove_alias(app_alias) ⇒ Object



945
946
947
# File 'lib/rhc/rest/mock.rb', line 945

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

#restartObject



921
922
923
# File 'lib/rhc/rest/mock.rb', line 921

def restart
  @app
end

#scale_downObject



937
938
939
# File 'lib/rhc/rest/mock.rb', line 937

def scale_down
  @app
end

#scale_upObject



933
934
935
# File 'lib/rhc/rest/mock.rb', line 933

def scale_up
  @app
end

#set_environment_variables(env_vars = []) ⇒ Object



961
962
963
964
965
966
967
# File 'lib/rhc/rest/mock.rb', line 961

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



913
914
915
# File 'lib/rhc/rest/mock.rb', line 913

def start
  @app
end

#stop(*args) ⇒ Object



917
918
919
# File 'lib/rhc/rest/mock.rb', line 917

def stop(*args)
  @app
end

#tidyObject



929
930
931
# File 'lib/rhc/rest/mock.rb', line 929

def tidy
  @app
end

#unset_environment_variables(env_vars = []) ⇒ Object



969
970
971
972
973
974
975
# File 'lib/rhc/rest/mock.rb', line 969

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