Esempio n. 1
0
def getConnectedPeersFromPeer(context, thisPeer):
    response = httpGetToContainer(context, thisPeer, "/network/peers")

    if response.status_code != 200:
        return None

    return getAttributeFromJSON("peers", response.json())
Esempio n. 2
0
def step_impl(context, attribute, expectedValue):
    assert 'responses' in context, "responses not found in context"
    for resp in context.responses:
        foundValue = getAttributeFromJSON(attribute, resp.json())
        assert (formatStringToCompare(foundValue) == expectedValue
                ), "For attribute %s, expected (%s), instead found (%s)" % (
                    attribute, expectedValue, foundValue)
Esempio n. 3
0
def getToken(context):
    #if 'token' in context:
    if hasattr(context, 'token'):
        return context.token

    headers = {
        'Accept': 'application/json',
        'Content-type': 'application/json'
    }
    #if context.byon:
    #    headers = {'Accept': 'application/vnd.ibm.zaci.payload+json;version=1.0',
    #               'Content-type': 'application/vnd.ibm.zaci.payload+json;version=1.0',
    #               'zACI-API': 'com.ibm.zaci.system/1.0'}

    #url = "{0}://{1}/api/com.ibm.zaci.system/api-tokens".format(getSchema(context.tls), context.remote_ip)
    url = "https://{1}/api/com.ibm.zaci.system/api-tokens".format(
        getSchema(context.tls), context.remote_ip)
    body = {
        "kind": "request",
        "parameters": {
            "user": "******",
            "password": "******"
        }
    }
    response = httpPost(url, body, headers=headers)
    try:
        context.token = getAttributeFromJSON("parameters.token",
                                             response.json())
    except:
        bdd_log("Unable to get the token for the network at {}".format(
            context.remote_ip))
        raise Exception, "Unable to get the network token"
    return response
Esempio n. 4
0
def getConnectedPeersFromPeer(context, thisPeer):
    response = httpGetToContainer(context, thisPeer, "/network/peers")

    if response.status_code != 200:
        return None

    return getAttributeFromJSON("peers", response.json())
Esempio n. 5
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(
        attribute, context.response.json(),
        "Attribute not found in response (%s)" % (attribute))
    assert (formatStringToCompare(foundValue) == expectedValue
            ), "For attribute %s, expected (%s), instead found (%s)" % (
                attribute, expectedValue, foundValue)
Esempio n. 6
0
def step_impl(context, chaincodeName, functionName, containerAlias, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"

    resp = bdd_request_util.httpGetToContainerAlias(context, containerAlias, "/chain")
    context.chainheight = getAttributeFromJSON("height", resp.json())
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerAlias)
Esempio n. 7
0
def step_impl(context, attribute, expectedValue):
    assert 'responses' in context, "responses not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    for resp in context.responses:
        foundValue = getAttributeFromJSON(attribute, resp.json())
        assert (formatStringToCompare(foundValue) == expectedValue), "For attribute %s, expected (%s), instead found (%s)" % (attribute, expectedValue, foundValue)
Esempio n. 8
0
def step_impl(context, action, attribute):
    assert attribute in context.response.json(
    ), "Attribute not found in response ({})".format(attribute)
    foundValue = context.response.json()[attribute]
    if action == 'store':
        foundValue = getAttributeFromJSON(attribute, context.response.json())
        setattr(context, attribute, foundValue)
        bdd_log("Stored %s: %s" % (attribute, getattr(context, attribute)))
Esempio n. 9
0
def step_impl(context, attribute, expectedValue):
    assert 'responses' in context, "responses not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    for resp in context.responses:
        foundValue = getAttributeFromJSON(attribute, resp.json(), "Attribute not found in response (%s)" %(attribute))
        assert (formatStringToCompare(foundValue) == expectedValue), "For attribute %s, expected (%s), instead found (%s)" % (attribute, expectedValue, foundValue)
Esempio n. 10
0
def getConnectedPeersFromPeer(context, thisPeer):
    url = buildUrl(context, thisPeer.ipAddress, "/network/peers")
    response = requests.get(url, headers={'Accept': 'application/json'}, verify=False)

    if response.status_code != 200:
        return None

    return getAttributeFromJSON("peers", response.json(), "There should be a peer json attribute")
Esempio n. 11
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(
        attribute, context.response.json(),
        "Attribute not found in response (%s)" % (attribute))
    assert (
        len(foundValue) == int(expectedValue)
    ), "For attribute %s, expected array of size (%s), instead found (%s)" % (
        attribute, expectedValue, len(foundValue))
Esempio n. 12
0
def step_impl(context, chaincodeName, functionName, containerAlias, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"

    resp = bdd_request_util.httpGetToContainerAlias(context, containerAlias,
                                                    "/chain")
    context.chainheight = getAttributeFromJSON("height", resp.json())
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerAlias)
Esempio n. 13
0
def step_impl(context, chaincodeName, functionName, containerName, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chain")
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to get chain height %s:  %s" % (request_url,resp.text)
    context.chainheight = getAttributeFromJSON("height", resp.json(), "Height not found in response.")
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerName)
Esempio n. 14
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(attribute, context.response.json())
    if attribute == 'height':
        checkHeight(context, foundValue, expectedValue)
    else:
        errStr = "For attribute %s, expected (%s), instead found (%s)" % (
            attribute, expectedValue, foundValue)
        assert (formatStringToCompare(foundValue) == expectedValue), errStr
    # Set the new value of the attribute
    setattr(context, attribute, foundValue)
Esempio n. 15
0
def step_impl(context, chaincodeName, functionName, containerName, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chain")
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to get chain height %s:  %s" % (request_url,resp.text)
    context.chainheight = getAttributeFromJSON("height", resp.json(), "Height not found in response.")
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerName)
Esempio n. 16
0
def getConnectedPeersFromPeer(context, thisPeer):
    url = buildUrl(context, thisPeer.ipAddress, "/network/peers")
    response = requests.get(url,
                            headers={'Accept': 'application/json'},
                            verify=False)

    if response.status_code != 200:
        return None

    return getAttributeFromJSON("peers", response.json(),
                                "There should be a peer json attribute")
Esempio n. 17
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(attribute, context.response.json())
    if expectedValue == 'previous':
        prev_value = getattr(context, attribute)
        bdd_log("Stored value: {}".format(prev_value))
        errStr = "For attribute %s, expected greater than (%s), instead found (%s)" % (
            attribute, prev_value, foundValue)
        assert (foundValue > prev_value), errStr
    else:
        errStr = "For attribute %s, expected greater than (%s), instead found (%s)" % (
            attribute, expectedValue, foundValue)
        assert (formatStringToCompare(foundValue) > expectedValue), errStr
    # Set the new value of the attribute
    setattr(context, attribute, foundValue)
Esempio n. 18
0
def allTransactionsCommittedToContainersWithinTimeout(context, containers, timeout):
    maxTime = datetime.now() + timedelta(seconds=timeout)
    endpoint = "/chain"
    expectedMinHeight = int(context.chainheight) + int(context.txcount)

    allTransactionsCommitted = lambda (response): \
        getAttributeFromJSON("height", response.json()) >= expectedMinHeight

    for container in containers:
        request_url = bdd_request_util.buildContainerUrl(context, container, endpoint)
        urlFound = httpGetUntilSuccessfulOrTimeout(request_url, maxTime, allTransactionsCommitted)

        assert urlFound, "Timed out waiting for transaction to be committed to {}" \
            .format(container.name)
Esempio n. 19
0
def step_impl(context, seconds):
    assert 'chainheight' in context, "chainheight not found in context"
    assert 'txcount' in context, "txcount not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    # Set the max time before stopping attempts
    maxTime = datetime.now() + timedelta(seconds=int(seconds))
    responseStatusCodeMap = {}

    aliases = context.table.headings
    for containerAlias in aliases:
        container = context.containerAliasMap[containerAlias]
        ipAddress = container.ipAddress
        request_url = buildUrl(context, ipAddress, "/chain")

        # Loop unless failure or time exceeded
        while (datetime.now() < maxTime):
            bdd_log("GETing path = {}".format(request_url))
            resp = requests.get(request_url,
                                headers={'Accept': 'application/json'},
                                verify=False)
            if resp.status_code == 404:
                # Pause then try again
                responseStatusCodeMap[container.name] = 404
                time.sleep(1)
                continue
            elif resp.status_code == 200:
                height = getAttributeFromJSON("height", resp.json(),
                                              "Height not found in response.")
                if height >= int(context.chainheight) + int(context.txcount):
                    # Success, continue
                    responseStatusCodeMap[container.name] = 200
                    break
                else:
                    continue
            else:
                raise Exception(
                    "Error requesting {0}, returned result code = {1}".format(
                        request_url, resp.status_code))
        else:
            raise Exception(
                "Max time exceeded waiting for transactions with current response map = {0}"
                .format(respMap))
    bdd_log(
        "Result of request to all peers = {0}".format(responseStatusCodeMap))
    bdd_log("")
Esempio n. 20
0
def allTransactionsCommittedToContainersWithinTimeout(context, containers,
                                                      timeout):
    maxTime = datetime.now() + timedelta(seconds=timeout)
    endpoint = "/chain"
    expectedMinHeight = int(context.chainheight) + int(context.txcount)

    allTransactionsCommitted = lambda (response): \
        getAttributeFromJSON("height", response.json()) >= expectedMinHeight

    for container in containers:
        request_url = bdd_request_util.buildContainerUrl(
            context, container, endpoint)
        urlFound = httpGetUntilSuccessfulOrTimeout(request_url, maxTime,
                                                   allTransactionsCommitted)

        assert urlFound, "Timed out waiting for transaction to be committed to {}" \
            .format(container.name)
Esempio n. 21
0
def step_impl(context, seconds):
    assert 'chainheight' in context, "chainheight not found in context"
    assert 'txcount' in context, "txcount not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    aliases =  context.table.headings
    containerDataList = bdd_test_util.getContainerDataValuesFromContext(context, aliases, lambda containerData: containerData)

    # Build map of "containerName" : resp.statusCode
    respMap = {container.containerName:0 for container in containerDataList}

    # Set the max time before stopping attempts
    maxTime = datetime.now() + timedelta(seconds = int(seconds))
    for container in containerDataList:
        ipAddress = container.ipAddress
        request_url = buildUrl(context, ipAddress, "/chain")

        # Loop unless failure or time exceeded
        while (datetime.now() < maxTime):
            print("{0} GETing path = {1}".format(currentTime(), request_url))
            resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
            if resp.status_code == 404:
                # Pause then try again
                respMap[container.containerName] = 404
                time.sleep(1)
                continue
            elif resp.status_code == 200:
                height = getAttributeFromJSON("height", resp.json(), "Height not found in response.")
		if height >= int(context.chainheight) + int(context.txcount):
                        # Success, continue
                        respMap[container.containerName] = 200
                        break
		else:
		        continue
            else:
                raise Exception("Error requesting {0}, returned result code = {1}".format(request_url, resp.status_code))
        else:
            raise Exception("Max time exceeded waiting for transactions with current response map = {0}".format(respMap))
    print("Result of request to all peers = {0}".format(respMap))
    print("")
Esempio n. 22
0
def step_impl(context, attribute):
    getAttributeFromJSON(attribute, context.response.json(), "Attribute not found in response (%s)" %(attribute))
Esempio n. 23
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(attribute, context.response.json())
    assert (len(foundValue) == int(expectedValue)), "For attribute %s, expected array of size (%s), instead found (%s)" % (attribute, expectedValue, len(foundValue))
Esempio n. 24
0
def step_impl(context, attribute, expectedValue):
    foundValue = getAttributeFromJSON(attribute, context.response.json())
    assert (formatStringToCompare(foundValue) == expectedValue), "For attribute %s, expected (%s), instead found (%s)" % (attribute, expectedValue, foundValue)
Esempio n. 25
0
def step_impl(context, attribute):
    try:
        getAttributeFromJSON(attribute, context.response.json())
        assert None, "Attribute found in response (%s)" %(attribute)
    except AssertionError:
        bdd_log("Attribute not found as was expected.")
Esempio n. 26
0
def step_impl(context, attribute):
    getAttributeFromJSON(attribute, context.response.json())
Esempio n. 27
0
def step_impl(context, attribute):
    getAttributeFromJSON(attribute, context.response.json())
Esempio n. 28
0
def step_impl(context, attribute):
    try:
        getAttributeFromJSON(attribute, context.response.json())
        assert None, "Attribute found in response (%s)" % (attribute)
    except AssertionError:
        bdd_log("Attribute not found as was expected.")
Esempio n. 29
0
def step_impl(context, attribute, expectedValue):
    assert 'responses' in context, "responses not found in context"
    for resp in context.responses:
        foundValue = getAttributeFromJSON(attribute, resp.json(), "Attribute not found in response (%s)" %(attribute))
        assert (formatStringToCompare(foundValue) == expectedValue), "For attribute %s, expected (%s), instead found (%s)" % (attribute, expectedValue, foundValue)
Esempio n. 30
0
def step_impl(context, attribute):
    getAttributeFromJSON(attribute, context.response.json(), "Attribute not found in response (%s)" %(attribute))