зеркало из https://github.com/Azure/Moodle.git
Validate template.
This commit is contained in:
Родитель
872cbdd29c
Коммит
88559e4d0d
|
@ -5,14 +5,6 @@ fi
|
|||
ARTIFACTS_LOCATION="https://raw.githubusercontent.com/${GITHUB_SLUG_BRANCH}/"
|
||||
echo "ARTIFACTS_LOCATION=$ARTIFACTS_LOCATION"
|
||||
|
||||
echo "Running Azure validation step."
|
||||
VALIDATION_RESULT=$(az group deployment validate --resource-group "$AZMDLGROUP" --template-file azuredeploy.json --parameters @azuredeploy.parameters.json sshPublicKey="$SPSSHKEY" _artifactsLocation="$ARTIFACTS_LOCATION" --query error)
|
||||
if [ -n "$VALIDATION_RESULT" ]; then
|
||||
echo "Azure template validation failed! Error message:"
|
||||
echo $VALIDATION_RESULT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Running Azure build step."
|
||||
az group deployment create --resource-group "$AZMDLGROUP" --template-file azuredeploy.json --parameters @azuredeploy.parameters.json sshPublicKey="$SPSSHKEY" _artifactsLocation="$ARTIFACTS_LOCATION" --no-wait
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
from azure.mgmt.resource import ResourceManagementClient
|
||||
from azure.mgmt.resource.resources.v2017_05_10.models import DeploymentMode
|
||||
from msrestazure.azure_active_directory import ServicePrincipalCredentials
|
||||
|
||||
from travis.Configuration import Configuration
|
||||
|
||||
|
||||
class DeploymentTester:
|
||||
ERROR_VALIDATION_FAILED = 1
|
||||
|
||||
def __init__(self):
|
||||
self.config = Configuration()
|
||||
self.credentials = None
|
||||
|
@ -15,6 +19,7 @@ class DeploymentTester:
|
|||
self.check_configuration()
|
||||
self.login()
|
||||
self.create_resource_group()
|
||||
self.validate()
|
||||
print('Job done!')
|
||||
|
||||
def check_configuration(self):
|
||||
|
@ -31,8 +36,33 @@ class DeploymentTester:
|
|||
secret=self.config.secret,
|
||||
tenant=self.config.tenant_id,
|
||||
)
|
||||
self.resource_client = ResourceManagementClient(self.credentials, self.config.subscription_id)
|
||||
|
||||
def create_resource_group(self):
|
||||
print('Creating group "{}" on "{}"...'.format(self.config.resource_group, self.config.location))
|
||||
client = ResourceManagementClient(self.credentials, self.config.subscription_id)
|
||||
client.resource_groups.create_or_update(self.config.resource_group, {'location': self.config.location})
|
||||
client.resource_groups.create_or_update(self.config.resource_group,
|
||||
{'location': self.config.location})
|
||||
|
||||
def validate(self):
|
||||
print('Validating deployment...')
|
||||
with open('azuredeploy.json', 'r') as template_file_fd:
|
||||
template = json.load(template_file_fd)
|
||||
with open('azuredeploy.parameters.json', 'r') as template_file_fd:
|
||||
parameters = json.load(template_file_fd)
|
||||
parameters = parameters['parameters']
|
||||
|
||||
properties = {
|
||||
'mode': DeploymentMode.incremental,
|
||||
'template': template,
|
||||
'parameters': parameters,
|
||||
}
|
||||
|
||||
client = ResourceManagementClient(self.credentials, self.config.subscription_id)
|
||||
validation = client.deployments.validate(self.config.resource_group,
|
||||
'azure-moodle-deployment-test',
|
||||
properties)
|
||||
if validation.error is not None:
|
||||
print("*** VALIDATION FAILED ***")
|
||||
print(validation.error.message)
|
||||
sys.exit(DeploymentTester.ERROR_VALIDATION_FAILED)
|
||||
|
|
Загрузка…
Ссылка в новой задаче