Class: BrpmAuto

Inherits:
Object
  • Object
show all
Defined in:
lib/brpm_auto.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.all_paramsObject (readonly)

Returns the value of attribute all_params.



13
14
15
# File 'lib/brpm_auto.rb', line 13

def all_params
  @all_params
end

.brpm_versionObject (readonly)

Returns the value of attribute brpm_version.



9
10
11
# File 'lib/brpm_auto.rb', line 9

def brpm_version
  @brpm_version
end

.configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/brpm_auto.rb', line 7

def config
  @config
end

.framework_root_pathObject (readonly)

Returns the value of attribute framework_root_path.



16
17
18
# File 'lib/brpm_auto.rb', line 16

def framework_root_path
  @framework_root_path
end

.gemfile_lockObject (readonly)

Returns the value of attribute gemfile_lock.



19
20
21
# File 'lib/brpm_auto.rb', line 19

def gemfile_lock
  @gemfile_lock
end

.gems_root_pathObject (readonly)

Returns the value of attribute gems_root_path.



18
19
20
# File 'lib/brpm_auto.rb', line 18

def gems_root_path
  @gems_root_path
end

.integration_settingsObject (readonly)

Returns the value of attribute integration_settings.



14
15
16
# File 'lib/brpm_auto.rb', line 14

def integration_settings
  @integration_settings
end

.loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/brpm_auto.rb', line 10

def logger
  @logger
end

.paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/brpm_auto.rb', line 11

def params
  @params
end

.request_paramsObject (readonly)

Returns the value of attribute request_params.



12
13
14
# File 'lib/brpm_auto.rb', line 12

def request_params
  @request_params
end

.versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/brpm_auto.rb', line 8

def version
  @version
end

Class Method Details

.brpm_installed?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/brpm_auto.rb', line 129

def brpm_installed?
  ENV["BRPM_HOME"] and ! ENV["BRPM_HOME"].empty?
end

.get_latest_installed_version(module_name) ⇒ Object

Raises:

  • (Gem::GemNotFoundException)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/brpm_auto.rb', line 180

def get_latest_installed_version(module_name)
  latest_version_path = get_module_gem_path(module_name, "latest")
  return "latest" if File.exists?(latest_version_path)

  # TODO: use Gem::Specification.find_by_name(@module_name, Gem::Requirement.create(Gem::Version.new(@module_version)))
  all_version_search = get_module_gem_path(module_name, "*")
  version_paths = Dir.glob(all_version_search)

  raise Gem::GemNotFoundException, "Could not find any installed version of module #{module_name}. Expected them in #{get_module_gem_path(module_name, "*")}" if version_paths.empty?

  versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }

  versions.sort{ |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
end

.get_module_gem_path(module_name, module_version) ⇒ Object



176
177
178
# File 'lib/brpm_auto.rb', line 176

def get_module_gem_path(module_name, module_version)
  "#{@gems_root_path}/gems/#{module_name}-#{module_version}"
end

.get_request_params_for_request(automation_results_dir, application, request_id) ⇒ Object



121
122
123
# File 'lib/brpm_auto.rb', line 121

def get_request_params_for_request(automation_results_dir, application, request_id)
  RequestParams.new_for_request(automation_results_dir, application, request_id)
end

.initObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/brpm_auto.rb', line 21

def init
  @framework_root_path = File.expand_path("#{File.dirname(__FILE__)}/..")

  require "logging/brpm_logger"

  require_libs_no_file_logging @framework_root_path

  self.extend Utilities

  @config = get_config
  @version = @config["version"]

  @brpm_version = get_brpm_version if self.brpm_installed?
  @gems_root_path = get_gems_root_path
end

.initialize_integration_settings(dns, username, password, details) ⇒ Object



125
126
127
# File 'lib/brpm_auto.rb', line 125

def initialize_integration_settings(dns, username, password, details)
  @integration_settings = IntegrationSettings.new(dns, username, password, details)
end

.initialize_logger(log_file, also_log_to_console = false) ⇒ Object



97
98
99
# File 'lib/brpm_auto.rb', line 97

def initialize_logger(log_file, also_log_to_console = false)
  @logger = SimpleLogger.new(log_file, also_log_to_console)
end

.initialize_request_params(path) ⇒ Object



117
118
119
# File 'lib/brpm_auto.rb', line 117

def initialize_request_params(path)
  @request_params = RequestParams.new(path)
end

.load_customer_include_fileObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/brpm_auto.rb', line 84

def load_customer_include_file
  customer_include_file_path = "#{self.params.config_dir}/customer_include.rb"
  if File.exists?(customer_include_file_path)
    load customer_include_file_path # use load instead of require to avoid having to restart BRPM after modifying the customer include file in a resource automation scenario
    if defined?(get_customer_include_params)
      customer_include_params = get_customer_include_params
      customer_include_params.each do |key, value|
        @params[key] = value
      end
    end
  end
end

.load_server_paramsObject



74
75
76
77
78
79
80
81
82
# File 'lib/brpm_auto.rb', line 74

def load_server_params
  server_config_file_path = "#{self.params.config_dir}/server.yml"
  if File.exists?(server_config_file_path)
    server_config = YAML.load_file(server_config_file_path)
    server_config.each do |key, value|
      @params[key] = value unless @params.has_key?(key)
    end
  end
end

.log(message) ⇒ Object



105
106
107
# File 'lib/brpm_auto.rb', line 105

def log(message)
  @logger.log(message)
end

.log_error(message) ⇒ Object



109
110
111
# File 'lib/brpm_auto.rb', line 109

def log_error(message)
  @logger.log_error(message)
end

.message_box(message, m_type = "sep") ⇒ Object



113
114
115
# File 'lib/brpm_auto.rb', line 113

def message_box(message, m_type = "sep")
  @logger.message_box(message, m_type)
end

.refresh_gems_root_pathObject



195
196
197
# File 'lib/brpm_auto.rb', line 195

def refresh_gems_root_path
  @gems_root_path = get_gems_root_path
end

.require_module(module_name, module_version = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/brpm_auto.rb', line 133

def require_module(module_name, module_version = nil)
  module_version ||= get_latest_installed_version(module_name)
  module_path = get_module_gem_path(module_name, module_version)

  module_config_file_path = "#{module_path}/config.yml"

  if File.exist?(module_config_file_path)
    module_config = YAML.load_file(module_config_file_path)

    if module_config["dependencies"]
      BrpmAuto.log "Loading the dependent modules..."
      module_config["dependencies"].each do |dependency|
        if dependency.is_a?(Hash)
          dep_module_name = dependency.keys[0]
          if @gemfile_lock
            dep_module_version = get_version_from_gemfile_lock(dep_module_name)
          else
            dep_module_version = dependency.values[0]["version"]
          end
        else
          dep_module_name = dependency

          if @gemfile_lock
            dep_module_version = get_version_from_gemfile_lock(dep_module_name)
          else
            dep_module_version = get_latest_installed_version(dep_module_name)
          end
        end

        BrpmAuto.log "Loading module #{dep_module_name} version #{dep_module_version}..."
        require_module(dep_module_name, dep_module_version)
      end
    end
  else
    BrpmAuto.log "No config file found."
  end

  BrpmAuto.log "Loading the libraries of module #{module_name}..."
  require_libs(module_path)

  module_path
end

.run_from_brpmObject



101
102
103
# File 'lib/brpm_auto.rb', line 101

def run_from_brpm
  @params.run_from_brpm
end

.setup(params = {}) ⇒ Object



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
# File 'lib/brpm_auto.rb', line 37

def setup(params = {})
  @params = Params.new(params)

  load_server_params
  load_customer_include_file

  if @params.run_from_brpm
    @logger = BrpmLogger.new
    @request_params = RequestParams.new_for_request(@params.automation_results_dir, @params.application, @params.request_id)
  else
    initialize_logger(@params.log_file, @params.also_log_to_console)
    initialize_request_params(@params.output_dir)
  end

  @all_params = AllParams.new(@params, @request_params)

  if @params["SS_integration_dns"]
    @integration_settings = IntegrationSettings.new(
        @params["SS_integration_dns"],
        @params["SS_integration_username"],
        @params["SS_integration_password"],
        @params["SS_integration_details"],
        @params["SS_project_server"],
        @params["SS_project_server_id"]
    )
  elsif defined?(SS_integration_dns)
    @integration_settings = IntegrationSettings.new(
        SS_integration_dns,
        SS_integration_username,
        SS_integration_password,
        SS_integration_details,
        SS_project_server,
        SS_project_server_id
    )
  end
end