How to use show_version method in tempest

Best Python code snippet using tempest_python

ex2_show_version.py

Source:ex2_show_version.py Github

copy

Full Screen

1#!/usr/bin/env python2'''3II. On GitHub, there is the following show version output:4https://github.com/ktbyers/pynet/blob/master/learnpy_ecourse/class8/show_version.txt5 A. Create three functions in three separate modules and put6them in a show_version directory (in practice you wouldn't do7this--you would just have them all in one file, but this will let8you experiment with packages).9 1. Function1 = obtain_os_version -- process the show10version output and return the OS version (Version 15.0(1)M4) else11return None.12 2. Function2 = obtain_uptime -- process the show13version output and return the network device's uptime string14(uptime is 12 weeks, 5 days, 1 hour, 4 minutes) else return None.15 3. Function3 = obtain_model -- process the show version16output and return the model (881) else return None.17 B. Make a package out of this 'show_version' directory using a18blank __init__.py file.19 1. Now that this package has been created, test20importing each of the modules individually from the parent21directory. In other words, you have a parent directory that22contains the following:23.24./show_version25./show_version/__init__.py26./show_version/os_version.py27./show_version/model.py28./show_version/uptime.py29Python interpreter shell demonstrating this (with blank __init__.py)30>>> import show_version.os_version31>>> import show_version.model32>>> import show_version.uptime33>>>34>>> dir()35['__builtins__', '__doc__', '__name__', '__package__', 'show_version']36>>> f = open("show_version.txt")37>>> show_ver = f.read()38>>> show_version.os_version.obtain_os_version(show_ver)39'15.0(1)M4'40>>> show_version.model.obtain_model(show_ver)41'881'42>>> show_version.uptime.obtain_uptime(show_ver)43'12 weeks, 5 days, 1 hour, 4 minutes'44 2. Now edit the __init__.py file such that it45automatically loads each of the modules. In other words, you46should be able to type:47>>> import show_version48Python interpreter shell demonstrating this (with __init__.py as shown in GitHub)49>>> import show_version50>>> dir(show_version)51['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__',52'model', 'obtain_model', 'obtain_os_version', 'obtain_uptime', 'os_version',53'uptime']54>>> f = open("show_version.txt")55>>> show_ver = f.read()56>>> show_version.obtain_model(show_ver)57'881'58>>> show_version.obtain_os_version(show_ver)59'15.0(1)M4'60>>> show_version.obtain_uptime(show_ver)61'12 weeks, 5 days, 1 hour, 4 minutes'62 C. Write a script that processes the show_version output using63this package. It should return something similar to the following:64 model: 88165 os_version: Version 15.0(1)M466 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes67'''68import show_version69def main():70 '''71 Write a script that processes the show_version output using the 'show_version' package72 It should return something similar to the following:73 model: 88174 os_version: Version 15.0(1)M475 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes76 '''77 with open("show_version.txt", "r") as version_file:78 show_ver = version_file.read()79 model = show_version.obtain_model(show_ver)80 os_version = show_version.obtain_os_version(show_ver)81 uptime = show_version.obtain_uptime(show_ver)82 print83 print "%15s: %-50s" % ("model", model)84 print "%15s: %-50s" % ("os_version", os_version)85 print "%15s: %-50s" % ("uptime", uptime)86 print87if __name__ == "__main__":...

Full Screen

Full Screen

week8exercise2.py

Source:week8exercise2.py Github

copy

Full Screen

1'''2II. On GitHub, there is the following show version output:3https://github.com/ktbyers/pynet/blob/master/learnpy_ecourse/class8/show_version.txt4 A. Create three functions in three separate modules and put them in a show_version directory (in practice you wouldn't do this--you would just have them all in one file, but this will let you experiment with packages).5 1. Function1 = obtain_os_version -- process the show version output and return the OS version (Version 15.0(1)M4) else return None.6 2. Function2 = obtain_uptime -- process the show version output and return the network device's uptime string (uptime is 12 weeks, 5 days, 1 hour, 4 minutes) else return None.7 3. Function3 = obtain_model -- process the show version output and return the model (881) else return None.8 B. Make a package out of this 'show_version' directory using a blank __init__.py file.9 1. Now that this package has been created, test importing each of the modules individually from the parent directory. In other words, you have a parent directory that contains the following:10.11./show_version12./show_version/__init__.py13./show_version/os_version.py14./show_version/model.py15./show_version/uptime.py16From the parent directory go into the Python interpreter shell and make sure you can do the following:17>>> import show_version.os_version18>>> import show_version.model19>>> import show_version.uptime20 2. Now edit the __init__.py file such that it automatically loads each of the modules. In other words, you should be able to type:21>>> import show_version22and have all of your functions available as follows:23>>> show_version.obtain_model(show_ver_data)24>>> show_version.obtain_os_version(show_ver_data)25>>> show_version.obtain_uptime(show_ver_data)26 C. Write a script that processes the show_version output using this package. It should return something similar to the following:27 model: 88128 os_version: Version 15.0(1)M429 uptime: uptime is 12 weeks, 5 days, 1 hour, 4 minutes30'''31import show_version32with open("show_version.txt", "rU") as a_file:33 data = a_file.read()34 model = show_version.obtain_model(data)35 version = show_version.obtain_version(data)36 uptime = show_version.obtain_uptime(data)37 print "%10s %-20s" %("model:", model)38 print "%10s %-20s" %("version:", version)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful