def take_action(self, action, process): with SSHConnection(address=self.ip, username=self.username, password=self.password) as client: stdin, stdout, stderr = client.exec_command( "sudo service fabric-enabler-" + process + " " + action) output = "".join(stdout.readlines()) error_output = "".join(stderr.readlines()).strip() if error_output: raise Exception("Error starting enabler" + process + ":", error_output) print "Waiting for things to get settled" time.sleep(200) return True
def check_status(self, process): with SSHConnection(address=self.ip, username=self.username, password=self.password) as client: stdin, stdout, stderr = client.exec_command( "sudo service fabric-enabler-" + process + " status") output = "".join(stdout.readlines()) error_output = "".join(stderr.readlines()).strip() if error_output: raise Exception("Error while checking status of " + process) failure_list = ["stop/waiting"] for word in failure_list: if word in output: print ("Alert: Process " + process + " not running") return False return True
def check_output(self, node_ip, node_username, node_password, uplink_interface, str_to_search): with SSHConnection(address=node_ip, username=node_username, password=node_password) as client: stdin, stdout, stderr = client.exec_command( "sudo vdptool -t -i " + uplink_interface + " -V assoc -c mode=assoc") output = "".join(stdout.readlines()) print "VDPTOOL command output:", output error_output = "".join(stderr.readlines()).strip() if error_output: raise Exception("Error:", error_output) inst_str = str_to_search if inst_str in output: print "String found in vdptool cmd output.\n" return True else: print "String not found in vdptool cmd output.\n" return False # TODO: Return correct retval
def verify_ping_qdhcpns(self, node_address, username, password, network_id, dest_ip): with SSHConnection(address=node_address, username=username, password=password) as client: failure_list = ["unreachable", "100% packet loss", "0 received"] stdin, stdout, stderr = client.exec_command( "sudo ip netns exec qdhcp-" + network_id + " ping -c 3 " + dest_ip) cmd = "sudo ip netns exec qdhcp-" + network_id + " ping -c 3 " + dest_ip print "Command is:", cmd output = "".join(stdout.readlines()).strip() error_output = "".join(stderr.readlines()).strip() print "Output:", output if error_output: print "Error:", error_output raise Exception("Ping failed...Failing test case\n") for word in failure_list: if word in output: raise Exception("Ping failed...Failing test case\n") return True
def check_output(self, node_ip, node_username, node_password, bridge_name, search_str): with SSHConnection(address=node_ip, username=node_username, password=node_password) as client: stdin, stdout, stderr = client.exec_command( "sudo ovs-ofctl dump-flows " + bridge_name) output = "".join(stdout.readlines()) error_output = "".join(stderr.readlines()).strip() if error_output: raise Exception(bridge_name + " Error:", error_output) print "Output:", output if search_str in output: print search_str + " found in " + bridge_name + " flows\n" return True else: print search_str + " not found in " + bridge_name + " flows\n" return False
def runTest(self): try: # Basic checks for status of services status_inst = CheckStatusOfServices(self.config_dict) status = CheckStatusOfServices.check(status_inst) if not status: print "Some service/s not running...Unable to run testcase" return resultConstants.RESULT_ABORT # Create project & user new_project_user = self.controller.createProjectUser( self.new_tenant, self.new_user, self.new_password) # Create network and subnetwork new_network_inst1 = self.controller.createNetworkSubNetwork( self.new_tenant, self.new_network1, self.new_subnw1, self.new_user, self.new_password) # This is because results were different without adding delay time.sleep(5) with SSHConnection(address=self.dcnm_ip, username=self.dcnm_sys_username, password=self.dcnm_sys_password) as client: stdin, stdout, stderr = client.exec_command( "ldapsearch -x -v -D 'cn=" + self.ldap_username + ",dc=cisco,dc=com' -w '" + self.ldap_password + "' -b 'dc=cisco,dc=com'") output = stdout.readlines() # print output org_str = "orgName: " + self.new_tenant org_found = False part_str = "vrfName: " + self.new_tenant + ":CTX" part_found = False net_str = "networkName: " + self.new_network1 net_found = False for line in output: line = line.strip() if not org_found and org_str in line: print "Organization created on DCNM" org_found = True if not part_found and part_str in line: print "Partition CTX created on DCNM" part_found = True if not net_found and net_str in line: print "Network created on DCNM" net_found = True if not org_found: raise Exception("Organization NOT found on DCNM") elif not part_found: raise Exception("Partition NOT found on DCNM") elif not net_found: raise Exception("Network NOT found on DCNM") except Exception as e: print "Error:", e self.cleanup() return ReturnValue.FAILURE self.cleanup() return ReturnValue.SUCCESS
def runTest(self): try: # Basic checks for status of services status_inst = CheckStatusOfServices(self.config_dict) status = CheckStatusOfServices.check(status_inst) if not status: print "Some service/s not running...Unable to run testcase" return resultConstants.RESULT_ABORT # Create project new_project = self.controller.createProject(self.new_tenant) # Create user new_user = self.controller.createUser( new_project, new_username=self.new_user, new_password=self.new_password) # Create network new_network1 = self.controller.createNetwork( self.new_tenant, self.new_network1, self.new_user, self.new_password) print "New Network:", new_network1 # Create subnet new_subnet = self.controller.createSubnet( new_network1.get('network').get('id'), self.new_tenant, self.new_user, self.new_password, self.new_subnw1) print "New Subnetwork:", new_subnet # Create key-pair key_pair = self.controller.createKeyPair(new_project.id, self.new_user, self.new_password) # Create security groups and rules self.controller.createSecurityGroup(new_project.id, self.new_user, self.new_password) # Create instance host1 = self.controller.createInstance( new_project.id, self.new_user, self.new_password, new_network1.get('network').get('id'), self.new_inst1, key_name=key_pair, availability_zone=None) print "Host1:", host1 print "Connecting to database" # Connect to database mysql_db = MySqlConnection(self.config_dict) with MySqlConnection(self.config_dict) as mysql_connection: data = mysql_db.get_instances(mysql_connection, self.new_inst1) print "Host name is:", data[MySqlDbTables.INSTANCES_HOST_NAME] host_name = data[MySqlDbTables.INSTANCES_HOST_NAME] print "Getting uplink info...\n" uplinkInst = Uplink(self.config_dict) uplink_info = UplinkInfo() uplink_info = Uplink.get_info(uplinkInst, host_name) print "uplink switchIp:", uplink_info.switchIp fabricSwInst = FabricSwitch(self.config_dict) fabric_sw_info = FabricSwitchInfo() fabric_sw_info = FabricSwitch.get_info(fabricSwInst, uplink_info.switchIp, self.config_dict) print "Checking for VDP Keep alive on the fabric connection...\n" with SSHConnection(address=uplink_info.switchIp, username=fabric_sw_info.username, password=fabric_sw_info.password) as client: stdin, stdout, stderr = client.exec_command("show run vlan") output = "".join(stdout.readlines()).strip() error_output = "".join(stderr.readlines()).strip() print "Output:", output except Exception as e: print "Created Exception: ", e self.cleanup() return ReturnValue.FAILURE