Esempio n. 1
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'cloud'
    cf.delete_app(app)
Esempio n. 2
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'actuator'
    cf.delete_app(app)
    # create service
    service = 'p.mysql'
    plan = 'db-small'
    instance = 'myMySqlService'
    cf.create_service(service, plan, instance)
Esempio n. 3
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'redis-connector'
    cf.delete_app(app)
    # create service
    service = 'p-redis'
    plan = 'shared-vm'
    instance = 'myRedisService'
    cf.create_service(service, plan, instance)
Esempio n. 4
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'foo'
    cf.delete_app(app)
    # create service
    service = 'p-config-server'
    plan = 'standard'
    instance = 'myConfigServer'
    args = ['-c', './config-server.json']
    cf.create_service(service, plan, instance, args)
Esempio n. 5
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'rabbitmq-connector'
    cf.delete_app(app)
    # create service
    service = 'p-rabbitmq'
    plan = 'standard'
    instance = 'myRabbitMQService'
    cf.delete_service(instance)
    cf.create_service(service, plan, instance)
Esempio n. 6
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous app
    app = 'postgresefcore-connector'
    cf.delete_app(app)
    # create service
    service = 'postgresql-10-odb'
    plan = 'standalone'
    instance = 'myPostgres'
    args = ['-c',
            '\'{"db_name":"postgresample", "db_username":"******", "owner_name":"Steeltoe Demo", "owner_email":"*****@*****.**"}\'']
    cf.create_service(service, plan, instance, args)
Esempio n. 7
0
def setup(context, scenario):
    """
    set up scenario scaffolding for Cloud Foundry samples
    :type context: behave.runner.Context
    :type scenario: behave.model.Scenario
    """
    cf = cloudfoundry.CloudFoundry(context)

    # CloudFoundry options
    creds = [
        context.options.cf.apiurl, context.options.cf.username,
        context.options.cf.password, context.options.cf.org
    ]
    if [cred for cred in creds if cred]:
        if None in creds:
            raise Exception(
                'if setting CloudFoundry credentials, all of cf_apiurl, cf_username, cf_password, cf_org must be set'
            )
        context.env['CF_HOME'] = context.sandbox_dir
        cf.login(context.options.cf.apiurl, context.options.cf.username,
                 context.options.cf.password, context.options.cf.org,
                 'development')
    else:
        context.log.info(
            'CloudFoundry credentials not provided, assuming already logged in'
        )
    context.cf_space = context.options.cf.space
    if not context.cf_space:
        tld = re.split('/|\\\\', scenario.filename)[0]
        feature_file = os.path.basename(scenario.filename)
        context.cf_space = "{}-{}-{}".format(tld,
                                             os.path.splitext(feature_file)[0],
                                             context.platform).lower()
    context.log.info('CloudFoundry space -> {}'.format(context.cf_space))
    context.cf_domain = context.options.cf.domain
    if not context.cf_domain:
        context.cf_domain = cf.get_api_endpoint()
        context.log.info('guessing CloudFoundry domain')
        endpoint = cf.get_api_endpoint()
        context.cf_domain = urlparse(endpoint).hostname.replace(
            'api.run', 'apps')
    context.log.info('CloudFoundry domain -> {}'.format(context.cf_domain))

    # CloudFoundry sandbox
    cf.create_space(context.cf_space)
    cf.target_space(context.cf_space)
Esempio n. 8
0
def setup(context):
    """
    :type context: behave.runner.Context
    """
    cf = cloudfoundry.CloudFoundry(context)
    # remove previous apps
    cf.delete_app('single-signon')
    # cf.delete_app('uaa')
    # create UAA service and app
    if not cf.service_exists('myOAuthService'):
        credentials = '\'{{"client_id":"myTestApp", "client_secret":"myTestApp", "uri":"{}"}}\''.format(
            dns.resolve_url(context, 'uaa://uaa.x.y.z'))
        cf.create_user_provided_service('myOAuthService', credentials)
    if not cf.app_exists('uaa'):
        hostname = dns.resolve_hostname(context, 'uaa')
        domainname = dns.resolve_domainname(context, 'x.y.z')
        uaa_repo = os.path.join(context.project_dir, 'uaa')
        if os.path.exists(uaa_repo):

            def remove_readonly(func, path, excinfo):
                os.chmod(path, stat.S_IWRITE)
                func(path)

            shutil.rmtree(uaa_repo, onerror=remove_readonly)
        for cmd_s in [
                'git clone https://github.com/cloudfoundry/uaa.git',
                'git -C uaa checkout 4.7.1',
                'uaa/gradlew -p uaa -Dapp={} -Dapp-domain={} manifests -Dorg.gradle.daemon=false'
                .format(hostname, domainname),
        ]:
            Command(context, cmd_s).run()
        cf.push_app('uaa/build/sample-manifests/uaa-cf-application.yml')
        for cmd_s in [
                'uaac target {}'.format(
                    dns.resolve_url(context, 'https://uaa.x.y.z')),
                'uaac token client get admin -s adminsecret',
                'uaac contexts',
                'uaac group add testgroup',
                'uaac user add testuser --given_name Test --family_name User --emails [email protected] --password Password1!',
                'uaac member add testgroup testuser',
                'uaac client add myTestApp --scope cloud_controller.read,cloud_controller_service_permissions.read,openid,testgroup --authorized_grant_types authorization_code,refresh_token --authorities uaa.resource --redirect_uri {} --autoapprove cloud_controller.read,cloud_controller_service_permissions.read,openid,testgroup --secret myTestApp'
                .format('https://single-signon.x.y.z/signin-cloudfoundry'),
        ]:
            Command(context, cmd_s).run()