Class: MesaTestSubmitter
- Inherits:
-
Object
- Object
- MesaTestSubmitter
- Defined in:
- lib/mesa_test.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#compiler ⇒ Object
Returns the value of attribute compiler.
-
#compiler_version ⇒ Object
Returns the value of attribute compiler_version.
-
#computer_name ⇒ Object
Returns the value of attribute computer_name.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#platform_version ⇒ Object
Returns the value of attribute platform_version.
-
#processor ⇒ Object
Returns the value of attribute processor.
-
#ram_gb ⇒ Object
Returns the value of attribute ram_gb.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Class Method Summary collapse
Instance Method Summary collapse
- #confirm_computer ⇒ Object
- #confirm_computer_data ⇒ Object
-
#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) {|_self| ... } ⇒ MesaTestSubmitter
constructor
many defaults are set in body.
- #load_computer_data ⇒ Object
-
#save_computer_data ⇒ Object
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.
-
#setup ⇒ Object
set up config file for computer.
-
#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.
- #submit_all(mesa) ⇒ Object
-
#submit_params(test_case) ⇒ Object
create and return hash of parameters for a TestInstance submission.
-
#update {|_self| ... } ⇒ Object
ease setup of a blank/default submitter.
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) {|_self| ... } ⇒ MesaTestSubmitter
many defaults are set in body
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mesa_test.rb', line 114 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 ) @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 # 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_uri ⇒ Object
Returns the value of attribute base_uri.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def base_uri @base_uri end |
#compiler ⇒ Object
Returns the value of attribute compiler.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def compiler @compiler end |
#compiler_version ⇒ Object
Returns the value of attribute compiler_version.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def compiler_version @compiler_version end |
#computer_name ⇒ Object
Returns the value of attribute computer_name.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def computer_name @computer_name end |
#config_file ⇒ Object
Returns the value of attribute config_file.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def config_file @config_file end |
#email ⇒ Object
Returns the value of attribute email.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def email @email end |
#password ⇒ Object
Returns the value of attribute password.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def password @password end |
#platform ⇒ Object
Returns the value of attribute platform.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def platform @platform end |
#platform_version ⇒ Object
Returns the value of attribute platform_version.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def platform_version @platform_version end |
#processor ⇒ Object
Returns the value of attribute processor.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def processor @processor end |
#ram_gb ⇒ Object
Returns the value of attribute ram_gb.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 def ram_gb @ram_gb end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
111 112 113 |
# File 'lib/mesa_test.rb', line 111 def shell @shell end |
#user_name ⇒ Object
Returns the value of attribute user_name.
107 108 109 |
# File 'lib/mesa_test.rb', line 107 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: 'https://mesa-test-hub.herokuapp.com') ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mesa_test.rb', line 92 def self.new_from_config( config_file: File.join(ENV['HOME'], '.mesa_test.yml'), force_setup: false, base_uri: 'https://mesa-test-hub.herokuapp.com' ) 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_computer ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/mesa_test.rb', line 246 def confirm_computer uri = URI.parse(base_uri + '/check_computer.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.body = { email: email, password: password, computer_name: computer_name }.to_json JSON.parse(https.request(request).body).to_hash end |
#confirm_computer_data ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/mesa_test.rb', line 155 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 "Config location #{config_file}" puts '-------------------------------------------------------' puts '' shell = Thor.new response = shell.ask 'Is this correct? (y/Y = Yes, anything else = No):' return true if response.strip.casecmp 'y' false end |
#load_computer_data ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/mesa_test.rb', line 205 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'] end |
#save_computer_data ⇒ Object
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.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/mesa_test.rb', line 189 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 } File.open(config_file, 'w') { |f| f.write(YAML.dump(data_hash))} end |
#setup ⇒ Object
set up config file for computer
17 18 19 20 21 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 |
# File 'lib/mesa_test.rb', line 17 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}):", color = :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}):", color = :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}):", color = :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})", color = :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}):", color = :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}):", color = :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}):", color = :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}) ", color = :blue s.ram_gb = response.to_i unless response.empty? # Get compiler information response = shell.ask "Which compiler are you using? (#{s.compiler}):", color = :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}): ", color = :blue s.compiler_version = response 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:", color = :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.
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 |
# File 'lib/mesa_test.rb', line 267 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::HTTPUnprocessableEntity end |
#submit_all(mesa) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/mesa_test.rb', line 293 def submit_all(mesa) submitted_cases = [] unsubmitted_cases = [] mesa.test_names.each do |mod, test_names| test_names.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 submitted = false unless test_case.outcome == :not_tested submitted = submit(test_case) end if submitted submitted_cases << test_name else unsubmitted_cases << test_name end end end puts '' if submitted_cases.empty? shell.say 'Submitted the following cases:', :green puts submitted_cases.join("\n") else shell.say 'Did not successfully submit any cases.', :red end if unsubmitted_cases.empty? puts "\n\n\n" shell.say 'Failed to submit the following cases:', :red puts unsubmitted_cases.join("\n") end # return true if all cases were submitted submitted_cases.length == mesa.test_names.length end |
#submit_params(test_case) ⇒ Object
create and return hash of parameters for a TestInstance submission
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/mesa_test.rb', line 220 def submit_params(test_case) res = { test_case: test_case.test_name, computer: computer_name, email: email, password: password, runtime_seconds: test_case.runtime_seconds, mesa_version: test_case.mesa_version, 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 } # enter in test-specific data 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 |
#update {|_self| ... } ⇒ Object
ease setup of a blank/default submitter
151 152 153 |
# File 'lib/mesa_test.rb', line 151 def update yield self if block_given? end |