示例#1
0
        def test_Server(self):
            import json
            data = [1,2,3,'a','b', {'d1':'v1'}]
            data ='abcdef,2,3,4'
            jstring = json.dumps(data)
            print('json string:', jstring)
            jdata = json.loads(jstring)



            cmd ='telnet localhost'
            attr={'TIMEOUT': 10,'LOGIN': '******','CMD':'telnet localhost', 'SUT':'', 'EXP':'login:'******'LINEEND':"u''+chr(13)"}
            sut = {'tel':attr}
        #    import CCase
            port =50101
            svr = Server('localhost', port,'Case', 'Case',{'name':'abc', 'suts':sut,  'logdir':'../log', 'caseconfigfile':'../lib/case.cfg'}, 'IsAlive')
            from Socket import SendRequest2Server
            cmd = ['ActionCheck', ['tel', 'ping localhost', '.*', 1]]
            jcmd = json.dumps(cmd)
            rsp =SendRequest2Server('localhost', port, jcmd)
            cmd =['AddClient', '127.0.0.1_41715_CASE2014-12-2513:36:38']
            jcmd = json.dumps(cmd)
            rsp =SendRequest2Server('localhost', port, jcmd)
            cmd = ['EndCase', 1]
            jcmd = json.dumps(cmd)
            rsp =SendRequest2Server('localhost', port, jcmd)

            print(rsp)

            import time
            while svr.IsHandlerAlive():

                time.sleep(1)
            svr.StopServer()
示例#2
0
        def test_Case(self):
            from common import DumpStack
            try:
                try :
                    abc='str, abc'
                    import inspect
                    print(globals())
                    print(locals())
                    trace= inspect.trace()
                    lastframe = trace[-1][0]
                    locals= repr(lastframe.f_locals).replace('\\\\', '\\')
                    globals= repr(lastframe.f_globals).replace('\\\\', '\\')
                    print(locals)
                    print(globals)
                    raise 'abc'

                except Exception as e:
                    def dumpenv(env):
                        import operator
                        d = {}
                        s=''
                        key =env.keys()
                        key = sorted(key)
                        for k in key:
                            n = k
                            o= env[k]
                            s+='\t%s: %s\n'%(repr(n),repr(o).replace('\\\\', '\\'))
                        print(s)
                        return d
                    dumpenv(locals())
                    def dump_into_ns(env,*x):
                        class A:
                            def __init__(self):
                                for n,o in env.items():
                                    vars(self).update({n: o})

                        return A(*x)


                    a = 19
                    b = 'Monday'
                    c = 'Wednesday'

                    print()
                    def ftry(x,y):
                        palat = 'obastey'
                        a = x -1
                        b = y +100
                        c = x*y -8
                        return dump_into_ns(locals(),a,b,c)


                    import sys,traceback
                    h = dump_into_ns(globals())
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    str = traceback.format_exception(exc_type, exc_value,exc_traceback)
                    str = ''.join(str)
                    str=str.replace('\n', '\n*\t')

                    trace= inspect.trace()
                    lastframe = trace[-1][0]
                    locals= repr(lastframe.f_locals).replace('\\\\', '\\')
                    globals= repr(lastframe.f_globals).replace('\\\\', '\\')
                    from common import csvstring2array
                    d =csvstring2array(locals)
                    print(d)




                cmd = 'telnet 192.168.1.112'
                attr={'TIMEOUT':180,'LOGIN': '******','CMD':cmd, 'LINEEND':u''+chr(13), 'EXP':'name:', 'SUT':'' }

                #attr={'TIMEOUT': 10,'LOGIN': '******','CMD':'telnet 192.168.1.112' 'EXP':'login:'******'LINEEND':"u''+chr(13)"}
                sut = {'tel':attr}
                tcpport =50001
                ip = '192.168.1.110'
                from Server import Server

                svr = Server(ip, tcpport,'Case', 'Case',{'name':'abc', 'suts':sut,  'logdir':'../log', 'caseconfigfile':'../lib/case.cfg'}, 'IsAlive')
                c = svr.Handler
                try :
                    raise 'abc'

                except Exception as e:
                    s =DumpStack(e)
                    print(s)
                print(c.pp('SUTs'))
                #c.ActionCheck(['telLocal','pwd','~]',10])
                c.troubleshooting()
                client='192.168.1.100_61429_CASE2014-07-1702:20:12'
                resp =c.AddClient(client)
                resp = c.RequestSUTOutput(client,"tel")
                c.ActionCheck(['tel','ping localhost','.*', 1])
                c.ActionCheck(['tel','try 3:ctrl:c','SLV1 >', 30])
                #time.sleep(10)
                #resp =c.ActionCheck(['__case__', 'RequestSUTOutput("192.168.1.100_55710_CASE2014-07-1719:42:25""'])
                #resp =c.ActionCheck(['__case__', 'RequestSUTOutput("192.168.1.100_55710_CASE2014-07-1719:42:25""'])
                #resp =c.RequestSUTOutput(client,'tel')
                #time.sleep(10)
                #resp =c.RequestSUTOutput(client,'tel')
                #    c.ActionCheck(['telLocal','SLEEP(20.0)','~]',30])
                #c.ActionCheck(['telLocal','TRY 2:pwd','no:abc',30])
                #c.ActionCheck(['telLocal','TRY 2:noaction:pwd','nowait:no:abc',30])
                #import base64
                import json
                cmd =['RequestSUTOutput', client, 'tel']
                jcmd =json.dumps(cmd)
                from CSocket import SendRequest2Server
                resp = SendRequest2Server(ip, tcpport, jcmd)
                print(resp)
                #time.sleep(2)
        #        resp = SendRequest2Server(ip, tcpport, jcmd)
                c.EndCase(True)
                svr.StopServer()
            except Exception as e:

                print(DumpStack(e))
                print(e.__str__())
                msg = traceback.format_exc()
                print(msg)
                print('!!!!!!!!!!!!!!!!!!!!!!!!!!!CASE Failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
                exit(1)

            print('!!!!!!!!!!!!!!!!!!!!!!!!!!!CASE End!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
            exit(0)