Python server性能测试 - REST request 模拟器 - 多线程并发

#! /usr/bin/python
#-*- coding: utf-8 -*-
#FileName: NotificationSimu.py
from BaseModule import BaseSimu
import urllib
import httplib
import base64
import json
import string
import ConfigParser
import multiprocessing
import uuid
import time
from datetime import datetime
import tmslog
import threading
import Queue
import sys

CFG_DATA = "test_cfg.txt"
DEVICES_DATA = "view_devices.txt"
SIMU_LOG = 'mdmi_simu_log.txt'
TEST_DATA = ConfigParser.ConfigParser()
TEST_DATA.read(CFG_DATA)

class NotificationSimu(BaseSimu):
    def __init__(self, flag=0, acct_index=0, url_tab=()):
        BaseSimu.__init__(self)
        auth_list = []
        auth = self._init_auth_str(self.username, self.password)
        auth_list.append(auth)
        auth = self._init_auth_str(self.username2, self.password)
        auth_list.append(auth)
        auth = self._init_auth_str(self.username3, self.password)
        auth_list.append(auth)
        auth = self._init_auth_str(self.username4, self.password)
        auth_list.append(auth)
        auth = self._init_auth_str(self.username, self.wrongpassword)
        auth_list.append(auth)
        self.auth_str_tab = tuple(auth_list)
        self.install_url_tab = url_tab
        pass
    
    def _init_auth_str(self, username, password):
        auth = base64.b64encode(username + ':' + password)
        auth = ' '.join(['Basic', auth])
        return auth
        pass

    def rest_removeprofile(self):
        """
        this method is used for simulating air-watch call to remove device profile to REST Service
        """
        params = {
                "RequestID": "123456789abcdef",
                "User": {
                      "Email": "xwang@websense.com"
                    },
                "Device": {
                      "Udid": "4B6D5E40DFB22BD57EC4AF54DA1F297A3221388B"
                    }
                }       

        ns_url = TEST_DATA.get("Notification Server", "REST_RemoveProfile")
        response = self.execute_request('POST', ns_url, params, 0, 0)
        print response
        return response

    def rest_removeprofile_406(self):
        """
        this method is used for simulating air-watch call to remove device profile to REST Service
        """
        params = {
                "RequestID": "123456789abcdef",
                "User": {
                      "Email": "xwang@websense.com"
                    },
                "Device": {
                      "Udid": "4B6D5E40DFB22BD57EC4AF54DA1F297A3221388B"
                    }
                }       

        ns_url = TEST_DATA.get("Notification Server", "REST_RemoveProfile")
        response = self.execute_request('POST', ns_url, params, 1, 0)
        print response
        return response

    def rest_removeprofile_401(self):
        """
        this method is used for simulating air-watch call to remove device profile to REST Service
        """
        params = {
                "RequestID": "123456789abcdef",
                "User": {
                      "Email": "xwang@websense.com"
                    },
                "Device": {
                      "Udid": "4B6D5E40DFB22BD57EC4AF54DA1F297A3221388B"
                    }
                }       

        ns_url = TEST_DATA.get("Notification Server", "REST_RemoveProfile")
        response = self.execute_request('POST', ns_url, params, 0, 1)
        print response
        return response

    def update_params(self, device, params, acct_index):
        """
        this method is used to update the params payload with the device info.
        """
        device = device.split()
        print "%s - Account:%d " % (device, acct_index)
        request_id = base64.b64encode(uuid.uuid4().get_bytes())
        callback_url = "http://10.230.48.19:80/cgi-py/installvpn.py?requestid=%s" % request_id
        params['RequestID']
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值