networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.09k stars 712 forks source link

Another mechanism for command extraction during tests #1445

Open max-dw-i opened 1 year ago

max-dw-i commented 1 year ago

At the moment commands are extracted from directory names during tests. It works nice when the command does not have any 'special' characters in it. But some commands do have 'special' characters. For example, command :put [:resolve ...] on mikrotik_routeros. On LInux it's ok but Windows won't even allow to make a directory/file with such characters in the name.

Even if we are going to use only Linux, it's still broken here cause glob treats square brackets specially.

Maybe it makes sense to add a new file with the *.cmd extension (similar to current *.raw, *.yml) with the test command in it. Or another way to use tests for commands with 'special' characters.

jvanderaa commented 1 year ago

Does it work within Docker on Windows?

max-dw-i commented 1 year ago

I don't have Windows at hand but since the base image in the dockerfile is python-slim (which uses Debian under the hood), I'm pretty sure it's going to work. If docker-based development is the only officially supported option, it's not a problem, I guess.

But still such commands (with square brackets, semicolons and other special characters) makes directory/file names less readable (in my opinion, of course).

So I'm curious whether it's a good idea to make a more general way of getting commands during tests (not from directory paths)?

And if the decision is that extracting commands from directories' names is fine then this thing

Even if we are going to use only Linux, it's still broken here cause glob treats square brackets specially.

still should be fixed (I could prepare PR).

mjbear commented 1 month ago

At the moment commands are extracted from directory names during tests. It works nice when the command does not have any 'special' characters in it. But some commands do have 'special' characters. For example, command :put [:resolve ...] on mikrotik_routeros. On LInux it's ok but Windows won't even allow to make a directory/file with such characters in the name.

@max-dw-i I was curious about this issue ticket so I started looking into it. There are not any template test data directories that include special characters such as square brackets [ ].

It is pretty simple the way things are now. If there truly becomes a problem maybe it's just a matter of escaping characters (ex: glob.escape()) as an alternative.

itdependsnetworks commented 1 month ago

We should probably run it through a "slugify" like filter.