Class: MesaTestSubmitter

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

Constant Summary collapse

DEFAULT_URI =
'https://mesa-test-hub.herokuapp.com'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(computer_name: nil, user_name: nil, email: nil, platform: nil, platform_version: nil, processor: nil, ram_gb: nil, compiler: nil, compiler_version: nil, config_file: nil, base_uri: nil, last_tested: nil) {|_self| ... } ⇒ MesaTestSubmitter

many defaults are set in body

Yields:

  • (_self)

Yield Parameters:



126
127
128
129
130
131
132
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
# File 'lib/mesa_test.rb', line 126

def initialize(
    computer_name: nil, user_name: nil, email: nil, platform: nil,
    platform_version: nil, processor: nil, ram_gb: nil, compiler: nil,
    compiler_version: nil, config_file: nil, base_uri: nil, last_tested: nil
)
  @computer_name = computer_name || Socket.gethostname.scan(/^[^\.]+\.?/)[0]
  @computer_name.chomp!('.') if @computer_name
  @user_name = user_name || (ENV['USER'] || ENV['USERNAME'])
  @email = email || ''
  @password = password || ''
  @platform = platform
  if @platform.nil?
    @platform =
      if OS.osx?
        'macOS'
      elsif OS.linux?
        'Linux'
      else
        ''
      end
  end
  @platform_version = platform_version || ''
  @processor = processor || ''
  @ram_gb = ram_gb || 0
  @compiler = compiler || 'SDK'
  @compiler_version = compiler_version || ''
  @config_file = config_file || File.join(ENV['HOME'], '.mesa_test.yml')
  @base_uri = base_uri
  @last_tested = last_tested || DEFAULT_REVISION

  # set up thor-proof way to get responses from user. Thor hijacks the
  # gets command, so we have to use its built-in "ask" method, which is
  # actually more useful
  @shell = Thor::Shell::Color.new
  yield self if block_given?
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



119
120
121
# File 'lib/mesa_test.rb', line 119

def base_uri
  @base_uri
end

#compilerObject

Returns the value of attribute compiler.



119
120
121
# File 'lib/mesa_test.rb', line 119

def compiler
  @compiler
end

#compiler_versionObject

Returns the value of attribute compiler_version.



119
120
121
# File 'lib/mesa_test.rb', line 119

def compiler_version
  @compiler_version
end

#computer_nameObject

Returns the value of attribute computer_name.



119
120
121
# File 'lib/mesa_test.rb', line 119

def computer_name
  @computer_name
end

#config_fileObject

Returns the value of attribute config_file.



119
120
121
# File 'lib/mesa_test.rb', line 119

def config_file
  @config_file
end

#emailObject

Returns the value of attribute email.



119
120
121
# File 'lib/mesa_test.rb', line 119

def email
  @email
end

#last_testedObject

Returns the value of attribute last_tested.



119
120
121
# File 'lib/mesa_test.rb', line 119

def last_tested
  @last_tested
end

#passwordObject

Returns the value of attribute password.



119
120
121
# File 'lib/mesa_test.rb', line 119

def password
  @password
end

#platformObject

Returns the value of attribute platform.



119
120
121
# File 'lib/mesa_test.rb', line 119

def platform
  @platform
end

#platform_versionObject

Returns the value of attribute platform_version.



119
120
121
# File 'lib/mesa_test.rb', line 119

def platform_version
  @platform_version
end

#processorObject

Returns the value of attribute processor.



119
120
121
# File 'lib/mesa_test.rb', line 119

def processor
  @processor
end

#ram_gbObject

Returns the value of attribute ram_gb.



119
120
121
# File 'lib/mesa_test.rb', line 119

def ram_gb
  @ram_gb
end

#shellObject (readonly)

Returns the value of attribute shell.



123
124
125
# File 'lib/mesa_test.rb', line 123

def shell
  @shell
end

#user_nameObject

Returns the value of attribute user_name.



119
120
121
# File 'lib/mesa_test.rb', line 119

def user_name
  @user_name
end

Class Method Details

.new_from_config(config_file: File.join(ENV['HOME'], '.mesa_test.yml'), force_setup: false, base_uri: DEFAULT_URI) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/mesa_test.rb', line 103

def self.new_from_config(
  config_file: File.join(ENV['HOME'], '.mesa_test.yml'), force_setup: false,
  base_uri: DEFAULT_URI
  # base_uri: 'http://localhost:3000'
)
  new_submitter = new(config_file: config_file, base_uri: base_uri)
  if force_setup
    new_submitter.setup
  elsif not File.exist? config_file
    puts "No such config file #{config_file}. Starting setup wizard."
    new_submitter.setup
  end
  new_submitter.load_computer_data
  return new_submitter
end

Instance Method Details

#confirm_computerObject



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/mesa_test.rb', line 316

def confirm_computer
  uri = URI.parse(base_uri + '/check_computer.json')
  https = Net::HTTP.new(uri.hostname, uri.port)
  https.use_ssl = base_uri.include? 'https'

  request = Net::HTTP::Post.new(
    uri, initheader = { 'Content-Type' => 'application/json' }
  )
  request.body = {
    email: email,
    password: password,
    computer_name: computer_name
  }.to_json
  JSON.parse(https.request(request).body).to_hash
end

#confirm_computer_dataObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/mesa_test.rb', line 168

def confirm_computer_data
  puts 'Ready to submit the following data:'
  puts '-------------------------------------------------------'
  puts "Computer Name           #{computer_name}"
  puts "User Name               #{user_name}"
  puts "User email              #{email}"
  puts 'Password                ***********'
  puts "Platform                #{platform} #{platform_version}"
  puts "Processor               #{processor}"
  puts "RAM                     #{ram_gb} GB"
  puts "Compiler                #{compiler} #{compiler_version}"
  puts "Last tested revision    #{last_tested}"
  puts "Config location         #{config_file}"
  puts '-------------------------------------------------------'
  puts ''
  response = shell.ask 'Is this correct? (y/Y = Yes, anything else = No):'
  response.strip.casecmp('y').zero?
end

#load_computer_dataObject



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/mesa_test.rb', line 218

def load_computer_data
  data_hash = YAML.safe_load(File.read(config_file), [Symbol])
  @computer_name = data_hash['computer_name']
  @user_name = data_hash['user_name']
  @email = data_hash['email']
  @password = data_hash['password']
  @platform = data_hash['platform']
  @processor = data_hash['processor']
  @ram_gb = data_hash['ram_gb']
  @platform_version = data_hash['platform_version']
  @compiler = data_hash['compiler']
  @compiler_version = data_hash['compiler_version']
  @last_tested = data_hash['last_tested'] || @last_tested
end

#revision_submit_params(mesa) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/mesa_test.rb', line 265

def revision_submit_params(mesa)
  mesa.load_svn_data if mesa.use_svn?      
  # version gives data about version
  # user gives data about the user and computer submitting information
  # instances is array of hashes that identify test instances (more below)
  res = {
          version: {number: mesa.version_number},
          user: {email: email, password: password, computer: computer_name},
          instances: []
        }
  if mesa.use_svn?
    res[:version][:author] = mesa.svn_author
    res[:version][:log] = mesa.svn_log
  end

  # hold on to test case names that fail in synthesizing params
  has_errors = []

  # each instance has basic information in :test_instance and extra
  # information that requires the web app to work, stored in :extra
  mesa.test_names.each do |mod, names|
    names.each do |test_name|
      begin
        test_case = mesa.test_cases[mod][test_name]
        res[:instances] << {
          test_instance: {
            runtime_seconds: test_case.runtime_seconds,
            passed: test_case.passed?,
            compiler: compiler,
            compiler_version: compiler_version,
            platform_version: platform_version,
            omp_num_threads: test_case.test_omp_num_threads,
            success_type: test_case.success_type,
            failure_type: test_case.failure_type,
            steps: test_case.steps,
            retries: test_case.retries,
            backups: test_case.backups,
            summary_text: test_case.summary_text
          },
          extra: { test_case: test_name, mod: mod }
        }
      rescue TestCaseDirError
        shell.say "Passage status for #{test_case.test_name} not yet "\
                  'known. Run test first and then submit.', :red
        has_errors.append(test_case)
      end
    end
  end
  [res, has_errors]
end

#save_computer_dataObject

For one “computer” on the web server, and for [subjective] consistency reasons, the platform, processor, and RAM cannot be changed! If you change platforms (i.e. switch from mac to linux, or change between linux flavors), you should create a new computer account. Similarly, create new computer accounts if you change your RAM or processor. You do not need to change computers if you upgrade your platform (macOS 10.12 -> 10.13) or if you try different compilers

Note this is NOT checked! The server really only uses the test-by-test quantities (platform version, compiler, compiler version) and the computer name. Once the computer is found (by the name) all the other data is assumed to be fixed. The others… probably shouldn’t be here, but remain so you can confirm that the computer on the web server is the same one you think you are working with locally.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/mesa_test.rb', line 201

def save_computer_data
  data_hash = {
    'computer_name' => computer_name,
    'user_name' => user_name,
    'email' => email,
    'password' => password,
    'platform' => platform,
    'processor' => processor,
    'ram_gb' => ram_gb,
    'platform_version' => platform_version,
    'compiler' => compiler,
    'compiler_version' => compiler_version,
    'last_tested' => last_tested
  }
  File.open(config_file, 'w') { |f| f.write(YAML.dump(data_hash)) }
end

#setupObject

set up config file for computer



22
23
24
25
26
27
28
29
30
31
32
33
34
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
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
# File 'lib/mesa_test.rb', line 22

def setup
  update do |s|
    shell.say 'This wizard will guide you through setting up a computer
profile and default data for test case submissions to MESATestHub. You
will be able to confirm entries at the end. Default/current values are always
shown in parentheses at the end of a prompt. Pressing enter will accept the
default values.

To submit to MESATestHub, a valid computer name, email address, and password
are all required. All other data are useful, but optional. Any data
transferred to MESATestHub will be encrypted via HTTPS, but be warned that your
e-mail and password will be stored in plain text.'
    # Get computer name
    response = shell.ask('What is the name of this computer (required)? ' \
      "(#{s.computer_name}):", :blue)
    s.computer_name = response unless response.empty?

    # Get user name
    response = shell.ask 'What is the name of the operator of this ' \
      "computer? (#{s.user_name}):", :blue
    s.user_name = response unless response.empty?

    # Get user e-mail
    response = shell.ask 'What is the email you can be reached ' \
      "at (required)? (#{s.email}):", :blue
    s.email = response unless response.empty?

    # Get user password
    response = shell.ask 'What is the password associated with the email ' \
      "#{s.email} (required)? (#{s.password})", :blue
    s.password = response unless response.empty?

    # Get platform information
    response = shell.ask 'What is the platform of this computer (eg. ' \
      "macOS, Ubuntu)? (#{s.platform}):", :blue
    s.platform = response unless response.empty?
    response = shell.ask 'What is the version of the platform (eg. 10.13, ' \
      "16.04)? (#{s.platform_version}):", :blue
    s.platform_version = response unless response.empty?

    # Get processor information
    response = shell.ask 'What type of processor does this computer have ' \
      "(eg. 3.1 GHz Intel i7)? (#{s.processor}):", :blue
    s.processor = response unless response.empty?

    # Get ram information
    response = shell.ask 'How much RAM (in integer GB) does this computer ' \
      "have (eg. 8)? (#{s.ram_gb}) ", :blue
    s.ram_gb = response.to_i unless response.empty?

    # Get compiler information
    response = shell.ask "Which compiler are you using? (#{s.compiler}):",
                         :blue, limited_to: ['', 'SDK', 'gfortran', 'ifort']
    s.compiler = response unless response.empty?

    # Get compiler version
    response = shell.ask 'What version of the compiler (eg. 20170921 or ' \
      "7.2.0)? (#{s.compiler_version}): ", :blue
    s.compiler_version = response unless response.empty?

    # Get earliest revision to check
    response = shell.ask "What's the earliest revision to search back to " \
      'when finding the latest testable revision (eg. 10000)? ' \
      "(#{s.last_tested}): ", :blue
    s.last_tested = response.to_i unless response.empty?

    # Confirm save location
    response = shell.ask "This will be saved in #{s.config_file}. Press " \
      'enter to accept or enter a new location:', :blue, path: true
    s.config_file = response unless response.empty?
  end

  # Confirm data. If not confirmed, restart whole wizard.
  if confirm_computer_data
    save_computer_data
  else
    puts "Restarting wizard.\n"
    setup
  end
end

#submit(test_case) ⇒ Object

attempt to post to MesaTestHub with test_case parameters returns true if the id is in the returned JSON (indicating success) otherwise returns false (maybe failed in authorization or in finding computer or test case) No error thrown for failure, though.



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/mesa_test.rb', line 336

def submit(test_case)
  uri = URI.parse(base_uri + '/test_instances/submit.json')
  https = Net::HTTP.new(uri.hostname, uri.port)
  https.use_ssl = true if base_uri.include? 'https'

  request = Net::HTTP::Post.new(
    uri,
    initheader = { 'Content-Type' => 'application/json' }
  )
  begin
    request.body = submit_params(test_case).to_json
  rescue TestCaseDirError
    shell.say "\nPassage status for #{test_case.test_name} not yet known. " \
              'Run test first and then submit.', :red
    return false
  end

  # verbose = true
  # puts "\n" if verbose
  # puts JSON.parse(request.body).to_hash if verbose

  response = https.request request
  # puts JSON.parse(response.body).to_hash if verbose
  response.is_a? Net::HTTPCreated
end

#submit_all(mesa, mod = :all) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/mesa_test.rb', line 362

def submit_all(mesa, mod = :all)
   = []
  unsubmitted_cases = []
  if mod == :all
    success = true
    mesa.test_names.each_key do |this_mod|
      success &&= submit_all(mesa, mod = this_mod)
    end
  else
    mesa.test_names[mod].each do |test_name|
      # get at test case
      test_case = mesa.test_cases[mod][test_name]
      # try to submit and note if it does or doesn't successfully submit
       = false
       = submit(test_case) unless test_case.outcome == :not_tested
      if 
         << test_name
      else
        unsubmitted_cases << test_name
      end
    end
    puts "\n Submission results for #{mod} module:"
    puts '#####################################'
    if !.empty?
      shell.say 'Submitted the following cases:', :green
      puts .join("\n")
    else
      shell.say 'Did not successfully submit any cases.', :red
    end
    unless unsubmitted_cases.empty?
      puts "\n\n\n"
      shell.say 'Failed to submit the following cases:', :red
      puts unsubmitted_cases.join("\n")
    end
    # return true and update last tested if all cases were submitted
    success = .length == mesa.test_names[mod].length
    if success
      @last_tested = mesa.version_number
      shell.say "\n\nUpdating last tested revision to #{last_tested}."
      save_computer_data
    end
  end
  # return boolean indicating whether or not all cases successfully
  # SUBMITTED (irrespective of passing status)
  success
end

#submit_params(test_case) ⇒ Object

create and return hash of parameters for a TestInstance submission



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/mesa_test.rb', line 234

def submit_params(test_case)
  res = {
    test_case: test_case.test_name,
    mod: test_case.mod,
    computer: computer_name,
    email: email,
    password: password,
    runtime_seconds: test_case.runtime_seconds,
    mesa_version: test_case.mesa_version,
    passed: test_case.passed? ? 1 : 0,
    compiler: compiler,
    compiler_version: compiler_version,
    platform_version: platform_version,
    omp_num_threads: test_case.test_omp_num_threads,
    success_type: test_case.success_type,
    failure_type: test_case.failure_type,
    steps: test_case.steps,
    retries: test_case.retries,
    backups: test_case.backups,
    summary_text: test_case.summary_text
  }

  # enter in test-specific data, DISABLED FOR NOW
  # test_case.data_names.each do |data_name|
  #   unless test_case.data[data_name].nil?
  #     res[data_name] = test_case.data[data_name]
  #   end
  # end
  res
end

#submit_revision(mesa) ⇒ Object

similar to submit_all, but does EVERYTHING in one post, including version information. No support for individual modules now.



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/mesa_test.rb', line 411

def submit_revision(mesa)
  uri = URI.parse(base_uri + '/versions/submit_revision.json')
  https = Net::HTTP.new(uri.hostname, uri.port)
  https.use_ssl = true if base_uri.include? 'https'

  request = Net::HTTP::Post.new(
    uri,
    initheader = { 'Content-Type' => 'application/json' }
  )
  request_data, error_cases = revision_submit_params(mesa)
  if request_data[:instances].empty?
    shell.say "No completed test data found in #{mesa.mesa_dir}. Aborting.",
              :red
    return false
  end
  request.body = request_data.to_json

  # verbose = true
  # puts "\n" if verbose
  # puts JSON.parse(request.body).to_hash if verbose

  response = https.request request
  # puts JSON.parse(response.body).to_hash if verbose
  if !response.is_a? Net::HTTPCreated
    shell.say "\nFailed to submit some or all cases and/or version data.",
              :red
    false
  elsif !error_cases.empty?
    shell.say "\nFailed to gather data for the following cases:", :red
    error_cases.each { |tc| shell.say "  #{tc.test_name}", :red }
    false
  end
  true
end

#update {|_self| ... } ⇒ Object

ease setup of a blank/default submitter

Yields:

  • (_self)

Yield Parameters:



164
165
166
# File 'lib/mesa_test.rb', line 164

def update
  yield self if block_given?
end