How to use RobotFramework for system administration

Hi,

I need guidance to understand RobotFramework. How can I use it for System Administration for example? Please guide. Thanks in Advance.

Best Regards,

Kaushal

Hi Kaushal,

This is not something that RF would be normally used for, as most system administrators use native scripting tools to automate their system administration.

Likewise there is nothing that would prevent you doing so. Without more specific questions i’m not sure how much help you will get. Also you are likely going to need to create the keywords that will perform the system administration tasks.

To start I’ll ask which OS are you trying to administer? This will help me guide you.

Dave.

Hi Dave. I am interesting in this post , and would love ask some questions .

Related to this post - I have an application and I can login as a root user and perform some actions,
and also I can go to admin menu ( manually only ) and lets say to run reboot system or pull upgrade - is there any way to automate it with RF? -


linux

there is a screenshot of admin menu - how it looks approximately when you entered .
Thank you.

Hi Sam,

I’m guessing this screenshot is taken using putty from a windows machine ssh’ed into the linux machine?

When connecting to the linux machine there are a couple of libraries that you could consider, this is the order I would look at them in:

Once you choose the library is simply a matter using the libraries keywords to send the same commands / keystrokes you would send manually.

Dave.

Thank you for your response.
The screenshot is random from internet.
But its similar.
I have automated that I can login as a root user , using sshlibrary.
Works awesome.
Does what I need.
But, lets say when as a root user I type [ su admin] - manually, it gives me admin menu , blue screen with commands, upgrade , reboot , quit, and etc.
Since I am new, I only using sshlibrary, postgresqldb most of the time. All the work related [ su admin] I do manually. Wondering if there is a library for that too.
Thank you.
Mainframe library- dont even heard yet about that. Would take a look.

Hi Sam,

Bear in mind I’ve not done this myself, but below is what I would expect:

After you send su admin with Write, then do a Read and you should get a text representation of the screen, hopefully there is a character that is different from the others that represents the selected position, then you could use a regex to find the associated button/list text
After this send Write Bare with a \t to send a tab (move to the next button/item) followed by another Read to confirm the cursor moved.

From here you should be able to work out what commands you need to send and build your keywords to interact with that screen.

Dave.

Hi Dave.
So, the good news is I was able {with your help} to get inside admin menu, by simply writing

  • Write su admin
    — Read —> it was giving me empty result. Till I mention delay=3s

— Also I was managed to navigate to < Reboot> line

  • admin menu has around 17 lines. And < Reboot> is almost last one.
  • Write /bare Reboot — doesn’t work
    It has 3 lines starting with R letter( I have Resize ; restart and Reboot)
    It worked only when I put - Write R,R,R
    Then I can see on my output that it moved to the Reboot line and pressed it.
    And Confirmation message appears. Where is option- yes or no.
    Found a way how to press Yes and reboot service.
    For some reason it works not all the time , sometimes like 40-50% fails - says couldn’t find Confirm. That means command → Write R,R,R – not always works.
    — \t doesn’t work.

Is anyway to move it like Using manually up / down / enter keys? - like commands that simulate keyboard.

  • also is there anyway to insert some value into admin menu?
  • for instance - I need to change a hostname. Was able to go there, then need to clear the actual hostname and write there new hostname? - any library / commands that can handle it?

And thank you so much for the help!!!

update: Now I can write a hostname whatever I want , but still having some issue to clear the box before writing hostname , ( would be good if is there a way to capture that value and save it)

Hi Sam,

It sounds like you’re becoming the expert on automating these console GUI’s :grin:

Unfortunately there’s not much documentation for that SSL Library with regards to sending keystrokes, so below is a guess:

Combining the information from here Control character - Wikipedia and here ANSI escape code - Wikipedia

you could try:

Write Bare	\e[B     # Down 

or

Write Bare	\eB     # Down 

if one of those works for sending a down key then the second link gives you the other letters for the other keys, i.e. A=Up, C=Right, D=Left, etc Function keys, Home End etc are all listed on that page.

I’ll be interested in how you get on, hopefully this helps,

Dave.

Hi Dave,
Unfortunately it doesn’t work. I have tried multiple variants , no results.
Wrire Bare \e[B and the rest not working. Tried to clear input for the hostname in admin menu , before I write a new , same no luck .
The only Reboot task was done using admin menu! — which is good :slight_smile:

Maybe there is another way , how to move lines , remove some text and etc using buildin.shhlibrary or maybe others ( not selenium - by the way it has an option to press key / keys —which is nice!)
Thank you for getting involved!
Will keep loooking :face_with_monocle:

Sam

1 Like

Hi Sam,

You made me curious :grin:

I setup a vm with a minimal Debian 11 install, then installed Network-Manager to give me a console gui application (nmtui) that looks like this:

This gives something anyone can reproduce with my robot file below: sam-sshtui.robot

I tried various things but what I found works best (actually the only thing that worked for me) was to send via Write Bare the first letter of the item I want to select

From your example if you want to select menu item Gauge Progress Bar you would just need to use Write Bare g and it should just straight to the item you want, and you don’t even need to navigate past Editor and File_Menu

Hopefully this works for you,

Dave.

sam-sshtui.robot

*** Settings ***
Library			SSHLibrary

Suite Teardown	Close All Connections
*** Variables ***
${HOST}                testbox
${USERNAME}            sam
${PASSWORD}            test123


*** Test Cases ***
ssh tui test
	Open Connection And Log In
	Run Tui


*** Keywords ***
Open Connection And Log In
	# Open Connection     ${HOST}		term_type=vt100
	Open Connection     ${HOST}		term_type=vt220
	# term_type=ansi
	# Open Connection     ${HOST}		term_type=ansi
	# escape_ansi=true
	# Open Connection     ${HOST}		term_type=vt100		escape_ansi=true
	Login               ${USERNAME}        ${PASSWORD}


Run Tui
	# sudo nmtui
	# ${output}=	Execute Command    sudo nmtui
	${written}=	Write	sudo nmtui
	${output}=	Read	delay=0.5s
	${written}=	Write	${PASSWORD}
	${output}=	Read	delay=0.5s


	# Try Key Sequence	\e[B
	# Try Key Sequence	\eB
	# Try Key Sequence	^[[<n>B
	# Try Key Sequence	^[[B

	# Try Key Sequence	^N
	# Try Key Sequence	^P
	# Try Key Sequence	\eN
	# Try Key Sequence	\e^N
	# Try Key Sequence	\e[[B
	# Try Key Sequence	\e^B

	# Try Key Sequence	[DOWN]
	# Try Key Sequence	[down]

	# Try Key Sequence	^[[B
	# Try Key Sequence	^[[N

	Try Key Sequence	a
	Try Key Sequence	e
	Try Key Sequence	s
	Try Key Sequence	q

	${written}=	Write Bare	\t
	${output}=	Read	delay=0.5s


Try Key Sequence
	[Arguments]		${keys}
	${written}=	Write Bare	${keys}
	${output}=	Read	delay=0.5s

1 Like

Hi Dave. Thank you for your help and time. I will defenetly look into it. And as soon as I get some results I will write here.
I wasn’t aware of << Try Key Sequence >> command . This might be really helpfull !
and thank you for commented out your tries that I can see.

Scroll to the bottom of that example I gave, Try Key Sequence is a keyword I created for testing out different key sequences.

whenever I do sequence of commands repetitively I create a keyword for it.

Dave.

Hi Dave,
Right , it makes sense for me now. I was looking for that keyword :grinning: :grinning:
Then I realised that this keyword is custom, and then you message me :slight_smile:

I will use that as well - Wow, RobotFramework is Awesome.
Ok, back to that admin menu - so , none of that commnads didnt work for me , but …
I found that it best dispayed in my log - visibility - less unknown symbols - that when I do
— term_type=vt100 and escape_ansi=true . Write Bare - did not work for me.
I still trying to use Write.
However I was able to Navigate through admin menu using Write command and putting one Letter
— Write N —> it will go to Network line and click on that
— Write R,R,R,R —> it will go to Reboot line → why 4 Rs? - because its 3 lines before Reboot with R

—> even to change hostname — its in Network
– so I do Write N ---- it goes inside network
— then Write H – it clicks on hostname
then I can see the screen with current hostname ---- but its not visible in log at all – but its there actually –
— I can even put a new hostname and save it , but it will be adding to the previous hostname –
– like hostname1hostname2
— can’t find a way how to remove old one and put new one. Other then that with your help I can navigate in admin menu now :+1:
on the screenshot you can see that how it displayed now , less strange symbols . but hostname not visible — but its there. And I can’t find a way how to clear that line

Sam

Hi Sam,

Actually what you got in the log is the same as your screenshot (imagine the screen shot in black and white) :+1:t3:

you could try with escape_ansi=true and see if you get the hostname (but you will get all the colour character codes too)

I guess you need to figure out what the backspace key is to remove the existing hostname

You could try Write \b,2 (referring to Control character - Wikipedia ) as we know \t worked for you, so hopefully \b will be a backspace :crossed_fingers:t2:

Dave.

You was right ! it does actually printed , but not visible since its black on black.
So, all the commands just keep adding to the existing hostname , without deleting it.
Keep trying multiple combination :slight_smile:

1 Like

Hey Dave,
So , I found how make it work, for me it was
${Bakspace} Evaluate '\x7Fl'
Now I can erase one character at the time.
My code look like this :
Write ${DEL}${DEL}${DEL}${DEL}${DEL}${DEL}${DEL}${DEL}${DEL}${DEL}${new_hostname}

at the end add a new hostname, it delete old and add new hostname.
Is there any way to make it shorter ?
I was trying to get an original hostname - get how many characters are there , lets say 10, then was trying to run for loop like that:
FOR ${counter} IN RANGE 10
Write ${DEL}
END`
Trying to count characters first and then just delete as many as it needs , but it only delete on at the time.
Any ideas ?
Also tried
Write ${Del} * 13
doesnt work as well.

Hi Sam,

This is one of those occasions where having the ability to use python in the Evaluate keyword is really handy

*** Test Cases ***

expand del

	${DEL}= 	Evaluate 	'\x7Fl'
	Log 	${DEL}
	${DELDEL}= 	Evaluate 	"${DEL}"*5
	Log 	${DELDEL}

expand Sam
	${mul}=		Set Variable 	15
	${SAM}= 	Evaluate 	"Sam"
	Log 	${SAM}
	${SAMSAM}= 	Evaluate 	"${SAM}"*${mul}
	Log 	${SAMSAM}

Dave.

Hey Dave,
Really good idea, not I can read how many characters in the hostname and do backspace exact same times.
Thank you!

Sam,

You could just do ~25 backspaces as most hostnames are usually shorter than that, in the old days (windows 2000 and earlier) there was a 15 character limit on windows hostnames, so in the past you could rely on that.

And this is easier than what you had :grinning:

${DELDEL}= 	Evaluate 	"${DEL}"*25

Dave.