-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create garderos model and model unit tests
- garderos.rb: new garderos model - spec/model/: new unit test framework for models with ssh input - node.rb: added a debug message before creating a crashfile
- Loading branch information
cheramr
committed
Aug 30, 2024
1 parent
48885d4
commit 1b082e1
Showing
8 changed files
with
407 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
# 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 | ||
show system serial: |- | ||
show system serial | ||
Serial : R77079012345 | ||
Hardware: Model R-7700, Board GWUZ, Ethernet | ||
\e[4m\rLAB-R1234_Garderos#\e[m\x20 | ||
show hardware wwan wwan0 sim: |- | ||
show hardware wwan wwan0 sim | ||
Unknown command 'wwan'. | ||
\e[4m\rLAB-R1234_Garderos#\e[m\x20 | ||
# This is a not working configuration - but it shows everything we need to make unit tests | ||
show configuration running: |- | ||
show configuration running | ||
acl.ipv4.input.1.action=ACCEPT | ||
acl.ipv4.input.1.description=allow ssh from management | ||
acl.ipv4.input.1.dest-ports=22 | ||
acl.ipv4.input.1.protocol=tcp | ||
acl.ipv4.input.1.source-network=10.42.0.0/24 | ||
acl.ipv4.input.999.action=DROP | ||
hardware.rs-232.1.enable=true | ||
hardware.rs-232.1.name=ttyS0 | ||
interface.eth.1.description=WAN | ||
interface.eth.1.ip-assignment=static | ||
interface.eth.1.ipv4=10.42.101.5/24 | ||
interface.eth.1.name=eth1 | ||
route.ipv4.1.gateway=10.42.101.1 | ||
route.ipv4.1.network=10.0.0.0/8 | ||
service.console.0.authenticate.0.client-ref=TACACS-1 | ||
service.console.0.authenticate.0.type=tacacs+ | ||
service.console.0.authenticate.1.client-ref=TACACS-2 | ||
service.console.0.authenticate.1.type=tacacs+ | ||
service.console.0.authenticate.2.type=local | ||
service.console.0.hardware-ref=ttyS0 | ||
service.snmp.query-agent.enable=true | ||
service.snmp.query-agent.server.0.community.0.name=SECRET | ||
service.tacacs.client.0.name=TACACS-1 | ||
service.tacacs.client.0.server.1.key={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
service.tacacs.client.0.server.1.name=10.42.0.42 | ||
service.tacacs.client.1.name=TACACS-2 | ||
service.tacacs.client.1.server.1.key={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
service.tacacs.client.1.server.1.name=10.42.0.43 | ||
system.name=LAB-R1234_Garderos | ||
system.secret={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD | ||
system.timezone=Europe/Berlin | ||
tunnel.ipsec.2.auth.psk.psk={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
user.account.0.level=15 | ||
user.account.0.name=oxidized | ||
user.account.0.password={sha256}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD | ||
user.enable.0.password={sha256}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD | ||
\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 | ||
# Serial : R77079012345 | ||
# Hardware: Model R-7700, Board GWUZ, Ethernet | ||
#\x20 | ||
acl.ipv4.input.1.action=ACCEPT | ||
acl.ipv4.input.1.description=allow ssh from management | ||
acl.ipv4.input.1.dest-ports=22 | ||
acl.ipv4.input.1.protocol=tcp | ||
acl.ipv4.input.1.source-network=10.42.0.0/24 | ||
acl.ipv4.input.999.action=DROP | ||
hardware.rs-232.1.enable=true | ||
hardware.rs-232.1.name=ttyS0 | ||
interface.eth.1.description=WAN | ||
interface.eth.1.ip-assignment=static | ||
interface.eth.1.ipv4=10.42.101.5/24 | ||
interface.eth.1.name=eth1 | ||
route.ipv4.1.gateway=10.42.101.1 | ||
route.ipv4.1.network=10.0.0.0/8 | ||
service.console.0.authenticate.0.client-ref=TACACS-1 | ||
service.console.0.authenticate.0.type=tacacs+ | ||
service.console.0.authenticate.1.client-ref=TACACS-2 | ||
service.console.0.authenticate.1.type=tacacs+ | ||
service.console.0.authenticate.2.type=local | ||
service.console.0.hardware-ref=ttyS0 | ||
service.snmp.query-agent.enable=true | ||
service.snmp.query-agent.server.0.community.0.name=SECRET | ||
service.tacacs.client.0.name=TACACS-1 | ||
service.tacacs.client.0.server.1.key={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
service.tacacs.client.0.server.1.name=10.42.0.42 | ||
service.tacacs.client.1.name=TACACS-2 | ||
service.tacacs.client.1.server.1.key={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
service.tacacs.client.1.server.1.name=10.42.0.43 | ||
system.name=LAB-R1234_Garderos | ||
system.secret={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD | ||
system.timezone=Europe/Berlin | ||
tunnel.ipsec.2.auth.psk.psk={enc2}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD | ||
user.account.0.level=15 | ||
user.account.0.name=oxidized | ||
user.account.0.password={sha256}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD | ||
user.enable.0.password={sha256}AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD\n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Garderos < Oxidized::Model | ||
using Refinements | ||
# Garderos GmbH https://www.garderos.com/ | ||
# Routers for harsh environments | ||
# grs = Garderos Router Software | ||
|
||
# remove all ANSI escape codes, as GRS uses them :-( | ||
# the prompt does not need to match escape codes, as they have been removed | ||
expect %r{\e\[\d*m\r?} do |data, re| | ||
data.gsub re, '' | ||
end | ||
|
||
prompt %r{[\w-]+# } | ||
comment '# ' | ||
|
||
cmd :all do |cfg| | ||
# Remove the echo of the entered command and the prompt after it | ||
cfg.cut_both | ||
end | ||
|
||
cmd 'show system version' do |cfg| | ||
comment "#{cfg}\n" | ||
end | ||
|
||
cmd 'show system serial' do |cfg| | ||
comment "#{cfg}\n" | ||
end | ||
|
||
# If we have a radio modem installed, we'd like to list the SIM Card | ||
cmd 'show hardware wwan wwan0 sim' do |cfg| | ||
if cfg.start_with? 'Unknown command' | ||
'' | ||
else | ||
comment "#{cfg}\n" | ||
end | ||
end | ||
|
||
cmd 'show configuration running' | ||
|
||
cfg :ssh do | ||
pre_logout 'exit' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require_relative 'model_helper' | ||
|
||
describe 'model/Garderos' do | ||
before(:each) do | ||
init_model_helper | ||
@node = Oxidized::Node.new(name: 'example.com', | ||
input: 'ssh', | ||
model: 'garderos') | ||
end | ||
|
||
it 'matches different prompts' do | ||
# Pretty prompt | ||
# Note that the real prompt looks like "\e[4m\rLAB-R1234_Garderos#\e[m\x20" | ||
# The ANSI escape sequences are cleaned by the model (expect), | ||
# this is tested in the test 'runs on R7709 with OS 003_006_068' | ||
_('LAB-R1234_Garderos# ').must_match Garderos.prompt | ||
end | ||
|
||
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 | ||
|
||
_(status).must_equal :success | ||
_(result.to_cfg).must_equal mockmodel.oxidized_output | ||
end | ||
end |
Oops, something went wrong.