github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/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  @given(u'I wait "{seconds}" seconds')
    34  @when(u'I wait "{seconds}" seconds')
    35  @then(u'I wait "{seconds}" seconds')
    36  def step_impl(context, seconds):
    37      time.sleep(float(seconds))
    38  
    39  @given(u'we compose "{composeYamlFile}"')
    40  def compose_impl(context, composeYamlFile, projectName=None, startContainers=True):
    41      composition = compose_util.Composition(context, composeYamlFile,
    42                                             projectName=projectName,
    43                                             startContainers=startContainers)
    44      context.compose_containers = composition.containerDataList
    45      context.composition = composition
    46  
    47  @given(u'I have a bootstrapped fabric network')
    48  def step_impl(context):
    49      bootstrapped_impl(context, "solo")
    50  
    51  @given(u'I have a bootstrapped fabric network of type {networkType}')
    52  def bootstrapped_impl(context, networkType):
    53      assert networkType in ORDERER_TYPES, "Unknown network type '%s'" % networkType
    54      curpath = os.path.realpath('.')
    55      context.composeFile = "%s/docker-compose/docker-compose-%s.yml" % (curpath, networkType)
    56      assert os.path.exists(context.composeFile), "The docker compose file does not exist: {0}".format(context.composeFile)
    57      context.ordererProfile = PROFILE_TYPES.get(networkType, "SampleInsecureSolo")
    58      channelID = endorser_util.SYS_CHANNEL_ID
    59      projectName = str(uuid.uuid1()).replace('-','')
    60      config_util.generateCrypto(projectName)
    61      config_util.generateConfig(channelID, config_util.CHANNEL_PROFILE, context.ordererProfile, projectName)
    62      compose_impl(context, context.composeFile, projectName=projectName)
    63  
    64  @given(u'"{component}" is taken down')
    65  def step_impl(context, component):
    66      assert component in context.composition.collectServiceNames(), "Unknown component '{0}'".format(component)
    67      context.composition.stop([component])
    68  
    69  @given(u'"{component}" comes back up')
    70  def step_impl(context, component):
    71      assert component in context.composition.collectServiceNames(), "Unknown component '{0}'".format(component)
    72      context.composition.start([component])