From e794481c8582e08d58b76da590e689d9f35b81f3 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Sat, 7 Sep 2024 16:38:46 +0200 Subject: [PATCH] Improve model unit tests and device simulation Explicit tell model developpers that unit tests for models are optional YAML simulation files are placed under /examples/device-simulation - A README.md explains how to generate a YAML simulation file - The script device2yaml.rb does most of the task A README.md explains how to write model unit tests - New function result2file to generate the expected output of Oxidized when runned against the YAML simulation file - interpolate_yaml uses String#undump YAML simulation files & model unit tests for aoscx, ios and asa --- docs/Creating-Models.md | 98 +--- examples/device-simulation/README.md | 167 ++++++ examples/device-simulation/cmdsets/aoscx | 10 + examples/device-simulation/cmdsets/asa | 7 + examples/device-simulation/cmdsets/ios | 7 + examples/device-simulation/device2yaml.rb | 177 ++++++ ...cx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml | 451 +++++++++++++++ .../asa_5512_9.12-4-67_single-context.yaml | 531 ++++++++++++++++++ .../yaml}/garderos_R7709_003_006_068.yaml | 0 .../yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml | 498 ++++++++++++++++ .../yaml/iosxe_C9800-L-F-K9_17.06.05.yaml | 393 +++++++++++++ spec/model/README.md | 215 +++++++ spec/model/aoscx_spec.rb | 24 + spec/model/apc_aos_spec.rb | 2 +- spec/model/asa_spec.rb | 25 + spec/model/garderos_spec.rb | 2 +- spec/model/ios_spec.rb | 35 ++ spec/model/model_helper.rb | 35 +- spec/model/model_helper_spec.rb | 2 +- 19 files changed, 2582 insertions(+), 97 deletions(-) create mode 100644 examples/device-simulation/README.md create mode 100644 examples/device-simulation/cmdsets/aoscx create mode 100644 examples/device-simulation/cmdsets/asa create mode 100644 examples/device-simulation/cmdsets/ios create mode 100755 examples/device-simulation/device2yaml.rb create mode 100644 examples/device-simulation/yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml create mode 100644 examples/device-simulation/yaml/asa_5512_9.12-4-67_single-context.yaml rename examples/{model => device-simulation/yaml}/garderos_R7709_003_006_068.yaml (100%) create mode 100644 examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml create mode 100644 examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml create mode 100644 spec/model/README.md create mode 100644 spec/model/aoscx_spec.rb create mode 100644 spec/model/asa_spec.rb create mode 100644 spec/model/ios_spec.rb diff --git a/docs/Creating-Models.md b/docs/Creating-Models.md index 194ab13c4..1122106e5 100644 --- a/docs/Creating-Models.md +++ b/docs/Creating-Models.md @@ -87,97 +87,31 @@ Intuitively, it is also possible to: * Testing/validation of an updated model from the [Oxidized GitHub repo models](https://github.com/ytti/oxidized/tree/master/lib/oxidized/model) by placing an updated model in the proper location without disrupting the gem-supplied model files. ## Create unit tests for the model -> :warning model unit tests are still work in progress and need some polishing. +> :warning: model unit tests are still a work in progress and need some polishing. If you want the model to be integrated into oxidized, you can [submit a pull request on github](https://github.com/ytti/oxidized/pulls). This is a greatly appreciated submission, as there are probably other users using the same network device as you are. -A good practice for submissions is to provide a unit test for your model. This -reduces the risk that further developments don't break it, and facilitates -debugging issues without having access to a physical network device for the -model. Writing a model unit test for SSH is described in the next lines. Most -of the work is writing a YAML file with the commands and their output, the ruby -code itself is copy & paste with a few modifications. If you encounter -problems, open an issue or ask for help within the pull request. - -You can have a look at the [Garderos unit test](/spec/model/garderos_spec.rb) for an example. The model unit test -consists of (at least) two files: -- a yaml file under `examples/model/`, containing the data used to simulate the network device. - - Please name your file `__.yaml`, for example in the garderos unit test: [garderos_R7709_003_006_068.yaml](/examples/model/garderos_R7709_003_006_068.yaml). - - You can create multiple files in order to support multiple devices or software versions. - - You may append a comment after the software version to differentiate between two tested features (something like `garderos_R7709_003_006_068_with_ipsec.yaml`). -- a ruby script containing the tests under `spec/model/`. - - It is named `_spec.rb`, for the garderos model: [garderos_spec.rb](/spec/model/garderos_spec.rb). - - The script described below is a minimal example; you can add as many tests as needed. - -### YAML description to simulate the network device. -The yaml file has three sections: -- init_prompt: describing the lines send by the device before we can send a command. It may include motd banners, and mus include the first prompt. -- commands: the commands the model sends to the network device and the expected output. Do not forget the command needed to logout from the device. -- oxidized_output: the expected output of oxidized, so that you can compare it to the output generated by the unit test. - -The outputs are multiline and use yaml block scalars (`|`), with the trailing \n removed (`-` after `|`). The outputs includes the echo of the given command and the next prompt. Some escape characters are interpreted, currently \n, \r, \x\, \\\\ - -Here is a shortened example of a YAML file: -```yaml ---- -# Trailing white spaces are coded as \x20 because some editors automatically remove trailing white spaces -init_prompt: |- - \e[4m\rLAB-R1234_Garderos#\e[m\x20 -commands: - show system version: |- - show system version - grs-gwuz-armel/003_005_068 (Garderos; 2021-04-30 16:19:35) - \e[4m\rLAB-R1234_Garderos#\e[m\x20 -# ... - exit: "" -oxidized_output: |- - # grs-gwuz-armel/003_005_068 (Garderos; 2021-04-30 16:19:35) - #\x20 -# ... -``` - -### Model unit test -When creating the unit test, it is handy to have a specific section for testing different -prompts without testing the whole configuration. This is done by the first test in the following -example. The second tests takes the defined yaml file, runs the model against it and -compares the result against the yaml-section `oxidized_output`. - -```ruby -require_relative 'model_helper' - -describe 'model/Garderos' do - # For each test, we initialize oxidized to some default values - # and create a node with the model we want to test - # replace 'garderos' with your model - before(:each) do - init_model_helper - @node = Oxidized::Node.new(name: 'example.com', - input: 'ssh', - model: 'garderos') - end +A good (and optional) practice for submissions is to provide a +[unit test for your model](/spec/model). This reduces the risk that further +developments don't break it, and facilitates debugging issues without having +access to a physical network device for the model. - it 'matches different prompts' do - _('LAB-R1234_Garderos# ').must_match Garderos.prompt - end - - # Name the test after the tesed HW and SW. Link to your yaml data - it 'runs on R7709 with OS 003_006_068' do - mockmodel = MockSsh.new('examples/model/garderos_R7709_003_006_068.yaml') - Net::SSH.stubs(:start).returns mockmodel - - status, result = @node.run +In order to simulate the device in the unit test, you need a +[YAML simulation file](/examples/device-simulation/), have a look at the +link for an explanation on how to create one. - _(status).must_equal :success - _(result.to_cfg).must_equal mockmodel.oxidized_output - end -end -``` +Creating the unit test itself is explained in +[README.md in the model unit test directory](/spec/model/README.md). -The unit tests use [minitest/spec](https://github.com/minitest/minitest?tab=readme-ov-file#specs-) and [mocha](https://github.com/freerange/mocha). -If you need more expectations for you tests, have a look at the [minitest documentation for expectations](https://docs.seattlerb.org/minitest/Minitest/Expectations.html) +Remember - producing a YAML simulation file and/or writing a unit test is +optional. +The most value comes from the YAML simulation file. The unit +test can be written by someone else, but you need access to the device for the +YAML simulation file. If you encounter problems, open an issue or ask for help +in your pull request. ## Advanced features diff --git a/examples/device-simulation/README.md b/examples/device-simulation/README.md new file mode 100644 index 000000000..f52621abc --- /dev/null +++ b/examples/device-simulation/README.md @@ -0,0 +1,167 @@ +# Device simulation +Oxidized supports [150+ devices](/docs/Supported-OS-Types.md). +No developer has access to all of these devices, which makes the task of +maintaining Oxidized difficult: + +- issues can't be resolved because the developer has no access to the device. +- further developments can produce regressions. + +In order to address this, we can simulate the devices. An example for a +simulation are the [model unit tests](/spec/model) but one could also simulate +a device within a ssh server. + +The simulation of devices is currently focused on ssh-based devices. This may +be extended to other inputs like telnet or ftp in the future. + +## YAML Simulation Data +The underlying data for the simulation is a [YAML](https://yaml.org/) file in +which we store all relevant information about the device. The most important +information is the responses to the commands used in the oxidized models. + +The YAML simulation files are stored under +[/examples/device-simulation/yaml/](/examples/device-simulation/yaml/). + +### Creating a YAML file with device2yaml.rb +A device does not only output the ASCII text we can see in the console. +It adds ANSI-escape code for nice colors, bold and underline, \r and so on. +These are key factors in prompt issues so they must be represented in the YAML +file. We use the ruby string format with interpolations like \r \e and so on. +Another important point is trailing spaces at the end of lines. Some text +editors automatically remove trailing spaces, so we code them with \x20. + +Although a YAML file could be written by hand, this is quite a tedious task to +catch all the extra codes and code them into YAML. This can be +automated with the ruby script +[device2yaml.rb](/examples/device-simulation/device2yaml.rb). + +`device2yaml.rb` needs ruby and the gem +[net-ssh](https://rubygems.org/gems/net-ssh/) to run. On debian, you can install +them with `sudo apt install ruby-net-ssh` + +Run `device2yaml.rb` in the directory `/examples/device-simulation/`, the +online help tells you the options. +``` +device-simulation$ ./device2yaml.rb +Usage: model-yaml.rb [user@]host [options] + -o, --output file Specify an output file instead of stdout + -c, --cmdset file Mandatory: specify the commands to be run + -t, --timout value Specify the idle timeout beween commands (default: 5 seconds) + -h, --help Print this help +``` + +- `[user@]host` specifies the user and host to connect to the device. The +password will be prompted interactively by the script. If you do not specify a +user, it will use the user executing the script. +- You must list the commands you want to run on the device in a file. Just +enter one command per line. It is important that you enter exactly the commands +used by the oxidized model, and no abbreviation like `sh run`. Do not forget +to insert the `post_login` commands at the beginning if the model has some and +also the `pre_logout`commands at the end. +Predefined command sets for some models are stored in +`/examples/device-simulation/cmdsets`. +- `device2yaml.rb` waits an idle timeout after the last received data before +sending the next command. The default is 5 seconds. If your device makes a +longer pause than 5 seconds before or within a command, you will see that the +output of the command is shortened or slips into the next command in the yaml +file. You will have to change the idle timeout to a greater value to address +this. +- When run without the output argument, `device2yaml.rb` will only print the ssh +output to the standard output. You must use `-o ` to store the +collected data in a YAML file. + +Note that `device2yaml.rb` takes some time to run because of the idle +timeout of (default) 5 seconds between each command. You can press the "Escape" +key if you know there is no more data to come for the current command (when you +see the prompt for the next command), and the script will stop waiting and +directly process the next command. + +Here is an example of how to run the script: +``` +./device2yaml.rb OX-SW123.sample.domain -c cmdsets/aoscx -o yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml +``` + +### Publishing the YAML simulation file to oxidized +Publishing the YAML simulation file of your device helps maintain oxidized. +This task may take some time, and we are very grateful that you take this time +for the community! + +You should pay attention to removing or replacing anything you don't want to +share with the rest of the world, for example: + +- Passwords +- IP Adresses +- Serial numbers + +You can also shorten the configuration if you want - we don't need 48 times the +same config for each interface, but it doesn't hurt either. + +Take your time, this is an important task: after you have +uploaded your file on github, it may be impossible to remove it. You can use +search/replace to make consistent and faster changes (change the hostname). + +You can leave the section `oxidized_output` unchanged, it is only used for +[model unit tests](/spec/model). You will find an explanation of how to produce +the `oxidized_output`-section in the README.md there. + +The YAML simulation file should be stored under +[/examples/device-simulation/yaml/](/examples/device-simulation/yaml/. It +should be named so that it can be easily recognized: model, hardware type, +software version and optionally a description if you need to differentiate two +YAML files: + +- #model_#hardware_#software.yaml +- #model_#hardware_#software_#description.yaml + +Examples: + +- garderos_R7709_003_006_068.yaml +- iosxe_C9200L-24P-4G_17.09.04a.yaml +- asa_5512_9.12-4-67_single-context.yaml + +### Interactive mode +The `device2yaml.rb` script is a little dumb and needs some help, especially +when having a device sending its output page by page and requiring you to press +space for the next page. `device2yaml.rb` does not know how to handle this. + +While `device2yaml.rb` is running, you can type anything to the keyboard, it +will be send to the remote device. So you can press space or 'n' to get the +next page. + +You can also use this to enter an enable password. + +If you press the "Esc" key, `device2yaml.rb` will not wait for the idle timeout +and will process the next command right away. + +### YAML Format +The yaml file has three sections: +- init_prompt: describing the lines send by the device before we can send a +command. It usually includes MOTD banners, and must include the first prompt. +- commands: the commands the oxidized model sends to the network device and the +expected output. +- oxidized_output: the expected output of oxidized, so that you can compare it +to the output generated by the unit test. This is optional and only used for +unit tests. + +The outputs are multiline and use YAML block scalars (`|`), with the trailing \n +removed (`-` after `|`). The outputs include the echo of the given command and +the next prompt. Escape characters are coded in Ruby style (\n, \r...). + +Here is a shortened example of a YAML file: +```yaml +--- +init_prompt: |- + \e[4m\rLAB-R1234_Garderos#\e[m\x20 +commands: + show system version: |- + show system version + grs-gwuz-armel/003_005_068 (Garderos; 2021-04-30 16:19:35) + \e[4m\rLAB-R1234_Garderos#\e[m\x20 +# ... + exit: "" +oxidized_output: | + # grs-gwuz-armel/003_005_068 (Garderos; 2021-04-30 16:19:35) + #\x20 +# ... +``` + + diff --git a/examples/device-simulation/cmdsets/aoscx b/examples/device-simulation/cmdsets/aoscx new file mode 100644 index 000000000..18e1eadc4 --- /dev/null +++ b/examples/device-simulation/cmdsets/aoscx @@ -0,0 +1,10 @@ +no page +show version +show environment +show module +show interface transceiver +show system | exclude "Up Time" | exclude "CPU" | exclude "Memory" | exclude "Pkts .x" | exclude "Lowest" | exclude "Missed" +show running-config +# commands beyond the oxidized model +show system +exit diff --git a/examples/device-simulation/cmdsets/asa b/examples/device-simulation/cmdsets/asa new file mode 100644 index 000000000..6ff37bd60 --- /dev/null +++ b/examples/device-simulation/cmdsets/asa @@ -0,0 +1,7 @@ +enable +terminal pager 0 +show mode +show version +show inventory +more system:running-config +exit diff --git a/examples/device-simulation/cmdsets/ios b/examples/device-simulation/cmdsets/ios new file mode 100644 index 000000000..9a3b60ad0 --- /dev/null +++ b/examples/device-simulation/cmdsets/ios @@ -0,0 +1,7 @@ +terminal length 0 +terminal width 0 +show version +show vtp status +show inventory +show running-config +exit diff --git a/examples/device-simulation/device2yaml.rb b/examples/device-simulation/device2yaml.rb new file mode 100755 index 000000000..240ffc320 --- /dev/null +++ b/examples/device-simulation/device2yaml.rb @@ -0,0 +1,177 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'net/ssh' +require 'optparse' +require 'etc' +require 'timeout' + +# This scripts logs in a network device and outputs a yaml file that can be +# used for model unit tests in spec/model/ + +# This script is quick & dirty - it grew with the time an could be a project +# for its own. It works, and that should be enough ;-) + +################# Methods +# runs the ssh loop to wait for ssh output, then print this output to @output, +# each line prepended with prepend +def wait_and_output(prepend = '') + @ssh_output = '' + # ssh_output gets appended by chanel.on-data (below) + # We store the current length of @ssh_output in @ssh_output_length + # if @ssh_output.length is bigger than @ssh_output_length, we got new data + @ssh_output_length = 0 + # One tomeslot is about 0.1 second long. + # When we reach @idle_timeout * 10 timeslots, we can exit the loop + timeslot = 0 + # Loop & wait for @idle_timeout seconds after last output + # 0.1 means that the loop should run at least once per 0.1 second + @ssh.loop(0.1) do + # if @ssh_output is longer than our saved length, we got new output + if @ssh_output_length < @ssh_output.length + # reset the timer and save the new output length + timeslot = 0 + @ssh_output_length = @ssh_output.length + end + timeslot += 1 + + # We wait for 0.1 seconds if a key was pressed + begin + Timeout.timeout(0.1) do + # Get input // this is a blocking call + char = $stdin.getch + # If escape is pressed, exit the loop and go to next cmd + if char == "\e" + timeslot += @idle_timeout * 10 + else + # if not, send the char through ssh + @ses.send_data char + end + end + rescue Timeout::Error + # No key pressed + end + + # exit the loop when the @idle_timeout has been reached (false = exit) + timeslot < @idle_timeout * 10 + end + + # Now print the collected output to @output + # as we want to prepend 'prepend' to each line, we need each_line and chomp + # chomp removes the trainling \n + @ssh_output.each_line(chomp: true) do |line| + # encode line and remove the first and the trailing double quote + line = line.dump[1..-2] + # Make sure trailing white spaces are coded with \0x20 + line.gsub!(/ $/, '\x20') + # prepend white spaces for the yaml block scalar + line = prepend + line + @output&.puts line + end +end + +################# Main loop + +# Define options +options = {} +optparse = OptionParser.new do |opts| + opts.banner = "Usage: device2yaml.rb [user@]host [options]" + + opts.on('-c', '--cmdset file', 'Mandatory: specify the commands to be run') do |file| + options[:cmdset] = file + end + opts.on('-o', '--output file', 'Specify an output YAML-file') do |file| + options[:output] = file + end + opts.on('-t', '--timout value', Integer, 'Specify the idle timeout beween commands (default: 5 seconds)') do |timeout| + options[:timeout] = timeout + end + opts.on '-h', '--help', 'Print this help' do + puts opts + exit + end +end + +# Catch and parse the first argument +if ARGV[0] && ARGV[0][0] != '-' + argument = ARGV.shift + if argument.include?('@') + ssh_user, ssh_host = argument.split('@') + else + ssh_user = Etc.getlogin + ssh_host = argument + end +else + puts 'Missing a host to connect to...' + puts + puts optparse + exit 1 +end + +# Parse the options +optparse.parse! + +# Get the commands to be run against ssh_host +unless options[:cmdset] + puts 'Missing a command set, use option -c' + puts + puts optparse + exit 1 +end +# make an array of commands to send, ignore empty lines +ssh_commands = File.read(options[:cmdset]).split(/\n+|\r+/) + +# Defaut idle timeout: 5 seconds, as tests showed that 2 seconds is too short +@idle_timeout = options[:timeout] || 5 + +# We will use safe navifation (&.) to call the methods on @output only +# if @output is not nil +@output = options[:output] ? File.open(options[:output], 'w') : nil + +@ssh = Net::SSH.start(ssh_host, + ssh_user, + { timeout: 10, + append_all_supported_algorithms: true }) +@ssh_output = '' + +@ses = @ssh.open_channel do |ch| + ch.on_data do |_ch, data| + @ssh_output += data + # Output the data to stdout for interactive control + print data + end + ch.request_pty(term: 'vt100') do |_ch, success_pty| + raise NoShell, "Can't get PTY" unless success_pty + + ch.send_channel_request 'shell' do |_ch, success_shell| + raise NoShell, "Can't get shell" unless success_shell + end + end + ch.on_extended_data do |_ch, _type, data| + $stderr.print "Error: #{data}\n" + end +end + +# get motd and fist prompt +@output&.puts '---', 'init_prompt: |-' + +wait_and_output(' ') + +@output&.puts "commands:" + +begin + ssh_commands.each do |cmd| + puts "\n### Sending #{cmd}..." + @output&.puts " #{cmd}: |-" + @ses.send_data cmd + "\n" + wait_and_output(' ') + end +rescue Errno::ECONNRESET, Net::SSH::Disconnect, IOError => e + puts "### Connection closed with message: #{e.message}" +end +(@ssh.close rescue true) unless @ssh.closed? + +@output&.puts 'oxidized_output: |' +@output&.puts ' !! needs to be written by hand or copy & paste from model output' + +@output&.close diff --git a/examples/device-simulation/yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml b/examples/device-simulation/yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml new file mode 100644 index 000000000..dd35c9338 --- /dev/null +++ b/examples/device-simulation/yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml @@ -0,0 +1,451 @@ +--- +init_prompt: |- + + Last login: 2024-10-21 06:01:45 from 10.42.0.7 + User \"oxidized\" has logged in 18 times in the past 30 days + OX-SW123#\x20 +commands: + no page: |- + no page + OX-SW123#\x20 + show version: |- + show version + ----------------------------------------------------------------------------- + ArubaOS-CX + (c) Copyright 2017-2021 Hewlett Packard Enterprise Development LP + ----------------------------------------------------------------------------- + Version : PL.10.08.1010 \x20 + Build Date : 2021-09-21 14:53:08 UTC \x20 + Build ID : ArubaOS-CX:PL.10.08.1010:51920eb359ca:202109211429 \x20 + Build SHA : 51920eb359caf6584f995926dea7a99242bab059 \x20 + Active Image : primary \x20 + + Service OS Version : PL.01.09.0003 \x20 + BIOS Version : PL.02.0002 \x20 + OX-SW123#\x20 + show environment: |- + show environment + show environment fan + Fan information + --------------------------------------------------------------------------- + Mbr/Fan Product Serial Number Speed Direction Status RPM + Name + --------------------------------------------------------------------------- + 1/1 N/A N/A N/A left-to-right ok N/A\x20 + 1/2 N/A N/A N/A left-to-right ok N/A\x20 + + + + show environment led + Mbr/Name State Status \x20 + ---------------------------------- + 1/locator off ok \x20 + + + show environment power-supply + ------------------------------------------------------------------------------ + Product Serial PSU Input Voltage Wattage + Mbr/PSU Number Number Status Type Range Maximum + ------------------------------------------------------------------------------ + 1/1 N/A N/A OK -- -- 460 + + + + show environment temperature + Temperature information + ------------------------------------------------------------------------------ + Current + Mbr/Slot-Sensor Module Type temperature Status + ------------------------------------------------------------------------------ + 1/1-PHY-01-08 line-card-module 49.00 C normal + 1/1-PHY-09-16 line-card-module 49.00 C normal + 1/1-PHY-17-24 line-card-module 46.00 C normal + 1/1-PHY-25-32 line-card-module 47.00 C normal + 1/1-PHY-33-40 line-card-module 47.00 C normal + 1/1-PHY-41-48 line-card-module 46.00 C normal + + 1/1-Inlet-Air management-module 27.75 C normal + 1/1-Switch-ASIC-Internal management-module 50.38 C normal + 1/1-Switch-CPU-1 management-module 49.88 C normal + 1/1-Switch-CPU-2 management-module 50.88 C normal + + OX-SW123#\x20 + show module: |- + show module + + Management Modules + ================== + + Product Serial + Name Number Description Number Status + ---- ------- -------------------------------------- ---------- ---------------- + 1/1 R8N85A 6000 48G CL4 4SFP Swch CN21FFFFFF Ready + + + Line Modules + ============ + + Product Serial + Name Number Description Number Status + ---- ------- -------------------------------------- ---------- ---------------- + 1/1 R8N85A 6000 48G CL4 4SFP Swch CN21FFFFFF Ready + + + OX-SW123#\x20 + show interface transceiver: |- + show interface transceiver + No pluggable modules found. + OX-SW123#\x20 + show system | exclude "Up Time" | exclude "CPU" | exclude "Memory" | exclude "Pkts .x" | exclude "Lowest" | exclude "Missed": |- + show system | exclude \"Up Time\" | exclude \"CPU\" | exclude \"Memory\" | e\rexclude \"Pkts .x\" | exclude \"Lowest\" | exclude \"Missed\" + Hostname : OX-SW123 \x20 + System Description : PL.10.08.1010 \x20 + System Contact : Oxidized_Admin \x20 + System Location : Here or there + + Vendor : Aruba \x20 + Product Name : R8N85A 6000 48G CL4 4SFP Swch \x20 + Chassis Serial Nbr : CN21FFFFFF \x20 + Base MAC Address : 9460d5-ff00ff \x20 + ArubaOS-CX Version : PL.10.08.1010 \x20 + + Time Zone : Europe/Berlin \x20 + + OX-SW123#\x20 + show running-config: |- + show running-config + Current configuration: + ! + !Version ArubaOS-CX PL.10.08.1010 + !export-password: default + hostname OX-SW123 + banner motd $ + + ######################################### + + Sample configuration provided by @robertcheramy + + ######################################### + + $ + user admin group administrators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user oxidzed group administrators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user operator group operators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + clock timezone europe/berlin + ntp server 10.42.0.2 prefer + ntp enable + ! + ! + ! + ! + tacacs-server host 10.42.0.11 key ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + tacacs-server host 10.42.0.12 key ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + ! + ! + aaa authentication login ssh group tacacs local + aaa authentication login default group tacacs local + aaa authentication login console group tacacs local + ! + aruba-central + disable + ssh server vrf default + vlan 1 + vlan 497 + name MANAGEMENT + vlan 498 + name OXIDIZED + vlan 499 + name ROCKS + spanning-tree mode rpvst + spanning-tree + spanning-tree vlan 497-499 + interface 1/1/1 + no shutdown + description OXIDIZED + vlan access 498 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/2 + no shutdown + vlan access 499 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/3 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/4 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/46 + no shutdown + description skipping a lot of interfaces + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/47 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/48 + no shutdown + no lldp trap enable + description Uplink + vlan trunk native 1 + vlan trunk allowed 497-499 + interface 1/1/49 + no shutdown + vlan access 1 + interface 1/1/50 + no shutdown + vlan access 1 + interface 1/1/51 + no shutdown + vlan access 1 + interface 1/1/52 + no shutdown + vlan access 1 + interface vlan 1 + ip dhcp + interface vlan 497 + ip address 10.0.42.2/29 + snmp-server vrf default + snmp-server system-location Here or there + snmp-server system-contact Oxidized_Admin + snmp-server community oxidized + access-level rw + ip route 0.0.0.0/0 10.0.42.1 + ! + ! + ! + ! + ! + https-server vrf default + OX-SW123#\x20 + show system: |- + show system + Hostname : OX-SW123 \x20 + System Description : PL.10.08.1010 \x20 + System Contact : Oxidized_Admin \x20 + System Location : Here or there + + Vendor : Aruba \x20 + Product Name : R8N85A 6000 48G CL4 4SFP Swch \x20 + Chassis Serial Nbr : CN21FFFFFF \x20 + Base MAC Address : 9460d5-ff00ff \x20 + ArubaOS-CX Version : PL.10.08.1010 \x20 + + Time Zone : Europe/Berlin \x20 + + Up Time : 51 weeks, 5 days, 17 hours, 17 minutes \x20 + CPU Util (%) : 3 \x20 + Memory Usage (%) : 29 \x20 + OX-SW123#\x20 + exit: |- + exit +oxidized_output: | + ! ----------------------------------------------------------------------------- + ! ArubaOS-CX + ! (c) Copyright 2017-2021 Hewlett Packard Enterprise Development LP + ! ----------------------------------------------------------------------------- + ! Version : PL.10.08.1010 \x20 + ! Build Date : 2021-09-21 14:53:08 UTC \x20 + ! Build ID : ArubaOS-CX:PL.10.08.1010:51920eb359ca:202109211429 \x20 + ! Build SHA : 51920eb359caf6584f995926dea7a99242bab059 \x20 + ! Active Image : primary \x20 + !\x20 + ! Service OS Version : PL.01.09.0003 \x20 + ! BIOS Version : PL.02.0002 \x20 + ! show environment fan + ! Fan information + ! --------------------------------------------------------------------------- + ! Mbr/Fan Product Serial Number Speed Direction Status RPM + ! Name + ! --------------------------------------------------------------------------- + ! 1/1 N/A N/A N/A left-to-right ok N/A\x20 + ! 1/2 N/A N/A N/A left-to-right ok N/A\x20 + !\x20 + !\x20 + !\x20 + ! show environment led + ! Mbr/Name State Status \x20 + ! ---------------------------------- + ! 1/locator off ok \x20 + !\x20 + !\x20 + ! show environment power-supply + ! ------------------------------------------------------------------------------ + ! Product Serial PSU Input Voltage Wattage + ! Mbr/PSU Number Number Status Type Range Maximum + ! ------------------------------------------------------------------------------ + ! 1/1 N/A N/A OK -- -- 460 + !\x20 + !\x20 + !\x20 + ! show environment temperature + ! Temperature information + ! ------------------------------------------------------------------------------ + ! Current + ! Mbr/Slot-Sensor Module Type temperature Status + ! ------------------------------------------------------------------------------ + ! 1/1-PHY-01-08 line-card-module normal + ! 1/1-PHY-09-16 line-card-module normal + ! 1/1-PHY-17-24 line-card-module normal + ! 1/1-PHY-25-32 line-card-module normal + ! 1/1-PHY-33-40 line-card-module normal + ! 1/1-PHY-41-48 line-card-module normal + !\x20 + ! 1/1-Inlet-Air management-module normal + ! 1/1-Switch-ASIC-Internal management-module normal + ! 1/1-Switch-CPU-1 management-module normal + ! 1/1-Switch-CPU-2 management-module normal + !\x20 + !\x20 + ! Management Modules + ! ================== + !\x20 + ! Product Serial + ! Name Number Description Number Status + ! ---- ------- -------------------------------------- ---------- ---------------- + ! 1/1 R8N85A 6000 48G CL4 4SFP Swch CN21FFFFFF Ready + !\x20 + !\x20 + ! Line Modules + ! ============ + !\x20 + ! Product Serial + ! Name Number Description Number Status + ! ---- ------- -------------------------------------- ---------- ---------------- + ! 1/1 R8N85A 6000 48G CL4 4SFP Swch CN21FFFFFF Ready + !\x20 + !\x20 + ! No pluggable modules found. + ! Hostname : OX-SW123 \x20 + ! System Description : PL.10.08.1010 \x20 + ! System Contact : Oxidized_Admin \x20 + ! System Location : Here or there + !\x20 + ! Vendor : Aruba \x20 + ! Product Name : R8N85A 6000 48G CL4 4SFP Swch \x20 + ! Chassis Serial Nbr : CN21FFFFFF \x20 + ! Base MAC Address : 9460d5-ff00ff \x20 + ! ArubaOS-CX Version : PL.10.08.1010 \x20 + !\x20 + ! Time Zone : Europe/Berlin \x20 + !\x20 + Current configuration: + ! + !Version ArubaOS-CX PL.10.08.1010 + !export-password: default + hostname OX-SW123 + banner motd $ + + ######################################### + + Sample configuration provided by @robertcheramy + + ######################################### + + $ + user admin group administrators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user oxidzed group administrators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user operator group operators password ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + clock timezone europe/berlin + ntp server 10.42.0.2 prefer + ntp enable + ! + ! + ! + ! + tacacs-server host 10.42.0.11 key ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + tacacs-server host 10.42.0.12 key ciphertext AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + ! + ! + aaa authentication login ssh group tacacs local + aaa authentication login default group tacacs local + aaa authentication login console group tacacs local + ! + aruba-central + disable + ssh server vrf default + vlan 1 + vlan 497 + name MANAGEMENT + vlan 498 + name OXIDIZED + vlan 499 + name ROCKS + spanning-tree mode rpvst + spanning-tree + spanning-tree vlan 497-499 + interface 1/1/1 + no shutdown + description OXIDIZED + vlan access 498 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/2 + no shutdown + vlan access 499 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/3 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/4 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/46 + no shutdown + description skipping a lot of interfaces + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/47 + no shutdown + vlan access 1 + spanning-tree bpdu-guard + spanning-tree port-type admin-edge + interface 1/1/48 + no shutdown + no lldp trap enable + description Uplink + vlan trunk native 1 + vlan trunk allowed 497-499 + interface 1/1/49 + no shutdown + vlan access 1 + interface 1/1/50 + no shutdown + vlan access 1 + interface 1/1/51 + no shutdown + vlan access 1 + interface 1/1/52 + no shutdown + vlan access 1 + interface vlan 1 + ip dhcp + interface vlan 497 + ip address 10.0.42.2/29 + snmp-server vrf default + snmp-server system-location Here or there + snmp-server system-contact Oxidized_Admin + snmp-server community oxidized + access-level rw + ip route 0.0.0.0/0 10.0.42.1 + ! + ! + ! + ! + ! + https-server vrf default + diff --git a/examples/device-simulation/yaml/asa_5512_9.12-4-67_single-context.yaml b/examples/device-simulation/yaml/asa_5512_9.12-4-67_single-context.yaml new file mode 100644 index 000000000..2552cb408 --- /dev/null +++ b/examples/device-simulation/yaml/asa_5512_9.12-4-67_single-context.yaml @@ -0,0 +1,531 @@ +--- +init_prompt: |- + . + Sample asa configuration with single context + Provided by @robertcheramy + . + User oxidzed logged in to LAB-ASA12-Oxidized-IPv6 + Logins over the last 91 days: 21. Last login: 20:01:14 CEST Oct 21 2024 from 10.42.0.17 + Failed logins since the last login: 0. \x20 + Type help or '?' for a list of available commands. + \rLAB-ASA12-Oxidized-IPv6>\x20 +commands: + enable: |- + enable + Password: ****************** + \rLAB-ASA12-Oxidized-IPv6#\x20 + terminal pager 0: |- + terminal pager 0 + \rLAB-ASA12-Oxidized-IPv6#\x20 + show mode: |- + show mode + Security context mode: single\x20 + \rLAB-ASA12-Oxidized-IPv6#\x20 + show version: |- + show version + + Cisco Adaptive Security Appliance Software Version 9.12(4)67\x20 + SSP Operating System Version 2.6(1.272) + + Compiled on Thu 14-Mar-24 18:01 GMT by builders + System image file is \"disk0:/asa9-12-4-67-smp-k8.bin\" + Config file at boot was \"startup-config\" + + LAB-ASA12-Oxidized-IPv6 up 173 days 16 hours + + Hardware: ASA5512, 4096 MB RAM, CPU Clarkdale 2800 MHz, 1 CPU (2 cores) + ASA: 1666 MB RAM, 1 CPU (1 core) + Internal ATA Compact Flash, 4096MB + BIOS Flash MX25EEEEEE @ 0xffbb0000, 8192KB + + Encryption hardware device : Cisco ASA Crypto on-board accelerator (revision 0x1) + Boot microcode : CNPx-MC-BOOT-2.00 + SSL/IKE microcode : CNPx-MC-SSL-SB-PLUS-0005 + IPSec microcode : CNPx-MC-IPSEC-MAIN-0026 + Number of accelerators: 1 + Baseboard Management Controller (revision 0x1) Firmware Version: 2.4 + + + 0: Int: Internal-Data0/0 : address is c08c.cafe.7303, irq 11 + 1: Ext: GigabitEthernet0/0 : address is c08c.cafe.7307, irq 10 + 2: Ext: GigabitEthernet0/1 : address is c08c.cafe.7304, irq 10 + 3: Ext: GigabitEthernet0/2 : address is c08c.cafe.7308, irq 5 + 4: Ext: GigabitEthernet0/3 : address is c08c.cafe.7305, irq 5 + 5: Ext: GigabitEthernet0/4 : address is c08c.cafe.7309, irq 10 + 6: Ext: GigabitEthernet0/5 : address is c08c.cafe.7306, irq 10 + 7: Int: Internal-Data0/1 : address is 0000.0001.0002, irq 0 + 8: Int: Internal-Control0/0 : address is 0000.0001.0001, irq 0 + 9: Int: Internal-Data0/2 : address is 0000.0001.0003, irq 0 + 10: Ext: Management0/0 : address is c08c.cafe.7303, irq 0 + 11: Int: Internal-Data0/3 : address is 0000.0100.0001, irq 0 + + Licensed features for this platform: + Maximum Physical Interfaces : Unlimited perpetual + Maximum VLANs : 50 perpetual + Inside Hosts : Unlimited perpetual + Failover : Disabled perpetual + Encryption-DES : Enabled perpetual + Encryption-3DES-AES : Enabled perpetual + Security Contexts : 2 perpetual + Carrier : Disabled perpetual + AnyConnect Premium Peers : 2 perpetual + AnyConnect Essentials : Disabled perpetual + Other VPN Peers : 250 perpetual + Total VPN Peers : 250 perpetual + AnyConnect for Mobile : Disabled perpetual + AnyConnect for Cisco VPN Phone : Disabled perpetual + Advanced Endpoint Assessment : Disabled perpetual + Shared License : Disabled perpetual + Total TLS Proxy Sessions : 2 perpetual + Botnet Traffic Filter : Disabled perpetual + IPS Module : Disabled perpetual + Cluster : Disabled perpetual + + This platform has a Base license. + + Serial Number: FCH17AAAAAA + Running Permanent Activation Key: 0x12345678 0x9f012345 0x00000000 0x11111111 0x22222222\x20 + Configuration register is 0x1 + + Image type : Release + Key version : A + + Configuration has not been modified since last system restart. + \rLAB-ASA12-Oxidized-IPv6# \x20 + show inventory: |- + show inventory + Name: \"Chassis\", DESCR: \"ASA 5512-X with SW, 6 GE Data, 1 GE Mgmt, AC\" + PID: ASA5512 , VID: V01 , SN: FGL17AAAAAA + + \rLAB-ASA12-Oxidized-IPv6#\x20 + 'more system:running-config': |- + more system:running-config + : Saved + + :\x20 + : Serial Number: FCH17AAAAAA + : Hardware: ASA5512, 4096 MB RAM, CPU Clarkdale 2800 MHz, 1 CPU (2 cores) + : Written by oxidzed at 20:03:32.236 CEST Mon Oct 21 2024 + ! + ASA Version 9.12(4)67\x20 + ! + hostname LAB-ASA12-Oxidized-IPv6 + domain-name lab + enable password $sha512$5000$AAAAAAAAAABBBBBBBBBBCCCCCCCCCC pbkdf2 + service-module 0 keepalive-timeout 4 + service-module 0 keepalive-counter 6 + service-module ips keepalive-timeout 4 + service-module ips keepalive-counter 6 + service-module cxsc keepalive-timeout 4 + service-module cxsc keepalive-counter 6 + xlate per-session deny tcp any4 any4 + xlate per-session deny tcp any4 any6 + xlate per-session deny tcp any6 any4 + xlate per-session deny tcp any6 any6 + xlate per-session deny udp any4 any4 eq domain + xlate per-session deny udp any4 any6 eq domain + xlate per-session deny udp any6 any4 eq domain + xlate per-session deny udp any6 any6 eq domain + passwd AAAAAAAAAABBBBBBBBBBCCCCCCCCCC encrypted + names + no mac-address auto + + ! + interface GigabitEthernet0/0 + nameif RZ + security-level 90 + no ip address + ipv6 address 2001:db8:0000:4200::12/64 + ipv6 nd suppress-ra + ! + interface GigabitEthernet0/1 + nameif WAN + security-level 10 + no ip address + ipv6 address 2001:db8:0000:4203::12/64 + ipv6 nd suppress-ra + ! + interface GigabitEthernet0/2 + description IPv4 DMZ NAT64 + nameif NAT64 + security-level 95 + ip address 10.42.1.2 255.255.255.240\x20 + ! + interface GigabitEthernet0/3 + description Oxidized + nameif OXIDIZED + security-level 20 + no ip address + ipv6 address 2001:db8:0000:4201::12/64 + ! + interface GigabitEthernet0/4 + shutdown + no nameif + no security-level + no ip address + ! + interface GigabitEthernet0/5 + shutdown + no nameif + no security-level + no ip address + ! + interface Management0/0 + description Management + management-only + nameif management + security-level 100 + ip address 10.42.2.12 255.255.255.0\x20 + ! + banner motd . + banner motd Sample asa configuration with single context + banner motd Provided by @robertcheramy + banner motd . + boot system disk0:/asa9-12-4-67-smp-k8.bin + ftp mode passive + clock timezone MET 1 + clock summer-time CEST recurring last Sun Mar 2:00 last Sun Oct 2:00 + dns server-group DefaultDNS + domain-name oxidized + object network OXIDIZED + subnet 10.42.3.64 255.255.255.224 + object network ROCKS + host 2001:db8:0000:4202::4:4 + object network SOME_OBJECT + host 10.42.0.12 + pager lines 24 + logging enable + logging buffer-size 65000 + logging monitor debugging + logging buffered notifications + mtu RZ 1500 + mtu WAN 1500 + mtu NAT64 1500 + mtu OXIDIZED 1500 + mtu management 1500 + icmp unreachable rate-limit 1 burst-size 1 + no asdm history enable + arp timeout 14400 + no arp permit-nonconnected + arp rate-limit 8192 + ipv6 route WAN 2001:db8:0000:4200::/56 2001:db8:0000:4203::801 + ipv6 route WAN 2001:db8:0000:4203::/64 2001:db8:0000:4203::801 + aaa-server TACACS protocol tacacs+ + aaa-server TACACS (management) host 10.42.0.12 + key AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + aaa-server TACACS (management) host 10.42.0.13 + key AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user-identity default-domain LOCAL + aaa authentication http console TACACS LOCAL + aaa authentication enable console TACACS LOCAL + aaa authentication serial console TACACS LOCAL + aaa authentication ssh console TACACS LOCAL + aaa authentication telnet console TACACS LOCAL + aaa authentication login-history + no snmp-server location + no snmp-server contact + ssh scopy enable + ssh stricthostkeycheck + ssh timeout 60 + ssh version 2 + ssh 10.42.0.0 255.255.0.0 management + console timeout 0 + threat-detection basic-threat + threat-detection statistics access-list + no threat-detection statistics tcp-intercept + ntp server 10.42.42.11 source management prefer + username oxidized password $sha512$5000$AAAAAAAAAABBBBBBBBBBCCCCCCCCCC== pbkdf2 + ! + class-map inspection_default + match default-inspection-traffic + ! + ! + policy-map type inspect dns preset_dns_map + parameters + message-length maximum client auto + message-length maximum 512 + no tcp-inspection + policy-map global_policy + class inspection_default + inspect dns preset_dns_map\x20 + inspect ftp\x20 + inspect h323 h225\x20 + inspect h323 ras\x20 + inspect ip-options\x20 + inspect netbios\x20 + inspect rsh\x20 + inspect rtsp\x20 + inspect skinny \x20 + inspect esmtp\x20 + inspect sqlnet\x20 + inspect sunrpc\x20 + inspect tftp\x20 + inspect sip \x20 + inspect xdmcp\x20 + inspect icmp\x20 + ! + service-policy global_policy global + prompt hostname context\x20 + no call-home reporting anonymous + call-home + profile CiscoTAC-1 + no active + destination address http https://tools.cisco.com/its/service/oddce/services/DDCEService + destination address email callhome@cisco.com + destination transport-method http + subscribe-to-alert-group diagnostic + subscribe-to-alert-group environment + subscribe-to-alert-group inventory periodic monthly 1 + subscribe-to-alert-group configuration periodic monthly 1 + subscribe-to-alert-group telemetry periodic daily + password encryption aes + Cryptochecksum:dddddddddffffffffffffffeeeeeeeee + : end + + \rLAB-ASA12-Oxidized-IPv6# \x20 + exit: |- +oxidized_output: | + !\x20 + ! Cisco Adaptive Security Appliance Software Version 9.12(4)67\x20 + ! SSP Operating System Version 2.6(1.272) + !\x20 + ! Compiled on Thu 14-Mar-24 18:01 GMT by builders + ! System image file is \"disk0:/asa9-12-4-67-smp-k8.bin\" + ! Config file at boot was \"startup-config\" + !\x20 + !\x20 + ! Hardware: ASA5512, 4096 MB RAM, CPU Clarkdale 2800 MHz, 1 CPU (2 cores) + ! ASA: 1666 MB RAM, 1 CPU (1 core) + ! Internal ATA Compact Flash, 4096MB + ! BIOS Flash MX25EEEEEE @ 0xffbb0000, 8192KB + !\x20 + ! Encryption hardware device : Cisco ASA Crypto on-board accelerator (revision 0x1) + ! Boot microcode : CNPx-MC-BOOT-2.00 + ! SSL/IKE microcode : CNPx-MC-SSL-SB-PLUS-0005 + ! IPSec microcode : CNPx-MC-IPSEC-MAIN-0026 + ! Number of accelerators: 1 + ! Baseboard Management Controller (revision 0x1) Firmware Version: 2.4 + !\x20 + !\x20 + ! 0: Int: Internal-Data0/0 : address is c08c.cafe.7303, irq 11 + ! 1: Ext: GigabitEthernet0/0 : address is c08c.cafe.7307, irq 10 + ! 2: Ext: GigabitEthernet0/1 : address is c08c.cafe.7304, irq 10 + ! 3: Ext: GigabitEthernet0/2 : address is c08c.cafe.7308, irq 5 + ! 4: Ext: GigabitEthernet0/3 : address is c08c.cafe.7305, irq 5 + ! 5: Ext: GigabitEthernet0/4 : address is c08c.cafe.7309, irq 10 + ! 6: Ext: GigabitEthernet0/5 : address is c08c.cafe.7306, irq 10 + ! 7: Int: Internal-Data0/1 : address is 0000.0001.0002, irq 0 + ! 8: Int: Internal-Control0/0 : address is 0000.0001.0001, irq 0 + ! 9: Int: Internal-Data0/2 : address is 0000.0001.0003, irq 0 + ! 10: Ext: Management0/0 : address is c08c.cafe.7303, irq 0 + ! 11: Int: Internal-Data0/3 : address is 0000.0100.0001, irq 0 + !\x20 + ! Licensed features for this platform: + ! Maximum Physical Interfaces : Unlimited perpetual + ! Maximum VLANs : 50 perpetual + ! Inside Hosts : Unlimited perpetual + ! Failover : Disabled perpetual + ! Encryption-DES : Enabled perpetual + ! Encryption-3DES-AES : Enabled perpetual + ! Security Contexts : 2 perpetual + ! Carrier : Disabled perpetual + ! AnyConnect Premium Peers : 2 perpetual + ! AnyConnect Essentials : Disabled perpetual + ! Other VPN Peers : 250 perpetual + ! Total VPN Peers : 250 perpetual + ! AnyConnect for Mobile : Disabled perpetual + ! AnyConnect for Cisco VPN Phone : Disabled perpetual + ! Advanced Endpoint Assessment : Disabled perpetual + ! Shared License : Disabled perpetual + ! Total TLS Proxy Sessions : 2 perpetual + ! Botnet Traffic Filter : Disabled perpetual + ! IPS Module : Disabled perpetual + ! Cluster : Disabled perpetual + !\x20 + ! This platform has a Base license. + !\x20 + ! Serial Number: FCH17AAAAAA + ! Running Permanent Activation Key: 0x12345678 0x9f012345 0x00000000 0x11111111 0x22222222\x20 + ! Configuration register is 0x1 + !\x20 + ! Image type : Release + ! Key version : A + !\x20 + ! Name: \"Chassis\", DESCR: \"ASA 5512-X with SW, 6 GE Data, 1 GE Mgmt, AC\" + ! PID: ASA5512 , VID: V01 , SN: FGL17AAAAAA + !\x20 + ! + ASA Version 9.12(4)67\x20 + ! + hostname LAB-ASA12-Oxidized-IPv6 + domain-name lab + enable password $sha512$5000$AAAAAAAAAABBBBBBBBBBCCCCCCCCCC pbkdf2 + service-module 0 keepalive-timeout 4 + service-module 0 keepalive-counter 6 + service-module ips keepalive-timeout 4 + service-module ips keepalive-counter 6 + service-module cxsc keepalive-timeout 4 + service-module cxsc keepalive-counter 6 + xlate per-session deny tcp any4 any4 + xlate per-session deny tcp any4 any6 + xlate per-session deny tcp any6 any4 + xlate per-session deny tcp any6 any6 + xlate per-session deny udp any4 any4 eq domain + xlate per-session deny udp any4 any6 eq domain + xlate per-session deny udp any6 any4 eq domain + xlate per-session deny udp any6 any6 eq domain + passwd AAAAAAAAAABBBBBBBBBBCCCCCCCCCC encrypted + names + no mac-address auto + + ! + interface GigabitEthernet0/0 + nameif RZ + security-level 90 + no ip address + ipv6 address 2001:db8:0000:4200::12/64 + ipv6 nd suppress-ra + ! + interface GigabitEthernet0/1 + nameif WAN + security-level 10 + no ip address + ipv6 address 2001:db8:0000:4203::12/64 + ipv6 nd suppress-ra + ! + interface GigabitEthernet0/2 + description IPv4 DMZ NAT64 + nameif NAT64 + security-level 95 + ip address 10.42.1.2 255.255.255.240\x20 + ! + interface GigabitEthernet0/3 + description Oxidized + nameif OXIDIZED + security-level 20 + no ip address + ipv6 address 2001:db8:0000:4201::12/64 + ! + interface GigabitEthernet0/4 + shutdown + no nameif + no security-level + no ip address + ! + interface GigabitEthernet0/5 + shutdown + no nameif + no security-level + no ip address + ! + interface Management0/0 + description Management + management-only + nameif management + security-level 100 + ip address 10.42.2.12 255.255.255.0\x20 + ! + banner motd . + banner motd Sample asa configuration with single context + banner motd Provided by @robertcheramy + banner motd . + boot system disk0:/asa9-12-4-67-smp-k8.bin + ftp mode passive + clock timezone MET 1 + clock summer-time CEST recurring last Sun Mar 2:00 last Sun Oct 2:00 + dns server-group DefaultDNS + domain-name oxidized + object network OXIDIZED + subnet 10.42.3.64 255.255.255.224 + object network ROCKS + host 2001:db8:0000:4202::4:4 + object network SOME_OBJECT + host 10.42.0.12 + pager lines 24 + logging enable + logging buffer-size 65000 + logging monitor debugging + logging buffered notifications + mtu RZ 1500 + mtu WAN 1500 + mtu NAT64 1500 + mtu OXIDIZED 1500 + mtu management 1500 + icmp unreachable rate-limit 1 burst-size 1 + no asdm history enable + arp timeout 14400 + no arp permit-nonconnected + arp rate-limit 8192 + ipv6 route WAN 2001:db8:0000:4200::/56 2001:db8:0000:4203::801 + ipv6 route WAN 2001:db8:0000:4203::/64 2001:db8:0000:4203::801 + aaa-server TACACS protocol tacacs+ + aaa-server TACACS (management) host 10.42.0.12 + key AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + aaa-server TACACS (management) host 10.42.0.13 + key AAAAAAAAAABBBBBBBBBBCCCCCCCCCC + user-identity default-domain LOCAL + aaa authentication http console TACACS LOCAL + aaa authentication enable console TACACS LOCAL + aaa authentication serial console TACACS LOCAL + aaa authentication ssh console TACACS LOCAL + aaa authentication telnet console TACACS LOCAL + aaa authentication login-history + no snmp-server location + no snmp-server contact + ssh scopy enable + ssh stricthostkeycheck + ssh timeout 60 + ssh version 2 + ssh 10.42.0.0 255.255.0.0 management + console timeout 0 + threat-detection basic-threat + threat-detection statistics access-list + no threat-detection statistics tcp-intercept + ntp server 10.42.42.11 source management prefer + username oxidized password $sha512$5000$AAAAAAAAAABBBBBBBBBBCCCCCCCCCC== pbkdf2 + ! + class-map inspection_default + match default-inspection-traffic + ! + ! + policy-map type inspect dns preset_dns_map + parameters + message-length maximum client auto + message-length maximum 512 + no tcp-inspection + policy-map global_policy + class inspection_default + inspect dns preset_dns_map\x20 + inspect ftp\x20 + inspect h323 h225\x20 + inspect h323 ras\x20 + inspect ip-options\x20 + inspect netbios\x20 + inspect rsh\x20 + inspect rtsp\x20 + inspect skinny \x20 + inspect esmtp\x20 + inspect sqlnet\x20 + inspect sunrpc\x20 + inspect tftp\x20 + inspect sip \x20 + inspect xdmcp\x20 + inspect icmp\x20 + ! + service-policy global_policy global + prompt hostname context\x20 + no call-home reporting anonymous + call-home + profile CiscoTAC-1 + no active + destination address http https://tools.cisco.com/its/service/oddce/services/DDCEService + destination address email callhome@cisco.com + destination transport-method http + subscribe-to-alert-group diagnostic + subscribe-to-alert-group environment + subscribe-to-alert-group inventory periodic monthly 1 + subscribe-to-alert-group configuration periodic monthly 1 + subscribe-to-alert-group telemetry periodic daily + password encryption aes + Cryptochecksum:dddddddddffffffffffffffeeeeeeeee\n +# End of YAML diff --git a/examples/model/garderos_R7709_003_006_068.yaml b/examples/device-simulation/yaml/garderos_R7709_003_006_068.yaml similarity index 100% rename from examples/model/garderos_R7709_003_006_068.yaml rename to examples/device-simulation/yaml/garderos_R7709_003_006_068.yaml diff --git a/examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml b/examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml new file mode 100644 index 000000000..cee47b551 --- /dev/null +++ b/examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml @@ -0,0 +1,498 @@ +--- +init_prompt: |- + + ### EXAMPLE IOS-XE 17.09.04a config on a C9200L-24P-4G ### + Retrieved 2024-09-09 by @robertcheramy + ### ### + LAB-SW123_9200L# +commands: + terminal length 0: |- + terminal length 0 + LAB-SW123_9200L# + terminal width 0: |- + terminal width 0 + LAB-SW123_9200L# + show version: |- + show version + Cisco IOS XE Software, Version 17.09.04a + Cisco IOS Software [Cupertino], Catalyst L3 Switch Software (CAT9K_LITE_IOSXE), Version 17.9.4a, RELEASE SOFTWARE (fc3) + Technical Support: http://www.cisco.com/techsupport + Copyright (c) 1986-2023 by Cisco Systems, Inc. + Compiled Fri 20-Oct-23 10:33 by mcpre + + + Cisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc. + All rights reserved. Certain components of Cisco IOS-XE software are + licensed under the GNU General Public License (\"GPL\") Version 2.0. The + software code licensed under GPL Version 2.0 is free software that comes + with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such + GPL code under the terms of GPL Version 2.0. For more details, see the + documentation or \"License Notice\" file accompanying the IOS-XE software, + or the applicable URL provided on the flyer accompanying the IOS-XE + software. + + + ROM: IOS-XE ROMMON + BOOTLDR: System Bootstrap, Version 17.9.1r [FC13], RELEASE SOFTWARE (P)\x20 + + LAB-SW123_9200L uptime is 44 weeks, 4 days, 1 hour, 16 minutes + Uptime for this control processor is 44 weeks, 4 days, 1 hour, 17 minutes + System returned to ROM by Reload Command at 11:29:34 CET Thu Nov 2 2023 + System restarted at 11:41:27 CET Thu Nov 2 2023 + System image file is \"flash:cat9k_lite_iosxe.17.09.04a.SPA.bin\" + Last reload reason: Reload Command + + + + This product contains cryptographic features and is subject to United + States and local country laws governing import, export, transfer and + use. Delivery of Cisco cryptographic products does not imply + third-party authority to import, export, distribute or use encryption. + Importers, exporters, distributors and users are responsible for + compliance with U.S. and local country laws. By using this product you + agree to comply with applicable laws and regulations. If you are unable + to comply with U.S. and local laws, return this product immediately. + + A summary of U.S. laws governing Cisco cryptographic products may be found at: + http://www.cisco.com/wwl/export/crypto/tool/stqrg.html + + If you require further assistance please contact us by sending email to + export@cisco.com. + + + Technology Package License Information:\x20 + + ------------------------------------------------------------------------------ + Technology-package Technology-package + Current Type Next reboot \x20 + ------------------------------------------------------------------------------ + network-essentials \tSmart License \t network-essentials \x20 + dna-essentials \tSubscription Smart License \t dna-essentials \x20 + + + Smart Licensing Status: Smart Licensing Using Policy + + cisco C9200L-24P-4G (ARM64) processor with 519464K/3071K bytes of memory. + Processor board ID JAE24FFFFFF + 2 Virtual Ethernet interfaces + 28 Gigabit Ethernet interfaces + 2048K bytes of non-volatile configuration memory. + 1973320K bytes of physical memory. + 819200K bytes of Crash Files at crashinfo:. + 1941504K bytes of Flash at flash:. + + Base Ethernet MAC Address : 40:f0:78:00:00:00 + Motherboard Assembly Number : 77-22222-00 + Motherboard Serial Number : JAE24FFFFFF + Model Revision Number : L0 + Motherboard Revision Number : A0 + Model Number : C9200L-24P-4G + System Serial Number : JAE24FFFFFF + CLEI Code Number : INM6000000 + + + Switch Ports Model SW Version SW Image Mode \x20 + ------ ----- ----- ---------- ---------- ---- \x20 + * 1 28 C9200L-24P-4G 17.09.04a CAT9K_LITE_IOSXE BUNDLE\x20 + + + Configuration register is 0x102 + + LAB-SW123_9200L# + show vtp status: |- + show vtp status + VTP Version capable : 1 to 3 + VTP version running : 1 + VTP Domain Name : Oxidized + VTP Pruning Mode : Disabled (Operationally Disabled) + VTP Traps Generation : Disabled + Device ID : 40f0.7800.0000 + Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00 + + Feature VLAN: + -------------- + VTP Operating Mode : Transparent + Maximum VLANs supported locally : 1005 + Number of existing VLANs : 10 + Configuration Revision : 0 + MD5 digest : 0x35 0x00 0x00 0x00 0x00 0x00 0x7F 0xB4\x20 + 0x07 0x00 0x00 0x00 0x00 0x00 0x09 0x6D\x20 + LAB-SW123_9200L# + show inventory: |- + show inventory + NAME: \"c92xxL Stack\", DESCR: \"c92xxL Stack\" + PID: C9200L-24P-4G , VID: V01 , SN: JAE24FFFFFF + + NAME: \"Switch 1\", DESCR: \"C9200L-24P-4G\" + PID: C9200L-24P-4G , VID: V01 , SN: JAE24FFFFFF + + NAME: \"Switch 1 - Power Supply A\", DESCR: \"Switch 1 - Power Supply A\" + PID: PWR-C5-600WAC , VID: V02 , SN: QCS24XXXXXX + + + LAB-SW123_9200L# + show running-config: |- + show running-config + Building configuration... + + Current configuration : 20546 bytes + ! + ! Last configuration change at 09:37:40 CEST Tue Aug 20 2024 by oxidized + ! NVRAM config last updated at 09:37:37 CEST Tue Aug 20 2024 by oxidized + ! + version 17.9 + service timestamps debug datetime localtime show-timezone year + service timestamps log datetime localtime show-timezone year + service password-encryption + ! + hostname LAB-SW123_9200L + ! + ! + vrf definition Mgmt-vrf + ! + address-family ipv4 + exit-address-family + ! + address-family ipv6 + exit-address-family + ! + logging buffered 65536 informational + no logging console + aaa new-model + ! + ! + aaa authentication login default group tacacs+ local + aaa authentication enable default group tacacs+ enable + aaa authorization exec default group tacacs+ if-authenticated\x20 + ! ... + no aaa accounting system guarantee-first + ! + ! + aaa session-id common + ! + ! + ! + clock timezone CET 1 0 + clock summer-time CEST recurring last Sun Mar 2:00 last Sun Oct 2:00 + boot system switch all flash:cat9k_lite_iosxe.17.09.05.SPA.bin + switch 1 provision c9200l-24p-4g + ! + ! + ! + ! + ! + ip name-server 10.42.0.1 10.42.0.2 + no ip domain lookup + ip domain name oxidized.local + ! + ! + ! + login on-success log + vtp domain Oxidized + vtp mode transparent + vtp version 1 + ! + ! + spanning-tree mode rapid-pvst + spanning-tree logging + spanning-tree portfast bpduguard default + spanning-tree extend system-id + ! + ! + errdisable recovery cause udld + errdisable recovery cause bpduguard + errdisable recovery cause security-violation + errdisable recovery cause dhcp-rate-limit + errdisable recovery cause arp-inspection + errdisable recovery cause loopback + ! + enable secret 9 $9$xxxSECRET_ENABLExxxxxxxxxxxxxx + ! + username oxidized secret 9 $9$xxxxxxxxxxSECRET_OXIDIZEDxxxxxxxxx + ! + transceiver type all + monitoring + ! + vlan 2 + name two + ! + vlan 3 + name three + ! + ! + interface GigabitEthernet0/0 + vrf forwarding Mgmt-vrf + no ip address + ! + interface GigabitEthernet1/0/1 + description oxidized test one + switchport access vlan 2 + switchport mode access + no snmp trap link-status + spanning-tree portfast + ! + interface GigabitEthernet1/0/2 + description oxidized two + switchport access vlan 3 + switchport mode access + ! + ! ... + ! + interface GigabitEthernet1/0/24 + description oxodized trunk + switchport trunk allowed vlan 2,3 + switchport mode trunk + switchport nonegotiate + ! + interface GigabitEthernet1/1/1 + ! + interface GigabitEthernet1/1/2 + ! + interface GigabitEthernet1/1/3 + ! + interface GigabitEthernet1/1/4 + ! + interface Vlan1 + no ip address + shutdown + ! + interface Vlan2 + description network management + ip address 10.42.11.42 255.255.255.0 + ! + ip default-gateway 10.41.11.1 + no ip http server + no ip http secure-server + ip ftp source-interface Vlan2 + ip tftp source-interface Vlan2 + ip tacacs source-interface Vlan2\x20 + ip ssh version 2 + ! + ! + ip access-list standard 5 + 10 permit 10.0.0.0 0.0.0.255 + 20 deny any + ! + snmp-server community public RW 5 + snmp-server location Here and there + snmp-server host 10.42.0.33 version 2c public\x20 + ! + ! + ! + ! + banner exec ^C + ### EXAMPLE IOS-XE 17.09.04a config on a C9200L-24P-4G ### + Retrieved 2024-09-09 by @robertcheramy + ### ### + ^C + banner login ^C + . + Login banner. + . + ^C + ! + ! + ! + ! + ! + end + + LAB-SW123_9200L# + exit: |- +oxidized_output: | + ! Cisco IOS XE Software, Version 17.09.04a + !\x20 + ! Image: Software: CAT9K_LITE_IOSXE, 17.9.4a, RELEASE SOFTWARE (fc3) + ! Image: Compiled: Fri 20-Oct-23 10:33 by mcpre + ! Image: flash:cat9k_lite_iosxe.17.09.04a.SPA.bin + ! Chassis type: C9200L-24P-4G + ! Memory: main 519464K/3071K + ! Processor ID: JAE24FFFFFF + ! CPU: ARM64 + ! Memory: nvram 2048K + !\x20 + ! VTP: VTP Version capable : 1 to 3 + ! VTP: VTP version running : 1 + ! VTP: VTP Domain Name : Oxidized + ! VTP: VTP Pruning Mode : Disabled (Operationally Disabled) + ! VTP: VTP Traps Generation : Disabled + ! VTP: Device ID : 40f0.7800.0000 + ! VTP: Feature VLAN: + ! VTP: -------------- + ! VTP: VTP Operating Mode : Transparent + ! VTP: Maximum VLANs supported locally : 1005 + ! VTP: Number of existing VLANs : 10 + ! VTP: Configuration Revision : 0 + ! VTP: MD5 digest : 0x35 0x00 0x00 0x00 0x00 0x00 0x7F 0xB4\x20 + ! VTP: 0x07 0x00 0x00 0x00 0x00 0x00 0x09 0x6D\x20 + !\x20 + ! NAME: \"c92xxL Stack\", DESCR: \"c92xxL Stack\" + ! PID: C9200L-24P-4G , VID: V01 , SN: JAE24FFFFFF + !\x20 + ! NAME: \"Switch 1\", DESCR: \"C9200L-24P-4G\" + ! PID: C9200L-24P-4G , VID: V01 , SN: JAE24FFFFFF + !\x20 + ! NAME: \"Switch 1 - Power Supply A\", DESCR: \"Switch 1 - Power Supply A\" + ! PID: PWR-C5-600WAC , VID: V02 , SN: QCS24XXXXXX + !\x20 + !\x20 + ! + ! Last configuration change at 09:37:40 CEST Tue Aug 20 2024 by oxidized + ! NVRAM config last updated at 09:37:37 CEST Tue Aug 20 2024 by oxidized + ! + version 17.9 + service timestamps debug datetime localtime show-timezone year + service timestamps log datetime localtime show-timezone year + service password-encryption + ! + hostname LAB-SW123_9200L + ! + ! + vrf definition Mgmt-vrf + ! + address-family ipv4 + exit-address-family + ! + address-family ipv6 + exit-address-family + ! + logging buffered 65536 informational + no logging console + aaa new-model + ! + ! + aaa authentication login default group tacacs+ local + aaa authentication enable default group tacacs+ enable + aaa authorization exec default group tacacs+ if-authenticated\x20 + ! ... + no aaa accounting system guarantee-first + ! + ! + aaa session-id common + ! + ! + ! + clock timezone CET 1 0 + clock summer-time CEST recurring last Sun Mar 2:00 last Sun Oct 2:00 + boot system switch all flash:cat9k_lite_iosxe.17.09.05.SPA.bin + switch 1 provision c9200l-24p-4g + ! + ! + ! + ! + ! + ip name-server 10.42.0.1 10.42.0.2 + no ip domain lookup + ip domain name oxidized.local + ! + ! + ! + login on-success log + vtp domain Oxidized + vtp mode transparent + vtp version 1 + ! + ! + spanning-tree mode rapid-pvst + spanning-tree logging + spanning-tree portfast bpduguard default + spanning-tree extend system-id + ! + ! + errdisable recovery cause udld + errdisable recovery cause bpduguard + errdisable recovery cause security-violation + errdisable recovery cause dhcp-rate-limit + errdisable recovery cause arp-inspection + errdisable recovery cause loopback + ! + enable secret 9 $9$xxxSECRET_ENABLExxxxxxxxxxxxxx + ! + username oxidized secret 9 $9$xxxxxxxxxxSECRET_OXIDIZEDxxxxxxxxx + ! + transceiver type all + monitoring + ! + vlan 2 + name two + ! + vlan 3 + name three + ! + ! + interface GigabitEthernet0/0 + vrf forwarding Mgmt-vrf + no ip address + ! + interface GigabitEthernet1/0/1 + description oxidized test one + switchport access vlan 2 + switchport mode access + no snmp trap link-status + spanning-tree portfast + ! + interface GigabitEthernet1/0/2 + description oxidized two + switchport access vlan 3 + switchport mode access + ! + ! ... + ! + interface GigabitEthernet1/0/24 + description oxodized trunk + switchport trunk allowed vlan 2,3 + switchport mode trunk + switchport nonegotiate + ! + interface GigabitEthernet1/1/1 + ! + interface GigabitEthernet1/1/2 + ! + interface GigabitEthernet1/1/3 + ! + interface GigabitEthernet1/1/4 + ! + interface Vlan1 + no ip address + shutdown + ! + interface Vlan2 + description network management + ip address 10.42.11.42 255.255.255.0 + ! + ip default-gateway 10.41.11.1 + no ip http server + no ip http secure-server + ip ftp source-interface Vlan2 + ip tftp source-interface Vlan2 + ip tacacs source-interface Vlan2\x20 + ip ssh version 2 + ! + ! + ip access-list standard 5 + 10 permit 10.0.0.0 0.0.0.255 + 20 deny any + ! + snmp-server community public RW 5 + snmp-server location Here and there + snmp-server host 10.42.0.33 version 2c public\x20 + ! + ! + ! + ! + banner exec ^C + ### EXAMPLE IOS-XE 17.09.04a config on a C9200L-24P-4G ### + Retrieved 2024-09-09 by @robertcheramy + ### ### + ^C + banner login ^C + . + Login banner. + . + ^C + ! + ! + ! + ! + ! + end\n diff --git a/examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml b/examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml new file mode 100644 index 000000000..90eb72097 --- /dev/null +++ b/examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml @@ -0,0 +1,393 @@ +--- +init_prompt: |- + OXIDIZED-WLC1# +commands: + terminal length 0: |- + terminal length 0 + OXIDIZED-WLC1# + terminal width 0: |- + terminal width 0 + OXIDIZED-WLC1# + show version: |- + show version + Cisco IOS XE Software, Version 17.06.05 + Cisco IOS Software [Bengaluru], C9800 Software (C9800_IOSXE-K9), Version 17.6.5, RELEASE SOFTWARE (fc2) + Technical Support: http://www.cisco.com/techsupport + Copyright (c) 1986-2023 by Cisco Systems, Inc. + Compiled Wed 25-Jan-23 16:09 by mcpre + + + Cisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc. + All rights reserved. Certain components of Cisco IOS-XE software are + licensed under the GNU General Public License (\"GPL\") Version 2.0. The + software code licensed under GPL Version 2.0 is free software that comes + with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such + GPL code under the terms of GPL Version 2.0. For more details, see the + documentation or \"License Notice\" file accompanying the IOS-XE software, + or the applicable URL provided on the flyer accompanying the IOS-XE + software. + + + ROM: 16.12(3r) + + OXIDIZED-WLC1 uptime is 25 weeks, 5 days, 22 hours, 52 minutes + Uptime for this control processor is 25 weeks, 5 days, 22 hours, 53 minutes + System returned to ROM by Reload Command at 13:53:05 CET Wed Mar 13 2024 + System restarted at 13:56:37 CET Wed Mar 13 2024 + System image file is \"bootflash:C9800-L-universalk9_wlc.17.06.05.SPA.bin\" + Last reload reason: Reload Command + + + + This product contains cryptographic features and is subject to United + States and local country laws governing import, export, transfer and + use. Delivery of Cisco cryptographic products does not imply + third-party authority to import, export, distribute or use encryption. + Importers, exporters, distributors and users are responsible for + compliance with U.S. and local country laws. By using this product you + agree to comply with applicable laws and regulations. If you are unable + to comply with U.S. and local laws, return this product immediately. + + A summary of U.S. laws governing Cisco cryptographic products may be found at: + http://www.cisco.com/wwl/export/crypto/tool/stqrg.html + + If you require further assistance please contact us by sending email to + export@cisco.com. + + License Type: Smart License is permanent + License Level: adventerprise + Next reload license Level: adventerprise + AIR License Level: AIR Network Essentials + Next reload AIR license Level: AIR Network Essentials + + The current crypto throughput level is 0 kbps\x20 + + + Smart Licensing Status: Registration Not Applicable/Not Applicable + + cisco C9800-L-F-K9 (KATAR) processor (revision KATAR) with 1688671K/6147K bytes of memory. + Processor board ID FCL2XXXXXXX + Router operating mode: Autonomous + 2 Virtual Ethernet interfaces + 4 2.5 Gigabit Ethernet interfaces + 2 Ten Gigabit Ethernet interfaces + 32768K bytes of non-volatile configuration memory. + 16777216K bytes of physical memory. + 26251263K bytes of eUSB flash at bootflash:. + + Base Ethernet MAC Address : 08:45:D1:00:00:00 + + Installation mode is BUNDLE\x20 + + Configuration register is 0x2102 + + OXIDIZED-WLC1# + show vtp status: |- + show vtp status + VTP Version capable : 1 to 3 + VTP version running : 1 + VTP Domain Name :\x20 + VTP Pruning Mode : Disabled (Operationally Disabled) + VTP Traps Generation : Disabled + Device ID : 0845.d100.0000 + Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00 + + Feature VLAN: + -------------- + VTP Operating Mode : Off + Maximum VLANs supported locally : 1005 + Number of existing VLANs : 8 + Configuration Revision : 0 + MD5 digest : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\x20 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\x20 + OXIDIZED-WLC1# + show inventory: |- + show inventory + NAME: \"Chassis 1\", DESCR: \"Cisco C9800-L-F-K9 Chassis\" + PID: C9800-L-F-K9 , VID: 01 , SN: FCL2XXXXXXX + + NAME: \"Chassis 1 Power Supply Module 0\", DESCR: \"Cisco Catalyst Wireless Controller 12V DC Generic Power Supply\" + PID: PWR-12V , VID: , SN: \x20 + + NAME: \"Chassis 1 Fan Tray\", DESCR: \"Cisco C9800-L-F-K9 Fan Tray\" + PID: C9800-L-F-K9-FAN , VID: , SN: \x20 + + NAME: \"module 0\", DESCR: \"Cisco C9800-L-F-K9 Modular Interface Processor\" + PID: C9800-L-F-K9 , VID: , SN: \x20 + + NAME: \"SPA subslot 0/0\", DESCR: \"Front Panel bay-0 4 ports 2.5 Gigabitethernet Module\" + PID: BUILT-IN-4x2_5GE , VID: V01 , SN: N/A \x20 + + NAME: \"SPA subslot 0/1\", DESCR: \"Front Panel bay-1 2 ports Ten/Gigabitethernet Module\" + PID: BUILT-IN-2x10GE-F , VID: V01 , SN: N/A \x20 + + NAME: \"module R0\", DESCR: \"Cisco C9800-L-F-K9 Route Processor\" + PID: C9800-L-F-K9 , VID: 01 , SN: FCL2XXXXXXX + + NAME: \"module F0\", DESCR: \"Cisco C9800-L-F-K9 Embedded Services Processor\" + PID: C9800-L-F-K9 , VID: , SN: \x20 + + + OXIDIZED-WLC1# + show running-config: |- + show running-config + Building configuration... + + Current configuration : 19796 bytes + ! + ! Last configuration change at 13:57:08 CET Wed Mar 13 2024 + ! NVRAM config last updated at 15:26:39 CET Wed Mar 13 2024 by oxidized + ! + version 17.6 + service timestamps debug datetime localtime show-timezone year + service timestamps log datetime localtime show-timezone year + service password-encryption + platform qos marker-statistics + platform qos match-statistics per-filter + ! + hostname OXIDIZED-WLC1 + ! + boot-start-marker + boot system flash bootflash:C9800-L-universalk9_wlc.17.06.05.SPA.bin + boot-end-marker + ! + ! + vrf definition Mgmt-intf + ! + address-family ipv4 + exit-address-family + ! + address-family ipv6 + exit-address-family + ! + logging monitor informational + enable secret 9 $9$SECRET_REMOVED + ! + ! + aaa server radius dynamic-author + client 10.42.0.7 server-key 7 REMOVED_SECRET + ! + aaa session-id common + clock timezone CET 1 0 + clock summer-time CET recurring last Sun Mar 2:00 last Sun Oct 2:00 + vtp mode off + ! + ! + ! + ! + subscriber templating + !\x20 + !\x20 + !\x20 + !\x20 + ! + ! + ! + ! + ! + interface TwoGigabitEthernet0/0/0 + description Uplink + switchport trunk allowed vlan 2,3,4 + switchport mode trunk + negotiation auto + no snmp trap link-status + ! + interface TwoGigabitEthernet0/0/1 + negotiation auto + no snmp trap link-status + ! + ! ... + ! + interface TenGigabitEthernet0/1/0 + no negotiation auto + no snmp trap link-status + ! + interface TenGigabitEthernet0/1/1 + no negotiation auto + no snmp trap link-status + ! + interface GigabitEthernet0 + description Mgmt + vrf forwarding Mgmt-intf + ip address 10.41.1.10 255.255.255.0 + negotiation auto + ! + interface Vlan1 + no ip address + shutdown + ! + ip http server + ip http authentication aaa + ip http secure-server + ip http session-idle-timeout 900\x20 + ip http client source-interface GigabitEthernet0 + ! ... + ip route 0.0.0.0 0.0.0.0 10.41.2.1 + ip route vrf Mgmt-intf 0.0.0.0 0.0.0.0 10.41.1.1 250 + ip ssh version 2 + ip scp server enable + ! + ! + banner login ^CThis is an actively monitored system! + Unauthorized access prohibited! + ^C + ! + ! ... + netconf-yang + end + + OXIDIZED-WLC1# + exit: |- +oxidized_output: | + ! Cisco IOS XE Software, Version 17.06.05 + !\x20 + ! Image: Software: C9800_IOSXE-K9, 17.6.5, RELEASE SOFTWARE (fc2) + ! Image: Compiled: Wed 25-Jan-23 16:09 by mcpre + ! Image: bootflash:C9800-L-universalk9_wlc.17.06.05.SPA.bin + ! Chassis type: C9800-L-F-K9 + ! Memory: main 1688671K/6147K + ! Processor ID: FCL2XXXXXXX + ! CPU: KATAR + ! Memory: nvram 32768K + !\x20 + ! VTP: VTP Version capable : 1 to 3 + ! VTP: VTP version running : 1 + ! VTP: VTP Domain Name :\x20 + ! VTP: VTP Pruning Mode : Disabled (Operationally Disabled) + ! VTP: VTP Traps Generation : Disabled + ! VTP: Device ID : 0845.d100.0000 + ! VTP: Feature VLAN: + ! VTP: -------------- + ! VTP: VTP Operating Mode : Off + ! VTP: Maximum VLANs supported locally : 1005 + ! VTP: Number of existing VLANs : 8 + ! VTP: Configuration Revision : 0 + ! VTP: MD5 digest : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\x20 + ! VTP: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\x20 + !\x20 + ! NAME: \"Chassis 1\", DESCR: \"Cisco C9800-L-F-K9 Chassis\" + ! PID: C9800-L-F-K9 , VID: 01 , SN: FCL2XXXXXXX + !\x20 + ! NAME: \"Chassis 1 Power Supply Module 0\", DESCR: \"Cisco Catalyst Wireless Controller 12V DC Generic Power Supply\" + ! PID: PWR-12V , VID: , SN: \x20 + !\x20 + ! NAME: \"Chassis 1 Fan Tray\", DESCR: \"Cisco C9800-L-F-K9 Fan Tray\" + ! PID: C9800-L-F-K9-FAN , VID: , SN: \x20 + !\x20 + ! NAME: \"module 0\", DESCR: \"Cisco C9800-L-F-K9 Modular Interface Processor\" + ! PID: C9800-L-F-K9 , VID: , SN: \x20 + !\x20 + ! NAME: \"SPA subslot 0/0\", DESCR: \"Front Panel bay-0 4 ports 2.5 Gigabitethernet Module\" + ! PID: BUILT-IN-4x2_5GE , VID: V01 , SN: N/A \x20 + !\x20 + ! NAME: \"SPA subslot 0/1\", DESCR: \"Front Panel bay-1 2 ports Ten/Gigabitethernet Module\" + ! PID: BUILT-IN-2x10GE-F , VID: V01 , SN: N/A \x20 + !\x20 + ! NAME: \"module R0\", DESCR: \"Cisco C9800-L-F-K9 Route Processor\" + ! PID: C9800-L-F-K9 , VID: 01 , SN: FCL2XXXXXXX + !\x20 + ! NAME: \"module F0\", DESCR: \"Cisco C9800-L-F-K9 Embedded Services Processor\" + ! PID: C9800-L-F-K9 , VID: , SN: \x20 + !\x20 + !\x20 + ! + ! NVRAM config last updated at 15:26:39 CET Wed Mar 13 2024 by oxidized + ! + version 17.6 + service timestamps debug datetime localtime show-timezone year + service timestamps log datetime localtime show-timezone year + service password-encryption + platform qos marker-statistics + platform qos match-statistics per-filter + ! + hostname OXIDIZED-WLC1 + ! + boot-start-marker + boot system flash bootflash:C9800-L-universalk9_wlc.17.06.05.SPA.bin + boot-end-marker + ! + ! + vrf definition Mgmt-intf + ! + address-family ipv4 + exit-address-family + ! + address-family ipv6 + exit-address-family + ! + logging monitor informational + enable secret 9 $9$SECRET_REMOVED + ! + ! + aaa server radius dynamic-author + client 10.42.0.7 server-key 7 REMOVED_SECRET + ! + aaa session-id common + clock timezone CET 1 0 + clock summer-time CET recurring last Sun Mar 2:00 last Sun Oct 2:00 + vtp mode off + ! + ! + ! + ! + subscriber templating + !\x20 + !\x20 + !\x20 + !\x20 + ! + ! + ! + ! + ! + interface TwoGigabitEthernet0/0/0 + description Uplink + switchport trunk allowed vlan 2,3,4 + switchport mode trunk + negotiation auto + no snmp trap link-status + ! + interface TwoGigabitEthernet0/0/1 + negotiation auto + no snmp trap link-status + ! + ! ... + ! + interface TenGigabitEthernet0/1/0 + no negotiation auto + no snmp trap link-status + ! + interface TenGigabitEthernet0/1/1 + no negotiation auto + no snmp trap link-status + ! + interface GigabitEthernet0 + description Mgmt + vrf forwarding Mgmt-intf + ip address 10.41.1.10 255.255.255.0 + negotiation auto + ! + interface Vlan1 + no ip address + shutdown + ! + ip http server + ip http authentication aaa + ip http secure-server + ip http session-idle-timeout 900\x20 + ip http client source-interface GigabitEthernet0 + ! ... + ip route 0.0.0.0 0.0.0.0 10.41.2.1 + ip route vrf Mgmt-intf 0.0.0.0 0.0.0.0 10.41.1.1 250 + ip ssh version 2 + ip scp server enable + ! + ! + banner login ^CThis is an actively monitored system! + Unauthorized access prohibited! + ^C + ! + ! ... + netconf-yang + end\n +# End of YAML file diff --git a/spec/model/README.md b/spec/model/README.md new file mode 100644 index 000000000..9447f5194 --- /dev/null +++ b/spec/model/README.md @@ -0,0 +1,215 @@ +# Model unit tests +Model unit tests are stored in this directory. Each test is named after the +model with `_spec.rb` appended at the end. + +## Writing a model unit test with model_helper_spec.rb +Although you can write your model unit test yourself according to your specific +needs, we have a [helper](model_helper_spec.rb) which facilitates the task. + +You need a [YAML simulation file](/examples/device-simulation/) for your +device, stored under `/examples/device-simulation/. See the link on how to +produce it. + +The unit test is a Ruby script in the directory `/spec/model/`. It is named +`_spec.rb`, for the ios model (which we will use as an example below): +[ios_spec.rb](/spec/model/ios_spec.rb). You can add more tests if you like, we +describe a minimal example here. + +The model unit test feeds the oxidized model with the command outputs in the +YAML simulation file and compares the result to the section `oxidized_output` +of the YAML simulation file. You will learn below how to write the section +`oxidized_output`. + +## Setting your environmment up to be able to run unit tests +Have a look at +[How to contribute content](/CONTRIBUTING.md#how-to-contribute-content). Here +is a summary of the commands to be executed: +```shell +# Fork the repository in github +git clone git@github.com:##yourname##/oxidized.git +cd oxidized +git checkout -b new_model +bundle config set --local path 'vendor/bundle' +bundle install +``` + +## Writing the model +Here is the skeleton of a very simple model. Copy & paste, adapt and save it to +the file `/spec/model/_spec.rb`. + +You will need to change the model name (`describe 'model/IOS' do` and +`model: 'ios'`), the name of the test +(`it 'runs on C9800-L-F-K9 with IOS-XE 17.06.05' do`) and the link to the YAML +file (`mockmodel = MockSsh.new('examples/device-simulation/yaml/.yaml')`). + +```ruby +require_relative 'model_helper' + +describe 'model/IOS' do + before(:each) do + init_model_helper + @node = Oxidized::Node.new(name: 'example.com', + input: 'ssh', + model: 'ios') + end + + it 'runs on C9800-L-F-K9 with IOS-XE 17.06.05' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml') + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + # result2file(result, 'model-output.txt') + _(result.to_cfg).must_equal mockmodel.oxidized_output + end +end +``` + +## Run the unit test +You can run the unit test with `bundle exec rake`, it will fail: + +```shell +~/oxidized$ bundle exec rake +Running RuboCop... +Inspecting 240 files +................................................................................ +................................................................................ +................................................................................ + +240 files inspected, no offenses detected +/usr/bin/ruby3.1 -I"lib:spec" /home/user/oxidized/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/ +rake_test_loader.rb "spec/cli_spec.rb" "spec/hook/githubrepo_spec.rb" "spec/input/ssh_spec.rb" "spec/model/aosw_spec.rb" "spec/model/apc_aos_spec.rb" "spec/model/garderos_spec.rb" "spec/model/ios_spec.rb" "spec/model/model_helper_spec.rb" "spec/node_spec.rb" "spec/nodes_spec.rb" "spec/output/git_spec.rb" "spec/refinements_spec.rb" "spec/source/http_spec.rb" +Run options: --seed 57029 + +# Running: + +..........F...................SS..........................S..S....S + +Finished in 2.555600s, 26.2169 runs/s, 63.7815 assertions/s. + + 1) Failure: +model/IOS#test_0003_runs on C9800-L-F-K9 with IOS-XE 17.06.05 [spec/model/ios_spec.rb:35]: +--- expected ++++ actual +@@ -1 +1,156 @@ +-"!! needs to be written by hand or copy & paste from model output" ++"! Cisco IOS XE Software, Version 17.06.05 ++! ++! Image: Software: C9800_IOSXE-K9, 17.6.5, RELEASE SOFTWARE (fc2) ++! Image: Compiled: Wed 25-Jan-23 16:09 by mcpre ++! Image: bootflash:C9800-L-universalk9_wlc.17.06.05.SPA.bin +(...) ++netconf-yang ++end ++ ++" + + +67 runs, 163 assertions, 1 failures, 0 errors, 5 skips +(...) +``` + +It fails because we haven't specified the expected output in the YAML file. As +this is a tedious task, we can make oxidized write it for us. For this, we +uncomment the line `# result2file(result, 'model-output.txt')` in the unit test. +It will save the output in the file `model-output.txt in the oxidized directory +next time you run the test. + +You can check the output, modify it or modify you model an re-run the test. +When you are happy with it, copy and paste it in the section `oxidized_output` +of the YAML simulation file: +```yaml +--- +# ... +oxidized_output: | + ! Cisco IOS XE Software, Version 17.06.05 + !\x20 + ! Image: Software: C9800_IOSXE-K9, 17.6.5, RELEASE SOFTWARE (fc2) + ! (...) + netconf-yang + end\n +# End of YAML file +``` + +There are a few things in the example above to pay attention to: +- Most of the outputs end with a trailing line feed (`\n`). This is addressed +by using `oxidized_output: |` instead of `oxidized_output: |-`, which would +strip the trailing line feed. +- Cisco IOS ends its config with two line feeds, so I added an extra one at the +end of the output. +- The comment `# End of YAML file` is optional, I use it to make sure I don't +have some garbage added by my editor. + +## Re-run the unit test +Now, remove the line `result2file(result, 'model-output.txt')` and the file +`model-output.txt`, and re-run the test. It should be successful: +```shell +~/oxidized$ bundle exec rake +Running RuboCop... +Inspecting 240 files +................................................................................ +................................................................................ +................................................................................ + +240 files inspected, no offenses detected +/usr/bin/ruby3.1 -I"lib:spec" /home/user/oxidized/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb "spec/cli_spec.rb" "spec/hook/githubrepo_spec.rb" "spec/input/ssh_spec.rb" "spec/model/aosw_spec.rb" "spec/model/apc_aos_spec.rb" "spec/model/garderos_spec.rb" "spec/model/ios_spec.rb" "spec/model/model_helper_spec.rb" "spec/node_spec.rb" "spec/nodes_spec.rb" "spec/output/git_spec.rb" "spec/refinements_spec.rb" "spec/source/http_spec.rb" +Run options: --seed 12233 + +# Running: + +.......................S.S...................S.........SS.......... + +Finished in 2.552535s, 26.2484 runs/s, 63.8581 assertions/s. + +67 runs, 163 assertions, 0 failures, 0 errors, 5 skips + +You have skipped tests. Run with --verbose for details. +Coverage report generated for RSpec to /home/oxidized/oxidized/coverage/coverage.xml. 1447 / 2169 LOC (66.71%) covered +Coverage report generated for RSpec to /home/oxidized/oxidized/coverage. 1447 / 2169 LOC (66.71%) covered. +``` + +If not, you will get an output of the differences and have to look into them. + +## Extend your test with a second device for the model +If you want the test to run against a second device, you will need a second +YAML simulation file, and you need to add a new `it 'test description' do` +to your test: +```ruby + it 'runs on C9200L-24P-4G with IOS-XE 17.09.04a' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml' +) + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + _(result.to_cfg).must_equal mockmodel.oxidized_output + end +``` + +## Test different prompts +You can also test your prompt regexp against different prompts with a specific +`it...` section: + +```ruby + it 'matches different prompts' do + _('LAB-SW123_9200L#').must_match IOS.prompt + _('OXIDIZED-WLC1#').must_match IOS.prompt + end +``` + +## Improve your oxidized output +Now you can edit the YAML file to specify the oxidized output you'd like to get, +and adjust your oxidized model until it outputs exactly the output you've +specified. Running `bundle exec rake` will check this for you and show you the +differences. + +Welcome to the beautiful world of Test-driven development (TDD)! ;-) + +## Information about unit tests in oxidized +The unit tests use +[minitest/spec](https://github.com/minitest/minitest?tab=readme-ov-file#specs-) +and [mocha](https://github.com/freerange/mocha). +If you need more expectations for your tests, have a look at the +[minitest documentation for expectations](https://docs.seattlerb.org/minitest/Minitest/Expectations.html) diff --git a/spec/model/aoscx_spec.rb b/spec/model/aoscx_spec.rb new file mode 100644 index 000000000..09ff50a04 --- /dev/null +++ b/spec/model/aoscx_spec.rb @@ -0,0 +1,24 @@ +require_relative 'model_helper' + +describe 'model/Aoscx' do + before(:each) do + init_model_helper + @node = Oxidized::Node.new(name: 'example.com', + input: 'ssh', + model: 'aoscx') + end + + it 'matches different prompts' do + _('LAB-SW1234# ').must_match Aoscx.prompt + end + + it 'runs on R8N85A (C6000-48G-CL4) with PL.10.08.1010' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/aoscx_R8N85A-C6000-48G-CL4_PL.10.08.1010.yaml') + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + _(result.to_cfg).must_equal mockmodel.oxidized_output + end +end diff --git a/spec/model/apc_aos_spec.rb b/spec/model/apc_aos_spec.rb index 2ed1693b8..225bae21f 100644 --- a/spec/model/apc_aos_spec.rb +++ b/spec/model/apc_aos_spec.rb @@ -74,7 +74,7 @@ # Not taking the whole configuration. # For now, the model does only mask the generation date -# In the future, it may hide passwords, so I included a line with snmp comunity strings +# In the future, it may hide passwords, so I included a line with snmp community strings CONFIGURATION_FILE = <<~HEREDOC.freeze ; Schneider Electric ; Network Management Card AOS v2.5.0.8 diff --git a/spec/model/asa_spec.rb b/spec/model/asa_spec.rb new file mode 100644 index 000000000..c8177c52a --- /dev/null +++ b/spec/model/asa_spec.rb @@ -0,0 +1,25 @@ +require_relative 'model_helper' + +describe 'model/ASA' do + before(:each) do + init_model_helper + @node = Oxidized::Node.new(name: 'example.com', + input: 'ssh', + model: 'asa') + end + + it 'matches different prompts' do + _("\rLAB-ASA12-Oxidized-IPv6> ").must_match ASA.prompt + _("\rLAB-ASA12-Oxidized-IPv6# ").must_match ASA.prompt + end + + it 'runs on 5515 with version 9.12(4)67' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/asa_5512_9.12-4-67_single-context.yaml') + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + _(result.to_cfg).must_equal mockmodel.oxidized_output + end +end diff --git a/spec/model/garderos_spec.rb b/spec/model/garderos_spec.rb index 4510d1ab6..c74931e74 100644 --- a/spec/model/garderos_spec.rb +++ b/spec/model/garderos_spec.rb @@ -17,7 +17,7 @@ end it 'runs on R7709 with OS 003_006_068' do - mockmodel = MockSsh.new('examples/model/garderos_R7709_003_006_068.yaml') + mockmodel = MockSsh.new('examples/device-simulation/yaml/garderos_R7709_003_006_068.yaml') Net::SSH.stubs(:start).returns mockmodel status, result = @node.run diff --git a/spec/model/ios_spec.rb b/spec/model/ios_spec.rb new file mode 100644 index 000000000..1e16f1452 --- /dev/null +++ b/spec/model/ios_spec.rb @@ -0,0 +1,35 @@ +require_relative 'model_helper' + +describe 'model/IOS' do + before(:each) do + init_model_helper + @node = Oxidized::Node.new(name: 'example.com', + input: 'ssh', + model: 'ios') + end + + it 'matches different prompts' do + _('LAB-SW123_9200L#').must_match IOS.prompt + _('OXIDIZED-WLC1#').must_match IOS.prompt + end + + it 'runs on C9200L-24P-4G with IOS-XE 17.09.04a' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/iosxe_C9200L-24P-4G_17.09.04a.yaml') + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + _(result.to_cfg).must_equal mockmodel.oxidized_output + end + + it 'runs on C9800-L-F-K9 with IOS-XE 17.06.05' do + mockmodel = MockSsh.new('examples/device-simulation/yaml/iosxe_C9800-L-F-K9_17.06.05.yaml') + Net::SSH.stubs(:start).returns mockmodel + + status, result = @node.run + + _(status).must_equal :success + _(result.to_cfg).must_equal mockmodel.oxidized_output + end +end diff --git a/spec/model/model_helper.rb b/spec/model/model_helper.rb index 2c4728683..f7cfe4687 100644 --- a/spec/model/model_helper.rb +++ b/spec/model/model_helper.rb @@ -12,7 +12,25 @@ def init_model_helper Oxidized::Node.any_instance.stubs(:resolve_output) end -# Simulate Net::SSH::Connection::Session +# save the result of a node.run into filename +# it is already formated for copy & paste into the YAML simulation file +# result is dormated as it is returned by "status, result = @node.run" +def result2file(result, filename) + File.open(filename, 'w') do |file| + # chomp: true removes the trailing \n after each line + result.to_cfg.each_line(chomp: true) do |line| + # encode line and remove first and trailing double quote + line = line.dump[1..-2] + # Make sure trailing white spaces are coded with \0x20 + line.gsub!(/ $/, '\x20') + # prepend white spaces for the yaml block scalar + line = ' ' + line + file.write "#{line}\n" + end + end +end + +# Class to Simulate Net::SSH::Connection::Session class MockSsh attr_reader :oxidized_output @@ -28,18 +46,11 @@ def initialize(yaml_model) @oxidized_output = interpolate_yaml(model['oxidized_output']) end - # We have to interpolate ourselves as yaml block scalars do not interpolate anything + # We have to interpolate ourselves as yaml block scalars do not interpolate + # anything def interpolate_yaml(text) - # Replace \x with its char - text.gsub!(/\\x(\h+)/) do - digit = Regexp.last_match(1) - digit.to_i(16).chr - end - text.gsub!('\n', "\n") - text.gsub!('\r', "\r") - text.gsub!('\e', "\e") - # Last, replace \\ with \. We use gsub instead of gsub! to return the final text - text.gsub('\\\\', '\\') + # we just add double quotes and undump the result + "\"#{text}\"".undump end def exec!(cmd) diff --git a/spec/model/model_helper_spec.rb b/spec/model/model_helper_spec.rb index 76fcaa0a6..3e85b679b 100644 --- a/spec/model/model_helper_spec.rb +++ b/spec/model/model_helper_spec.rb @@ -8,7 +8,7 @@ @node = Oxidized::Node.new(name: 'example.com', input: 'ssh', model: 'garderos') - @mockmodel = MockSsh.new('examples/model/garderos_R7709_003_006_068.yaml') + @mockmodel = MockSsh.new('examples/device-simulation/yaml/garderos_R7709_003_006_068.yaml') Net::SSH.stubs(:start).returns @mockmodel end