def _establishCalls(self, sip1_ip, sip2_ip, client1, client2, listen_testscript, invite_testscript, invite_csv, rtp=True):
        import pdb;pdb.set_trace()
        result_details = {}
        result_details['id'] = users
        if rtp:
            result_details['name'] = "Call test with RTP"
        else:
            result_details['name'] = "Call test without RTP"
        result_details['description'] = "Tests the IMS setup by making calls"
        result_details['category'] = self.test_type

        listen_cmd = self._generate_send_command(sip2_ip, listen_testscript)
        listen_result, err = utils.exec_command(listen_cmd, client2)
        time.sleep(50)
        invite_cmd = self._generate_invite_command(sip1_ip, invite_csv, invite_testscript)
        invite_result, err = utils.exec_command(invite_cmd, client1)

        #Analyze the invite and listen result
        invite_result = self._analyze_log(client1, invite_result, "invite", rtp=True)
        listen_result = self.analyze_log(client1, listen_result, "listen", rtp=True)

        if self.test_type == "Performance":
            success_rate = load * 0.95
        else:
            success_rate = load

        if int(invite_result['SuccessfulCall(C)']) >= success_rate:
            result_details['status'] = "PASSED"
        else:
            result_details['status'] = "FAILED"
        result_details['call_rate'] = invite_result['CallRate(C)']
        result_details['successful_calls'] = invite_result['SuccessfulCall(C)']
        result_details['failed_calls'] = invite_result['FailedCall(C)']
        except:
Exemple #2
0
    def __exec_sip_calls__(self, **kwargs):
        self._init_args(**kwargs)
        tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
        remote_dir_path = '/home/'+self.tvmc_username+'/testframework_tmp'

        tvmc_ftp.mkd(remote_dir_path)

        files_list = [self.tvm_config_file, self.caller_list, self.callee_list, self.perl_script]
        file_names = dict(zip(['config_file', 'caller_list', 'callee_list', 'perl_script'],[x.split('/')[-1] for x in files_list]))
        for fil in files_list:
            tvmc_ftp.cwd(remote_dir_path)
            tvmc_ftp.storbinary('STOR '+fil.split('/')[-1], open(fil, 'rb'))
        tvmc_ftp.quit()

        import pdb;pdb.set_trace()
        #time.sleep(180)
        tvmc_client = utils.get_ssh_conn(self.tvmc_host, self.tvmc_username, self.tvmc_password)
        interfaces = tvmutils.get_interfaces(tvmc_client)
        while len(interfaces) != num_of_test_clients():
            interfaces = tvmutils.get_interfaces(tvmc_client)
        #output, err = utils.exec_command("cli listInterfaces| tail --lines=+2 | awk '{print $1}'", client=tvmc_client)
        #interfaces = output.rstrip('\n').split('\n')
        

        import pdb;pdb.set_trace()
        cmd_perl = "perl "+remote_dir_path+'/'+file_names['perl_script']+" --config "+remote_dir_path+'/'+file_names['config_file']+' --calleelist '+remote_dir_path+'/'+file_names['callee_list']+' --callerlist '+remote_dir_path+'/'+file_names['caller_list']
        for interface_num in range(0, len(interfaces)):
            cmd_perl = cmd_perl + ' --interface '+interfaces[interface_num]
        cmd_perl = cmd_perl+"> voip_onecall.xml"
      
        cmds = [cmd_perl, "cli importTestGroup \"//\" voip_onecall.xml", "cli startTestGroup "+self.test_group, "cli listHosts|awk '{print $1, $3}'", "cli listApplications "+self.test_group+"|awk '{print $1, $3}'", "cli saveTestGroupCurrentDetailedResults "+self.test_group+" "+remote_dir_path+"/"+result_filename, "cli stopTestGroup "+self.test_group, "cli deleteTestGroup "+self.test_group]
        for cmd in cmds:
            import pdb;pdb.set_trace()
            output, err = utils.exec_command(cmd, client=tvmc_client)
            if 'awk' in cmd:
                 for line in output.rstrip().split('\n')[1:]:
                     if line.split()[1] != "Active":
                         print "Error"
                         #self.logger.warn("Error: %s not configured!!", line.split()[0])
            elif 'save' in cmd:
                 tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
                 tvmc_ftp.cwd(remote_dir_path)
                 tvmc_ftp.retrbinary('RETR '+remote_dir_path+'/'+result_filename, open(self.local_path+'/'+self.result_filename, 'wb').write)
                 tvmc_ftp.quit()
            elif 'stop' in cmd:
                 tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
                 tvmc_ftp.cwd(remote_dir_path)
		 for fil in tvmc_ftp.nlst():
                     tvmc_ftp.delete(fil)
                 tvmc_ftp.cwd('/home/'+self.tvmc_username)
                 tvmc_ftp.rmd(remote_dir_path)
                 tvmc_ftp.quit()
            elif 'start' in cmd:
                 time.sleep(100)    
            else:
                pass
Exemple #3
0
    def __exec_sip_calls__(self, **kwargs):
        self._init_args(**kwargs)
        tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
        remote_dir_path = '/home/'+self.tvmc_username+'/testframework_tmp'
        result_filename = "tvm_results_"+time.strftime("%Y%m%d-%H%M%S")+".zip"

        tvmc_ftp.mkd(remote_dir_path)

        files_list = [self.tvm_config_file, self.caller_list, self.callee_list, self.perl_script]
        file_names = dict(zip(['config_file', 'caller_list', 'callee_list', 'perl_script'],[x.split('/')[-1] for x in files_list]))
        for fil in files_list:
            tvmc_ftp.cwd(remote_dir_path)
            tvmc_ftp.storbinary('STOR '+fil.split('/')[-1], open(fil, 'rb'))
        tvmc_ftp.quit()

        tvmc_client = utils.get_ssh_conn(self.tvmc_host, self.tvmc_username, self.tvmc_password)
        interfaces = tvmutils.get_interfaces(tvmc_client)
        while len(interfaces) != 2:
            interfaces = tvmutils.get_interfaces(tvmc_client)

        cmd_perl = "perl "+remote_dir_path+'/'+file_names['perl_script']+" --config "+remote_dir_path+'/'+file_names['config_file']+' --calleelist '+remote_dir_path+'/'+file_names['callee_list']+' --callerlist '+remote_dir_path+'/'+file_names['caller_list']
        for interface_num in range(0, len(interfaces)):
            cmd_perl = cmd_perl + ' --interface '+interfaces[interface_num]
        cmd_perl = cmd_perl+"> voip_onecall.xml"
      
        cmds = [cmd_perl, "cli importTestGroup \"//\" voip_onecall.xml", "cli startTestGroup "+self.test_group, "cli saveTestGroupCurrentDetailedResults "+self.test_group+" "+remote_dir_path+"/"+result_filename, "cli stopTestGroup "+self.test_group, "cli deleteTestGroup "+self.test_group]
        for cmd in cmds:
            try:
                output, err = utils.exec_command(cmd, client=tvmc_client)
            except:
                pass
            if 'awk' in cmd:
                 for line in output.rstrip().split('\n')[1:]:
                     if line.split()[1] != "Active":
                         print "Error"
                         #self.logger.warn("Error: %s not configured!!", line.split()[0])
            elif 'save' in cmd:
                 tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
                 tvmc_ftp.cwd(remote_dir_path)
                 tvmc_ftp.retrbinary('RETR '+remote_dir_path+'/'+result_filename, open(self.local_path+'/'+result_filename, 'wb').write)
                 tvmc_ftp.quit()
            elif 'stop' in cmd:
                 tvmc_ftp = FTP(self.tvmc_host, self.tvmc_username, self.tvmc_password)
                 tvmc_ftp.cwd(remote_dir_path)
		 for fil in tvmc_ftp.nlst():
                     tvmc_ftp.delete(fil)
                 tvmc_ftp.cwd('/home/'+self.tvmc_username)
                 tvmc_ftp.rmd(remote_dir_path)
                 tvmc_ftp.quit()
            elif 'start' in cmd:
                 time.sleep(120)
            else:
                pass
        return self.__analyze_logs__(result_filename)
Exemple #4
0
def get_interfaces(client):
    retries = 0
    interface_set = True
    while interface_set:
        try:
            output, err = utils.exec_command("cli listInterfaces| tail --lines=+2 | awk '{print $1}'", client=client)
        except exception.TypeError:
            retries = retries + 1
            if retries > schema.MAX_RETRIES:
               break
        if output:
            interfaces = output.rstrip('\n').split('\n')
        return interfaces
 def _register_users(self, sip_ip, client, rtp=False, caller=False):
     if caller:
         user_file, invite_file = self._generate_users(client, rtp, caller)
     else:
         user_file = self._generate_users(client, rtp, caller)
     try:
         reg_cmd = self._generate_register_cmd(user_file, sip_ip)
         result, error = utils.exec_command(reg_cmd, client)
         time.sleep(30)
         self._base = self._base + self.users
         self._analyze_log(client, result, "register")
         if caller:
             return invite_file
     except:
         logger.debug("Unable to register users.")
         return ""
Exemple #6
0
def share_received_like(request):
    '''
    后台生成分享的图片
    '''
    import os
    from django.conf import settings

    result = {'flag': -1, 'result': '操作失败'}

    # 拼装获取指定用户赞的页面url
    url = "%s://%s/message/show_received_like?user_id=%s" % (
        request.META['wsgi.url_scheme'],
        'wwwinside.zhixuan.com',
        # request.META['HTTP_HOST'],
        request.user.id
    )

    # 定义生成临时图片位置
    file_name = '%s/static_local/temp_share/capty_%s.png' % (os.path.dirname(settings.SITE_ROOT), utils.uuid_without_dash())
    temp = None

    try:
        # 调用子程序 生成图片
        #cmd = 'python %s/common/capty.py %s %s' % (os.path.dirname(settings.SITE_ROOT), url, file_name)
        #cmd = 'python %s/common/_webkit2png.py -x 1366 768 -g 1366 0 -o %s %s' % (os.path.dirname(settings.SITE_ROOT), file_name, url)
        cmd = '/opt/python2.7.2/bin/python2.7 %s/common/_webkit2png.py -x 1366 768 -g 1366 0 -o %s %s' % (os.path.dirname(settings.SITE_ROOT), file_name, url)
        flag, msg = utils.exec_command(cmd, 20)
        logging.error(u'cmd is:\n%s\n msg is:%s' % (cmd, msg))
        if not flag:
            result = {'flag': -1, 'result': u'服务器响应超时, 请重试'}
        else:
            # 读取临时文件上传到七牛
            temp = open(file_name, 'rb')
            flag, img_name = qiniu_client.upload_img(temp)
            if flag:
                result = {'flag': 0, 'result': '%s/%s' % (settings.IMG0_DOMAIN, img_name.split('!')[0])}
            else:
                result = {'flag': -1, 'result': u'分享失败, 请重试'}
    except Exception, e:
        logging.error(debug.get_debug_detail(e))
        result = {'flag': -1, 'result': u'分享失败, 请重试'}
    def _generate_users(self, client, rtp=False, caller=False):
        import pdb;pdb.set_trace()
        """ Generated SIP users with IMS """
        if rtp:
            file_name = "register_rtp_"+self.users
        else:
            file_name = "register_no_rtp_"+self.users

        cmd = "python /home/tcs/scripts/EllisClient.py --ellis_ip " + self.ellis + " --call_count " + \
               str(self.users) + " --base_number " + str(self._base) + " --file_name " + file_name

        if caller:
             cmd += " --caller"
        try: 
            result, error = utils.exec_command(cmd, client)
        except:
            logger.debug("Unable to generate sip users.")

        #Get remote path from the config file.
        if caller:
            return self.sipp_cfg['remote_files_path']+'/'+file_name+'.csv', self.sipp_cfg['remote_files_path'] + \
                   "/invite_without_rtp_" + str(self.users) + ".csv"
        else:
            return self.sipp_cfg['remote_files_path']+'/'+file_name+'.csv'
    def run(self, execore):
        execore.set_report_title("TeraVM VOIP Execution with Clearwater IMS.")
        args = {'network': 'mgmt-if', 'subnet_name': 'mgmt-sub', 'cidr': '192.168.10.0/24'}
        mgmt_nw_id = execore.createNetwork(**args)
        args = {'network': 'ims-private', 'subnet_name': 'private-sub', 'cidr': '192.168.11.0/24'}
        private_nw_id = execore.createNetwork(**args)
        args = {'router_name': 'Router', 'external_network_name': 'public'}
        router_id = execore.createRouter(**args)

        ims_templateID = execore.onBoard('ims','/home/tcs/templates/Ims/zip/ims.zip')
        #ims_templateID = execore.onBoard('ims','/home/openstack/urvika/templates/Ims/zip/ims.zip')

        csObj = execore.createServiceRequestObject(router='Router', networks= {'mgmt-if': mgmt_nw_id, 'private': private_nw_id})
        csObj['name'] = 'Ims'
        csObj['qos'] = 'Silver'
        #TOCHK: Is Template ID required for create service??
        ims_srv = execore.createService(ims_templateID,**csObj)
        import pdb;pdb.set_trace()
        sip_external_proxy = utils.getVduParameter(ims_srv['vdus']['Ims']['vBono'][0], 'pkt-in')
        ellis_ip = utils.getVduParameter(ims_srv['vdus']['Ims']['vEllis'][0], 'mgmt-ip')
        import pdb;pdb.set_trace()
        tstCore = execore.initTest('tvm')

        import pdb;pdb.set_trace()
        tvm_ctl = tstCore.__dict__['tvmc_host']
        tvmc_username = tstCore.__dict__['tvmc_username']
        tvmc_password = tstCore.__dict__['tvmc_password']
        users = 5
        base = 6505550000
        sip1_ip = tstCore.__dict__['sip1_ip']
        sip2_ip = tstCore.__dict__['sip2_ip']
        gateway_ip = tstCore.__dict__['gateway_ip']
        file_name = "servers"
        fb = open(execore.sessionDir+'/'+file_name+'.ini', 'wb')
        test_group = "VoIPTest"
        fb.write("TestGroup_Name:"+test_group+"\nTVM1:"+sip1_ip+"/24\nTVM2:"+sip2_ip+"/24\nGateway_IP:"+gateway_ip+"\nSIPProxy_IP:"+sip_external_proxy);
        fb.close()
        cmd = "python /home/tcs/tvm_code/EllisClient.py --ellis_ip " + ellis_ip + " --call_count " + \
              str(users) + " --base_number " + base + "--Dir_path "+execore.sessionDir
        result, error = utils.exec_command(cmd)
        args1 = {}
        args1['tvmc_host'] = tvm_ctl
        args1['tvmc_username'] = tvmc_username
        args1['tvmc_password'] = tvmc_password
        args1['tvm_config_file'] = execore.sessionDir+'/'+file_name+'.ini'
        args1['caller_list'] = execore.sessionDir+'/callerlist.ini'
        args1['callee_list'] = execore.sessionDir+'/calleelist.ini'
        args1['test_group'] = test_group
        import pdb;pdb.set_trace()
        tstCore.execute('TEST_SIP_CALLS', **args1)

        base = base + users
        users = 10
        cmd = "python /home/tcs/tvm_code/EllisClient.py --ellis_ip " + ellis_ip + " --call_count " + \
              str(users) + " --base_number " + base + "--Dir_path "+execore.sessionDir
        result, error = utils.exec_command(cmd)
        tstCore.execute('TEST_SIP_CALLS', **args1)

        base = base + users
        users = 20
        cmd = "python /home/tcs/tvm_code/EllisClient.py --ellis_ip " + ellis_ip + " --call_count " + \
              str(users) + " --base_number " + base + "--Dir_path "+execore.sessionDir
        result, error = utils.exec_command(cmd)
        tstCore.execute('TEST_SIP_CALLS', **args1)

        base = base + users
        users = 50
        cmd = "python /home/tcs/tvm_code/EllisClient.py --ellis_ip " + ellis_ip + " --call_count " + \
              str(users) + " --base_number " + base + "--Dir_path "+execore.sessionDir
        result, error = utils.exec_command(cmd)
        tstCore.execute('TEST_SIP_CALLS', **args1)

        base = base + users
        users = 100
        cmd = "python /home/tcs/tvm_code/EllisClient.py --ellis_ip " + ellis_ip + " --call_count " + \
              str(users) + " --base_number " + base + "--Dir_path "+execore.sessionDir
        result, error = utils.exec_command(cmd)
        tstCore.execute('TEST_SIP_CALLS', **args1)

        
        #flavor_args = {'vcpus':'10','disk':'2048','name':'symphony','ram':'1024'}
        #import pdb;pdb.set_trace()
        #execore.createFlavor(**flavor_args)
        #execore.deleteTemplate(templateID)
        pass
 def _register_users(self, sip_ip, client, rtp=False, caller=False):
     user_file = self._generate_users(client, rtp, caller)
     reg_cmd = self._generate_register_cmd(user_file, sip_ip)
     result, error = utils.exec_command(reg_cmd, client)
     time.sleep(30)
     self._base = self._base + self.call_count