Skip to content

Commit

Permalink
update cumulus prompt
Browse files Browse the repository at this point in the history
- Make the ANSI Escape Code optional for reverse compatibility
- Removed unecessary parenthesis
- Match the whole prompt line
- Add a unit test to validate the prompt and the YAML Simulation File
- Renamed the YAML Simulation File to match the hardware model
- add "exit" to the command sets & the YAML Simulation File
  • Loading branch information
robertcheramy committed Dec 9, 2024
1 parent 790bd92 commit 6d28f00
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/device-simulation/cmdsets/cumulus_frr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cat /etc/cumulus/acl/policy.conf
cat /etc/default/isc-dhcp-relay
cat /etc/cumulus/etc.replace/os-release
cl-license
exit
1 change: 1 addition & 0 deletions examples/device-simulation/cmdsets/cumulus_nclu
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
net show configuration commands
exit
1 change: 1 addition & 0 deletions examples/device-simulation/cmdsets/cumulus_nvue
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nv config show --color off
exit
1 change: 1 addition & 0 deletions examples/device-simulation/cmdsets/cumulus_quagga
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cat /etc/cumulus/acl/policy.conf
cat /etc/default/isc-dhcp-relay
cat /etc/cumulus/etc.replace/os-release
cl-license
exit
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,202 @@ commands:
description: spine leaf bgp peer-group
remote-as: external
\e[?2004hroot@spine1-nyc2:~#\x20
exit: |-
exit
oxidized_output: |
!! needs to be written by hand or copy & paste from model output
\e[?2004l\r- header:
model: MSN2010
nvue-api-version: nvue_v1
rev-id: 1.0
version: Cumulus Linux 5.9.2
- set:
interface:
eth0:
ip:
address:
10.xx.xx.xx/23: {}
gateway:
10.xx.xx.yyy: {}
vrf: mgmt
type: eth
eth0,swp19-22:
link:
state:
up: {}
lo:
ip:
address:
10.xx.xx.xx/32: {}
type: loopback
swp1-18:
description: UNUSED 25G PORTS
link:
state:
down: {}
swp1-22:
type: swp
swp19:
description: 100G Link to edge1
swp19-22:
ip:
neighbor-discovery:
router-advertisement:
interval: 10000
swp20:
description: 100G Link to edge2
swp21:
description: 100G Link to leaf1
swp22:
description: 100G Link to leaf2
router:
bgp:
autonomous-system: 65432
enable: on
router-id: 10.xx.xx.xx
service:
snmp-server:
enable: on
listening-address:
10.xx.xx.xx:
vrf: mgmt
localhost: {}
username:
observium:
auth-sha:
xxxxxxxxxxxxxxxx:
encrypt-aes:
xxxxxxxxxxxxxxxx:
view: xxxxxxxxxxxxx
viewname:
xxxxxxxxxxxxx:
included: 1.3.6.1.2.1
syslog:
mgmt:
server:
10.xx.xx.xxx: {}
system:
aaa:
class:
nvapply:
action: allow
command-path:
/:
permission: all
nvshow:
action: allow
command-path:
/:
permission: ro
sudo:
action: allow
command-path:
/:
permission: all
role:
nvue-admin:
class:
nvapply: {}
nvue-monitor:
class:
nvshow: {}
system-admin:
class:
nvapply: {}
sudo: {}
user:
cumulus:
full-name: cumulus,,,
hashed-password: '*'
role: system-admin
api:
state: enabled
cli:
inactive-timeout: 1800
config:
auto-save:
enable: on
snippet:
sshd_config: |
HostKeyAlgorithms ssh-rsa,ecdsa-sha2-nistp256,rsa-sha2-256,rsa-sha2-512
PubkeyAcceptedAlgorithms +ssh-rsa
control-plane:
acl:
acl-default-dos:
inbound: {}
acl-default-whitelist:
inbound: {}
controlplane-in:
inbound: {}
hostname: spine1-nyc2
reboot:
mode: cold
ssh-server:
authentication-retries: 10
inactive-timeout: 1800
login-timeout: 200
permit-root-login: enabled
state: enabled
strict: enabled
timezone: Etc/UTC
wjh:
channel:
forwarding:
trigger:
l2: {}
l3: {}
tunnel: {}
enable: on
vrf:
default:
router:
bgp:
address-family:
ipv4-unicast:
enable: on
redistribute:
connected:
enable: on
ipv6-unicast:
enable: on
l2vpn-evpn:
enable: on
enable: on
neighbor:
swp19:
peer-group: fabric
type: unnumbered
swp20:
peer-group: fabric
type: unnumbered
swp21:
peer-group: fabric
type: unnumbered
swp22:
peer-group: fabric
type: unnumbered
path-selection:
multipath:
aspath-ignore: on
peer-group:
fabric:
address-family:
ipv4-unicast:
enable: on
nexthop-setting: self
soft-reconfiguration: on
ipv6-unicast:
enable: on
nexthop-setting: self
soft-reconfiguration: on
l2vpn-evpn:
enable: on
soft-reconfiguration: on
bfd:
detect-multiplier: 3
enable: on
min-rx-interval: 400
min-tx-interval: 400
capabilities:
extended-nexthop: on
description: spine leaf bgp peer-group
remote-as: external
5 changes: 4 additions & 1 deletion lib/oxidized/model/cumulus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class Cumulus < Oxidized::Model
using Refinements

prompt /^\[?[^h]+h(([\w.-]*)@(.*)):/
# (\e\[\?\d+h)? - optional ANSI escape code
# [\w.-]+@ - user@
# .+:.*# $ - host:path# <end of line>
prompt /^(\e\[\?\d+h)?[\w.-]+@.+:.*# $/
comment '# '

# add a comment in the final conf
Expand Down
32 changes: 32 additions & 0 deletions spec/model/cumulus_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative 'model_helper'

describe 'model/Cumulus' do
before(:each) do
init_model_helper

@node = Oxidized::Node.new(name: 'example.com',
input: 'ssh',
model: 'cumulus')
end

it 'matches different prompts' do
_('root@spine1-nyc2:~# ').must_match Cumulus.prompt
_("\e[?2004hroot@spine1-nyc2:~#\x20").must_match Cumulus.prompt
end

it 'runs on MSN2010 with Cumulus Linux 5.9.2 (nvue mode)' do
# Reload node with vars cumulus_use_nvue set
@node = Oxidized::Node.new(name: 'example.com',
input: 'ssh',
model: 'cumulus',
vars: { cumulus_use_nvue: true })

mockmodel = MockSsh.new('examples/device-simulation/yaml/cumulus_MSN2010_5.9.2_nvue.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

0 comments on commit 6d28f00

Please sign in to comment.