Class: Mu::Command::Cmd_runverify
- Inherits:
-
Mu::Command
- Object
- Mu::Command
- Mu::Command::Cmd_runverify
- Defined in:
- lib/mu/command/cmd_runverify.rb
Constant Summary
Constants inherited from Mu::Command
Constants included from Helper
Instance Attribute Summary collapse
-
#ddt_api ⇒ Object
Returns the value of attribute ddt_api.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Mu::Command
Instance Method Summary collapse
-
#cmd_help(argv) ⇒ Object
displays command-line help.
-
#cmd_run(argv) ⇒ Object
sets up, executes, and closes a Studio Verify session * argv = command-line arguments, requires a scenario (-s) argument, which must be an xml scenario template to be loaded onto the Mu * and a testset (-t) argument of an xml test set template to be loaded on the Mu * .msl and .csv files are not currently supported.
Methods inherited from Mu::Command
Methods included from Helper
#ask, #bin2hex, #error, #escape, #format_float, #get_file_as_string_array, #make_xml, #msg, #shift, #to_boolean
Constructor Details
This class inherits a constructor from Mu::Command
Instance Attribute Details
#ddt_api ⇒ Object
Returns the value of attribute ddt_api.
9 10 11 |
# File 'lib/mu/command/cmd_runverify.rb', line 9 def ddt_api @ddt_api end |
#errors ⇒ Object
Returns the value of attribute errors.
9 10 11 |
# File 'lib/mu/command/cmd_runverify.rb', line 9 def errors @errors end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/mu/command/cmd_runverify.rb', line 9 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/mu/command/cmd_runverify.rb', line 9 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/mu/command/cmd_runverify.rb', line 9 def username @username end |
Instance Method Details
#cmd_help(argv) ⇒ Object
displays command-line help
12 13 14 |
# File 'lib/mu/command/cmd_runverify.rb', line 12 def cmd_help argv help end |
#cmd_run(argv) ⇒ Object
sets up, executes, and closes a Studio Verify session
* argv = command-line arguments, requires a scenario (-s) argument, which must be an xml scenario template to be loaded onto the Mu
* and a testset (-t) argument of an xml test set template to be loaded on the Mu
* .msl and .csv files are not currently supported
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/mu/command/cmd_runverify.rb', line 20 def cmd_run argv args = parse_cli argv setup if not args['scenario'] msg "scenario required" return help else if args['scenario'].include?(".xml") scenario = args['scenario'] else # TODO: eventually, msl files may be supported by this api msg "only .xml files are currently supported" return help end end if not args['testset'] msg "testset required" return help else testset = args['testset'] end if not args['dir'] dir = "." else dir = args['dir'] end if scenario.include?("/") scenario_filename = scenario else scenario_filename = dir + "/" + scenario end if testset.include?("/") testset_filename = testset else testset_filename = dir + "/" + testset end if not args['interfaces'] @interfaces = Array.new # initialize an empty array else @interfaces = args['interfaces'].split(",") end if not args['options'] = Array.new # initialize an empty array else = args['options'].split(",") end if not args['channels'] @arg_channels = Array.new # initialize an empty array else @arg_channels = args['channels'].split(",") end @errors = Array.new hosts_array = Array.new roles_array = Array.new begin msg @ddt_api.new_session if File.extname(testset_filename) == ".xml" msg testset_filename, Logger::DEBUG f = File.open(testset_filename) doc = Nokogiri::XML(f) response = @http.post_xml("templates/import", doc) msg "response from post(#{testset_filename}):\n#{response}", Logger::DEBUG testset_uuid = doc.xpath("//ddt_set")[0].attribute('uuid') elsif File.extname(testset_filename) == ".csv" doc = Nokogiri::XML(@ddt_api.csv_import(testset_filename)) testset_uuid = doc.xpath("//message")[0].content else raise "Testset filename extension must be either .xml or .csv, but filename is #{testset}" end msg scenario_filename, Logger::DEBUG f = File.open(scenario_filename) doc = Nokogiri::XML(f) response = @http.post_xml("templates/import", doc) msg "response from post(#{scenario_filename}):\n#{response}", Logger::DEBUG scenario_name = doc.xpath("//scenario")[0].attribute('name') hosts = doc.xpath("//hosts/host") scenario_uuid = doc.xpath("//scenario")[0].attribute('uuid') roles = doc.xpath("//hosts/host/role") ids = doc.xpath("//hosts/host/id") channels = doc.xpath("//steps/channel") type = doc.xpath("//hosts/host/type")[0].text if !@interfaces.empty? if @interfaces.size != hosts.size msg "Error. The number of hosts/interfaces specified on the command-line does not equal the number of hosts in the template. #{@interfaces.size} != #{hosts.size}" return end end msg @ddt_api.load_scenario(scenario_uuid) roles.each_with_index do | r, i | content = r.content if @interfaces.empty? begin host = content.match(/\(.*\)/).to_s host = host[1, host.index(".") - 1].downcase hosts_array << host rescue => e puts e puts "no hosts were specified, and none were found embedded in the role, e.g. 'client (A1.V4)'" end else hosts_array << @interfaces[i] end roles_array << content # use the whole name for the role end msg @ddt_api.set_hosts(roles_array, hosts_array, type) # if there are channels in the scenario, bind them if channels.size > 0 if @arg_channels.size != channels.size msg "Error. The number of channels specified on the command-line does not equal the number of channels in the template. #{@arg_channels.size} != #{channels.size}" return end channel_roles = Array.new channel_names = Array.new @arg_channels.each do | c | channel_roles << "channel" # role is always "channel" channel_names << c end msg @ddt_api.set_channels(channel_roles, channel_names) end # if there are options specified on the command-line, set them if !.empty? option_names = Array.new option_values = Array.new .each do | o | opts = o.split(":") option_names << opts[0] option_values << opts[1] end msg @ddt_api.(option_names, option_values) end # verify the scenario msg @ddt_api.setup_test response = @ddt_api.run if response == "" msg "==> #{scenario_name} run returned without status" @errors << "#{scenario_name}: status = #{response}" else doc = Nokogiri::XML(response) status = doc.xpath("//status")[0].content msg "==> #{scenario_name}: status = #{status}" if status == 'failed' # on error, add to the errors array @errors << "#{scenario_name}: status = #{status}" end end msg @ddt_api.run_testset(testset_uuid) results = @ddt_api.collect_results # will wait until 'Done' is returned by status msg "results = #{results}" if results.to_s.include?("FAILED") @errors << "test failed" msg @ddt_api.teardown_test msg @ddt_api.close_session # clear the hosts and roles array for the next iteration roles_array.clear hosts_array.clear end # if !exclude_list.include? and hosts.length end ensure teardown end |