Esempio n. 1
0
def main(argv):
    inputfile = ''
    outputfile = ''
    testNum = '0'
    result = ''

    try:
        opts, args = getopt.getopt(
            argv, "hi:o:t:n:", ["ifile=", "ofile=", "testcase=", "netnode="])
    except getopt.GetoptError:
        print 'test.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'test.py -i <inputfile> -o <outputfile> -t <num>'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-t", "--testcase"):
            #testNum = int(arg)
            testNum = arg
        else:
            assert False, "unhandled option"

    #workName = raw_input('Please enter a work name:')
    res = util.setupAuthentication()

    if res != constants.OK_STR:
        sys.exit(1)

    if testNum in testCases2_ga.keys():
        print testCases2_ga[testNum][3]
        if testCases2_ga[testNum][0] == put_c:
            result = util.runRequestPUT(testCases2_ga[testNum][1],
                                        json.dumps(testCases2_ga[testNum][2]),
                                        sys._getframe().f_code.co_name)
        elif testCases2_ga[testNum][0] == post_c:
            #print json.dumps(testCases2_ga[testNum][2])
            result = util.runRequestPOST(testCases2_ga[testNum][1],
                                         json.dumps(testCases2_ga[testNum][2]),
                                         sys._getframe().f_code.co_name)
        elif testCases2_ga[testNum][0] == post_data_array_c:
            #print json.dumps(testCases2_ga[testNum][2])
            for inputData in (testCases2_ga[testNum][2]):
                result = util.runRequestPOST(testCases2_ga[testNum][1],
                                             json.dumps(inputData),
                                             sys._getframe().f_code.co_name)
        elif testCases2_ga[testNum][0] == get_c:
            result = util.runRequestGET(testCases2_ga[testNum][1],
                                        sys._getframe().f_code.co_name)
            print result
        elif testCases2_ga[testNum][0] == delete_c:
            result = util.runRequestDELETE(testCases2_ga[testNum][1],
                                           sys._getframe().f_code.co_name)
            print result
    else:
        result = testCases_ga[testNum][0](testCases_ga[testNum][1])
        print result
Esempio n. 2
0
def epMigrationDemo(desc):
    # unregister h35-3
    fabricId = "fabric:1"
    mac = "00:00:00:00:35:03"
    ip = "10.0.35.3"
    resp = util.runRequestGET(inputsFabric.get_epList_uri(),
                              sys._getframe().f_code.co_name)
    if resp == constants.ERROR_STR:
        print "ERROR: getOvsdbNodeIdByName() failed"
        return constants.ERROR_STR

    eplist = list()
    lswId = ''
    lport = ''
    endpointResp = json.loads(resp)
    if endpointResp.has_key("endpoints"):
        endpoints = endpointResp["endpoints"]
        if endpoints.has_key("endpoint"):
            for endpoint in endpoints["endpoint"]:
                if endpoint["ip-address"] == ip:
                    eplist.append(endpoint["endpoint-uuid"])
                    logicLocation = endpoint["logic-location"]
                    lswId = logicLocation["node-id"]
                    lport = logicLocation["tp-id"]
                    break

    result = util.runRequestPOST(
        inputsFabric.get_unregister_endpoint_uri(),
        json.dumps(
            inputsFabric.get_unregister_endpoint_data("fabric:1", eplist)),
        sys._getframe().f_code.co_name)

    # register h35-4
    fabricId = "fabric:1"
    mac = "00:00:00:00:35:04"
    ip = "10.0.35.4"
    gw = "10.0.35.1"
    port = "vethl-h35-4"
    nodeid = util.getOvsdbNodeIdByName("sw6")
    nodeRef = BRIDGE_REF_P % (nodeid)
    tpRef = TP_REF_P % (nodeid, port)

    if nodeid == constants.ERROR_STR:
        return constants.ERROR_STR

    result = util.runRequestPOST(
        inputsFabric.get_register_endpoint_uri(),
        json.dumps(
            inputsFabric.get_register_endpoint_data(fabricId, mac, ip, gw,
                                                    lswId, lport, nodeRef,
                                                    tpRef)),
        sys._getframe().f_code.co_name)

    return desc
Esempio n. 3
0
def main(argv):
  inputfile = ''
  outputfile = ''
  testNum = '0'
  result = ''

  try:
      opts, args = getopt.getopt(argv,"hi:o:t:n:",["ifile=","ofile=","testcase=", "netnode="])
  except getopt.GetoptError:
    print 'test.py -i <inputfile> -o <outputfile>'
    sys.exit(2)
  for opt, arg in opts:
    if opt == '-h':
      print 'test.py -i <inputfile> -o <outputfile> -t <num>'
      sys.exit()
    elif opt in ("-i", "--ifile"):
      inputfile = arg
    elif opt in ("-o", "--ofile"):
      outputfile = arg
    elif opt in ("-t", "--testcase"):
      #testNum = int(arg)
      testNum = arg
    else:
      assert False, "unhandled option"

  #workName = raw_input('Please enter a work name:')
  res = util.setupAuthentication()

  if res != constants.OK_STR:
    sys.exit(1)

  if testNum in testCases2_ga.keys():
    print testCases2_ga[testNum][3]
    if testCases2_ga[testNum][0] == put_c:
      result = util.runRequestPUT(testCases2_ga[testNum][1], json.dumps(testCases2_ga[testNum][2]), sys._getframe().f_code.co_name) 
    elif testCases2_ga[testNum][0] == post_c:
      #print json.dumps(testCases2_ga[testNum][2])
      result = util.runRequestPOST(testCases2_ga[testNum][1], json.dumps(testCases2_ga[testNum][2]), sys._getframe().f_code.co_name) 
    elif testCases2_ga[testNum][0] == post_data_array_c:
      #print json.dumps(testCases2_ga[testNum][2])
      for inputData in (testCases2_ga[testNum][2]):
        result = util.runRequestPOST(testCases2_ga[testNum][1], json.dumps(inputData), sys._getframe().f_code.co_name) 
    elif testCases2_ga[testNum][0] == get_c:
      result = util.runRequestGET(testCases2_ga[testNum][1], sys._getframe().f_code.co_name) 
      print result
    elif testCases2_ga[testNum][0] == delete_c:
      result = util.runRequestDELETE(testCases2_ga[testNum][1], sys._getframe().f_code.co_name) 
      print result
  else:
    result = testCases_ga[testNum][0](testCases_ga[testNum][1]) 
    print result
Esempio n. 4
0
def epMigrationDemo(desc):
   # unregister h35-3
   fabricId = "fabric:1" 
   mac = "00:00:00:00:35:03" 
   ip = "10.0.35.3"
   resp = util.runRequestGET(inputsFabric.get_epList_uri(), sys._getframe().f_code.co_name)
   if resp == constants.ERROR_STR:
      print "ERROR: getOvsdbNodeIdByName() failed"
      return constants.ERROR_STR
  
   eplist = list()
   lswId = ''
   lport = ''
   endpointResp=json.loads(resp)
   if endpointResp.has_key("endpoints"):
      endpoints = endpointResp["endpoints"]
      if endpoints.has_key("endpoint"):
         for endpoint in endpoints["endpoint"]:
            if endpoint["ip-address"] == ip:
               eplist.append(endpoint["endpoint-uuid"])
               logicLocation = endpoint["logic-location"]
               lswId = logicLocation["node-id"]
               lport = logicLocation["tp-id"]
               break

   result = util.runRequestPOST(inputsFabric.get_unregister_endpoint_uri(), json.dumps(inputsFabric.get_unregister_endpoint_data("fabric:1", eplist)), sys._getframe().f_code.co_name)

   # register h35-4
   fabricId = "fabric:1"
   mac = "00:00:00:00:35:04"
   ip = "10.0.35.4"
   gw = "10.0.35.1"
   port = "vethl-h35-4"
   nodeid = util.getOvsdbNodeIdByName("sw6")
   nodeRef = BRIDGE_REF_P % (nodeid)
   tpRef = TP_REF_P % (nodeid, port)

   if nodeid == constants.ERROR_STR:
      return constants.ERROR_STR

   result = util.runRequestPOST(inputsFabric.get_register_endpoint_uri(), json.dumps(inputsFabric.get_register_endpoint_data(fabricId, mac, ip, gw, lswId, lport, nodeRef, tpRef)), sys._getframe().f_code.co_name) 

   return desc