Skip to content

Commit

Permalink
Merge branch 'master' into ATOMS
Browse files Browse the repository at this point in the history
- Adapt new tests from master (fsos and cumulus prompts) to ATOMS
- Place the yaml files under spec/model/data
- Remove command sets from master
- The cumulus tests needs further development, which will be done after
the merge, so the tests are skipped for now
  • Loading branch information
robertcheramy committed Jan 9, 2025
2 parents fbcdaa5 + aa89265 commit 1aff4fc
Show file tree
Hide file tree
Showing 15 changed files with 3,461 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2', '3.3']
ruby-version: ['3.1', '3.2', '3.3', '3.4', 'ruby-head']
continue-on-error: ${{ matrix.ruby-version == 'ruby-head' }}

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
inherit_from: .rubocop_todo.yml

# Do not attempt to police vendored code
AllCops:
NewCops: enable
TargetRubyVersion: 3.1
# Do not attempt to police vendored code
Exclude:
- 'vendor/**/*'

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed
- sonicos: accept policy message. Fixes #3339 (@Steve-M-C, @robertcheramy)
- input/ssh: change input.debug to dump all characters and include sent commands. (@robertcheramy)
- cumulus: remove ANSI Escape codes and fix prompt issues. The prompt is more specific now (@alchemyx, @robertcheramy)
- model unit tests: the tests are automated and simpler to use (@ytti, @robertcheramy)
- device2yaml.rb: moved to extras, commands can be specified from the command line or from a file (no cmdsets provided anymore) (@robertcheramy)

Expand All @@ -21,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- asyncos: fix prompt for hostnames containing "-" . Fixes #3327 (@robertcheramy)
- sonicos: fix prompt for hostnames containing "-" . Fixes #3333 (@robertcheramy)
- xos: Hide radius accounting secret
- fsos: Hide AAA and SNMP secrets (@RayaneB35)

## [0.31.0 – 2024-11-29]

Expand Down
1 change: 1 addition & 0 deletions docs/Model-Notes/FSOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This has been tested against the following models and OS versions
|S3400-48T4SP |Version 2.0.2J Build 81736 |
|S3400-48T4SP |Version 2.0.2J Build 95262 |
|S3400-48T6SP |Version 2.2.0F Build 109661 |
|S3400-48T4SP |Version 2.0.2J Build 120538 |
|S3410-24TS-P |S3410_FSOS 11.4(1)B74S5 |
|S5850-48T4Q |Version 7.0.4.34 |
|S5800-48MBQ |Version 7.0.4.21 |
Expand Down
18 changes: 16 additions & 2 deletions lib/oxidized/model/cumulus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
class Cumulus < Oxidized::Model
using Refinements

prompt /^(([\w.-]*)@(.*)):/
# Remove ANSI escape codes
expect /\e\[[0-?]*[ -\/]*[@-~]\r?/ do |data, re|
data.gsub re, ''
end

# The prompt contains ANSI escape codes, which have already been removed
# from the expect call above
# ^ : match begin of line, to have the most specific prompt
# [\w.-]+@[\w.-]+ : user@hostname
# (:mgmt)? : optional when logged in out of band
# :~[#$] $ : end of prompt, containing the linux path,
# which is always "~" in our context
prompt /^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/
comment '# '

# add a comment in the final conf
Expand Down Expand Up @@ -79,7 +91,9 @@ def add_comment(comment)
cfg += cmd 'cat /etc/cumulus/switchd.conf'

cfg += add_comment 'PORTS'
cfg += cmd 'cat /etc/cumulus/ports.conf'
# in some configurations, ports.conf has no trailing Line Feed,
# which breaks the prompt, so we add one
cfg += cmd "cat /etc/cumulus/ports.conf; echo"

cfg += add_comment 'TRAFFIC'
cfg += cmd 'cat /etc/cumulus/datapath/traffic.conf'
Expand Down
6 changes: 5 additions & 1 deletion lib/oxidized/model/fsos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class FSOS < Oxidized::Model
# Fiberstore / fs.com
using Refinements
comment '! '
prompt /^([\w.@()-]+[#>]\s?)$/

# Handle paging
expect /^ --More--.*$/ do |data, re|
Expand All @@ -13,6 +14,9 @@ class FSOS < Oxidized::Model
cfg.gsub! /(secret \w+) (\S+).*/, '\\1 <secret hidden>'
cfg.gsub! /(password \d+) (\S+).*/, '\\1 <secret hidden>'
cfg.gsub! /(snmp-server community \d+) (\S+).*/, '\\1 <secret hidden>'
cfg.gsub! /^(snmp-server host \S+( udp-port \d+)?( permit|deny \d+)?( informs?)?( traps?)?(( version v3 (priv|auth|noauth))|( version (v1|v2c))?)) +\S+( .*)?$*/, '\\1 <secret hidden>'
cfg.gsub! /^(snmp-server user \S+ \S+ v3( priv (des|aes128|aes256|aes256-c))?( auth (md5|sha|sha256) \d+)) +\S+( .*)?$*/, '\\1 <secret hidden>'
cfg.gsub! /^(.*key \d+) (\S+).*/, '\\1 <secret hidden>'
cfg
end

Expand All @@ -37,7 +41,7 @@ class FSOS < Oxidized::Model
cfg :telnet, :ssh do
post_login 'enable'
post_login 'terminal length 0'
post_login 'terminal width 256'
post_login 'terminal width 512'
pre_logout 'exit'
pre_logout 'exit'
end
Expand Down
4 changes: 2 additions & 2 deletions oxidized.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'bundler', '~> 2.2'
s.add_development_dependency 'git', '~> 2'
s.add_development_dependency 'minitest', '~> 5.18'
s.add_development_dependency 'minitest', '~> 5.25.4'
s.add_development_dependency 'mocha', '~> 2.1'
s.add_development_dependency 'mutex_m'
s.add_development_dependency 'pry', '~> 0.15.0'
Expand All @@ -51,5 +51,5 @@ Gem::Specification.new do |s|

# Dependencies on optional libraries, used for unit tests & development
s.add_development_dependency 'oxidized-web', '>= 0.14.0'
s.add_development_dependency 'sequel', '~> 5.63'
s.add_development_dependency 'sequel', '~> 5.88.0'
end
48 changes: 48 additions & 0 deletions spec/model/cumulus_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 'runs on MSN2010 with Cumulus Linux 5.9.2 (nvue mode)' do
skip 'TODO: needs to be adapted to ATOMS'
# 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('data/cumulus:MSN2010_5.9.2_nvue:simulation.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 VX with Cumulus Linux 5.4.0 (frr mode)' do
skip 'TODO: needs to be adapted to ATOMS'
# Reload node with vars cumulus_use_nvue set
@node = Oxidized::Node.new(name: 'example.com',
input: 'ssh',
model: 'cumulus',
username: 'alma',
password: 'armud',
vars: { cumulus_routing_daemon: 'frr',
enable: true })

mockmodel = MockSsh.new('data/cumulus:VX_5.4.0_frr:simulation.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
Loading

0 comments on commit 1aff4fc

Please sign in to comment.