Support using shell's cf target

This commit is contained in:
Chris Cheetham 2017-11-17 18:54:36 -05:00
Родитель 4761b8b940
Коммит ddc7c65d67
17 изменённых файлов: 73 добавлений и 73 удалений

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: CloudFoundry Configuration Samples
In order to show you how to use Steeltoe for CloudFoundry configurations
You can run some CloudFoundry configuration samples
@ -6,7 +7,6 @@ Feature: CloudFoundry Configuration Samples
@win10-x64
Scenario: CloudFoundry Configuration Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
When you run: dotnet restore --configfile nuget.config
And you run: dotnet publish -f netcoreapp2.0 -r win10-x64
And you run in the background: cf push -f manifest-windows.yml -p bin/Debug/netcoreapp2.0/win10-x64/publish -s windows2012R2
@ -18,7 +18,6 @@ Feature: CloudFoundry Configuration Samples
@ubuntu.14.04-x64
Scenario: CloudFoundry Configuration Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
When you run: dotnet restore --configfile nuget.config
And you run: dotnet publish -f netcoreapp2.0 -r ubuntu.14.04-x64
And you run in the background: cf push -f manifest.yml -p bin/Debug/netcoreapp2.0/ubuntu.14.04-x64/publish
@ -30,7 +29,6 @@ Feature: CloudFoundry Configuration Samples
@win10-x64
Scenario: CloudFoundry Configuration Sample for .Net Framework 4.6.1 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
When you run: dotnet restore --configfile nuget.config
And you run: dotnet publish -f net461 -r win10-x64
And you run in the background: cf push -f manifest-windows.yml -p bin/Debug/net461/win10-x64/publish -s windows2012R2

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: Simple CloudFoundry Configuration Samples
In order to show you how to use Steeltoe for simple CloudFoundry configurations
You can run some simple CloudFoundry configuration samples
@ -6,7 +7,6 @@ Feature: Simple CloudFoundry Configuration Samples
@win10-x64
Scenario: Simple CloudFoundry Configuration Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-config-server installed
When you run: cf create-service p-config-server standard myConfigServer -c ./config-server.json
And you wait until CloudFoundry service myConfigServer is created
@ -21,7 +21,6 @@ Feature: Simple CloudFoundry Configuration Samples
@ubuntu.14.04-x64
Scenario: Simple CloudFoundry Configuration Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-config-server installed
When you run: cf create-service p-config-server standard myConfigServer -c ./config-server.json
And you wait until CloudFoundry service myConfigServer is created
@ -36,7 +35,6 @@ Feature: Simple CloudFoundry Configuration Samples
@win10-x64
Scenario: Simple CloudFoundry Configuration Sample for .Net Framework 4.6.1 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-config-server installed
When you run: cf create-service p-config-server standard myConfigServer -c ./config-server.json
And you wait until CloudFoundry service myConfigServer is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: MySql Connector Samples
In order to show you how to use Steeltoe for connecting to MySql
You can run some MySql connection samples
@ -6,7 +7,6 @@ Feature: MySql Connector Samples
@win10-x64
Scenario: MySql Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-mysql installed
When you run: cf create-service p-mysql 100mb myMySqlService
And you wait until CloudFoundry service myMySqlService is created
@ -22,7 +22,6 @@ Feature: MySql Connector Samples
@ubuntu.14.04-x64
Scenario: MySql Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-mysql installed
When you run: cf create-service p-mysql 100mb myMySqlService
And you wait until CloudFoundry service myMySqlService is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: MySqlEF6 Connector Samples
In order to show you how to use Steeltoe for connecting to MySql using EntityFramework 6
You can run some MySql using EntityFramework 6 connection samples
@ -6,7 +7,6 @@ Feature: MySqlEF6 Connector Samples
@win10-x64
Scenario: MySqlEF6 Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-mysql installed
When you run: cf create-service p-mysql 100mb myMySqlService
And you wait until CloudFoundry service myMySqlService is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: MySqlEFCore Connector Samples
In order to show you how to use Steeltoe for connecting to MySql using EntityFramework Core
You can run some MySql using EntityFramework Core connection samples
@ -6,7 +7,6 @@ Feature: MySqlEFCore Connector Samples
@win10-x64
Scenario: MySqlEFCore Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-mysql installed
When you run: cf create-service p-mysql 100mb myMySqlService
And you wait until CloudFoundry service myMySqlService is created
@ -22,7 +22,6 @@ Feature: MySqlEFCore Connector Samples
@ubuntu.14.04-x64
Scenario: MySqlEFCore Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-mysql installed
When you run: cf create-service p-mysql 100mb myMySqlService
And you wait until CloudFoundry service myMySqlService is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: PostgreEFCore Connector Samples
In order to show you how to use Steeltoe for connecting to PostgreSql using EntityFramework Core
You can run some PostgreSql using EntityFramework Core connection samples
@ -6,7 +7,6 @@ Feature: PostgreEFCore Connector Samples
@win10-x64
Scenario: PostgreEFCore Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service EDB-Shared-PostgreSQL installed
When you run: cf create-service EDB-Shared-PostgreSQL "Basic PostgreSQL Plan" myPostgres
And you wait until CloudFoundry service myPostgres is created
@ -22,7 +22,6 @@ Feature: PostgreEFCore Connector Samples
@ubuntu.14.04-x64
Scenario: PostgreEFCore Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service EDB-Shared-PostgreSQL installed
When you run: cf create-service EDB-Shared-PostgreSQL "Basic PostgreSQL Plan" myPostgres
And you wait until CloudFoundry service myPostgres is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: PostgreSql Connector Samples
In order to show you how to use Steeltoe for connecting to PostgreSql
You can run some PostgreSql connection samples
@ -6,7 +7,6 @@ Feature: PostgreSql Connector Samples
@win10-x64
Scenario: PostgreSql Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service EDB-Shared-PostgreSQL installed
When you run: cf create-service EDB-Shared-PostgreSQL "Basic PostgreSQL Plan" myPostgres
And you wait until CloudFoundry service myPostgres is created
@ -22,7 +22,6 @@ Feature: PostgreSql Connector Samples
@ubuntu.14.04-x64
Scenario: PostgreSql Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service EDB-Shared-PostgreSQL installed
When you run: cf create-service EDB-Shared-PostgreSQL "Basic PostgreSQL Plan" myPostgres
And you wait until CloudFoundry service myPostgres is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: Rabbit Connector Samples
In order to show you how to use Steeltoe for connecting to RabbitMQ
You can run some RabbitMQ connection samples
@ -6,7 +7,6 @@ Feature: Rabbit Connector Samples
@win10-x64
Scenario: Rabbit Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-rabbitmq installed
When you run: cf create-service p-rabbitmq standard myRabbitService
And you wait until CloudFoundry service myRabbitService is created
@ -22,7 +22,6 @@ Feature: Rabbit Connector Samples
@ubuntu.14.04-x64
Scenario: Rabbit Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-rabbitmq installed
When you run: cf create-service p-rabbitmq standard myRabbitService
And you wait until CloudFoundry service myRabbitService is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: Redis Connector Samples
In order to show you how to use Steeltoe for connecting to Redis
You can run some Redis connection samples
@ -6,7 +7,6 @@ Feature: Redis Connector Samples
@win10-x64
Scenario: Redis Connector Sample for .Net Core 2.0 (win10-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-redis installed
When you run: cf create-service p-redis shared-vm myRedisService
And you wait until CloudFoundry service myRedisService is created
@ -22,7 +22,6 @@ Feature: Redis Connector Samples
@ubuntu.14.04-x64
Scenario: Redis Connector Sample for .Net Core 2.0 (ubuntu.14.04-x64)
Given you have .NET Core SDK 2.0 installed
And you are logged into CloudFoundry
And you have CloudFoundry service p-redis installed
When you run: cf create-service p-redis shared-vm myRedisService
And you wait until CloudFoundry service myRedisService is created

Просмотреть файл

@ -1,3 +1,4 @@
@cloud
Feature: CloudFoundry Single SignOn Samples
In order to show you how to use Steeltoe with CloudFoundry Single SignOn
You can run some CloudFoundry Single SignOn samples
@ -8,7 +9,6 @@ Feature: CloudFoundry Single SignOn Samples
Given you have .NET Core SDK 2.0 installed
And you have Java 8 installed
And you have UAA Client 4 installed
And you are logged into CloudFoundry
# build/deploy UAA server
When you run: git clone https://github.com/cloudfoundry/uaa.git
And you run: git -C uaa checkout 4.7.1
@ -45,7 +45,6 @@ Feature: CloudFoundry Single SignOn Samples
Given you have .NET Core SDK 2.0 installed
And you have Java 8 installed
And you have UAA Client 4 installed
And you are logged into CloudFoundry
# build/deploy UAA server
When you run: git clone https://github.com/cloudfoundry/uaa.git
And you run: git -C uaa checkout 4.7.1
@ -82,7 +81,6 @@ Feature: CloudFoundry Single SignOn Samples
Given you have .NET Core SDK 2.0 installed
And you have Java 8 installed
And you have UAA Client 4 installed
And you are logged into CloudFoundry
# build/deploy UAA server
When you run: git clone https://github.com/cloudfoundry/uaa.git
And you run: git -C uaa checkout 4.7.1

Просмотреть файл

@ -103,9 +103,7 @@ Install the Python 3 packages needed to run the Samples project tests.
$ pip install -r pyenv.pkgs
```
### CloudFoundry Credentials
Testing samples that use CloudFoundry need credentials to access a CloudFoundry instance.
### CloudFoundry
_**Note**: There must be a space named `development` associated with the credentials.
Nothing is created in the `development` space; it's needed solely for the login process._
@ -114,8 +112,16 @@ Create a DOS INI file named `user.ini` in the repository root.
In the file, add a section named `behave.userdata`.
In that section, configure the CloudFoundry credentials using the following attributes:
`cf_apiurl`, `cf_username`, `cf_password`, `cf_org`, `cf_domain`.
#### Credentials
If you don't specify credentials, it is assumed you are already logged in to CloudFoundry endpoint.
To specify credentials, define the following attributes:
* `cf_apiurl`
* `cf_username`
* `cf_password`
* `cf_org`
_Example: CloudFoundry credentials_
```
@ -124,9 +130,12 @@ cf_apiurl = api.mypcf
cf_username = myusername
cf_password = mypassword
cf_org = myorg
cf_domain = my.domain
```
#### Other
TODO: describe *`cf_domain`, `cf_space`
## Run
_Note: it's assumed your Python 3 virtual environment is activated._

Просмотреть файл

@ -4,6 +4,10 @@ import shutil
import stat
import sure
import sys
import uuid
sys.path.append(os.path.join(os.getcwd(), 'pylib'))
import command
PLATFORM_SUPPORT = {
'netcoreapp2.0': ['windows', 'linux', 'osx'],
@ -41,7 +45,8 @@ def before_scenario(context, scenario):
behave hook called before running test scenario
'''
context.log.info('[---] {}'.format(scenario.name))
for tag in scenario.tags + scenario.feature.tags:
tags = scenario.tags + scenario.feature.tags
for tag in tags:
if tag in PLATFORM_SUPPORT:
if context.platform not in PLATFORM_SUPPORT[tag]:
context.log.info("{} not supported on {}".format(tag, context.platform))
@ -53,13 +58,35 @@ def before_scenario(context, scenario):
os.makedirs(context.sandbox_dir)
context.cleanups = []
setup_env(context, scenario)
context.cf_space = context.options.cf_space
if 'cloud' in tags:
setup_cloud(context, scenario)
def setup_env(context, scenario):
context.env = {}
context.env['CF_HOME'] = context.sandbox_dir
context.env['CF_COLOR'] = 'false'
def setup_cloud(context, scenario):
context.cf_space = context.options.cf.space
if not context.cf_space:
context.cf_space = uuid.uuid4()
if context.options.cf.apiurl:
context.env['CF_HOME'] = context.sandbox_dir
command.Command(context, 'cf login -a {} -u {} -p {} -o {} -s development'.format(
context.options.cf.apiurl,
context.options.cf.username,
context.options.cf.password,
context.options.cf.org
)).run()
else:
context.log.info('CloudFoundry credentials not provided, assuming already logged in')
command.Command(context, 'cf target -s development').run()
command.Command(context, 'cf create-space {}'.format(context.cf_space)).run()
command.Command(context, 'cf target -s {}'.format(context.cf_space)).run()
def cleanup():
cmd = command.Command(context, 'cf delete-space -f {}'.format(context.cf_space))
cmd.exec()
cmd.wait()
context.cleanups.append(cleanup)
def after_scenario(context, scenario):
'''
@ -114,25 +141,21 @@ def setup_options(context):
context.log.info("option: max attempts -> {}".format(context.options.max_attempts))
context.options.debug_on_error = context.config.userdata.getbool('debug_on_error')
context.log.info("option: debug on error? -> {}".format(context.options.debug_on_error))
context.options.cf_apiurl = context.config.userdata.get('cf_apiurl')
assert context.options.cf_apiurl, 'CloudFoundry API URL not set (option: cf_apiurl)'
context.log.info("option: CloudFoundry API URL -> {}".format(context.options.cf_apiurl))
context.options.cf_username = context.config.userdata.get('cf_username')
assert context.options.cf_username, 'CloudFoundry username not set (option: cf_username)'
context.log.info("option: CloudFoundry username -> {}".format(context.options.cf_username))
context.options.cf_password = context.config.userdata.get('cf_password')
assert context.options.cf_password, 'CloudFoundry password not set (option: cf_password)'
context.log.info("option: CloudFoundry password -> *")
context.options.cf_org = context.config.userdata.get('cf_org')
assert context.options.cf_org, 'CloudFoundry org not set (option: cf_org)'
context.log.info("option: CloudFoundry org -> {}".format(context.options.cf_org))
context.options.cf_domain = context.config.userdata.get('cf_domain')
assert context.options.cf_domain, 'CloudFoundry domain not set (option: cf_domain)'
context.log.info("option: CloudFoundry domain -> {}".format(context.options.cf_domain))
context.options.cf_space = context.config.userdata.get('cf_space')
context.log.info("option: CloudFoundry space -> {}".format(context.options.cf_space))
context.options.cf_max_attempts = context.config.userdata.getint('cf_max_attempts')
context.log.info("option: CloudFoundry max attempts -> {}".format(context.options.cf_max_attempts))
context.options.cf = type("", (), {})()
context.options.cf.apiurl = context.config.userdata.get('cf_apiurl')
context.log.info("option: CloudFoundry API URL -> {}".format(context.options.cf.apiurl))
context.options.cf.username = context.config.userdata.get('cf_username')
context.log.info("option: CloudFoundry username -> {}".format(context.options.cf.username))
context.options.cf.password = context.config.userdata.get('cf_password')
context.log.info("option: CloudFoundry password -> {}".format('*' if context.options.cf.password else None))
context.options.cf.org = context.config.userdata.get('cf_org')
context.log.info("option: CloudFoundry org -> {}".format(context.options.cf.org))
context.options.cf.domain = context.config.userdata.get('cf_domain')
context.log.info("option: CloudFoundry domain -> {}".format(context.options.cf.domain))
context.options.cf.space = context.config.userdata.get('cf.space')
context.log.info("option: CloudFoundry space -> {}".format(context.options.cf.space))
context.options.cf.max_attempts = context.config.userdata.getint('cf_max_attempts')
context.log.info("option: CloudFoundry max attempts -> {}".format(context.options.cf.max_attempts))
def setup_logging(context):
'''

0
steps/.gitignore → pylib/.gitignore поставляемый
Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -19,7 +19,7 @@ def hostname(context, name):
def domainname(context, name):
if name != 'x.y.z':
return name
return context.options.cf_domain
return context.options.cf.domain
def url(context, url):
'''

Просмотреть файл

@ -55,7 +55,7 @@ def step_impl(context, service):
status = match.group(1)
context.log.info('service "{}" status: "{}"'.format(service, status))
return status == 'create succeeded'
try_until(context, service_available, context.options.cf_max_attempts)
try_until(context, service_available, context.options.cf.max_attempts)
@when(u'you wait until CloudFoundry app {app} is started')
def step_impl(context, app):
@ -74,7 +74,7 @@ def step_impl(context, app):
status = match.group(1)
context.log.info('app "{}" status: "{}"'.format(app, status))
return status == 'running'
try_until(context, app_started, context.options.cf_max_attempts)
try_until(context, app_started, context.options.cf.max_attempts)
def try_until(context, function, max_attempts):
attempts = 0

Просмотреть файл

@ -1,6 +1,5 @@
import command
import re
import uuid
@given(u'you have .NET Core SDK {version} installed')
def step_impl(context, version):
@ -30,25 +29,6 @@ def step_impl(context, version):
actual = cmd.stdout
actual.should.match(r'{}.*'.format(version))
@given(u'you are logged into CloudFoundry')
def step_impl(context):
apiurl = context.options.cf_apiurl
username = context.options.cf_username
password = context.options.cf_password
org = context.options.cf_org
context.cf_space = context.options.cf_space
if not context.cf_space:
context.cf_space = uuid.uuid4()
command.Command(context, 'cf login -a {} -u {} -p {} -o {} -s development'.format(
apiurl, username, password, org)).run()
command.Command(context, 'cf create-space {}'.format(context.cf_space)).run()
command.Command(context, 'cf target -s {}'.format(context.cf_space)).run()
def cleanup():
cmd = command.Command(context, 'cf delete-space -f {}'.format(context.cf_space))
cmd.exec()
cmd.wait()
context.cleanups.append(cleanup)
@given(u'you have CloudFoundry service {service} installed')
def step_impl(context, service):
cmd = command.Command(context, "cf marketplace")