• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python commands.execute_cmd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tcutils.commands.execute_cmd函数的典型用法代码示例。如果您正苦于以下问题:Python execute_cmd函数的具体用法?Python execute_cmd怎么用?Python execute_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execute_cmd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: stop_tcpdump

 def stop_tcpdump(self, session):
     self.logger.info("Stopping any tcpdump process running")
     cmd = 'kill $(pidof tcpdump)'
     execute_cmd(session, cmd, self.logger)
     self.logger.info("Removing any encap-pcap files in /tmp")
     cmd = 'rm -f /tmp/encap*pcap'
     execute_cmd(session, cmd, self.logger)
开发者ID:chhandakm,项目名称:contrail-test,代码行数:7,代码来源:test_encap.py


示例2: start_tcpdump

 def start_tcpdump(self, server_ip, tap_intf):
     session = ssh(server_ip,self.inputs.host_data[server_ip]['username'],self.inputs.host_data[server_ip]['password'])
     pcap = '/tmp/%s.pcap' % tap_intf
     cmd = "tcpdump -nei %s tcp -w %s" % (tap_intf, pcap)
     self.logger.info("Staring tcpdump to capture the packets on server %s" % (server_ip))
     execute_cmd(session, cmd, self.logger)
     return pcap, session
开发者ID:ritamganguly,项目名称:contrail-test,代码行数:7,代码来源:base.py


示例3: verify_vrrp_action

 def verify_vrrp_action(self, src_vm, dst_vm, ip, vsrx=False):
     result = False
     self.logger.info('Will ping %s from %s and check if %s responds' % (
         ip, src_vm.vm_name, dst_vm.vm_name))
     compute_ip = dst_vm.vm_node_ip
     compute_user = self.inputs.host_data[compute_ip]['username']
     compute_password = self.inputs.host_data[compute_ip]['password']
     session = ssh(compute_ip, compute_user, compute_password)
     if vsrx:
         vm_tapintf = dst_vm.tap_intf[dst_vm.vn_fq_names[1]]['name']
     else:
         vm_tapintf = dst_vm.tap_intf[dst_vm.vn_fq_name]['name']
     cmd = 'tcpdump -nni %s -c 10 > /tmp/%s_out.log' % (
         vm_tapintf, vm_tapintf)
     execute_cmd(session, cmd, self.logger)
     assert src_vm.ping_with_certainty(ip), 'Ping to vIP failure'
     output_cmd = 'cat /tmp/%s_out.log' % vm_tapintf
     output, err = execute_cmd_out(session, output_cmd, self.logger)
     if ip in output:
         result = True
         self.logger.info(
             '%s is seen responding to ICMP Requests' % dst_vm.vm_name)
     else:
         self.logger.error('ICMP Requests not seen on the VRRP Master')
         result = False
     return result
开发者ID:dattamiruke,项目名称:contrail-test-ci,代码行数:26,代码来源:base.py


示例4: set_cpu_performance

 def set_cpu_performance(self, hosts):
     sessions = {}
     cmd = 'for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance > $f; cat $f; done'
     for i in range(0, 2):
         session = ssh(hosts[i]['host_ip'], hosts[i]['username'], hosts[i]['password'])
         execute_cmd(session, cmd, self.logger)
     return
开发者ID:rishiv,项目名称:contrail-test,代码行数:7,代码来源:config.py


示例5: start_tcpdump

 def start_tcpdump(self, session, tap_intf, vlan=None,  vm_fixtures=[], pcap_on_vm=False, no_header = False):
     filt_str = ''
     if not no_header:
         filt_str = 'udp port 8099'
     if not pcap_on_vm:
         pcap = '/tmp/mirror-%s_%s.pcap' % (tap_intf, get_random_name())
         cmd = 'rm -f %s' % pcap
         execute_cmd(session, cmd, self.logger)
         assert check_pcap_file_exists(session, pcap, expect=False),'pcap file still exists'
         if vlan:
             filt_str = 'greater 1200'
         cmd = "sudo tcpdump -ni %s -U %s -w %s" % (tap_intf, filt_str, pcap)
         self.logger.info("Starting tcpdump to capture the mirrored packets.")
         execute_cmd(session, cmd, self.logger)
         assert check_pcap_file_exists(session, pcap),'pcap file does not exist'
         return pcap
     else:
         pcap = '/tmp/%s.pcap' % (get_random_name())
         cmd_to_tcpdump = [ 'tcpdump -ni %s %s -w %s 1>/dev/null 2>/dev/null' % (tap_intf, filt_str, pcap) ]
         pidfile = pcap + '.pid'
         vm_fix_pcap_pid_files =[]
         for vm_fixture in vm_fixtures:
             vm_fixture.run_cmd_on_vm(cmds=cmd_to_tcpdump, as_daemon=True, pidfile=pidfile, as_sudo=True)
             vm_fix_pcap_pid_files.append((vm_fixture, pcap, pidfile))
         return vm_fix_pcap_pid_files
开发者ID:Juniper,项目名称:contrail-test,代码行数:25,代码来源:verify.py


示例6: verify_mirroring

 def verify_mirroring(self, si_fix, src_vm, dst_vm, mirr_vm=None):
     result = True
     if mirr_vm:
         svm = mirr_vm.vm_obj
     else:
         svms = self.get_svms_in_si(si_fix)
         svm = svms[0]
     if svm.status == 'ACTIVE':
         svm_name = svm.name
         host = self.get_svm_compute(svm_name)
         if mirr_vm:
             tapintf = self.get_svm_tapintf(svm_name)
         else:
            tapintf = self.get_bridge_svm_tapintf(svm_name, 'left')
         session = ssh(host['host_ip'], host['username'], host['password'])
         cmd = 'sudo tcpdump -nni %s -c 5 > /tmp/%s_out.log' % (tapintf, tapintf)
         execute_cmd(session, cmd, self.logger)
         assert src_vm.ping_with_certainty(dst_vm.vm_ip)
         sleep(10)
         output_cmd = 'sudo cat /tmp/%s_out.log' % tapintf
         out, err = execute_cmd_out(session, output_cmd, self.logger)
         print out
         if '8099' in out:
             self.logger.info('Mirroring action verified')
         else:
             result = False
             self.logger.warning('No mirroring action seen')
     return result
开发者ID:Juniper,项目名称:contrail-test,代码行数:28,代码来源:verify.py


示例7: stop_tcpdump_for_intf

def stop_tcpdump_for_intf(session, pcap, logger=None):
    if not logger:
        logger = contrail_logging.getLogger(__name__)
    cmd = 'sudo kill $(ps -ef|grep tcpdump | grep pcap| awk \'{print $2}\')'
    execute_cmd(session, cmd, logger)
    sleep(2)
    return True
开发者ID:Juniper,项目名称:contrail-test,代码行数:7,代码来源:tcpdump_utils.py


示例8: start_tcpdump_for_intf

def start_tcpdump_for_intf(ip, username, password, interface, filters='-v', logger=None):
    if not logger:
        logger = logging.getLogger(__name__)
    session = ssh(ip, username, password)
    pcap = '/tmp/%s_%s.pcap' % (interface, get_random_name())
    cmd = 'tcpdump -ni %s -U %s -w %s' % (interface, filters, pcap)
    execute_cmd(session, cmd, logger)
    return (session, pcap)
开发者ID:alokkumar223,项目名称:contrail-test-ci,代码行数:8,代码来源:tcpdump_utils.py


示例9: start_tcpdump

 def start_tcpdump(self, session, tap_intf):
     pcap = "/tmp/mirror-%s.pcap" % tap_intf
     cmd = "rm -f %s" % pcap
     execute_cmd(session, cmd, self.logger)
     sleep(5)
     cmd = "tcpdump -ni %s udp port 8099 -w %s" % (tap_intf, pcap)
     self.logger.info("Staring tcpdump to capture the mirrored packets.")
     execute_cmd(session, cmd, self.logger)
     return pcap
开发者ID:Juniper,项目名称:contrail-test-ci,代码行数:9,代码来源:config.py


示例10: start_tcpdump_for_vm_intf

def start_tcpdump_for_vm_intf(obj, vm_fix, vn_fq_name, filters='-v'):
    compute_ip = vm_fix.vm_node_ip
    compute_user = obj.inputs.host_data[compute_ip]['username']
    compute_password = obj.inputs.host_data[compute_ip]['password']
    session = ssh(compute_ip, compute_user, compute_password)
    vm_tapintf = vm_fix.tap_intf[vn_fq_name]['name']
    pcap = '/tmp/%s_%s.pcap' % (vm_tapintf, get_random_name())
    cmd = 'tcpdump -ni %s -U %s -w %s' % (vm_tapintf, filters, pcap)
    execute_cmd(session, cmd, obj.logger)

    return (session, pcap)
开发者ID:smurugap,项目名称:contrail-test,代码行数:11,代码来源:tcpdump_utils.py


示例11: stop_tcpdump

 def stop_tcpdump(self, session, pcap):
     self.logger.info("Waiting for the tcpdump write to complete.")
     sleep(30)
     cmd = 'sudo kill $(pidof tcpdump)'
     execute_cmd(session, cmd, self.logger)
     cmd = 'sudo tcpdump -r %s | wc -l' % pcap
     out, err = execute_cmd_out(session, cmd, self.logger)
     count = int(out.strip('\n'))
     cmd = 'sudo rm -f %s' % pcap
     execute_cmd(session, cmd, self.logger)
     return count
开发者ID:Ankitja,项目名称:contrail-test,代码行数:11,代码来源:flow_test_utils.py


示例12: stop_tcp_dump

 def stop_tcp_dump(self, sessions):
     self.logger.info("Waiting for the tcpdump write to complete.")
     sleep(30)
     cmd = 'kill $(pidof tcpdump)'
     execute_cmd(sessions[0], cmd, self.logger)
     execute_cmd(sessions[0], 'sync', self.logger)
     cmd = 'tcpdump -r %s | wc -l' % sessions[1]
     out, err = execute_cmd_out(sessions[0], cmd, self.logger)
     count = int(out.strip('\n'))
     #cmd = 'rm -f %s' % sessions[1]
     #execute_cmd(sessions[0], cmd, self.logger)
     return count
开发者ID:rishiv,项目名称:contrail-test,代码行数:12,代码来源:config.py


示例13: start_tcp_dump

 def start_tcp_dump(self, vm_fixture):
     sessions =[]
     vm_name = vm_fixture.vm_name
     host = self.inputs.host_data[vm_fixture.vm_node_ip]
     inspect_h = self.agent_inspect[vm_fixture.vm_node_ip]
     tapintf = inspect_h.get_vna_tap_interface_by_ip(vm_fixture.vm_ip)[0]['name']
     pcap = '/tmp/%s.pcap' % tapintf
     cmd = "tcpdump -ni %s udp -w %s" % (tapintf, pcap)
     session = ssh(host['host_ip'], host['username'], host['password'])
     self.logger.info("Staring tcpdump to capture the packets.")
     execute_cmd(session, cmd, self.logger)
     sessions.extend((session, pcap))
     return sessions
开发者ID:rishiv,项目名称:contrail-test,代码行数:13,代码来源:config.py


示例14: stop_tcpdump_on_vm_verify_cnt

def stop_tcpdump_on_vm_verify_cnt(obj, session, pcap, exp_count=None):

    cmd = 'tcpdump -r %s | wc -l' % pcap
    out, err = execute_cmd_out(session, cmd, obj.logger)
    count = int(out.strip('\n'))
    if exp_count and count != exp_count:
	obj.logger.warn("%s packets are found in tcpdump output but expected %s" % (count, exp_count))	
	return False
    elif count == 0:
        obj.logger.warn("No packets are found in tcpdump output but expected something")
        return False

    obj.logger.info("%s packets are found in tcpdump output", count)
    cmd = 'rm -f %s' % pcap
    execute_cmd(session, cmd, obj.logger)
    cmd = 'kill $(pidof tcpdump)'
    execute_cmd(session, cmd, obj.logger)
    return True 
开发者ID:chhandakm,项目名称:contrail-test,代码行数:18,代码来源:traffic.py


示例15: verify_flow_thru_si

 def verify_flow_thru_si(self, si_fix, src_vn):
     
     self.logger.info('Will start a tcpdump on the left-interfaces of the Service Instances to find out which flow is entering which Service Instance')
     flowcount= 0
     result= True
     si_count= si_fix.max_inst
     for i in range(1, si_count+1):
         svm_name = si_fix.si_name + '_%s'%i
         host = self.get_svm_compute(svm_name)
         tapintf = self.get_svm_tapintf_of_vn(svm_name, src_vn)
         session = ssh(host['host_ip'], host['username'], host['password'])
         cmd = 'tcpdump -ni %s proto 17 -vvv -c 5 > /tmp/%s_out.log' % (tapintf,tapintf)
         execute_cmd(session, cmd, self.logger)
     sleep(5)
     self.logger.info('***** Will check the result of tcpdump *****')
     for i in range(1, si_count+1):
         svm_name = si_fix.si_name + '_%s'%i
         host = self.get_svm_compute(svm_name)
         tapintf = self.get_svm_tapintf_of_vn(svm_name, src_vn)
         session = ssh(host['host_ip'], host['username'], host['password'])
         output_cmd = 'cat /tmp/%s_out.log' % tapintf 
         out, err = execute_cmd_out(session, output_cmd, self.logger)
         if '9000' in out:
             flowcount= flowcount + 1
             self.logger.info('Flow with dport 9000 seen flowing inside %s'%svm_name)
         if '9001' in out:
             flowcount= flowcount + 1
             self.logger.info('Flow with dport 9001 seen flowing inside %s'%svm_name)
         if '9002' in out:
             flowcount= flowcount + 1
             self.logger.info('Flow with dport 9002 seen flowing inside %s'%svm_name)
     if flowcount > 1:
         self.logger.info('Flows are distributed across the Service Instances')
     else:
         result= False
     assert result, 'No Flow distribution seen' 
开发者ID:smusuvat,项目名称:contrail-test,代码行数:36,代码来源:ecmp_traffic.py


示例16: stop_tcpdump

 def stop_tcpdump(self, session, pcap, filt=""):
     self.logger.info("Waiting for the tcpdump write to complete.")
     sleep(30)
     cmd = "kill $(pidof tcpdump)"
     execute_cmd(session, cmd, self.logger)
     execute_cmd(session, "sync", self.logger)
     cmd = "tcpdump -r %s %s | wc -l" % (pcap, filt)
     out, err = execute_cmd_out(session, cmd, self.logger)
     count = int(out.strip("\n"))
     cmd = "rm -f %s" % pcap
     execute_cmd(session, cmd, self.logger)
     return count
开发者ID:Juniper,项目名称:contrail-test-ci,代码行数:12,代码来源:config.py


示例17: stop_tcpdump

 def stop_tcpdump(self, session, pcap, filt='', vm_fix_pcap_pid_files=[], pcap_on_vm=False):
     self.logger.debug("Waiting for the tcpdump write to complete.")
     sleep(2)
     if not pcap_on_vm:
         cmd = 'sudo kill $(ps -ef|grep tcpdump | grep %s| awk \'{print $2}\')' %pcap
         execute_cmd(session, cmd, self.logger)
         execute_cmd(session, 'sync', self.logger)
         sleep(3)
         cmd = 'sudo tcpdump -n -r %s %s | wc -l' % (pcap, filt)
         out, err = execute_cmd_out(session, cmd, self.logger)
         count = int(out.strip('\n'))
         cmd = 'sudo tcpdump -n -r %s' % pcap
         #TODO
         # Temporary for debugging
         execute_cmd(session, cmd, self.logger)
         return count
     else:
         output = []
         pkt_count = []
         for vm_fix, pcap, pidfile in vm_fix_pcap_pid_files:
             cmd_to_output  = 'tcpdump -nr %s %s' % (pcap, filt)
             cmd_to_kill = 'cat %s | xargs kill ' % (pidfile)
             count = cmd_to_output + '| wc -l'
             vm_fix.run_cmd_on_vm(cmds=[cmd_to_kill], as_sudo=True)
             sleep(2)
             vm_fix.run_cmd_on_vm(cmds=[cmd_to_output], as_sudo=True)
             output.append(vm_fix.return_output_cmd_dict[cmd_to_output])
             vm_fix.run_cmd_on_vm(cmds=[count], as_sudo=True)
             pkt_count_list = vm_fix.return_output_cmd_dict[count].split('\n')
             try:
                 pkts = pkt_count_list[2]
             except:
                 pkts = pkt_count_list[1]
             pkts = int(pkts)
             pkt_count.append(pkts)
             total_pkts = sum(pkt_count)
         return output, total_pkts
开发者ID:Juniper,项目名称:contrail-test,代码行数:37,代码来源:verify.py


示例18: start_tcpdump_on_intf

 def start_tcpdump_on_intf(self, host, tapintf):
     session = ssh(host["host_ip"], host["username"], host["password"])
     cmd = "tcpdump -nni %s -c 10 > /tmp/%s_out.log" % (tapintf, tapintf)
     execute_cmd(session, cmd, self.logger)
开发者ID:smurugap,项目名称:contrail-test,代码行数:4,代码来源:config.py


示例19: stop_tcpdump_for_vm_intf

def stop_tcpdump_for_vm_intf(obj, session, pcap):
    cmd = 'rm -f %s' % pcap
    execute_cmd(session, cmd, obj.logger)
    cmd = 'kill $(ps -ef|grep tcpdump | grep pcap| awk \'{print $2}\')'
    execute_cmd(session, cmd, obj.logger)
    return True
开发者ID:smurugap,项目名称:contrail-test,代码行数:6,代码来源:tcpdump_utils.py


示例20: verify_flow_thru_si

    def verify_flow_thru_si(self, si_fix, src_vn=None):
        self.logger.info(
            'Will start a tcpdump on the left-interfaces of the Service Instances to find out which flow is entering which Service Instance')
        flowcount = 0
        result = True
        flow_pattern = {}
        svms = self.get_svms_in_si(si_fix, self.inputs.project_name)
        svms = sorted(set(svms))
        if None in svms:
            svms.remove(None)
        for svm in svms:
            self.logger.info('SVM %s is in %s state' % (svm.name, svm.status))
            if svm.status == 'ACTIVE':
                svm_name = svm.name
                host = self.get_svm_compute(svm_name)
                if src_vn is not None:
                    tapintf = self.get_svm_tapintf_of_vn(svm_name, src_vn)
                else:
                    direction = 'left'
                    tapintf = self.get_bridge_svm_tapintf(svm_name, direction)
                session = ssh(
                    host['host_ip'], host['username'], host['password'])
                cmd = 'tcpdump -nni %s -c 10 > /tmp/%s_out.log' % (
                    tapintf, tapintf)
                execute_cmd(session, cmd, self.logger)
            else:
                self.logger.info('%s is not in ACTIVE state' % svm.name)
        sleep(15)

        self.logger.info('%%%%% Will check the result of tcpdump %%%%%')
        svms = self.get_svms_in_si(si_fix, self.inputs.project_name)
        svms = sorted(set(svms))
        if None in svms:
            svms.remove(None)
        for svm in svms:
            self.logger.info('SVM %s is in %s state' % (svm.name, svm.status))
            if svm.status == 'ACTIVE':
                svm_name = svm.name
                host = self.get_svm_compute(svm_name)
                if src_vn is not None:
                    tapintf = self.get_svm_tapintf_of_vn(svm_name, src_vn)
                else:
                    direction = 'left'
                    tapintf = self.get_bridge_svm_tapintf(svm_name, direction)
                session = ssh(
                    host['host_ip'], host['username'], host['password'])
                output_cmd = 'cat /tmp/%s_out.log' % tapintf
                out, err = execute_cmd_out(session, output_cmd, self.logger)
                if '9000' in out:
                    flowcount = flowcount + 1
                    self.logger.info(
                        'Flow with dport 9000 seen flowing inside %s' % svm_name)
                    flow_pattern['9000'] = svm_name
                if '9001' in out:
                    flowcount = flowcount + 1
                    self.logger.info(
                        'Flow with dport 9001 seen flowing inside %s' % svm_name)
                    flow_pattern['9001'] = svm_name
                if '9002' in out:
                    flowcount = flowcount + 1
                    self.logger.info(
                        'Flow with dport 9002 seen flowing inside %s' % svm_name)
                    flow_pattern['9002'] = svm_name
            else:
                self.logger.info('%s is not in ACTIVE state' % svm.name)
        if flowcount > 0:
            self.logger.info(
                'Flows are distributed across the Service Instances as :')
            self.logger.info('%s' % flow_pattern)
        else:
            result = False
        assert result, 'No Flow distribution seen'
开发者ID:Juniper,项目名称:contrail-test-ci,代码行数:72,代码来源:ecmp_traffic.py



注:本文中的tcutils.commands.execute_cmd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_utils.assertEqual函数代码示例发布时间:2022-05-27
下一篇:
Python db.GroupByResult类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap