def Host_powercycle(self, host): ''' power cycle a host and wait for it to come back. ''' t = test.Test() node = t.node(host) ipAddr = node.ip() t.power_cycle(host, minutes=0) helpers.log("*****system went through power cycle********") helpers.sleep(120) count = 0 while (True): loss = helpers.ping(ipAddr) helpers.log("loss is: %s" % loss) if (loss != 0): if (count > 10): helpers.warn( "Cannot connect to the IP Address: %s - Tried for 5 Minutes" % ipAddr) return False helpers.sleep(60) count += 1 helpers.log( "Trying to connect to the IP Address: %s - Try %s" % (ipAddr, count)) else: helpers.log( "USR INFO: system just came alive. Waiting for it to become fully functional" ) helpers.sleep(30) break return True
def stop_syslog_monitor(self): global syslogMonitorFlag if (syslogMonitorFlag): c1_pidList = self.get_syslog_monitor_pid('c1') c2_pidList = self.get_syslog_monitor_pid('c2') t = test.Test() c1 = t.controller('c1') c2 = t.controller('c2') helpers.log("Stopping syslog Monitor on C1") for c1_pid in c1_pidList: c1.sudo('kill -9 %s' % (c1_pid)) helpers.log("Stopping syslog Monitor on C2") for c2_pid in c2_pidList: c2.sudo('kill -9 %s' % (c2_pid)) syslogMonitorFlag = False try: helpers.log( "**************** syslog Log From C1 ****************" ) result = c1.sudo('cat c1_syslog_dump.txt') split = re.split('\n', result['content'])[1:-1] if split: helpers.warn("syslog Errors Were Detected At: %s " % helpers.ts_long_local()) except (AttributeError): helpers.log("No Errors From syslog Monitor on C1") try: helpers.log( "**************** syslog Log From C2 ****************" ) result = c2.sudo('cat c2_syslog_dump.txt') split = re.split('\n', result['content'])[1:-1] if split: helpers.warn("syslog Errors Were Detected At: %s " % helpers.ts_long_local()) except (AttributeError): helpers.log("No Errors From syslog Monitor on C2") return True else: helpers.log("syslogMonitorFlag is not set: Returning")
def do_show_run_vns_verify(self, vnsName, numMembers): t = test.Test() master = t.controller("master") url = "/api/v1/data/controller/applications/bvs/tenant?config=true" result = master.rest.get(url) helpers.log("Show run output is: %s " % result["content"][0]['vns'][0]['port-group-membership-rules']) vnsList = result["content"][0]['vns'][0]['port-group-membership-rules'] if (len(vnsList) != int(numMembers)): helpers.warn("Show run output is not correct for VNS members. Collecting support logs from the mininet") mynet = mininet.Mininet() out = mynet.mininet_bugreport() helpers.log("Bug Report Location is: %s " % out) for i in range(0, 2): helpers.warn("Show run output is not correct for VNS members. Please collect switch support logs") sleep(30) else: helpers.log("Show run output is correct for VNS members")
def rest_delete_user(self, numUsers=1): numWarn = 0 t = test.Test() master = t.controller("master") usersString = [] numErrors = 0 for i in range (0, int(numUsers)): url = "/api/v1/data/controller/core/aaa/local-user[user-name=\"" user = "******" + str(i+1) usersString.append(user) url = url + user + "\"]" master.rest.delete(url, {}) sleep(1) if not master.rest.status_code_ok(): helpers.test_failure(master.rest.error()) numErrors += 1 else: helpers.log("Successfully deleted user: %s " % user) if(numErrors > 0): return False else: url = "/api/v1/data/controller/core/aaa/local-user" result = master.rest.get(url) showUsers = [] for i in range (0, len(result["content"])): showUsers.append(result["content"][i]['user-name']) sleep(5) for user in usersString: if user in showUsers: numWarn += 1 helpers.warn("User: %s present in the show users" % user) if (numWarn > 0): return False else: return True
def Host_reboot(self, host): ''' Reboot a host and wait for it to come back. ''' t = test.Test() node = t.node(host) ipAddr = node.ip() content = node.bash('reboot')['content'] helpers.log("*****Output is :*******\n%s" % content) if re.search(r'The system is going down for reboot NOW!', content): helpers.log("system is rebooting") helpers.sleep(120) else: helpers.log("USR ERROR: system did NOT reboot") return False count = 0 while (True): loss = helpers.ping(ipAddr) helpers.log("loss is: %s" % loss) if (loss != 0): if (count > 5): helpers.warn( "Cannot connect to the IP Address: %s - Tried for 5 Minutes" % ipAddr) return False helpers.sleep(60) count += 1 helpers.log( "Trying to connect to the IP Address: %s - Try %s" % (ipAddr, count)) else: helpers.log( "USR INFO: system just came alive. Waiting for it to become fully functional" ) helpers.sleep(30) break return True
def node_id(self): """ Node-id is mainly supported for BVS platform but that may change over time. For now, all derived nodes should simply return None. For BVS, get the node-id for the specified node. The REST 'show cluster' API has 'local-node-id' which is the node-id for the node we want. Input: Node name (e.g., 'master', 'c1', 'c2', etc.) Output: Integer value for the node-id """ node = self.name() n = self.t.controller(node) if not helpers.is_bvs(n.platform()): return None count = 0 while (True): try: url = '/api/v1/data/controller/cluster' content = n.rest.get(url)['content'] nodeid = content[0]['status']['local-node-id'] helpers.log("'%s' has local-node-id %s" % (node, nodeid)) break except (KeyError): if (count < 5): helpers.warn("'%s' KeyError while retrieving" " local-node-id. Sleeping for 10 seconds." % node) helpers.sleep(10) count += 1 else: helpers.test_error("'%s' KeyError while retrieving" " local-node-id." % node) return nodeid
def stop_syslog_monitor(self): ''' Stop the monitoring by killing the pid of tail process Input: None ''' global syslogMonitorFlag if (syslogMonitorFlag): c1_pidList = self.get_syslog_monitor_pid('c1') c2_pidList = self.get_syslog_monitor_pid('c2') t = test.Test() c1 = t.controller('c1') c2 = t.controller('c2') helpers.log("Stopping syslog Monitor on C1") for c1_pid in c1_pidList: helpers.log("PID on C1 is %s: " % (c1_pid)) c1.sudo('kill -9 %s' % (c1_pid)) helpers.log("Stopping syslog Monitor on C2") for c2_pid in c2_pidList: helpers.log("PID on C2 is %s: " % (c2_pid)) c2.sudo('kill -9 %s' % (c2_pid)) syslogMonitorFlag = False try: helpers.log( "**************** syslog Log From C1 ****************" ) result = c1.sudo('cat c1_syslog_dump.txt') split = re.split('\n', result['content'])[2:-1] except: helpers.log("Split failed for c1") return False else: if split: helpers.warn("syslog Errors Were Detected %s At: %s " % (split, helpers.ts_long_local())) helpers.sleep(2) return False else: helpers.log("No Errors From syslog Monitor on C1") try: helpers.log( "**************** syslog Log From C2 ****************" ) result = c2.sudo('cat c2_syslog_dump.txt') split = re.split('\n', result['content'])[2:-1] except: helpers.log("Split failed for c2") return False else: if split: helpers.warn("syslog Errors Were Detected %s At: %s " % (split, helpers.ts_long_local())) helpers.sleep(2) return False else: helpers.log("No Errors From syslog Monitor on C2") helpers.sleep(2) return True else: helpers.log("syslogMonitorFlag is not set: Returning") helpers.sleep(2) return False
def ixia_l2_add(self, **kwargs): ''' This Helper Method created L2 related Config on IXIA to start Traffic with given arguments ''' helpers.log("###Starting L2 IXIA ADD Config ...") ix_handle = self._handle ix_ports = [port for port in self._port_map_list.values()] s_mac = kwargs.get('src_mac', None) d_mac = kwargs.get('dst_mac', None) d_cnt = kwargs.get('d_cnt', 1) s_cnt = kwargs.get('s_cnt', 1) d_step = kwargs.get('d_step', '00:00:00:01:00:00') s_step = kwargs.get('s_step', '00:00:00:01:00:00') frame_rate = kwargs.get('frame_rate', 100) frame_cnt = kwargs.get('frame_cnt', None) frame_size = kwargs.get('frame_size', 70) frame_type = kwargs.get('frame_type', 'fixed') frame_mode = kwargs.get('frame_mode', 'framesPerSecond') name = kwargs.get('name', 'gobot_default') ix_tcl_server = self._tcl_server_ip flow = kwargs.get('flow', 'None') if ix_tcl_server is None or ix_ports is None or s_mac is None or d_mac is None: helpers.warn( 'Please Provide Required Args for IXIA_L2_ADD helper method !!' ) raise IxNetwork.IxNetError( 'Please provide Required Args for IXIA_L2_ADD helper method !!' ) get_version = ix_handle.getVersion() helpers.log("###Current Version of Ixia Chassis : %s " % get_version) ix_handle.setDebug( False) # Set Debug True to print Ixia Server Interactions # Create vports: if len(self._vports) == 0: vports = self.ix_create_vports() helpers.log('### vports Created : %s' % vports) # Map to Chassis Physhical Ports: if self.ix_map_vports_pyhsical_ports(): helpers.log( '### Successfully mapped vport to physical ixia ports..') else: helpers.warn('Unable to connect to Ixia Chassis') return False else: helpers.log('### vports already Created : %s' % self._vports) if len(self._topology) == 0: # Create Topo: self.ix_create_topo() helpers.log('### Topology Created: %s' % self._topology) else: helpers.log('###Topology already created: %s' % self._topology) create_topo = [] match_uni1 = re.match(r'(\w+)->(\w+)', flow) match_uni2 = re.match(r'(\w+)<-(\w+)', flow) match_bi = re.match(r'(\w+)<->(\w+)', flow) stream_flow = '' if match_uni1: create_topo.append(self._topology[match_uni1.group(1).lower()]) create_topo.append(self._topology[match_uni1.group(2).lower()]) stream_flow = 'uni-directional' elif match_uni2: create_topo.append(self._topology[match_uni2.group(2).lower()]) create_topo.append(self._topology[match_uni2.group(1).lower()]) stream_flow = 'uni-directional' elif match_bi: create_topo.append(self._topology[match_bi.group(2).lower()]) create_topo.append(self._topology[match_bi.group(1).lower()]) stream_flow = 'bi-directional' #Create Ether Device: mac_devices = self.ix_create_device_ethernet(create_topo, s_cnt, d_cnt, s_mac, d_mac, s_step, d_step) helpers.log('### Created Mac Devices with corrsponding Topos ...') #Create Traffic Stream: traffic_stream = self.ix_setup_traffic_streams_ethernet( mac_devices[0], mac_devices[1], frame_type, frame_size, frame_rate, frame_mode, frame_cnt, stream_flow, name) helpers.log('Created Traffic Stream : %s' % traffic_stream) self._traffic_stream[name] = traffic_stream return traffic_stream