github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/test/feature/steps/basic_impl.py (about) 1 # Copyright IBM Corp. 2017 All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 from behave import * 17 import time 18 import os 19 import uuid 20 import compose_util 21 import config_util 22 import endorser_util 23 24 25 ORDERER_TYPES = ["solo", 26 "kafka", 27 "solo-msp"] 28 29 PROFILE_TYPES = {"solo": "SampleInsecureSolo", 30 "kafka": "SampleInsecureKafka", 31 "solo-msp": "SampleSingleMSPSolo"} 32 33 34 @given(u'I wait "{seconds}" seconds') 35 @when(u'I wait "{seconds}" seconds') 36 @then(u'I wait "{seconds}" seconds') 37 def step_impl(context, seconds): 38 time.sleep(float(seconds)) 39 40 @given(u'we compose "{composeYamlFile}"') 41 def compose_impl(context, composeYamlFile, projectName=None, startContainers=True): 42 composition = compose_util.Composition(context, composeYamlFile, 43 projectName=projectName, 44 startContainers=startContainers) 45 context.compose_containers = composition.containerDataList 46 context.composition = composition 47 48 @given(u'I have a bootstrapped fabric network') 49 def step_impl(context): 50 bootstrapped_impl(context, "solo") 51 52 @given(u'I have a bootstrapped fabric network of type {networkType}') 53 def bootstrapped_impl(context, networkType): 54 assert networkType in ORDERER_TYPES, "Unknown network type '%s'" % networkType 55 curpath = os.path.realpath('.') 56 context.composeFile = "%s/docker-compose/docker-compose-%s.yml" % (curpath, networkType) 57 assert os.path.exists(context.composeFile), "The docker compose file does not exist: {0}".format(context.composeFile) 58 profile = PROFILE_TYPES.get(networkType, "SampleInsecureSolo") 59 channelID = endorser_util.TEST_CHANNEL_ID 60 projectName = str(uuid.uuid1()).replace('-','') 61 config_util.generateCrypto(projectName) 62 config_util.generateConfig(channelID, profile, projectName) 63 compose_impl(context, context.composeFile, projectName=projectName) 64 65 @given(u'"{component}" is taken down') 66 def step_impl(context, component): 67 assert component in context.composition.collectServiceNames(), "Unknown component '{0}'".format(component) 68 context.composition.stop([component]) 69 70 @given(u'"{component}" comes back up') 71 def step_impl(context, component): 72 assert component in context.composition.collectServiceNames(), "Unknown component '{0}'".format(component) 73 context.composition.start([component])