def navigate_to_san_managers_page_negative(renavigate=False): if not renavigate and ui_lib.wait_for_element_visible( FusionSANManagersPage.ID_PAGE_LABEL): logger._info('Label [SAN Managers] is shown') return True def page_navigated(self): xpath_main_menu = FusionUIBaseElements.ID_MAIN_MENU_CONTROL xpath_page_label = FusionSANManagersPage.ID_PAGE_LINK # xpath_details_title = FusionSANManagersPage.DETAILS_TITLE try: style = ui_lib.get_webelement_attribute(locator=xpath_main_menu, attribute='style') if 'width' not in style: logger._info('Clicking Main Menu [%s]' % xpath_main_menu) ui_lib.wait_for_element_and_click(xpath_main_menu) logger._info('Waiting for link [SAN Managers] shown') ui_lib.wait_for_element_visible(xpath_page_label, 5) logger._info('Clicking [SAN Managers] [%s]' % xpath_page_label) ui_lib.wait_for_element_and_click(xpath_page_label) logger._info('Waiting for page label [SAN Managers] shown') except: return False return True selenium2lib = ui_lib.get_s2l() timeout = CONF_DICT['timeout'] or 10 wait = WebDriverWait(selenium2lib._current_browser(), timeout, CONF_DICT['speed'], StaleElementReferenceException) logger._info('Waiting for navigation') return wait.until(page_navigated)
def _untaken_transitions_in_state(self, state): ''' List of untaken transitions in given state(uses flattened states) ''' logging._debug("Calling _untaken_transitions_in_state") logging._debug("Got State: '%s'" % state) if (not isinstance(state, str)): state = self._flatten_state(state) if self.debug: logging._log_to_console( "Looking for untaken transitions in state: %s" % pprint.pformat(state)) transitions = self.flat_model[state] untaken = [] for transition in transitions: if '-taken' not in transition: if self.debug: logging._log_to_console("Found untaken transition: %s" % pprint.pformat(transition)) untaken.append(transition) if self.debug: logging._info("_untaken_transitions_in_state returning: %s" % pprint.pformat(untaken)) return untaken
def validate_json_schema(data, schema): """ validate json schema using jsonschema Draft3Validator """ logger._info("Validating JSON schema") validate_ok = True if not isinstance(data, dict): data = json.loads(data) if not isinstance(schema, dict): schema = json.loads(schema) try: jsonschema.Draft3Validator.check_schema(schema) v = jsonschema.Draft3Validator(schema) for error in sorted(v.iter_errors(data), key=str): logger._warn("Invalid JSON data: For key '%s', %s" % (error.path.pop(), error.message)) validate_ok = False except jsonschema.ValidationError as e: logger._warn("Invalid data: %s" % e.message) validate_ok = False except jsonschema.SchemaError as e: logger._warn("Invalid schema: %s" % e.message) validate_ok = False return validate_ok
def set_active_session(self, session_id): self._session_id = session_id logger._info(session_id) self._http.set_headers({ 'auth': self._session_id, 'content-type': 'application/json', 'accept': 'application/json' })
def highlight_san_manager(sanmgr_value): xpath_input = (FusionSANManagersPage.ID_SAN_MANAGER_LIST + "[text()='%s']" % sanmgr_value) try: ui_lib.wait_for_element_visible(xpath_input, 5) except: pass logger._info("Highlighting san manager=%s" % sanmgr_value) ui_lib.wait_for_element_and_click(xpath_input)
def is_dialog_open(self): if ui_lib.wait_for_element_visible(xpath_dialog_title): return True try: logger._info('Clicking %s' % xpath_edit_action) ui_lib.wait_for_element_and_click(xpath_edit_action, 5) logger._info('Clicking %s' % xpath_edit) ui_lib.wait_for_element_and_click(xpath_edit, 5) except: return False return True
def click_san_edit_help(): xpath_help = FusionSANPage.ID_SAN_EDIT_HELP_LINK try: ui_lib.wait_for_element_visible(xpath_help, 5) except: pass logger._info("Click on SAN edit help icon") ui_lib.wait_for_element_and_click(xpath_help)
def validate_default_main_heading(san_value): xpath_san = (FusionSANPage.ID_SAN_MAIN_HEADING + " text()='%s']" % san_value) try: ui_lib.wait_for_element_visible(xpath_san, 10) except: pass logger._info("Validate main header=%s" % san_value) BuiltIn().should_be_true(ui_lib.wait_for_element_visible(xpath_san), san_value)
def click_map_level(maplevel): if (maplevel == 'Level1'): xpath_level = FusionSANManagersPage.ID_MAP_TOP_LEVEL else: xpath_level = FusionSANManagersPage.ID_MAP_SECOND_LEVEL try: ui_lib.wait_for_element_visible(xpath_level, 5) except: pass logger._info("Click on Map page level=%s" % maplevel) ui_lib.wait_for_element_and_click(xpath_level)
def _verify_state(self, state): ''' executes and verifies a state ''' state = string.replace(state, "_", " ") logging._info("Verifying state: " + state) rtnCode = BuiltIn.run_keyword_and_return_status(self.built_in, state) if not rtnCode: raise Exception("Failed to verify state " + state) else: logging._info("Verified state " + state) return rtnCode
def run_random_model(self, model, type="online", file=None, transitions=None, minutes=None, debug=0, skip_keyword_validation=0): ''' Executes a Model based test in a random sequence constrained by time or number of transitions. Example: | Run Random Model | model=model1.xml | minutes=30 | Run Random Model | model=model1.xml | transitions=10 ''' if transitions is not None: logging._info("Running model with %s transitions" % transitions) if minutes is not None: logging._info("Running model for %s minutes" % minutes) logging._info("Running %s model" % type) # Execute StateChartMBT mbt = StateChartMBT(model, debug, skip_keyword_validation) mbt.run_random_path(type=type, file=file, transitions=transitions, minutes=minutes) logging._info("Successfully completed Random Model execution on %s" % model)
def _verify_event(self, event): ''' executes and verifies an event ''' event = string.replace(event, "_", " ") # Initiate instead of Verify logging._info("Executing event: " + event) rtnCode = BuiltIn.run_keyword_and_return_status(self.built_in, event) if not rtnCode: raise RuntimeError("Failed to verify event " + event) else: logging._info("Executed event " + event) return rtnCode
def is_dialog_open(self): if not ui_lib.wait_for_element_visible(xpath_dialog_title): return True try: logger._info('Clicking %s' % xpath_cancel) ui_lib.wait_for_element_and_click(xpath_cancel, 5) logger._info('Waiting for [Add SAN Manager] dialog close') # ui_base.wait_elt_disappear(xpath_dialog_title, 10) # if ui_lib.wait_for_element_visible(xpath_dialog_title): # return False except: return False return True
def is_dialog_open(self): if ui_lib.wait_for_element_visible(xpath_dialog_title): return True try: logger._info('Clicking %s' % xpath_add_san_manager_link) ui_lib.wait_for_element_and_click(xpath_add_san_manager_link, 5) logger._info('Waiting for [Add San Manager] dialog open') # ui_lib.wait_for_element_visible(xpath_dialog_title, 10) # if not ui_lib.wait_for_element_visible(xpath_dialog_title): # return False except: return False return True
def __init__(self, xml=None, debug=0, skip_keyword_validation=0): ''' Constructor ''' # initialize some attributes we might use later self.states = {} self.debug = debug self.skip_keyword_validation = skip_keyword_validation self.flat_model = None self.root = None self.built_in = BuiltIn() if xml is not None: self.set_xml(xml) if self.debug: logging._info("Module Debug Mode Enabled")
def run_defined_paths(self, model, file, minutes=None, debug=0, skip_keyword_validation=0): ''' Executes path defined in specified 'file' against defined 'model' for an optional time constraint 'minutes'. Example: | `Run Defined Paths` | model=model1.xml | file=offline_paths.txt ''' logging._info("Running all model transitions") mbt = StateChartMBT(model, debug, skip_keyword_validation) mbt.run_defined_path(path=file, minutes=minutes) logging._info("Successfully completed Defined Path execution on %s" % model)
def do_request(self, cmd, uri, resource=None, headers=None): if (not self._client): raise RESTException("HTTPClient: Client not initialized") xuri = self._construct_url(uri) xbody, xhdrs = self._update_request(body=resource, headers=headers) logger._info("HTTPClient: Performing %s on %s" % (cmd, xuri)) logger._debug("\nRequest header: %s" % json.dumps( xhdrs, sort_keys=True, indent=4, separators=(',', ': '))) logger._debug("HTTPClient: Request Body %s" % xbody) try: resp, content = self._client.request(xuri, cmd, body=xbody, headers=xhdrs) logger._debug("\nHTTPClient: Response Header %s" % json.dumps( resp, sort_keys=True, indent=4, separators=(',', ': '))) except Exception as e: logger._info( "HTTPClient: Caught exception making %s request, E (%s) =\n\t%s" % (cmd, type(e), e)) raise if content: if "content-type" in resp and HTTPClient.isJSON( resp["content-type"]): resp.body = json.loads(content) # Convert list responses into dictionary if isinstance(resp.body, list): count = len(resp.body) resp.body = {'members': resp.body} resp.body['count'] = count logger._debug("\nHTTPClient Response body: %s" % json.dumps(resp.body, sort_keys=True, indent=4, separators=(',', ': '))) else: logger._info( "do_request: missing or unknown content type (%s)" % resp["content-type"]) resp.body = content else: resp.body = {} if resp.status >= 300: msg = "Error handling request: CMD %s, Headers %s, Resource %s" % ( cmd, xhdrs, xbody) logger._info(msg) # raise RESTException(msg, resp) logger._debug( "\nHTTPClient: Response %s" % json.dumps(resp, sort_keys=True, indent=4, separators=(',', ': '))) return resp
def run_all_transitions_model(self, model, type="online", file=None, minutes=None, debug=0, skip_keyword_validation=0): ''' Executes all available transitions in a Model based test. Example: | `Run All Transitions Model` | model=model1.xml ''' logging._info("Running all transitions model") mbt = StateChartMBT(model, debug, skip_keyword_validation) mbt.run_all_transitions(type=type, file=file, minutes=minutes) logging._info( "Successfully completed All Transitions Model execution on %s" % model)
def login_ilo(host, cred, headers=None, legacy=False, odata_status=True): """ Logs into the iLO, creating an iLO session 'host' IP address of the iLO 'cred' the Username and Password for the iLO session in a dictionary format """ logger._info('Login to Host: %s with credentials: %s' % (host, cred)) if '[' not in host: host = '[' + host + ']' ilo_client = PERISClient() ilo_client._host = host ilo_client._cred = cred or { "UserName": "******", "Password": "******" } # something weird with the tabs, added this so the file detects something new if 'X-Auth-Token' in ilo_client._headers: ilo_client._headers.pop('X-Auth-Token') if legacy: uri = BuiltIn().get_variable_value("${iLO_REST_SESSION_URI}") else: uri = BuiltIn().get_variable_value("${iLO_REDFISH_SESSION_URI}") if odata_status: ilo_client.update_headers( 'OData-Version', BuiltIn().get_variable_value("${iLO_REDFISH_VERSION}")) logger._debug('POST Body: %s' % json.dumps(cred)) resp = ilo_client.post(uri, headers=headers, data=json.dumps(cred)) sessionID = None if 'x-auth-token' in resp.headers: sessionID = resp.headers['x-auth-token'] logger._debug('X-Auth-Token: %s' % sessionID) # leaving below here in case we need to test more than 1 active sessions # ilo_client._active_sessions[cred['UserName']] = {'Password': cred['Password'], 'sessionID': sessionID} ilo_client._sessionID = sessionID ilo_client.update_headers('X-Auth-Token', sessionID) logger._info('Session URI: %s' % sessionID) if 'location' in resp.headers: ilo_client._session_uri = resp.headers['location'] ilo_client._session_uri = ilo_client._session_uri.split(']')[1] return ilo_client, resp, sessionID
def click_and_select_file_for_upload(locator, filename): """ Click a browser element which selects a file for upload, populate the dialog with the filename, and continue. Note that since opening a native dialog in WebDriver is a blocking action, we must use a thread to perform this operation. Otherwise, the UI will block execution until the dialog is closed. """ s2l = get_s2l() # Since clicking the file selection element blocks the UI, we need to do this in a separate thread Thread(target=s2l.click_element, args=(locator, )).start() browser_name = s2l._current_browser().capabilities['browserName'] logger._info("*** Browser version '{0}' ***".format(browser_name)) if browser_name == 'firefox': window_title = "File Upload" elif browser_name == 'chrome': window_title = "Open" elif browser_name == 'internet explorer': window_title = "Choose File to Upload" else: raise AssertionError("Unknown browser name '{0}'".format(browser_name)) rg = BuiltIn().get_library_instance('RoboGalaxyLibrary') rg.send_keys_to_native_window(window_title, "%n{0}%o".format(filename))
def login(self, appliance, user, passwd): self._http._set_base_url(PROTOCOL_BASE_HTTPS + appliance) self._http.set_headers({ 'content-type': 'application/json', 'accept': 'application/json' }) body = self.make_user_dto(user, passwd) try: resp = self._http.post(HPCIManager.uri['loginSessions'], body) except HTTPClient.RESTException as e: print "Exception occurred while logging in as '%s'" % user raise e except Exception as e: msg = "Exception occurred while logging in as '%s', %s" % (user, e) print msg raise HTTPClient.RESTException(msg) if resp.status != 200: msg = "Status (%d) rcvd from login request as '%s'" % (resp.status, user) # raise HTTPClient.RESTException(msg, resp) if 'sessionID' not in resp.body: info = ("Resp body from login as '%s' doesn't contain sessionID" % user, "Response body: %s" % resp.body) logger._info(info) # raise Exception(*info) login_session = None # default session ID - in case of login failure if 'sessionID' in resp.body: login_session = self._session_id = resp.body['sessionID'] self._http.set_headers({ 'auth': self._session_id, 'content-type': 'application/json', 'accept': 'application/json' }) if resp.body: resp.update(resp.body) return resp, login_session
def page_navigated(self): xpath_main_menu = FusionUIBaseElements.ID_MAIN_MENU_CONTROL xpath_page_label = FusionSANManagersPage.ID_PAGE_LINK # xpath_details_title = FusionSANManagersPage.DETAILS_TITLE try: style = ui_lib.get_webelement_attribute(locator=xpath_main_menu, attribute='style') if 'width' not in style: logger._info('Clicking Main Menu [%s]' % xpath_main_menu) ui_lib.wait_for_element_and_click(xpath_main_menu) logger._info('Waiting for link [SAN Managers] shown') ui_lib.wait_for_element_visible(xpath_page_label, 5) logger._info('Clicking [SAN Managers] [%s]' % xpath_page_label) ui_lib.wait_for_element_and_click(xpath_page_label) logger._info('Waiting for page label [SAN Managers] shown') except: return False return True
def ui_log_html_source(loglevel='INFO'): """ UI Get HTML Source Description : Log HTML Source of the current page. It's useful got scanning ui objects """ selenium2lib = get_s2l() logger._info(selenium2lib.log_source(loglevel))
def check_user_privileges(user_name): s2l = ui_lib.get_s2l() if not ui_lib.wait_for_element(FusionLSGPage.ID_PAGE_LABEL): navigate() user = test_data.get_privilege_by_name(user_name) logger._log_to_console_and_log_file("Create logical switch groups for %s" % user_name) if ((user.create).lower() == "yes"): logger._info("should pass") if ui_lib.wait_for_element_and_click( FusionLSGPage.ID_LINK_CREATE_LOGICAL_SWITCH_GROUP): ui_lib.wait_for_element_and_click(FusionLSGPage.ID_BTN_CLOSE_LSG) ui_lib.wait_for_element_remove(FusionLSGPage.ID_CREATE_LSG_DIALOG) logger._log_to_console_and_log_file( "Successfully clicked create Logical Switch Groups") else: return False else: logger._log_to_console_and_log_file("should fail") if not ui_lib.wait_for_element_and_click( FusionLSGPage.ID_LINK_CREATE_LOGICAL_SWITCH_GROUP): logger._log_to_console_and_log_file( "Create LSG button not visible as expected") else: return False logger._log_to_console_and_log_file("Read logical switch groups for %s" % user_name) if ((user.read).lower() == "yes"): logger._log_to_console_and_log_file("should pass") if ui_lib.wait_for_element_visible( FusionLSGPage.ID_ELEMENT_LSG_NAME_BASE % user.lsgname, PerfConstants.DEFAULT_SYNC_TIME): select_lsg(user.lsgname) logger._log_to_console_and_log_file( "Able to Read logical switch groups for %s" % user.lsgname) else: return False else: logger._log_to_console_and_log_file("should fail") if not ui_lib.wait_for_element_visible( FusionLSGPage.ID_ELEMENT_LSG_NAME_BASE % user.lsgname, PerfConstants.DEFAULT_SYNC_TIME): logger._log_to_console_and_log_file( "Unable to Read logical switch groups as expected") else: return False logger._log_to_console_and_log_file("Update logical switch groups for %s" % user_name) if ((user.update).lower() == "yes"): logger._log_to_console_and_log_file("should pass") select_lsg(user.lsgname) if ui_lib.wait_for_element_and_click(FusionLSGPage.ID_ACTION_MAIN_BTN): if ui_lib.wait_for_element_and_click( FusionLSGPage.ID_ACTION_MENU_EDIT_LSG): ui_lib.wait_for_element_and_input_text( FusionLSGPage.ID_INPUT_EDIT_LSGNAME, user.newName) ui_lib.wait_for_element_and_click( FusionLSGPage.ID_BTN_EDIT_CANCEL) logger._log_to_console_and_log_file( "Able to Edit logical switch groups") else: return False else: return False else: logger._log_to_console_and_log_file("should fail") if not ui_lib.wait_for_element_and_click( FusionLSGPage.ID_ACTION_MAIN_BTN): logger._log_to_console_and_log_file( "Unable to Edit logical switch groups as expected") else: return False logger._log_to_console_and_log_file("Delete logical switch groups for %s" % user_name) if ((user.delete).lower() == "yes"): logger._log_to_console_and_log_file("should pass") select_lsg(user.lsgname) if ui_lib.wait_for_element_and_click(FusionLSGPage.ID_ACTION_MAIN_BTN): if ui_lib.wait_for_element_and_click( FusionLSGPage.ID_ACTION_MENU_DELETE_LSG): logger._log_to_console_and_log_file( "Able to delete logical switch groups") else: return False else: return False else: logger._log_to_console_and_log_file("should fail") if not ui_lib.wait_for_element_and_click( FusionLSGPage.ID_ACTION_MAIN_BTN): logger._log_to_console_and_log_file( "Unable to delete logical switch groups as expected") else: return False return True
def run_all_transitions( self, type="online", file=None, minutes=None, ): ''' Runs all transitions usage: runAllTransitions(minutes, type, file) minutes -- maximum number of minutes to run type -- online or offline (defaults to onliine) file -- file to log transitions ''' path = None fh = None start = time.time() # Validate args if (type is None) or (string.lower(type) != "online" and string.lower(type) != "offline"): raise AttributeError( "run_all_transitions requires 'type' arg set to \ offline or online") if (string.lower(type) == "offline" and (file is None)): raise AttributeError("run_all_transitions requires 'file' arg for \ offline run") if (string.lower(type) == "offline" and minutes is not None): raise AttributeError( "can't use 'minutes' constraint in offline test \ generation") if self.root is None: raise AttributeError("can't run_all_transitions without SCXML to \ constructor") # State with initial state curr_states = self._get_full_state(self.root.attrib['initial']) self._flatten_state(curr_states) if file is None: path = [] for state in curr_states: path.append("state: %s" % state['id']) else: path = file fh = open(file, "w") for state in curr_states: fh.write("state: %s\n" % state['id']) # for trans in self._untaken_transitions(): while self._untaken_transitions(): if self.debug: logging._log_to_console( "=======================================================") logging._log_to_console("Now in state: %s\n" % pprint.pformat(curr_states[0]['id'])) # Check for exit conditions if minutes is not None: if (time.time() - start) > (int(minutes) * 60): logging._info( "Time Constraint of %s minutes has been exceeded. Execution complete." % minutes) break # Get to closest state with untaken transitions transitions = self._transitions_to_needed_state(curr_states) if transitions is None: state_ids = [state['id'] for state in curr_states] raise RuntimeError("Unable to get to needed states from %s" % ' '.join(state_ids)) # Log transitions to get to that state for trans in transitions: curr_states = self._get_next_state(curr_states, trans) if file is not None: fh.write("event: %s\n" % trans['event']) # FIXME: Better way to do this for state in curr_states: fh.write("state: %s\n" % state['id']) else: path.append("event: %s" % trans['event']) # FIXME: Better way to do this for state in curr_states: path.append("state: %s" % state['id']) logging._debug("curr_states: %s" % pprint.pformat(curr_states)) # Choose an untaken transition if self.debug: logging._log_to_console("Getting untaken transitions...") transitions = self._untaken_transitions_in_state(curr_states) if self.debug: logging._log_to_console("Selecting from transitions: %s" % pprint.pformat(transitions)) trans = transitions[random.randint(0, len(transitions) - 1)] trans['-taken'] = 1 curr_states = self._get_next_state(curr_states, trans) self._flatten_state(curr_states) if self.debug: logging._log_to_console("\nTook transition: %s" % pprint.pformat(trans)) # Log it if file is not None: logging._debug("Writing event '%s' to file." % trans['event']) fh.write("event: %s\n" % trans['event']) for state in curr_states: logging._debug("Writing state '%s' to file." % state['id']) fh.write("state: %s\n" % state['id']) else: path.append("event: %s" % trans['event']) for state in curr_states: path.append("state: %s" % state['id']) if file is not None: fh.close() # Run this path if online, otherwise done if string.lower(type) == "online": return self.run_defined_path(path) return True
def server_ipassignment_ping(self, server_obj): ''' This function is exclusively written to handle the case where it will login to the server with ssh ip mentioned in the data file for the server. Then it performs a series of actions like grepping for the interface using mac address and assigning ip to it, after assigning it runs ping to the other server ip mentioned in the datafile. This function is written to execute ping commands and also iperf commands depending on the "action" option selecetd by the user in data file,. Arguments: commmand = requirement specific command for iperf/ping command1 = requirement specific command for iperf/ping command2 = requirement specific command for iperf/ping command3 = requirement specific command for iperf/ping command4 = requirement specific command for iperf/ping command5 = requirement specific command for iperf/ping iLoip = server ip to ssh to the server username = username of ssh password = password for ssh session action = enter the action you want here i,e., either iperf/ping Example od Data file: For ping: <server iLOIP="10.10.3.125" username="******" password="******" action = "ping" command="ifconfig -a|grep -i -B 2 D0:BF:9C:03:BB:96|cut -d ' ' -f 1|sed 's/:$//'>interface|echo $?" command1="ip addr flush `cat interface`|echo $?" command2="ifconfig `cat interface` 80.0.0.5 netmask 255.0.0.0 up|echo $?" command3="ping -c 5 80.0.0.15" command4="service firewalld stop" command5="ping -c 5 80.0.0.15|echo $?"/> For iperf: <server iLOIP="10.10.3.125" username="******" password="******" action = "iperf" command="ip route list|grep -i default|cut -d ' ' -f 3 > defaultgw" command1="route del default gw `cat defaultgw`" command2="route add default gw 60.0.0.15|echo $?" command3="service firewalld stop" command4="iperf3 -b 5g -c 60.0.0.15" command5="echo $?"/> ''' if hasattr(server_obj, "command"): logger._log_to_console_and_log_file('Entering prompt') command = server_obj.command command1 = server_obj.command1 command2 = server_obj.command2 client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.WarningPolicy()) hostname = server_obj.iLOIP username = server_obj.username password = server_obj.password port = 22 client.connect(hostname, port=port, username=username, password=password) # open channel to the leaf node chan = client.invoke_shell() BuiltIn().sleep(10) logger._log_to_console_and_log_file('Executing %s' % command) chan.send(command + '\n') resp = chan.recv(999) BuiltIn().sleep(5) logger._log_to_console_and_log_file('Response is %s' % resp) logger._log_to_console_and_log_file('Executing %s' % command1) chan.send(command1 + '\n') BuiltIn().sleep(5) resp = chan.recv(999) BuiltIn().sleep(5) logger._log_to_console_and_log_file('Response is %s' % resp) logger._log_to_console_and_log_file('Executing %s' % command2) chan.send(command2 + '\n') resp = chan.recv(999) BuiltIn().sleep(5) logger._log_to_console_and_log_file('Response is %s' % resp) command3 = server_obj.command3 command4 = server_obj.command4 command5 = server_obj.command5 logger._log_to_console_and_log_file('Executing %s' % command3) BuiltIn().sleep(5) chan.send(command3 + '\n') BuiltIn().sleep(5) data1 = chan.recv(999) logger._log_to_console_and_log_file("Data is %s" % data1) logger._log_to_console_and_log_file('Executing %s' % command4) BuiltIn().sleep(5) chan.send(command4 + '\n') BuiltIn().sleep(5) data1 = chan.recv(999) logger._log_to_console_and_log_file("Data is %s" % data1) logger._log_to_console_and_log_file('Executing %s' % command5) BuiltIn().sleep(5) chan.send(command5 + '\n') BuiltIn().sleep(5) datareceived = chan.recv(999) iscommandsuccess = datareceived.splitlines()[1] logger._log_to_console_and_log_file("Command sucess value is %s" % iscommandsuccess) action = server_obj.action logger._log_to_console_and_log_file("Action performed is %s" % action) if (action == "ping"): if iscommandsuccess != '0': logger._log_to_console_and_log_file( "Seems ping is not working") chan.send('exit \n') return False else: logger._info("ping is successfull") chan.send('exit \n') return True if (action == "iperf"): fullreport = data1.splitlines()[-1] bandwidth = fullreport.split()[6] logger._log_to_console_and_log_file("bandwidth is: %s" % bandwidth) return bandwidth client.close()