Class: MesaTestSubmitter
- Inherits:
-
Object
- Object
- MesaTestSubmitter
- Defined in:
- lib/mesa_test.rb
Constant Summary collapse
- DEFAULT_URI =
'https://mesa-test-hub.herokuapp.com'.freeze
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#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.
-
#github_protocol ⇒ Object
Returns the value of attribute github_protocol.
-
#last_tested ⇒ Object
Returns the value of attribute last_tested.
-
#mesa_mirror ⇒ Object
Returns the value of attribute mesa_mirror.
-
#mesa_work ⇒ Object
Returns the value of attribute mesa_work.
-
#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.
-
#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
-
#commit_params(mesa, entire: true, empty: false) ⇒ Object
Parameters to be submitted in JSON format for reporting information about the overall commit being tested; used even if only submitting an entire test.
-
#confirm_computer ⇒ Object
Phone home to testhub and confirm that computer and user are valid.
- #confirm_computer_data ⇒ Object
-
#initialize(computer_name: nil, user_name: nil, email: nil, github_protocol: nil, mesa_mirror: nil, platform: nil, platform_version: nil, processor: nil, config_file: nil, base_uri: nil, last_tested: nil) {|_self| ... } ⇒ MesaTestSubmitter
constructor
many defaults are set in body.
-
#instance_params(mesa) ⇒ Object
Given a valid
Mesaobject, create an array of hashes that describe the test cases and the test results. - #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.
-
#single_instance_params(test_case) ⇒ Object
Parameters for a single test case.
-
#submit_commit(mesa, empty: false) ⇒ Object
submit entire commit’s worth of test cases, OR submit compilation status and NO test cases.
-
#submit_instance(mesa, test_case) ⇒ Object
submit results for a single test case instance.
-
#submitter_params ⇒ Object
Parameters to be submitted in JSON format for reporting information about the submitting user and computer.
-
#update {|_self| ... } ⇒ Object
ease setup of a blank/default submitter.
Constructor Details
#initialize(computer_name: nil, user_name: nil, email: nil, github_protocol: nil, mesa_mirror: nil, platform: nil, platform_version: nil, processor: nil, config_file: nil, base_uri: nil, last_tested: nil) {|_self| ... } ⇒ MesaTestSubmitter
many defaults are set in body
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 149 150 151 152 153 154 |
# File 'lib/mesa_test.rb', line 116 def initialize( computer_name: nil, user_name: nil, email: nil, github_protocol: nil, mesa_mirror: nil, platform: nil, platform_version: nil, processor: 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 || '' @github_protocol = github_protocol || :ssh @mesa_mirror = mesa_mirror || File.join(ENV['HOME'], '.mesa_test', 'mirror') @mesa_work = mesa_work || File.join(ENV['HOME'], '.mesa_test', 'work') @platform = platform if @platform.nil? @platform = if OS.osx? 'macOS' elsif OS.linux? 'Linux' else '' end end @platform_version = platform_version || '' @processor = processor || '' @config_file = config_file || File.join(ENV['HOME'], '.mesa_test', 'config.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.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def base_uri @base_uri end |
#computer_name ⇒ Object
Returns the value of attribute computer_name.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def computer_name @computer_name end |
#config_file ⇒ Object
Returns the value of attribute config_file.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def config_file @config_file end |
#email ⇒ Object
Returns the value of attribute email.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def email @email end |
#github_protocol ⇒ Object
Returns the value of attribute github_protocol.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def github_protocol @github_protocol end |
#last_tested ⇒ Object
Returns the value of attribute last_tested.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def last_tested @last_tested end |
#mesa_mirror ⇒ Object
Returns the value of attribute mesa_mirror.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def mesa_mirror @mesa_mirror end |
#mesa_work ⇒ Object
Returns the value of attribute mesa_work.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def mesa_work @mesa_work end |
#password ⇒ Object
Returns the value of attribute password.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def password @password end |
#platform ⇒ Object
Returns the value of attribute platform.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def platform @platform end |
#platform_version ⇒ Object
Returns the value of attribute platform_version.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def platform_version @platform_version end |
#processor ⇒ Object
Returns the value of attribute processor.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def processor @processor end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
113 114 115 |
# File 'lib/mesa_test.rb', line 113 def shell @shell end |
#user_name ⇒ Object
Returns the value of attribute user_name.
109 110 111 |
# File 'lib/mesa_test.rb', line 109 def user_name @user_name end |
Class Method Details
.new_from_config(config_file: File.join(ENV['HOME'], '.mesa_test', 'config.yml'), force_setup: false, base_uri: DEFAULT_URI) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mesa_test.rb', line 93 def self.new_from_config( config_file: File.join(ENV['HOME'], '.mesa_test', 'config.yml'), force_setup: false, base_uri: DEFAULT_URI ) 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
#commit_params(mesa, entire: true, empty: false) ⇒ Object
Parameters to be submitted in JSON format for reporting information about the overall commit being tested; used even if only submitting an entire test. This also determines if the submission is for an entire commit (compilation information and every test), an empty commit (just compilation information), or a non-empty, but also non-entire submission (results for a single test without compilation information)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/mesa_test.rb', line 231 def commit_params(mesa, entire: true, empty: false) # the compiler data should be able to be used as-is, but right now the # names don't match with what the database expects, so we do some renaming # shenanigans. # #################################### # THIS SHOULD GO BEFORE PRODUCTION # { sha: mesa.sha, compiled: mesa.installed?, entire: entire, empty: empty, }.merge(mesa.compiler_hash) end |
#confirm_computer ⇒ Object
Phone home to testhub and confirm that computer and user are valid. Useful for confirming that submissions will be accepted before wasting time on a test later.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/mesa_test.rb', line 284 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_data ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mesa_test.rb', line 161 def confirm_computer_data puts 'Ready to submit the following data:' puts '-------------------------------------------------------' puts "Computer Name #{computer_name}" puts "User email #{email}" puts 'Password ***********' puts "GitHub Protocol #{github_protocol}" puts "MESA Mirror Location #{mesa_mirror}" puts "MESA Work Location #{mesa_work}" puts "Platform #{platform} #{platform_version}" 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 |
#instance_params(mesa) ⇒ Object
Given a valid Mesa object, create an array of hashes that describe the test cases and the test results. These will be encoded as an array of JSON objects.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/mesa_test.rb', line 249 def instance_params(mesa) has_errors = [] res = [] mesa.test_case_names.each do |mod, names| names.each do |test_name| begin test_case = mesa.test_cases[mod][test_name] res << test_case.results_hash rescue TestCaseDirError # shell.say "It appears that #{test_case.test_name} has not been "\ # 'run yet. Unable to submit data for this test.', :red has_errors << test_case end end end unless has_errors.empty? shell.say "The following test cases could NOT be read for submission:", :red has_errors.each do |test_case| shell.say "- #{test_case.test_name}", :red end end res end |
#load_computer_data ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/mesa_test.rb', line 202 def load_computer_data data_hash = YAML.safe_load(File.read(config_file), [Symbol]) @computer_name = data_hash['computer_name'] @email = data_hash['email'] @password = data_hash['password'] @github_protocol = data_hash['github_protocol'].to_sym @mesa_mirror = data_hash['mesa_mirror'] @mesa_work = data_hash['mesa_work'] @platform = data_hash['platform'] @platform_version = data_hash['platform_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
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/mesa_test.rb', line 184 def save_computer_data data_hash = { 'computer_name' => computer_name, 'email' => email, 'password' => password, 'github_protocol' => github_protocol, 'mesa_mirror' => mesa_mirror, 'mesa_work' => mesa_work, 'platform' => platform, 'platform_version' => platform_version, } # make sure there's a directory to write to unless dir_or_symlink_exists? File.dirname(config_file) FileUtils.mkdir_p File.dirname(config_file) end File.open(config_file, 'w') { |f| f.write(YAML.dump(data_hash)) } end |
#setup ⇒ Object
set up config file for computer
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 |
# File 'lib/mesa_test.rb', line 23 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. To actually run a test, you need to specify a location for your base MESA git repository. 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 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? # Determine if we'll use ssh or https to access github response = shell.ask 'When accessing GitHub, which protocol do you '\ 'want to use? ', :blue, limited_to: %w[ssh https] s.github_protocol = response.strip.downcase.to_sym # Get location of source MESA repo (the mirror) response = shell.ask "Where is/should your mirrored MESA repository " \ "located? This is where a mirror will be stored from which test " \ "repos will be generated. You won't touch this in regular operation. " \ "(#{s.mesa_mirror}):", :blue s.mesa_mirror = response unless response.empty? # Get location of source MESA work (where testing happens) response = shell.ask "Where is/should your working directory for "\ "testing be located? This is where testing actually occurs, but all "\ "files it uses are cached in the mirror repo to save time later. " \ "(#{s.mesa_work}):", :blue s.mesa_work = 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.15.5, ' \ "Ubuntu 16.04)? (#{s.platform_version}):", :blue s.platform_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:', :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 shell.say "Restarting wizard.\n" setup end end |
#single_instance_params(test_case) ⇒ Object
Parameters for a single test case. mesa is an instance of Mesa, and test_case is an instance of MesaTestCase representing the test case to be submitted
277 278 279 |
# File 'lib/mesa_test.rb', line 277 def single_instance_params(test_case) [test_case.results_hash] end |
#submit_commit(mesa, empty: false) ⇒ Object
submit entire commit’s worth of test cases, OR submit compilation status and NO test cases
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 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/mesa_test.rb', line 302 def submit_commit(mesa, empty: false) uri = URI.parse(base_uri + '/submissions/create.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' } ) # create the request body for submission to the submissions API # # if we have an empty submission, then it is necessarily not entire. # Similarly, a non-empty submission is necessarily entire (otherwise one # would use +submit_instance+) request_data = {submitter: submitter_params, commit: commit_params(mesa, empty: empty, entire: !empty)} # don't need test instances if it's an empty submission or if compilation # failed if !empty && request_data[:commit][:compiled] request_data[:instances] = instance_params(mesa) end request.body = request_data.to_json # actually do the submission response = https.request request if !response.is_a? Net::HTTPCreated shell.say "\nFailed to submit some or all test case instances and/or "\ 'commit data.', :red false else shell.say "\nSuccessfully submitted commit #{mesa.sha}.", :green true end end |
#submit_instance(mesa, test_case) ⇒ Object
submit results for a single test case instance. Does not report overall compilation status to testhub. Use an empty commit submission for that
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/mesa_test.rb', line 341 def submit_instance(mesa, test_case) uri = URI.parse(base_uri + '/submissions/create.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' } ) # create the request body for submission to the submissions API # # submission is not empty (there is one test case), and it is also not # entire (... there is only test case) request_data = {submitter: submitter_params, commit: commit_params(mesa, empty: false, entire: false), instances: single_instance_params(test_case)} request.body = request_data.to_json # actually do the submission response = https.request request if !response.is_a? Net::HTTPCreated shell.say "\nFailed to submit #{test_case.test_name} for commit "\ "#{mesa.sha}", :red false else shell.say "\nSuccessfully submitted instance of #{test_case.test_name} "\ "for commit #{mesa.sha}.", :green true end end |
#submitter_params ⇒ Object
Parameters to be submitted in JSON format for reporting information about the submitting user and computer
216 217 218 219 220 221 222 223 |
# File 'lib/mesa_test.rb', line 216 def submitter_params { email: email, password: password, computer: computer_name, platform_version: platform_version } end |
#update {|_self| ... } ⇒ Object
ease setup of a blank/default submitter
157 158 159 |
# File 'lib/mesa_test.rb', line 157 def update yield self if block_given? end |