Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update expected prompt #3332

Merged
merged 13 commits into from
Jan 3, 2025
Merged

Update expected prompt #3332

merged 13 commits into from
Jan 3, 2025

Conversation

alchemyx
Copy link
Contributor

@alchemyx alchemyx commented Dec 3, 2024

This is to fix issue #3330 so multiline output won't break the module.

Pre-Request Checklist

  • Passes rubocop code analysis (try rubocop --auto-correct)
  • Tests added or adapted (try rake test)
  • Changes are reflected in the documentation
  • User-visible changes appended to CHANGELOG.md

Description

Closes issue #3330

This is to fix issue ytti#3330 so multiline output won't break the module.
@ytti
Copy link
Owner

ytti commented Dec 3, 2024

This seems like a bad risk.

What characters the #3320 issue has in front of the prompt that make it not match? Is it \r? If so, perhaps ^\r? instead of removing the ^.

Another option is removing screen scraping and turning on exec mode.

@alchemyx
Copy link
Contributor Author

alchemyx commented Dec 3, 2024

Hi @ytti ,

I posted what shows when doing interactive SSH in the issue #3330 :

$ ssh spine1 -l oxidized
Debian GNU/Linux 12
Linux spine1-nyc2 6.1.0-cl-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1+cl5.9.2u6 (2024-08-20) x86_64


UNAUTHORIZED USE OF THIS SYSTEM IS STRICTLY PROHIBITED!
Please contact xxx@xxx to gain
access to this equipment if you need authorization.
Last login: Mon Dec  2 10:47:29 2024 from 10.11.110.8
oxidized@spine1-nyc2:mgmt:~$

With ^ it just doesn't work. This is a default prompt of Cumulus. I had a look and they are defined as standard as it can be:

PS1='\u@\h${VRF}:\w\$ '
PS2='> '
PS4='+ '

Please note that I was checking this via https://regex101.com/ and the above is not matched when ^ is present. My understanding is that it treats input as single multiline string?

@robertcheramy
Copy link
Collaborator

robertcheramy commented Dec 5, 2024

Most prompts in oxidized match the line begin ('^') and line end ('$').
I suspect that when motd is activated, cumulus adds some ANSI Escape Codes which makes the prompt regex fail.
The real fix for this issue would be to match these ANSI Escape Codes in the regex. I'll prepare a cmdset for cumulus and ask you to add a YAML device simulation file in this PR. This will help us to understand where the problem is.

As the model has four different modes, I've added four cmfsets.
@robertcheramy
Copy link
Collaborator

The cumulus model is not very nice, and I don't check what the different modes are, so I provided four command sets.
Could you provide a YAML simulation file in this PR for your mode / model, with motd on and motd off?

Instructions: https://github.com/alchemyx/oxidized/blob/patch-1/docs/Issues.md#sumbit-a-yaml-simulation-file

Command line (choose your cmdset filename according to the mode):

./device2yaml.rb user@host -c cmdsets/cumulus_<mode> -o yaml/cumulus_<with or without>-motd.yaml

@alchemyx
Copy link
Contributor Author

alchemyx commented Dec 6, 2024 via email

@ytti
Copy link
Owner

ytti commented Dec 6, 2024

The codes (2004h, 2004l) you are seeing is 'bracketed paste', that could come also if you did copy+paste yourself, instead of actually being in the output.
If you didn't insert them, they are actually the output, can you change TERM on the device to get rid of them?

In case those are actually in the output, for prompt maybe ^\[?[^h]+h at the start

Did you have chance to test of 'exec mode' works, this would remove the need for prompt detection.

@alchemyx
Copy link
Contributor Author

alchemyx commented Dec 6, 2024

Nah, it was all created by the script. I have updated prompt to

prompt /^\[?[^h]+h(([\w.-]*)@(.*)):/

And tested, it works fine. I have updated my pull request and renamed yaml filename to something more meaningful (unless we want to remove the simulation output which is fine).

@ytti
Copy link
Owner

ytti commented Dec 6, 2024

Nah, it was all created by the script. I have updated prompt to

prompt /^\[?[^h]+h(([\w.-]*)@(.*)):/

And tested, it works fine. I have updated my pull request and renamed yaml filename to something more meaningful (unless we want to remove the simulation output which is fine).

You can't actuaklly use that, as you need to make the whole code part optional i.e. enclose it in ()?

- 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
exit: |-
exit
oxidized_output: |
\e[?2004l\r- header:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: not nice - escape code in the saved config.

@robertcheramy
Copy link
Collaborator

The device2yaml.rb script is pretty cool for testing such things as ugly ANSI Escape Codes ;-)

I've updated the prompt to make the ANSI Escape Code optional for backward compatibility.

There is still one thing wich is not very nice - Cumulus produces an ANSI Escape code in the configuration. Should we remove it or live it alone?

@codecov-commenter
Copy link

codecov-commenter commented Dec 9, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.41%. Comparing base (9942d81) to head (ade3093).
Report is 12 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3332      +/-   ##
==========================================
+ Coverage   70.42%   71.41%   +0.98%     
==========================================
  Files          77       82       +5     
  Lines        3202     3372     +170     
==========================================
+ Hits         2255     2408     +153     
- Misses        947      964      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ytti
Copy link
Owner

ytti commented Dec 9, 2024

There is still one thing wich is not very nice - Cumulus produces an ANSI Escape code in the configuration. Should we remove it or live it alone?

We probably should. Procurve has this:

  # replace all used vt100 control sequences
  expect /\e\[\??\d+(;\d+)*[A-Za-z]/ do |data, re|
    data.gsub re, ''
  end

robertcheramy added a commit that referenced this pull request Dec 9, 2024
- Updated the garderos model, as we have unit tests for it an it uses
ANSI ESC codes.
- This will help me to improve PR #3332 with an universal approach.
- No documentation to CHANGELOG.md, as documentation / change in
Garderos covered by unit tests
- now the output looks better
- added an entry in CHANGELOG.md
@robertcheramy
Copy link
Collaborator

@alchemyx - if the new code works for you, I would merge it into master.

robertcheramy added a commit that referenced this pull request Dec 10, 2024
Lessons learned from the cumuls model (PR #3332)
- Adds an optional "\r" at the end of the regexp
- Tests the change on the garderos model unit test
- Updates the garderos model unit test so that it can tests prompts with
ESC Codes
@alchemyx
Copy link
Contributor Author

alchemyx commented Dec 10, 2024

Unfortunately this version stops for me at prompt

I, [2024-12-10T08:00:51.645095 #6845]  INFO -- : Oxidized starting, running as pid 6845
I, [2024-12-10T08:00:51.649449 #6845]  INFO -- : lib/oxidized/nodes.rb: Loading nodes
I, [2024-12-10T08:00:51.758521 #6845]  INFO -- : lib/oxidized/nodes.rb: Loaded 1 nodes
D, [2024-12-10T08:00:52.072032 #6845] DEBUG -- net.ssh.transport.session[334]: establishing connection to x.x.x.x:22
D, [2024-12-10T08:00:52.130389 #6845] DEBUG -- net.ssh.transport.session[334]: connection established
I, [2024-12-10T08:00:52.130476 #6845]  INFO -- net.ssh.transport.server_version[348]: negotiating protocol version
D, [2024-12-10T08:00:52.130491 #6845] DEBUG -- net.ssh.transport.server_version[348]: local is `SSH-2.0-Ruby/Net::SSH_7.3.0 x86_64-linux'
D, [2024-12-10T08:00:52.228548 #6845] DEBUG -- net.ssh.transport.server_version[348]: remote is `SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3'
I, [2024-12-10T08:00:52.232996 #6845]  INFO -- net.ssh.transport.algorithms[35c]: sending KEXINIT
D, [2024-12-10T08:00:52.233169 #6845] DEBUG -- socket[370]: queueing packet nr 0 type 20 len 1532
D, [2024-12-10T08:00:52.233232 #6845] DEBUG -- socket[370]: sent 1536 bytes
D, [2024-12-10T08:00:52.285351 #6845] DEBUG -- socket[370]: read 856 bytes
D, [2024-12-10T08:00:52.285421 #6845] DEBUG -- socket[370]: received packet nr 0 type 20 len 852
I, [2024-12-10T08:00:52.285467 #6845]  INFO -- net.ssh.transport.algorithms[35c]: got KEXINIT from server
I, [2024-12-10T08:00:52.285518 #6845]  INFO -- net.ssh.transport.algorithms[35c]: negotiating algorithms
D, [2024-12-10T08:00:52.285585 #6845] DEBUG -- net.ssh.transport.algorithms[35c]: negotiated:
* kex: ecdh-sha2-nistp521
* host_key: ecdsa-sha2-nistp256
* encryption_server: aes256-ctr
* encryption_client: aes256-ctr
* hmac_client: [email protected]
* hmac_server: [email protected]
* compression_client: none
* compression_server: none
* language_client:
* language_server:
D, [2024-12-10T08:00:52.285610 #6845] DEBUG -- net.ssh.transport.algorithms[35c]: exchanging keys
D, [2024-12-10T08:00:52.287243 #6845] DEBUG -- socket[370]: queueing packet nr 1 type 30 len 148
D, [2024-12-10T08:00:52.287274 #6845] DEBUG -- socket[370]: sent 152 bytes
D, [2024-12-10T08:00:52.359684 #6845] DEBUG -- socket[370]: read 376 bytes
D, [2024-12-10T08:00:52.359754 #6845] DEBUG -- socket[370]: received packet nr 1 type 31 len 356
D, [2024-12-10T08:00:52.360698 #6845] DEBUG -- socket[370]: queueing packet nr 2 type 21 len 20
D, [2024-12-10T08:00:52.360746 #6845] DEBUG -- socket[370]: sent 24 bytes
D, [2024-12-10T08:00:52.360780 #6845] DEBUG -- socket[370]: received packet nr 2 type 21 len 12
D, [2024-12-10T08:00:52.360992 #6845] DEBUG -- net.ssh.authentication.session[384]: beginning authentication of `oxidized'
D, [2024-12-10T08:00:52.361032 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:52.361087 #6845] DEBUG -- socket[370]: queueing packet nr 3 type 5 len 32
D, [2024-12-10T08:00:52.361104 #6845] DEBUG -- socket[370]: sent 100 bytes
D, [2024-12-10T08:00:52.517709 #6845] DEBUG -- socket[370]: read 100 bytes
D, [2024-12-10T08:00:52.517796 #6845] DEBUG -- socket[370]: received packet nr 3 type 6 len 32
D, [2024-12-10T08:00:52.517864 #6845] DEBUG -- net.ssh.authentication.session[384]: trying none
D, [2024-12-10T08:00:52.517926 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:52.517958 #6845] DEBUG -- socket[370]: queueing packet nr 4 type 50 len 48
D, [2024-12-10T08:00:52.517996 #6845] DEBUG -- socket[370]: sent 116 bytes
D, [2024-12-10T08:00:52.581441 #6845] DEBUG -- socket[370]: read 248 bytes
D, [2024-12-10T08:00:52.581575 #6845] DEBUG -- socket[370]: received packet nr 4 type 53 len 48
I, [2024-12-10T08:00:52.581653 #6845]  INFO -- net.ssh.authentication.session[384]: Debian GNU/Linux 12

D, [2024-12-10T08:00:52.581735 #6845] DEBUG -- socket[370]: received packet nr 5 type 51 len 64
D, [2024-12-10T08:00:52.581764 #6845] DEBUG -- net.ssh.authentication.session[384]: allowed methods: publickey,password,keyboard-interactive
D, [2024-12-10T08:00:52.581791 #6845] DEBUG -- net.ssh.authentication.methods.none[398]: none failed
D, [2024-12-10T08:00:52.581826 #6845] DEBUG -- net.ssh.authentication.session[384]: trying publickey
D, [2024-12-10T08:00:52.582033 #6845] DEBUG -- net.ssh.authentication.agent[3ac]: connecting to ssh-agent
E, [2024-12-10T08:00:52.582074 #6845] ERROR -- net.ssh.authentication.agent[3ac]: could not connect to ssh-agent: Agent not configured
D, [2024-12-10T08:00:52.582188 #6845] DEBUG -- net.ssh.authentication.methods.publickey[3d4]: trying publickey (xxxxxxx) alg rsa-sha2-256
D, [2024-12-10T08:00:52.582257 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:52.582297 #6845] DEBUG -- socket[370]: queueing packet nr 5 type 50 len 608
D, [2024-12-10T08:00:52.582334 #6845] DEBUG -- socket[370]: sent 676 bytes
D, [2024-12-10T08:00:52.640562 #6845] DEBUG -- socket[370]: read 628 bytes
D, [2024-12-10T08:00:52.640664 #6845] DEBUG -- socket[370]: received packet nr 6 type 60 len 560
D, [2024-12-10T08:00:52.645960 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:52.646007 #6845] DEBUG -- socket[370]: queueing packet nr 6 type 50 len 1152
D, [2024-12-10T08:00:52.646047 #6845] DEBUG -- socket[370]: sent 1220 bytes
D, [2024-12-10T08:00:52.710627 #6845] DEBUG -- socket[370]: read 84 bytes
D, [2024-12-10T08:00:52.710773 #6845] DEBUG -- socket[370]: received packet nr 7 type 52 len 16
D, [2024-12-10T08:00:52.710830 #6845] DEBUG -- net.ssh.authentication.methods.publickey[3d4]: publickey succeeded (0d:10:31:7d:8b:1a:36:65:75:18:f9:23:6c:7d:81:26)
D, [2024-12-10T08:00:52.710981 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:52.711030 #6845] DEBUG -- socket[370]: queueing packet nr 7 type 90 len 32
D, [2024-12-10T08:00:52.711084 #6845] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^[\w.-]+@.+:.*# $/] at spine1-nyc2
D, [2024-12-10T08:00:52.811441 #6845] DEBUG -- socket[370]: read 1068 bytes
D, [2024-12-10T08:00:52.811530 #6845] DEBUG -- socket[370]: received packet nr 8 type 80 len 608
I, [2024-12-10T08:00:52.811598 #6845]  INFO -- net.ssh.connection.session[3e8]: global request received: [email protected] false
D, [2024-12-10T08:00:52.811674 #6845] DEBUG -- socket[370]: received packet nr 9 type 4 len 128
D, [2024-12-10T08:00:52.811699 #6845] DEBUG -- net.ssh.transport.session[334]: /home/oxidized/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
D, [2024-12-10T08:00:52.811744 #6845] DEBUG -- socket[370]: received packet nr 10 type 4 len 128
D, [2024-12-10T08:00:52.811764 #6845] DEBUG -- net.ssh.transport.session[334]: /home/oxidized/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
D, [2024-12-10T08:00:52.911955 #6845] DEBUG -- socket[370]: sent 100 bytes
D, [2024-12-10T08:00:53.012162 #6845] DEBUG -- socket[370]: read 100 bytes
D, [2024-12-10T08:00:53.012308 #6845] DEBUG -- socket[370]: received packet nr 11 type 91 len 32
I, [2024-12-10T08:00:53.012358 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_open_confirmation: 0 0 0 32768
I, [2024-12-10T08:00:53.012441 #6845]  INFO -- net.ssh.connection.channel[3fc]: sending channel request "env"
D, [2024-12-10T08:00:53.012509 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:53.012547 #6845] DEBUG -- socket[370]: queueing packet nr 8 type 98 len 48
I, [2024-12-10T08:00:53.012668 #6845]  INFO -- net.ssh.connection.channel[3fc]: sending channel request "pty-req"
D, [2024-12-10T08:00:53.012718 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:53.012746 #6845] DEBUG -- socket[370]: queueing packet nr 9 type 98 len 64
D, [2024-12-10T08:00:53.071559 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:53.112944 #6845] DEBUG -- socket[370]: sent 248 bytes
D, [2024-12-10T08:00:53.213336 #6845] DEBUG -- socket[370]: read 84 bytes
D, [2024-12-10T08:00:53.213544 #6845] DEBUG -- socket[370]: received packet nr 12 type 99 len 16
I, [2024-12-10T08:00:53.213620 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_success: 0
I, [2024-12-10T08:00:53.213666 #6845]  INFO -- net.ssh.connection.channel[3fc]: sending channel request "shell"
D, [2024-12-10T08:00:53.213737 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:53.213775 #6845] DEBUG -- socket[370]: queueing packet nr 10 type 98 len 32
D, [2024-12-10T08:00:53.314121 #6845] DEBUG -- socket[370]: sent 100 bytes
D, [2024-12-10T08:00:53.414403 #6845] DEBUG -- socket[370]: read 1072 bytes
D, [2024-12-10T08:00:53.414553 #6845] DEBUG -- socket[370]: received packet nr 13 type 93 len 16
I, [2024-12-10T08:00:53.414618 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_window_adjust: 0 +2097152
D, [2024-12-10T08:00:53.414682 #6845] DEBUG -- socket[370]: received packet nr 14 type 99 len 16
I, [2024-12-10T08:00:53.414710 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_success: 0
D, [2024-12-10T08:00:53.414758 #6845] DEBUG -- socket[370]: received packet nr 15 type 94 len 96
I, [2024-12-10T08:00:53.414783 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 78b
D, [2024-12-10T08:00:53.414900 #6845] DEBUG -- socket[370]: received packet nr 16 type 94 len 80
I, [2024-12-10T08:00:53.414926 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 52b
D, [2024-12-10T08:00:53.414984 #6845] DEBUG -- socket[370]: received packet nr 17 type 94 len 80
I, [2024-12-10T08:00:53.415005 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 55b
D, [2024-12-10T08:00:53.415061 #6845] DEBUG -- socket[370]: received packet nr 18 type 94 len 32
I, [2024-12-10T08:00:53.415082 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 17b
D, [2024-12-10T08:00:53.415131 #6845] DEBUG -- socket[370]: received packet nr 19 type 94 len 128
I, [2024-12-10T08:00:53.415151 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 99b
D, [2024-12-10T08:00:53.415204 #6845] DEBUG -- socket[370]: received packet nr 20 type 94 len 80
I, [2024-12-10T08:00:53.415224 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 53b
I, [2024-12-10T08:00:53.615876 #6845]  INFO -- net.ssh.connection.keepalive[410]: sending keepalive 0
I, [2024-12-10T08:00:53.616079 #6845]  INFO -- net.ssh.connection.session[3e8]: sending global request [email protected]
D, [2024-12-10T08:00:53.616357 #6845] DEBUG -- socket[370]: using encrypt-then-mac
D, [2024-12-10T08:00:53.616502 #6845] DEBUG -- socket[370]: queueing packet nr 11 type 80 len 32
D, [2024-12-10T08:00:53.817174 #6845] DEBUG -- socket[370]: sent 100 bytes
D, [2024-12-10T08:00:53.917673 #6845] DEBUG -- socket[370]: read 84 bytes
D, [2024-12-10T08:00:53.917988 #6845] DEBUG -- socket[370]: received packet nr 21 type 82 len 16
I, [2024-12-10T08:00:53.918065 #6845]  INFO -- net.ssh.connection.session[3e8]: global request failure
D, [2024-12-10T08:00:53.918116 #6845] DEBUG -- net.ssh.connection.keepalive[410]: keepalive response successful. Missed 0 keepalives
D, [2024-12-10T08:00:54.072787 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:54.077812 #6845] DEBUG -- socket[370]: read 116 bytes
D, [2024-12-10T08:00:54.178203 #6845] DEBUG -- socket[370]: received packet nr 22 type 94 len 48
I, [2024-12-10T08:00:54.178318 #6845]  INFO -- net.ssh.connection.session[3e8]: channel_data: 0 32b
D, [2024-12-10T08:00:55.073314 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:56.074493 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:57.075329 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:58.076324 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-10T08:00:59.077488 #6845] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel

This is diff between working and not working version:

--- /etc/oxidized/model/cumulus.rb	2024-12-10 07:08:03.513549779 +0000
+++ /tmp/puppet-file20241210-14322-jpbil4	2024-12-10 08:05:36.520345798 +0000
@@ -2,16 +2,7 @@
 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 has ANSI ESC codes, the are removed from the code above
-  # [\w.-]+@    - user@
-  # .+:.*# $    - host:path# <end of line>
-  prompt /^[\w.-]+@.+:.*# $/
+  prompt /(([\w.-]*)@(.*)):/
   comment '# '

   # add a comment in the final conf

@alchemyx
Copy link
Contributor Author

Colleague at work recommended using \b and I tested, this also works:

prompt /\b(([\w.-]*)@(.*)):/

@robertcheramy
Copy link
Collaborator

Interesting problem, as it works with the unit tests.
Now I've installed a cumulus vx on my gns3, and see that you first get a non-root user (prompt cumulus@cumulus:mgmt:~$ )

Could you try following prompt (on last commit)?

  prompt /^[\w.-]+@.+:.*[#$] $/

@robertcheramy
Copy link
Collaborator

robertcheramy commented Dec 12, 2024

Okay, found one problem: (cumulus in normal mode):

cat /etc/cumulus/ports.conf
# ports.conf --
#
#   configure port speed, aggregation, and subdivision.
#
#   The ports in Cumulus VX are not configurable from here.
#root@cumulus:mgmt:~#\x20

The file ports.conf does not end with a new line, so the prompt gets polluted with the last line of ports.conf (#).

So we are back to the initial commit to this PR, removing the match on a newline in the prompt, which @ytti did not like. With the following commits in the PR, the prompt at least got better and matches the end of the prompt, which I think is a good compensation for not matching the newline in the prompt.

@ytti
Copy link
Owner

ytti commented Dec 12, 2024

How about cat /etc/cumulus/ports.conf; echo

Some cumulus commands results do not end with \n, so the prompt gets
polluted by the trailing line of the previous command.
This is the case of `cat /etc/cumulus/ports.conf` in the new example
attached in this commit.
@robertcheramy
Copy link
Collaborator

How about cat /etc/cumulus/ports.conf; echo

This is an interesting option and I tested it: it works 👍

But the cumulus model has ~20 commands, and It makes the model somewhat unaesthetic to add ;echo everywhere

About 20% of our models don't match on the line beginning, so I think it should be OK, as long as the prompt is specific enough. The new prompt (prompt /[\w.-]+@.+:.*[#$] $/) could be more specific (.+ for the hostname and .* for the unix path), so I will adapt it further.

@alchemyx - could you check if the new prompt works for you? If yes I'll make it more specific and let you try again ;-)

@alchemyx
Copy link
Contributor Author

alchemyx commented Dec 13, 2024 via email

Making it more specific to avoid side effects as we cannot match on ^
@ytti
Copy link
Owner

ytti commented Dec 13, 2024

About 20% of our models don't match on the line beginning, so I think it should be OK, as long as the prompt is specific enough. The new prompt (prompt /[\w.-]+@.+:.*[#$] $/) could be more specific (.+ for the hostname and .* for the unix path), so I will adapt it further.

Lot of the models are really low quality, but priority is that it was useful to someone, that someone maybe didn't have good idea what they are doing, but they got results that were sufficient to them.

Prompt detection is incredibly fragile fundamentally, because we don't parse any data and data has lot of free form field, like descriptions, MOTD etc. The more relaxed our prompt is, the more often we get people misdiagnosing their problems like 'oxidized can't handle large config', because large config happened to have false positive prompt detection, causing desync between issuing command and assuming command output has ended.

The order of preference should be.

  1. exec mode
  2. ^prompt$
  3. ^prompt
  4. prompt

We don't know if Cumulus guarantees new line at end of some files, and not others. It is very very likely, that any cumulus customer could open ticket and have them fix this one file so that Cumulus guarantees it has new line. I'm not against any solution, including poor prompt or ;echo after every command, but perosnally I'd just put ;echo after poorly generated file, and work on assumption not all of them are poorly generated.

@alchemyx
Copy link
Contributor Author

I can raise a ticket with Cumulus (Nvidia now) and ask them to fix that but I would need specifics. If we are tallking about /etc/cumulus/ports.conf mine looks completely different on a working switch

# Auto-generated by NVUE!
# Any local modifications will prevent NVUE from re-generating this file.
# md5sum: 26732df6e8830f9255002a847f0010d4
# See /usr/share/cumulus-platform/mlnx/msn2010/etc/cumulus/ports.conf
# for additional details about this file.
1=1x
2=1x
3=1x
4=1x
5=1x
6=1x
7=1x
8=1x
9=1x
10=1x
11=1x
12=1x
13=1x
14=1x
15=1x
16=1x
17=1x
18=1x
19=1x
20=1x
21=1x
22=1x

My understanding is also that exec mode should also work. They run modified Debian 12 after all.

@ytti
Copy link
Owner

ytti commented Dec 13, 2024

Please try exec mode.

I think your production device having new line in the file is more support that the example where we do not see new line would be accepted as bug. But agreed, we need to know more about it, like are we sure that case wasn't operator error?

At any rate, I'm still perfectly OK with any solution. While my preferred solution is 'exec mode' and if not possible, strong prompt and ';echo' where needed.

@robertcheramy
Copy link
Collaborator

Exec mode will only work if there is no 2-step login (enable mode), so I think this is not an option that will work for every cumulus user.
The arguments in favor of a strong prompt convinced me, so I'll change the model (again) to match ^ in the newline and add ;echo where needed. I still don't know where the problem on @alchemyx 's device is, so I'll update input/ssh.rb to produce better messages when input.debug is true.

@ytti
Copy link
Owner

ytti commented Dec 13, 2024

Usually including $ is very easy too, \s*$ reduces lot of false positives in MOTD/description case.

@alchemyx
Copy link
Contributor Author

Hi,

While I am happy to help not sure how can I migrate that module over to exec mode? In our setup we don't have 2-step login, we just create dedicated oxidized account and add it to groups like frr and netshow.

@ytti
Copy link
Owner

ytti commented Dec 16, 2024

While I am happy to help not sure how can I migrate that module over to exec mode? In our setup we don't have 2-step login, we just create dedicated oxidized account and add it to groups like frr and netshow.

Yes @robertcheramy explained this as well, we cannot migrate if we need enable

... and add an echo to /etc/cumulus/ports.conf because in some cases, it
has no new line at EOF.
@robertcheramy
Copy link
Collaborator

@alchemyx - I've updated the prompt, and it will not work for you.
Can you please activate debug and input debug in the configuration:

---
debug: true
input:
  debug: true

I need the logs output of oxidized containing the last command sent (DEBUG -- : lib/oxidized/input/ssh.rb "(command)" @ (hostname) with expect: /^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/ until WARN -- : (hostname) status no_connection, and the last content of the file ~/.config/oxidized/log/<IP-Address>-ssh (or whereever your config-dir is), starting with send "(command)".
⚠️ Be careful - this content may be sensitive, you can replace every text you do not want to share, just don't touch the special chars especially at the end of the strings.

~/.config/oxidized/log/<IP-Address>-ssh will be overwritten at each run, so you may need tail -f ~/.config/oxidized/log/<IP-Address>-ssh .

On my devices, it looks like this:

D, [2024-12-17T05:55:43.671280 #12688] DEBUG -- : lib/oxidized/input/ssh.rb "cat /etc/cumulus/ports.conf" @ sw103 with expect: /^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/
D, [2024-12-17T05:55:43.671503 #12688] DEBUG -- socket[de8]: using encrypt-then-mac
D, [2024-12-17T05:55:43.671772 #12688] DEBUG -- socket[de8]: queueing packet nr 28 type 94 len 48
D, [2024-12-17T05:55:43.671848 #12688] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/] at sw103
D, [2024-12-17T05:55:43.832071 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:43.872415 #12688] DEBUG -- socket[de8]: sent 116 bytes
D, [2024-12-17T05:55:43.972856 #12688] DEBUG -- socket[de8]: read 460 bytes
D, [2024-12-17T05:55:43.973255 #12688] DEBUG -- socket[de8]: received packet nr 85 type 94 len 48
I, [2024-12-17T05:55:43.973358 #12688]  INFO -- net.ssh.connection.session[ec4]: channel_data: 0 29b
D, [2024-12-17T05:55:43.973694 #12688] DEBUG -- socket[de8]: received packet nr 86 type 94 len 160
I, [2024-12-17T05:55:43.973777 #12688]  INFO -- net.ssh.connection.session[ec4]: channel_data: 0 142b
D, [2024-12-17T05:55:43.974080 #12688] DEBUG -- socket[de8]: received packet nr 87 type 94 len 48
I, [2024-12-17T05:55:43.974155 #12688]  INFO -- net.ssh.connection.session[ec4]: channel_data: 0 21b
I, [2024-12-17T05:55:44.174916 #12688]  INFO -- net.ssh.connection.keepalive[f14]: sending keepalive 0
I, [2024-12-17T05:55:44.175007 #12688]  INFO -- net.ssh.connection.session[ec4]: sending global request [email protected]
D, [2024-12-17T05:55:44.175164 #12688] DEBUG -- socket[de8]: using encrypt-then-mac
D, [2024-12-17T05:55:44.175457 #12688] DEBUG -- socket[de8]: queueing packet nr 29 type 80 len 32
D, [2024-12-17T05:55:44.376248 #12688] DEBUG -- socket[de8]: sent 100 bytes
D, [2024-12-17T05:55:44.476686 #12688] DEBUG -- socket[de8]: read 84 bytes
D, [2024-12-17T05:55:44.477059 #12688] DEBUG -- socket[de8]: received packet nr 88 type 82 len 16
I, [2024-12-17T05:55:44.477137 #12688]  INFO -- net.ssh.connection.session[ec4]: global request failure
D, [2024-12-17T05:55:44.477186 #12688] DEBUG -- net.ssh.connection.keepalive[f14]: keepalive response successful. Missed 0 keepalives
D, [2024-12-17T05:55:44.833330 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:45.833994 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:46.835177 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:47.836498 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:48.837688 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:49.839004 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:50.840184 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:51.840410 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:52.841599 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:53.842772 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:54.844024 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:55.845241 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:56.846485 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:57.847645 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:58.848390 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:55:59.848918 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:56:00.850075 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:56:01.851342 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2024-12-17T05:56:02.852521 #12688] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
W, [2024-12-17T05:56:03.672272 #12688]  WARN -- : 10.0.2.103 raised Timeout::Error with msg "execution expired"
D, [2024-12-17T05:56:03.672375 #12688] DEBUG -- : lib/oxidized/node.rb: Oxidized::SSH failed for sw103
D, [2024-12-17T05:56:03.672458 #12688] DEBUG -- : lib/oxidized/job.rb: Config fetched for sw103 at 2024-12-17 04:56:03 UTC
W, [2024-12-17T05:56:03.854384 #12688]  WARN -- : /sw103 status no_connection, retry attempt 1
D, [2024-12-17T05:56:03.854447 #12688] DEBUG -- : lib/oxidized/worker.rb: Jobs running: 0 of 1 - ended: 0 of 1

And the debug output file, including tail telling me (in German) that the file was overwritten:

sent "cat /etc/cumulus/ports.conf"
received "cat /etc/cumulus/ports.conf\r\n"
received "# ports.conf --\r\n#\r\n#   configure port speed, aggregation, and subdivision.\r\n#\r\n#   The ports in Cumulus VX are not configurable from here.\r\n#"
received "root@cumulus:mgmt:~# "
tail: 10.0.2.103-ssh: Datei abgeschnitten

@alchemyx
Copy link
Contributor Author

This time it worked, I got the full config output without any issues, /etc/oxidized/logs/ip-ssh:

Last login: Mon Dec 23 06:21:00 2024 from x.x.x.x


UNAUTHORIZED USE OF THIS SYSTEM IS STRICTLY PROHIBITED!
Please contact [email protected] to gain
access to this equipment if you need authorization.
oxidized@spine1-nyc2:~$ nv config show --color off
- header:
    model: MSN2010
    nvue-api-version: nvue_v1
    rev-id: 1.0
    version: Cumulus Linux 5.9.2
[... FULL CONFIG GOES HERE ..]
                remote-as: external
oxidized@spine1-nyc2:~$ exit
logout

And there was no execution of cat /etc/cumulus/ports.conf, I assume because we have this in our config

vars:
  cumulus_routing_daemon: frr
  cumulus_use_nvue: true
  remove_secret: true

Which is further confirmed by oxidized.log snippet

D, [2024-12-23T07:00:40.140871 #6060] DEBUG -- : lib/oxidized/input/cli.rb: Running post_login commands at spine1-nyc2
D, [2024-12-23T07:00:40.140941 #6060] DEBUG -- : lib/oxidized/input/cli.rb: Running post_login command: nil, block: #<Proc:0x00000000024143d8 /etc/oxidized/model/cumulus.rb:121> at spine1-nyc2
D, [2024-12-23T07:00:40.141014 #6060] DEBUG -- : lib/oxidized/model/model.rb Collecting commands' outputs
D, [2024-12-23T07:00:40.141083 #6060] DEBUG -- : lib/oxidized/model/model.rb Executing nv config show --color off
D, [2024-12-23T07:00:40.141098 #6060] DEBUG -- : lib/oxidized/input/ssh.rb nv config show --color off @ spine1-nyc2 with expect: /^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/

@robertcheramy
Copy link
Collaborator

Great! So, to sum up:

  • we have a working prompt, which is as specific as possible
  • we have a workaround for the ports.conf when not using nclu / nvue modes
    Time to squash, merge an commit ;-)

@robertcheramy robertcheramy merged commit d9639c8 into ytti:master Jan 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants