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

Basic commands not supported #161

Open
ansiblejunky opened this issue Apr 17, 2021 · 7 comments
Open

Basic commands not supported #161

ansiblejunky opened this issue Apr 17, 2021 · 7 comments

Comments

@ansiblejunky
Copy link

ansiblejunky commented Apr 17, 2021

Trying to perform show version or show config or show run or even exit from main switch prompt but none of these appear to be supported. Any thoughts or ideas? I am using the following command:
fake-switches --listen-host localhost --listen-port 3080 --model cisco_generic

switch>exit
No such command : exit
@fbouliane
Copy link
Contributor

Hi @ansiblejunky
I'm not sure you are enabling successfully. I am able, trough the dockerfile build in #165
my guess is the switch enable's doesn't work, maybe because of python3 / password issues ?

You can start with the docker to make sure it's not an external issue
I execute commands such as :

docker build . -t fakwswitchlatest
docker run -P -it fakwswitchlatest fake-switches --listen-host 0.0.0.0 --listen-port 22 --model cisco_generic
ssh -l root localhost -p 32769
> enable[ENTER]
Password:
>root[ENTER]
switch#\
>show run[ENTER]
Building configuration...
...
interface FastEthernet0/7
!

and it works fine. Anything special in the environment you are working on ?

@ansiblejunky
Copy link
Author

Yeah, I didn't know we need to enable first before we can exit the interface. When I first try to exit it doesn't work or allow exiting at all. Partly my fault for not understanding how these switches behave.

@ansiblejunky
Copy link
Author

But yes, when using python3 it additionally struggles with the enable command as it prompts for the password but never accepts anything at all and continues to request password, but that's a python3 issue.

@fbouliane
Copy link
Contributor

no, don't take the blame.
https://github.com/internap/fake-switches/blob/master/fake_switches/cisco/command_processor/default.py#L27
The default processor only allows to enable, pretty sure a real switch would allow you to do other commands.

fake switches has been implemented on a need-basis. So in our case we always enable before doing anything so it has not been an issue. However it is misleading.

python3 it additionally struggles with the enable

I think I already saw this and it was a string vs byte comparison
I exepect it would be fixed within https://github.com/internap/fake-switches/pull/155/files
but python3 support has never officially landed :/

@simon-begin
Copy link

Yes. The modification in ssh_service.py was there to handle the password issue.

@ansiblejunky
Copy link
Author

@fbouliane Do you have some instructions on how to add support for more commands and/or devices? Was looking at doing that in the future.

@fbouliane
Copy link
Contributor

you basically connect to real the switch, learn how it works.
Then you write a single unit test for the command you want and how it should behave ,
https://github.com/internap/fake-switches/blob/master/tests/cisco/test_cisco_switch_protocol.py#L28-L32
And then you would update the commandprocessor so it update it's internal state and reply how you want it
https://github.com/internap/fake-switches/blob/master/fake_switches/cisco/command_processor/config_interface.py

Internal state is objects so should be doable if you're seasoned with python unittest and get to understand the architecture.
It's not something "external people" has done so far, so spoiler alert. there might be some documentation missing.

however, i'm sure we'll be glad to receive pull request and guide you trough it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants