1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add Azure provider support to ansible-test and CI.

ci_complete
This commit is contained in:
Matt Clay 2017-11-29 00:46:08 -08:00
parent 58286ef93b
commit 1b5c4b72bd
14 changed files with 83 additions and 30 deletions

View file

@ -79,7 +79,7 @@ class AwsCloudProvider(CloudProvider):
""" """
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
return AnsibleCoreCI(self.args, 'aws', 'sts', persist=False, stage=self.args.remote_stage) return AnsibleCoreCI(self.args, 'aws', 'sts', persist=False, stage=self.args.remote_stage, provider=self.args.remote_provider)
class AwsCloudEnvironment(CloudEnvironment): class AwsCloudEnvironment(CloudEnvironment):

View file

@ -114,7 +114,7 @@ class AzureCloudProvider(CloudProvider):
""" """
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
return AnsibleCoreCI(self.args, 'azure', 'sherlock', persist=False, stage=self.args.remote_stage) return AnsibleCoreCI(self.args, 'azure', 'sherlock', persist=False, stage=self.args.remote_stage, provider=self.args.remote_provider)
class AzureCloudEnvironment(CloudEnvironment): class AzureCloudEnvironment(CloudEnvironment):

View file

@ -48,9 +48,13 @@ class EnvironmentConfig(CommonConfig):
self.tox_sitepackages = args.tox_sitepackages # type: bool self.tox_sitepackages = args.tox_sitepackages # type: bool
self.remote_stage = args.remote_stage # type: str self.remote_stage = args.remote_stage # type: str
self.remote_provider = args.remote_provider # type: str
self.remote_aws_region = args.remote_aws_region # type: str self.remote_aws_region = args.remote_aws_region # type: str
self.remote_terminate = args.remote_terminate # type: str self.remote_terminate = args.remote_terminate # type: str
if self.remote_provider == 'default':
self.remote_provider = None
self.requirements = args.requirements # type: bool self.requirements = args.requirements # type: bool
if self.python == 'default': if self.python == 'default':

View file

@ -36,7 +36,7 @@ AWS_ENDPOINTS = {
class AnsibleCoreCI(object): class AnsibleCoreCI(object):
"""Client for Ansible Core CI services.""" """Client for Ansible Core CI services."""
def __init__(self, args, platform, version, stage='prod', persist=True, load=True, name=None): def __init__(self, args, platform, version, stage='prod', persist=True, load=True, name=None, provider=None):
""" """
:type args: EnvironmentConfig :type args: EnvironmentConfig
:type platform: str :type platform: str
@ -57,8 +57,12 @@ class AnsibleCoreCI(object):
self.max_threshold = 1 self.max_threshold = 1
self.name = name if name else '%s-%s' % (self.platform, self.version) self.name = name if name else '%s-%s' % (self.platform, self.version)
self.ci_key = os.path.expanduser('~/.ansible-core-ci.key') self.ci_key = os.path.expanduser('~/.ansible-core-ci.key')
self.resource = 'jobs'
aws_platforms = ( # Assign each supported platform to one provider.
# This is used to determine the provider from the platform when no provider is specified.
providers = dict(
aws=(
'aws', 'aws',
'azure', 'azure',
'windows', 'windows',
@ -67,13 +71,28 @@ class AnsibleCoreCI(object):
'vyos', 'vyos',
'junos', 'junos',
'ios', 'ios',
) ),
azure=(
osx_platforms = ( ),
parallels=(
'osx', 'osx',
),
) )
if self.platform in aws_platforms: if provider:
# override default provider selection (not all combinations are valid)
self.provider = provider
else:
for candidate in providers:
if platform in providers[candidate]:
# assign default provider based on platform
self.provider = candidate
break
if self.provider in ('aws', 'azure'):
if self.provider != 'aws':
self.resource = self.provider
if args.remote_aws_region: if args.remote_aws_region:
# permit command-line override of region selection # permit command-line override of region selection
region = args.remote_aws_region region = args.remote_aws_region
@ -97,7 +116,7 @@ class AnsibleCoreCI(object):
else: else:
self.ssh_key = SshKey(args) self.ssh_key = SshKey(args)
self.port = 22 self.port = 22
elif self.platform in osx_platforms: elif self.provider == 'parallels':
self.endpoints = self._get_parallels_endpoints() self.endpoints = self._get_parallels_endpoints()
self.max_threshold = 6 self.max_threshold = 6
@ -106,7 +125,7 @@ class AnsibleCoreCI(object):
else: else:
raise ApplicationError('Unsupported platform: %s' % platform) raise ApplicationError('Unsupported platform: %s' % platform)
self.path = os.path.expanduser('~/.ansible/test/instances/%s-%s' % (self.name, self.stage)) self.path = os.path.expanduser('~/.ansible/test/instances/%s-%s-%s' % (self.name, self.provider, self.stage))
if persist and load and self._load(): if persist and load and self._load():
try: try:
@ -292,7 +311,7 @@ class AnsibleCoreCI(object):
@property @property
def _uri(self): def _uri(self):
return '%s/%s/jobs/%s' % (self.endpoint, self.stage, self.instance_id) return '%s/%s/%s/%s' % (self.endpoint, self.stage, self.resource, self.instance_id)
def _start(self, auth): def _start(self, auth):
"""Start instance.""" """Start instance."""

View file

@ -280,7 +280,7 @@ def delegate_remote(args, exclude, require):
platform = parts[0] platform = parts[0]
version = parts[1] version = parts[1]
core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage) core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage, provider=args.remote_provider)
success = False success = False
try: try:

View file

@ -406,7 +406,7 @@ def network_start(args, platform, version):
:type version: str :type version: str
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage) core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage, provider=args.remote_provider)
core_ci.start() core_ci.start()
return core_ci.save() return core_ci.save()
@ -420,7 +420,7 @@ def network_run(args, platform, version, config):
:type config: dict[str, str] :type config: dict[str, str]
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage, load=False) core_ci = AnsibleCoreCI(args, platform, version, stage=args.remote_stage, provider=args.remote_provider, load=False)
core_ci.load(config) core_ci.load(config)
core_ci.wait() core_ci.wait()
@ -548,7 +548,7 @@ def windows_start(args, version):
:type version: str :type version: str
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
core_ci = AnsibleCoreCI(args, 'windows', version, stage=args.remote_stage) core_ci = AnsibleCoreCI(args, 'windows', version, stage=args.remote_stage, provider=args.remote_provider)
core_ci.start() core_ci.start()
return core_ci.save() return core_ci.save()
@ -561,7 +561,7 @@ def windows_run(args, version, config):
:type config: dict[str, str] :type config: dict[str, str]
:rtype: AnsibleCoreCI :rtype: AnsibleCoreCI
""" """
core_ci = AnsibleCoreCI(args, 'windows', version, stage=args.remote_stage, load=False) core_ci = AnsibleCoreCI(args, 'windows', version, stage=args.remote_stage, provider=args.remote_provider, load=False)
core_ci.load(config) core_ci.load(config)
core_ci.wait() core_ci.wait()

View file

@ -131,7 +131,12 @@ class ManagePosixCI(object):
self.ssh_args += ['-o', '%s=%s' % (ssh_option, ssh_options[ssh_option])] self.ssh_args += ['-o', '%s=%s' % (ssh_option, ssh_options[ssh_option])]
if self.core_ci.platform == 'freebsd': if self.core_ci.platform == 'freebsd':
if self.core_ci.provider == 'aws':
self.become = ['su', '-l', 'root', '-c'] self.become = ['su', '-l', 'root', '-c']
elif self.core_ci.provider == 'azure':
self.become = ['sudo', '-in', 'sh', '-c']
else:
raise NotImplementedError('provider %s has not been implemented' % self.core_ci.provider)
elif self.core_ci.platform == 'osx': elif self.core_ci.platform == 'osx':
self.become = ['sudo', '-in', 'PATH=/usr/local/bin:$PATH'] self.become = ['sudo', '-in', 'PATH=/usr/local/bin:$PATH']
elif self.core_ci.platform == 'rhel': elif self.core_ci.platform == 'rhel':

View file

@ -10,6 +10,7 @@ cd ~/
if [ "${platform}" = "freebsd" ]; then if [ "${platform}" = "freebsd" ]; then
while true; do while true; do
env ASSUME_ALWAYS_YES=YES pkg bootstrap && \
pkg install -y \ pkg install -y \
bash \ bash \
curl \ curl \

View file

@ -514,6 +514,7 @@ def add_environments(parser, tox_version=False, tox_only=False):
docker=None, docker=None,
remote=None, remote=None,
remote_stage=None, remote_stage=None,
remote_provider=None,
remote_aws_region=None, remote_aws_region=None,
remote_terminate=None, remote_terminate=None,
) )
@ -540,6 +541,12 @@ def add_environments(parser, tox_version=False, tox_only=False):
choices=['prod', 'dev'], choices=['prod', 'dev'],
default='prod') default='prod')
remote.add_argument('--remote-provider',
metavar='PROVIDER',
help='remote provider to use: %(choices)s',
choices=['default', 'aws', 'azure', 'parallels'],
default='default')
remote.add_argument('--remote-aws-region', remote.add_argument('--remote-aws-region',
metavar='REGION', metavar='REGION',
help='remote aws region to use: %(choices)s (default: auto)', help='remote aws region to use: %(choices)s (default: auto)',

View file

@ -14,7 +14,10 @@ else
target="posix/ci/" target="posix/ci/"
fi fi
stage="${S:-prod}"
provider="${P:-default}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
--exclude "posix/ci/cloud/" \ --exclude "posix/ci/cloud/" \
--remote "${platform}/${version}" --remote-terminate always --remote "${platform}/${version}" --remote-terminate always --remote-stage "${stage}" --remote-provider "${provider}"

View file

@ -12,6 +12,9 @@ fi
target="network/ci/" target="network/ci/"
stage="${S:-prod}"
provider="${P:-default}"
# python versions to test in order # python versions to test in order
# all versions run full tests # all versions run full tests
python_versions=( python_versions=(
@ -50,5 +53,6 @@ for version in "${python_versions[@]}"; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ansible-test network-integration --color -v --retry-on-error "${target}" --docker default --python "${version}" \ ansible-test network-integration --color -v --retry-on-error "${target}" --docker default --python "${version}" \
${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} "${platforms[@]}" --remote-terminate "${terminate}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} "${platforms[@]}" \
--remote-terminate "${terminate}" --remote-stage "${stage}" --remote-provider "${provider}"
done done

View file

@ -14,7 +14,10 @@ else
target="posix/ci/" target="posix/ci/"
fi fi
stage="${S:-prod}"
provider="${P:-default}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
--exclude "posix/ci/cloud/" \ --exclude "posix/ci/cloud/" \
--remote "${platform}/${version}" --remote-terminate always --remote "${platform}/${version}" --remote-terminate always --remote-stage "${stage}" --remote-provider "${provider}"

View file

@ -14,7 +14,10 @@ else
target="posix/ci/" target="posix/ci/"
fi fi
stage="${S:-prod}"
provider="${P:-default}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
--exclude "posix/ci/cloud/" \ --exclude "posix/ci/cloud/" \
--remote "${platform}/${version}" --remote-terminate always --remote "${platform}/${version}" --remote-terminate always --remote-stage "${stage}" --remote-provider "${provider}"

View file

@ -7,6 +7,9 @@ IFS='/:' read -ra args <<< "$1"
target="windows/ci/group${args[1]}/" target="windows/ci/group${args[1]}/"
stage="${S:-prod}"
provider="${P:-default}"
# python versions to test in order # python versions to test in order
# python 2.7 runs full tests while other versions run minimal tests # python 2.7 runs full tests while other versions run minimal tests
python_versions=( python_versions=(
@ -76,5 +79,6 @@ for version in "${python_versions[@]}"; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ansible-test windows-integration --color -v --retry-on-error "${ci}" --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ ansible-test windows-integration --color -v --retry-on-error "${ci}" --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
"${platforms[@]}" --changed-all-target "${changed_all_target}" --remote-terminate "${terminate}" "${platforms[@]}" --changed-all-target "${changed_all_target}" \
--remote-terminate "${terminate}" --remote-stage "${stage}" --remote-provider "${provider}"
done done