github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/bddtests/steps/peer_logging_impl.py (about) 1 # 2 # Copyright IBM Corp. 2016 All Rights Reserved. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 import os 18 import os.path 19 import re 20 import time 21 import copy 22 from datetime import datetime, timedelta 23 from behave import * 24 25 import sys, requests, json 26 27 import bdd_test_util 28 29 @then(u'I wait up to {waitTime} seconds for an error in the logs for peer {peerName}') 30 def step_impl(context, waitTime, peerName): 31 timeout = time.time() + float(waitTime) 32 hasError = False 33 34 while timeout > time.time(): 35 stdout, stderr = getPeerLogs(context, peerName) 36 hasError = logHasError(stdout) or logHasError(stderr) 37 38 if hasError: 39 break 40 41 time.sleep(1.0) 42 43 assert hasError is True 44 45 def getPeerLogs(context, peerName): 46 fullContainerName = bdd_test_util.fullNameFromContainerNamePart(peerName, context.compose_containers) 47 stdout, stderr, retcode = bdd_test_util.cli_call(["docker", "logs", fullContainerName], expect_success=True) 48 49 return stdout, stderr 50 51 def logHasError(logText): 52 # This seems to be an acceptable heuristic for detecting errors 53 return logText.find("-> ERRO") >= 0 54 55 @then(u'ensure after {waitTime} seconds there are no errors in the logs for peer {peerName}') 56 def step_impl(context, waitTime, peerName): 57 time.sleep(float(waitTime)) 58 stdout, stderr = getPeerLogs(context, peerName) 59 60 assert logHasError(stdout) is False 61 assert logHasError(stderr) is False