def rest_noshut_switch_interface(self, switch, intf): ''' Function to remove shutdown command from the switch interface Input: switch and interface Output : remove shutdown command ''' t = test.Test() c = t.controller('master') try: url_to_get = '/api/v1/data/controller/core/switch-config?config=true' c.rest.get(url_to_get) except: helpers.log("Could not execute GET on URL") return False else: data = c.rest.content() for i in range(0, len(data)): try: value = data[i]["interface"] helpers.log("the intf is %s" % value) for j in range(0, len(data[i]["interface"])): url = '/api/v1/data/controller/core/switch-config[name="%s"]/interface[name="%s"]' % ( data[i]["name"], data[i]["interface"][j]["name"]) c.rest.delete(url, {"shutdown": None}) helpers.sleep(5) return True except: helpers.log("Could not execute GET on URL") return False
def flap_eth0_controller(self,controllerRole): ''' Flap eth0 on Controller Input: controllerRole Where to execute the command. Accepted values are `Master` and `Slave` Return Value: True if the configuration is successful, false otherwise ''' t=test.Test() if (controllerRole=='Master'): c= t.controller('master') else: c= t.controller('slave') conn = SSH2() conn.connect(c.ip) conn.login(Account("admin","adminadmin")) conn.execute('debug bash') conn.execute("echo '#!/bin/bash' > test.sh") conn.execute("echo 'sleep 15' >> test.sh") conn.execute("echo 'sudo ifconfig eth0 down' >> test.sh") conn.execute("echo 'sleep 10' >> test.sh") conn.execute("echo 'sudo ifconfig eth0 up' >> test.sh") conn.execute("echo 'sleep 10' >> test.sh") conn.execute("sh test.sh &") helpers.sleep(float(30)) conn.send('exit\r') conn.close() return True
def execute_switch_command_return_output(self, ip_address, input): '''Execute a generic command on the switch and return ouput. Input: ip_address IP Address of Switch input Command to be executed on switch Return Value: Output from command execution Example: |${syslog_op}= | execute switch command return output | 10.192.75.7 | debug ofad 'help; cat /var/log/syslog | grep \"Disabling port port-channel1\"' | ''' try: t = test.Test() conn = SSH2() conn.connect(ip_address) conn.login(Account("admin", "adminadmin")) conn.execute('enable') helpers.sleep(float(1)) conn.execute(input) helpers.sleep(float(1)) output = conn.response conn.send('logout\r') helpers.log("Input is '%s' \n Output is %s" % (input, output)) conn.close() return output except: helpers.test_failure( "Could not execute command. Please check log for errors") return False
def rest_create_nat_scale(self, tenant, subnet, remote_tenant, remote_segment, count, name="n"): '''Function to add nat profile in a tenant in a loop Input: tenant name, subnet for the external network (e.g , 40.0.0) , external tenant , externl segment , count , always starts with name = n ''' t = test.Test() c = t.controller('master') i = 2 count = int(count) count = count + 1 while (i <= count): nat_profile = name nat_profile += str(i) public_ip = subnet + "." + "%s" % i self.rest_add_nat_profile(tenant, nat_profile) self.rest_add_nat_remote_tenant(tenant, nat_profile, remote_tenant, remote_segment) helpers.sleep(5) self.rest_add_pat(tenant, nat_profile) self.rest_add_pat_public_ip(tenant, nat_profile, public_ip) i = i + 1
def show_switch_ip_address(self, console_ip, console_port): '''Detect the IP address of a switch when IP address is not known Inputs: console_ip: Console IP Address console_port: Console Port Number ''' try: user = "******" password = "******" tn = telnetlib.Telnet(str(console_ip), int(console_port)) tn.read_until("login: "******"\r\n") tn.read_until("Password: "******"\r\n") tn.read_until('') tn.write("show interface ma1 \r\n") helpers.sleep(10) output = tn.read_very_eager() for item in output.split("\n"): if "IPv4 Address" in item: output_1 = string.split(item, ': ') output_2 = string.split(output_1[1], '/') ip_address_subnet = { 'ip-address': str(output_2[0]), 'subnet': str(output_2[1].rstrip('\r')) } tn.write("exit \r\n") tn.write("exit \r\n") tn.close() return (ip_address_subnet) except: helpers.test_failure( "Could not execute command. Please check log for errors") return False
def restart_controller(self, controller_role): '''Restart a process on controller Input: processName Name of process to be restarted controller_role Where to execute the command. Accepted values are `Master` and `Slave` Return Value: True if the configuration is successful, false otherwise ''' try: t = test.Test() if (controller_role == 'Master'): c = t.controller('master') else: c = t.controller('slave') c.bash("echo '#!/bin/bash' > test_reboot.sh") c.bash("echo 'sleep 15' >> test_reboot.sh") c.bash("echo 'sudo reboot' >> test_reboot.sh") c.bash("sh test_reboot.sh &") helpers.sleep(300) except: helpers.test_log(c.rest.error()) return False else: return True
def console_reconnect(self, driver=None): # Delay for 1 second to allow the output to settle. helpers.sleep(1) if self._console_info['type'] == 'libvirt': self.dev_console.send("virsh console %s" % self._console_info['libvirt_vm_name']) return self.dev_console
def configure_dhcp_ip(self, console_ip, console_port): '''Configure static IP address configuration on switch. ''' try: user = "******" password = "******" tn = telnetlib.Telnet(str(console_ip), int(console_port)) tn.read_until("login: "******"\r\n") tn.read_until("Password: "******"\r\n") tn.read_until('') tn.write("enable \r\n") tn.write("conf t \r\n") tn.write("interface ma1 ip-address dhcp \r\n") helpers.sleep(10) tn.read_until(">") tn.write("exit \r\n") tn.write("exit \r\n") tn.close() return True except: helpers.test_failure( "Could not execute command. Please check log for errors") return False
def task_finish_check_parallel(self, results, result_dict, timer=60, timeout=1500): ''' task_finish_check_parallel Input: Output: Author: Mingtao ''' helpers.log("***Entering==> task_finish_check_parallel \n") is_pending = True iteration = 0 flag = True while is_pending: is_pending = False iteration += 1 helpers.sleep(int(timer)) helpers.log("USR INFO: result is %s" % results) for res in results: task_id = res.task_id action = result_dict[task_id]["node"] + ' ' + result_dict[task_id]["action"] if res.ready() == True: helpers.log("****** %d.READY - task_id(%s)['%s']" % (iteration, res.task_id, action)) output = res.get() helpers.log("Output after it is ready is %s" % output) else: helpers.log("****** %d.NOT-READY - task_id(%s)['%s']" % (iteration, res.task_id, action)) is_pending = True output = res.get() helpers.log("Output before it is ready is %s" % output) if iteration >= int(timeout) / int(timer): # helpers.test_failure("USR ERROR: the parallel execution did not finish with %s seconds" %timeout) helpers.log("USR ERROR: the parallel execution did not finish with %s seconds" % timeout) return False helpers.log("*** Parallel tasks completed ") # # Check task output # for res in results: helpers.log("Inside for res value is %s" % res) task_id = res.task_id helpers.log_task_output(task_id) helpers.log("Inside for res task id is %s" % task_id) output = res.get() helpers.log("USER INFO: for task %s , result is %s " % (task_id, output)) result_dict[task_id]["result"] = output if output is False: flag = False helpers.log("***** result_dict:\n%s" % helpers.prettify(result_dict)) helpers.log("USER INFO ***** result flag is: %s" % flag) return flag
def off(self): max_count = 5 sec = 5 if self._thread: count = 0 while self.has_lock() and count < max_count: count += 1 helpers.log("Test Monitor '%s' - found lock on task." " Sleeping for %s before disabling (count=%s)." % (self.name(), sec, count)) helpers.sleep(sec) helpers.log("Test Monitor '%s' - disabling (%s total events)" % (self.name(), self.counter())) self._thread.cancel() self._thread = None # reset
def cli_t5_switch_config_interface_1g(self, switch, interface): '''Function to configure interface on switch as 1G input - switch , interface Output - True if success ''' try: t = test.Test() s1 = t.switch(switch) intf = str(interface) cli_input1 = "interface %s 1g-sfp" % intf s1.config(cli_input1) helpers.sleep(5) return True except: helpers.log("could not execute command, check for log") return False
def rest_enable_nat_switch_interfaces(self, nat_switch): '''Function to disable leaf interfaces for the nat ivs switch connected Input: vswitch name ''' t = test.Test() c = t.controller('master') url = '/api/v1/data/controller/applications/bcf/info/fabric/port-group[name="%s"]' % nat_switch c.rest.get(url) data = c.rest.content() for i in range(0, len(data[0]["interface"])): switch = data[0]["interface"][i]["switch-name"] interface = data[0]["interface"][i]["interface-name"] url = '/api/v1/data/controller/core/switch-config[name="%s"]/interface[name="%s"]' % ( switch, interface) c.rest.delete(url, {"shutdown": None}) helpers.sleep(3)
def rest_delete_breakout_interface(self, switch, intf, timeout=30): ''' Function to delete force breakout interface input - switch , interface output - returns true ''' try: t = test.Test() c = t.controller('master') url = '/api/v1/data/controller/core/switch-config[name="%s"]/interface[name="%s"]' % ( switch, intf) c.rest.delete(url, {"breakout": None}) helpers.sleep(20) return True except: helpers.log("Could not get the rest output.see log for errors\n") return False
def http_request(self, *args, **kwargs): retries = int(kwargs.pop('retries', 0)) sleep_time = float(kwargs.pop('sleep_time_between_retries', 10)) while True: try: result = self._http_request(*args, **kwargs) except: helpers.log('HTTP request error:\n%s' % helpers.exception_info()) if retries > 0: helpers.log( 'Retrying HTTP request in %s seconds (retries=%s)' % (sleep_time, retries)) retries -= 1 helpers.sleep(sleep_time) else: raise else: if int(result['status_code']) == 401: if self.session_cookie_loop > 5: helpers.test_error("Detected session cookie loop.") elif ('description' in result['content'] and re.match( r'.*cookie.*', result['content']['description'], re.I)): # Retry if: # "Authorization failed: No session found for cookie" # "Authorization failed: No session cookie provided" self.session_cookie_loop += 1 helpers.log( "It appears the session cookie has expired." " Requesting new session cookie.") self.request_session_cookie() # helpers.sleep(2) # Re-run command result = self._http_request(*args, **kwargs) else: # Error, possibly due to "invalid user/password combination" or others. helpers.test_error("Unable to create session cookie.") else: self.session_cookie_loop = 0 break return result
def activate_deactivate_controller(self, ip_address, iteration): '''Activate and deactivate controller configuration on switch Inputs: ip_address IP Address of Switch iteration Number of times the operation has to be performed ''' try: t = test.Test() c = t.controller() conn = SSH2() conn.connect(ip_address) conn.login(Account("admin", "adminadmin")) mycount = 1 while (mycount <= iteration): conn.execute('enable') conn.execute('conf t') inp = "no controller " + str(c.ip) conn.execute(inp) conn.execute('end') conn.execute('show running-config openflow') print conn.response helpers.sleep(10) conn.execute('conf t') inp = "controller " + str(c.ip) conn.execute(inp) conn.execute('end') conn.execute('show running-config openflow') print conn.response if iteration > mycount: mycount = mycount + 1 helpers.sleep(10) elif mycount == iteration: conn.send('exit\r') conn.send('exit\r') conn.send('exit\r') conn.close() return True except: helpers.test_failure( "Could not execute command. Please check log for errors") return False
def cli_t5_switch_add_dhcp_ip(self, node): ''' Objective: - Configure static IP address configuration on switch. Inputs: | console_ip | IP Address of Console Server | | console_port | Console Port Number | | ip_address | IP Address of Switch | | subnet | Switch subnet in /18 /24 format | | gateway | IP address of default gateway | Return Value: - True on configuration success - False on configuration failure ''' try: t = test.Test() user = "******" password = "******" tn = t.dev_console(node) #console_ip = t.params(node, "console_ip") #console_port = t.params(node, "console_port") #tn = telnetlib.Telnet(str(console_ip), int(console_port)) tn.read_until("login: "******"\r\n") tn.read_until("Password: "******"\r\n") tn.read_until('') tn.write("enable \r\n") tn.write("conf t \r\n") tn.write("interface ma1 ip-address dhcp \r\n") helpers.sleep(10) tn.read_until(">") tn.write("exit \r\n") tn.write("exit \r\n") tn.close() return True except: helpers.test_failure( "Could not execute command. Please check log for errors") return False
def rest_config_breakout_interface(self, switch, intf): ''' Function to configure force breakout interface input - switch , interface output - returns true ''' try: t = test.Test() c = t.controller('master') url1 = '/api/v1/data/controller/core/switch-config[name="%s"]/interface[name="%s"]' % ( switch, intf) c.rest.put(url1, {"name": str(intf)}) url2 = '/api/v1/data/controller/core/switch-config[name="%s"]/interface[name="%s"]' % ( switch, intf) c.rest.patch(url2, {"breakout": True}) helpers.sleep(20) return True except: helpers.log("Could not get the rest output.see log for errors\n") return False
def configure_controller(self, ip_address, controller_ip): '''Configure controller IP address on switch Input: ip_address: IP Address of switch ''' t = test.Test() try: conn = SSH2() conn.connect(ip_address) conn.login(Account("admin", "adminadmin")) conn.execute('enable') conn.execute('conf t') input = "controller " + controller_ip conn.execute(input) helpers.sleep(float(30)) return True except: helpers.test_failure("Configuration delete failed") return False
def cli_boot_factory_default_and_first_boot(self, node, reboot_sleep=60, **kwargs): """ Call 'cli boot factory default' to put device in first-boot mode. Then call 'cli_add_first_boot' to configure the device. """ do_factory_boot = True do_first_boot = True if not helpers.is_controller(node): helpers.test_error("Node must be a controller ('c1', 'c2').") if do_factory_boot: self.cli_boot_factory_default(node) helpers.log("Sleeping for %s seconds before first boot setup" % reboot_sleep) helpers.sleep(reboot_sleep) if do_first_boot: return self.cli_add_first_boot(node, **kwargs)
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 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 task_one_finish_check_parallel(self, results, result_dict, timer=60, timeout=1200): ''' task_one_finish_check_parallel, check to see at least one job finished Input: Output: Author: Mingtao ''' helpers.log("***Entering==> task_one_finish_check_parallel \n") is_pending = True iteration = 0 while is_pending: is_pending = False iteration += 1 helpers.sleep(int(timer)) helpers.log("USR INFO: result is %s" % results) for res in results: task_id = res.task_id action = result_dict[task_id]["node"] + ' ' + result_dict[task_id]["action"] if res.ready() == True: helpers.log("****** %d.READY - task_id(%s)['%s']" % (iteration, res.task_id, action)) helpers.log("USR INFO: on job is ready") helpers.log_task_output(task_id) return True else: helpers.log("****** %d.NOT-READY - task_id(%s)['%s']" % (iteration, res.task_id, action)) is_pending = True if iteration >= int(timeout) / int(timer): # helpers.test_failure("USR ERROR: the parallel execution did not finish with %s seconds" %timeout) helpers.log("USR ERROR: the parallel execution did not finish with %s seconds" % timeout) return False
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 vm_setup(self, **kwargs): result = { "status_code": True, "status_descr": "Success", } try: vm_name = kwargs.get("vm_name", None) kvm_host = kwargs.get("kvm_host", KVM_SERVER) kvm_user = kwargs.get("kvm_user", KVM_USER) kvm_password = kwargs.get("kvm_password", KVM_PASSWORD) vm_host_name = kwargs.get("vm_host_name", None) vm_type = kwargs.get("vm_type", "bcf") qcow_path = kwargs.get("qcow_path", None) qcow_vm_path = None ip = kwargs.get("ip", None) vm_ram = kwargs.get("vm_ram", "2048") build_number = kwargs.get("build_number", None) if ip == 'None': ip = None cluster_ip = kwargs.get("cluster_ip", None) netmask = kwargs.get("netmask", "18") gateway = kwargs.get("gateway", "10.8.0.1") network_interface = kwargs.get("network_interface", "br0") self.log_path = LOG_BASE_PATH + '/' + vm_name try: if os.path.exists(self.log_path) or os.path.islink( self.log_path): pass else: os.makedirs(self.log_path) except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST and os.path.isdir(LOG_BASE_PATH): pass else: # Last resort - put logs in /tmp self.log_path = '/tmp' + '/' + vm_name os.makedirs(self.log_path) # export IS_GOBOT="False" helpers.set_env("AUTOBOT_LOG", "%s/%s.log" % (self.log_path, vm_name)) helpers.bigrobot_log_path_exec_instance(self.log_path) # Note: helpers.summary_log() and helpers.log() are not called # until after we've initialized the BigRobot log path # (above). Don't attempt to write to logs before that # or it will write logs to /tmp directory instead of the # /tmp/<vm_name>/. helpers.summary_log("Creating VM with Name: %s " % vm_name) helpers.summary_log("Created log_path %s" % self.log_path) # remote_qcow_bvs_path = kwargs.get("remote_qcow_bvs_path", "/var/lib/jenkins/jobs/bvs\ master/lastSuccessful/archive/target/appliance/images/bcf/controller-bcf-2.0.8-SNAPSHOT.qcow2") remote_qcow_bvs_path = kwargs.get( "remote_qcow_bvs_path", "/var/lib/jenkins/jobs/bcf_master/lastSuccessful/archive/controller-bcf-*.qcow2" ) remote_qcow_mininet_path = kwargs.get( "remote_qcow_mininet_path", "/var/lib/jenkins/jobs/t6-mininet-vm/builds/lastSuccessfulBuild/archive/t6-mininet-vm/ubuntu-kvm/t6-mininet.qcow2" ) topo_file = self._create_temp_topo(kvm_host=kvm_host, vm_name=vm_name) # set the BIG ROBOT Topo file for console connections helpers.bigrobot_topology(topo_file) helpers.bigrobot_params("none") kvm_handle = self._connect_to_kvm_host(hostname=kvm_host, user=kvm_user, password=kvm_password) if vm_name in kvm_handle.bash('sudo virsh list --all')['content']: helpers.summary_log( "VM with given name %s already exists in KVM Host %s" % (vm_name, kvm_host)) return False if qcow_path is not None: helpers.log( "QCOW path is provided using it locally NO SCP just copy to images.." ) qcow_vm_path = self._cp_qcow_to_images_folder( kvm_handle=kvm_handle, qcow_path=qcow_path, vm_name=vm_name) else: helpers.log( "no VMDK path is given copying from latest bvs build from jenkins server" ) if vm_type == 'mininet': helpers.log( "Scp'ing Latest Mininet qcow file from jenkins to kvm Host.." ) qcow_vm_path = self._scp_file_to_kvm_host( kvm_handle=kvm_handle, remote_qcow_path=remote_qcow_mininet_path, vm_type='mininet', vm_name=vm_name, build_number=build_number) else: helpers.log( "Scp'ing Latest BVS qcow file %s from jenkins to kvm Host.." % remote_qcow_bvs_path) qcow_vm_path = self._scp_file_to_kvm_host( kvm_handle=kvm_handle, remote_qcow_path=remote_qcow_bvs_path, vm_name=vm_name, build_number=build_number) helpers.log("Creating VM on KVM Host with Name : %s " % vm_name) self.create_vm_on_kvm_host(vm_type=vm_type, qcow_path=qcow_vm_path, vm_name=vm_name, kvm_handle=kvm_handle, kvm_host=kvm_host, network_interface=network_interface, vm_ram=vm_ram) result['vm_name'] = vm_name result['kvm_host'] = kvm_host result['image_path'] = qcow_vm_path result['vm_ip'] = ip # result['content'] = helpers.file_read_once("%s/%s.log" # % (self.log_path, # vm_name)) if vm_type == 'mininet': # FIX ME configure mininet with user specified ip / return the DHCP ip of mininet VM helpers.log("Success Creating Mininet vm!!") helpers.log("Configuring IP for mininet if provided") result['vm_ip'] = self.set_mininet_ip(node="c1", ip=ip, get_ip=True) return result # For controller, attempt First Boot helpers.log("SLeep another 60 sec for controller to boot up..") time.sleep(30) result['vm_ip'] = self._configure_vm_first_boot( cluster_ip=cluster_ip, ip_address=ip, netmask=netmask, vm_host_name=vm_host_name, gateway=gateway) helpers.summary_log( "Copying firstboot-config on New Controller: %s" % result['vm_ip']) helpers.sleep(10) bvs = ControllerDevConf(host=result['vm_ip'], user="******", password="******", name="test-bvs") bvs.config("copy running-config snapshot://firstboot-config") helpers.summary_log("Success saving firstboot-config") helpers.summary_log("Done! Logs are written to %s" % self.log_path) return result except: inst = helpers.exception_info_traceback() helpers.log("Exception Details:\n%s" % inst) result['status_code'] = False result['status_descr'] = inst return result
def verify_switch_tcam_limitaion(self, node,policy, match_type='mixed',base='10.0.0.0',step='0.1.0.1',v6base='1001:0:0:0:0:0:0:0',v6step='0:0:1:0:1:0:0:0'): """ verify the switch tcam flow limitaion Usage: verify_switch_tcam S203 type type - 'ipv4' 'ipv6' mixed return: the tcam flow entries -- Mingtao """ t = test.Test() c = t.controller('master') bigtap = BigTap.BigTap() i = 0 sequence = 0 expect_flow = 0 ether_type = [] if match_type == 'ipv4': ether_type.extend(['2048']) v6Flag = None v4Flag = True elif match_type == 'ipv6': ether_type.extend(['34525']) v6Flag = True v4Flag = None else: ether_type.extend(['2048']) ether_type.extend(['34525']) v6Flag = True v4Flag = True for num in ['100','20','5','1']: if v4Flag is not None: v4Flag = True if v6Flag is not None: v6Flag = True while v4Flag or v6Flag: i = i + 1 g_size = int(num) if match_type == 'ipv4' or match_type == 'mixed' : name = 'G_'+str(i)+'_'+num bigtap.rest_add_address_group(name,'ipv4') bigtap.gen_add_address_group_entries(name,'ipv4',base,step, '255.255.255.255', g_size) base = helpers.get_next_address('ipv4', base,'5.0.0.0') if match_type == 'ipv6' or match_type == 'mixed' : name6 = 'G6_'+str(i)+'_'+num bigtap.rest_add_address_group(name6,'ipv6') bigtap.gen_add_address_group_entries(name6,'ipv6',v6base,v6step, 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', g_size) v6base = helpers.get_next_address('ipv6', v6base,'11:0:0:0:0:0:0:0') for loop in range(0,8): if not v4Flag and not v6Flag: helpers.log("INFO: ********* break of of the loop *****" ) break for ether in ether_type: if ether == '2048': Gname = name if not v4Flag: continue elif ether == '34525': Gname = name6 if not v6Flag: continue sequence = sequence + 10 if loop == 0: data = '{'+'"sequence":'+ str(sequence) +','+'"src-ip-list":'+'"'+Gname+'"'+','+'"ether-type":'+ ether+'}' elif loop == 1: data = '{'+'"sequence":'+ str(sequence) +','+'"dst-ip-list":'+'"'+Gname+'"'+','+'"ether-type":'+ ether+'}' elif loop == 2: data = '{'+'"sequence":'+ str(sequence) +','+'"src-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 6,'+'"src-tp-port":80,'+'"ether-type":'+ ether+'}' elif loop == 3: data = '{'+'"sequence":'+ str(sequence) +','+'"src-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 6,'+'"dst-tp-port":100,'+'"ether-type":'+ ether+'}' elif loop == 2: data = '{'+'"sequence":'+ str(sequence) +','+'"dst-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 6,'+'"src-tp-port":120,'+'"ether-type":'+ ether+'}' elif loop == 3: data = '{'+'"sequence":'+ str(sequence) +','+'"dst-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 6,'+'"dst-tp-port":140,'+'"ether-type":'+ ether+'}' elif loop == 4: data = '{'+'"sequence":'+ str(sequence) +','+'"src-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 17,'+'"dst-tp-port":160,'+'"ether-type":'+ ether+'}' elif loop == 5: data = '{'+'"sequence":'+ str(sequence) +','+'"src-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 17,'+'"src-tp-port":200,'+'"ether-type":'+ ether+'}' elif loop == 6: data = '{'+'"sequence":'+ str(sequence) +','+'"dst-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 17,'+'"dst-tp-port":240,'+'"ether-type":'+ ether+'}' else: data = '{'+'"sequence":'+ str(sequence) +','+'"dst-ip-list":'+'"'+Gname+'"'+','+'"ip-proto": 17,'+'"src-tp-port":280,'+'"ether-type":'+ ether+'}' helpers.log("INFO: ********* data is %s*****" % data) if not bigtap.rest_add_policy_match('admin-view', policy, sequence, data): helpers.test_failure(c.rest.error()) expect_flow = expect_flow + g_size helpers.sleep(30) flow = bigtap.rest_show_switch_flow(node=node ) if flow == expect_flow: helpers.test_log("INFO: Switch - %s tcam entry - %s" % (node, str(flow))) elif flow == 0: helpers.test_log("ERROR: Switch - %s tcam expect - %s, actual - %s" % (node, str(expect_flow), str(flow))) if not bigtap.rest_delete_policy_match('admin-view', policy,sequence): helpers.test_failure(c.rest.error()) expect_flow = expect_flow - g_size helpers.sleep(60) flow = bigtap.rest_show_switch_flow(node=node) if flow == expect_flow: if ether == '2048': v4Flag = False elif ether == '34525': v6Flag = False helpers.test_log("INFO: ****Finished group - %s type - %s entries - %s ***" % (num, str(ether), str(expect_flow)) ) if num == '1' and not v4Flag and not v6Flag: helpers.test_log("INFO: **** # of flows is switch - %s ***" % str(flow)) return expect_flow continue else: helpers.test_failure("ERROR: mismatch Switch - %s tcam expect - %s, actual - %s" % (node, str(expect_flow), str(flow))) else: helpers.test_log("ERROR: Switch - %s tcam expect - %s, actual - %s" % (node, str(expect_flow), str(flow))) helpers.test_failure("ERROR: mismatch Switch - %s tcam expect - %s, actual - %s" % (node, str(expect_flow), str(flow)))
def cli_add_first_boot( self, node, ip_address=None, netmask='', gateway='', dns_server='', dns_search='', ntp_server='', hostname='mycontroller', cluster_name='mycluster', cluster_descr='', admin_password='******', platform='bvs', ): """ First boot setup fpr BVS - It will then connect to the console to complete the first-boot configuration steps (call 'cli add first boot'). """ if platform != 'bvs': helpers.test_error("Only 'bvs' platform is supported") t = test.Test() n = t.node(node) if not ip_address: ip_address = n.ip() helpers.log("Getting the console session for '%s'" % node) n_console = n.console() _ = """ Note: Below is the basic first boot question/answer output. root@qa-kvm-32:~# virsh console vui-bvs Connected to domain vui-bvs Escape character is ^] Big Virtual Switch Appliance 2.0.5-SNAPSHOT (bvs master #1223) Log in as 'admin' to configure controller login: admin <=== Last login: Mon Mar 17 20:28:31 UTC 2014 from 10.192.123.117 on pts/0 The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. <clear screen> This product is governed by an End User License Agreement (EULA). You must accept this EULA to continue using this product. You can view this EULA by typing 'View', or from our website at: http://www.bigswitch.com/eula Do you accept the EULA for this product? (Yes/No/View) [Yes] > Yes <=== Running system pre-check Found eth0 Found 2 CPU cores Found 2.00 GB of memory Finished system pre-check Starting first-time setup Local Node Configuration ------------------------ Password for emergency recovery user > bsn <=== Retype Password for emergency recovery user > bsn <=== Please choose an IP mode: [1] Manual [2] Automatic via DHCP > 1 <=== IP address [0.0.0.0/0] > 10.192.104.2 <=== CIDR prefix length [24] > 18 <=== Default gateway address (Optional) > 10.192.64.1 <=== DNS server address (Optional) > 10.192.3.1 <=== DNS search domain (Optional) > bigswitch.com <=== Hostname > blah <=== Controller Clustering --------------------- Please choose a cluster option: [1] Start a new cluster [2] Join an existing cluster > 1 <=== Cluster name > bleh <=== Cluster description (Optional) > [enter] <=== Administrator password for cluster > adminadmin <=== Retype Administrator password for cluster > adminadmin <=== System Time ----------- Enter NTP server [0.bigswitch.pool.ntp.org] > [enter] <=== Menu ---- Please choose an option: [ 1] Apply settings [ 2] Reset and start over [ 3] Update Emergency Recovery Password (***) [ 4] Update IP Auto/Manual (Manual) [ 5] Update Local IP Address (10.192.104.2) [ 6] Update CIDR Prefix Length (18) [ 7] Update Gateway (10.192.64.1) [ 8] Update DNS Server (10.192.3.1) [ 9] Update DNS Search Domain (bigswitch.com) [10] Update Hostname (blah) [11] Update Cluster Option (Start a new cluster) [12] Update Cluster Name (bleh) [13] Update Cluster Description (<none>) [14] Update Cluster Admin Password (***) [15] Update NTP Server (0.bigswitch.pool.ntp.org) [1] > 1 <=== [Stage 0] Initializing system [Stage 1] Configuring controller Waiting for network configuration IP address on eth0 is 10.192.104.2 Generating cryptographic keys Retrieving time from NTP server 0.bigswitch.pool.ntp.org [Stage 2] Configuring cluster Cluster configured successfully. Current node ID is 3146 All cluster nodes: Node 3146: 10.192.104.2:6642 First-time setup is complete! Press enter to continue > [enter] <=== Big Virtual Switch Appliance 2.0.5-SNAPSHOT (bvs master #1223) Log in as 'admin' to configure blah login: admin <=== Password: ***** <=== Last login: Mon Mar 17 19:01:17 UTC 2014 on ttyS0 Big Virtual Switch Appliance 2.0.5-SNAPSHOT (bvs master #1223) Logged in as admin, 2014-03-17 20:24:20.843000 UTC, auth from blah blah> """ n_console.expect(r'Escape character.*[\r\n]') n_console.send('') # press <Enter> and expect to see the login prompt # We might be in midst of a previously failed first boot setup. # Interrupt it (Control-C) and press <Enter> to log out... n_console.send(helpers.ctrl('c')) helpers.sleep(2) n_console.send('') n_console.expect(helpers.regex_bvs()) n_console.expect(r'login:'******'admin') # Need to enable developer mode to use DHCP option. Magic string # to enable it is 'dhcp'. n_console.expect(r'Do you accept the EULA.* > ') n_console.send('dhcp') n_console.expect(r'Developer.* mode enabled.*') # The "real" EULA n_console.expect(r'Do you accept the EULA.* > ') n_console.send('Yes') n_console.expect(r'Local Node Configuration') n_console.expect(r'Password for emergency recovery user > ') n_console.send('bsn') n_console.expect(r'Retype Password for emergency recovery user > ') n_console.send('bsn') n_console.expect(r'Please choose an IP mode:.*[\r\n]') n_console.expect(r'> ') n_console.send('1') # Manual n_console.expect(r'IP address .* > ') n_console.send(ip_address) if not re.match(r'.*/\d+', ip_address): # Send netmask if IP address doesn't contain prefix length n_console.expect(r'CIDR prefix length .* > ') n_console.send(netmask) n_console.expect(r'Default gateway address .* > ') n_console.send(gateway) n_console.expect(r'DNS server address .* > ') n_console.send(dns_server) n_console.expect(r'DNS search domain .* > ') n_console.send(dns_search) n_console.expect(r'Hostname > ') n_console.send(hostname) n_console.expect(r'Controller Clustering') n_console.expect(r'> ') n_console.send('1') # Start a new cluster n_console.expect(r'Cluster name > ') n_console.send(cluster_name) n_console.expect(r'Cluster description .* > ') n_console.send(cluster_descr) n_console.expect(r'Administrator password for cluster > ') n_console.send(admin_password) n_console.expect(r'Retype .* > ') n_console.send(admin_password) n_console.expect(r'System Time') n_console.expect(r'Enter NTP server .* > ') n_console.send(ntp_server) n_console.expect(r'Please choose an option:.*[\r\n]') n_console.expect(r'\[1\] > ') n_console.send('1') # Apply settings n_console.expect(r'Initializing system.*[\r\n]') n_console.expect(r'Configuring controller.*[\r\n]') n_console.expect(r'Configuring cluster.*[\r\n]') n_console.expect(r'First-time setup is complete.*[\r\n]') n_console.expect(r'Press enter to continue > ') n_console.send('') helpers.log("Closing console connection for '%s'" % node) n.console_close() helpers.sleep(3) # Sleep for a few seconds just in case... # Check that controller is now pingable. # First remove the prefix from the IP address. new_ip_address = re.sub(r'/\d+$', '', ip_address) loss = helpers.ping(new_ip_address) if loss < 50: helpers.log("Node '%s' has survived first-boot!" % node) return True else: return False
def cli_upgrade_image(self, node=None, package=None, timeout=600, sleep_time=600): ''' Objective: - Execute CLI commands to download given upgrade package to Master (and Slave if exists) Controllers and upgrade them Input: | `package` | URL to the upgrade package | | `node` | Node to be upgraded. Leave empty to upgrade all nodes in your topology | | `timeout` | Timeout (in seconds) for "upgrade" command to be execute | | `sleep` | Time (in seconds) of sleep after upgrade, before next actions | Return Value: - True if configuration is successful - False otherwise ''' t = test.Test() if not package: helpers.test_error("You must specify a package name") if not node: # assume all controllers if node is not specified node_handles = t.controllers() controller_qty = len(t.controllers()) else: node_handles = [t.controller(node)] controller_qty = 1 helpers.log("Number of controllers %s" % controller_qty) if controller_qty > 2 or controller_qty < 1: helpers.test_log( "More than two controllers or no controller configured") return False for i in range(0, controller_qty): try: if controller_qty > 1: n = t.controller('slave') else: n = node_handles[0] helpers.log("No %s : Upgrade '%s' to image '%s'" % (i, n.name(), package)) n.bash("cd /home/images/") n.bash("sudo rm *") n.bash("sudo wget %s" % package) n.bash("exit") helpers.log("Image downloaded successfully") n.enable('enable') n.send("upgrade") n.expect(r"\(yes to continue\)") n.send("yes") n.expect(r"Password:"******"adminadmin", timeout=timeout) n.send("reload") n.expect(r"Confirm Reload \(yes to continue\)") n.send("yes") helpers.sleep(sleep_time) except: helpers.test_log("Output: %s" % n.cli_content()) return False return True
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 sleepnow(self, intTime): helpers.sleep(float(intTime))
bigrobot_path = os.path.dirname(__file__) + '/../..' exscript_path = bigrobot_path + '/vendors/exscript/src' esb_path = bigrobot_path + '/esb' sys.path.insert(0, bigrobot_path) sys.path.insert(1, exscript_path) sys.path.insert(2, esb_path) from template_services import tasks import autobot.helpers as helpers if __name__ == "__main__": task = tasks.BsnCommands() res1 = task.add.delay(1, 5) # res1 = task.addition(1, 5) # print "*** res1: %s" % res1 # sys.exit(1) # helpers.sleep(0.2) # while res1.ready() == False: # print("Sleeping for 1 sec") # helpers.sleep(1) helpers.sleep(1) output = res1.get() print("** task_id: %s" % res1.task_id) print("** output: %s" % output)