Merge "Initial granular deployment config with validation"

This commit is contained in:
Jenkins 2015-01-19 15:42:20 +00:00 committed by Gerrit Code Review
commit 0672675ab1
5 changed files with 198 additions and 0 deletions

View File

@ -0,0 +1,75 @@
#STAGES
- id: deploy
type: stage
#GROUPS
- id: primary-controller
type: group
role: [primary-controller]
required_for: [deploy]
parameters:
strategy:
type: one_by_one
- id: controller
type: group
role: [controller]
requires: [primary-controller]
required_for: [deploy]
parameters:
strategy:
type: parallel
amount: 6
- id: cinder
type: group
role: [cinder]
requires: [controller]
required_for: [deploy]
parameters:
strategy:
type: parallel
- id: compute
type: group
role: [compute]
requires: [controller]
required_for: [deploy]
parameters:
strategy:
type: parallel
- id: zabbix-server
type: group
role: [zabbix-server]
required_for: [deploy]
parameters:
strategy:
type: one_by_one
- id: mongo
type: group
role: [mongo]
requires: [zabbix-server]
required_for: [deploy, primary-controller, controller]
parameters:
strategy:
type: parallel
- id: primary-mongo
type: group
role: [primary-mongo]
requires: [mongo]
required_for: [deploy, primary-controller, controller]
parameters:
strategy:
type: one_by_one
- id: ceph-osd
type: group
role: [ceph-osd]
requires: [controller]
required_for: [deploy]
parameters:
strategy:
type: parallel
- id: base-os
type: group
role: [base-os]
required_for: [deploy]
parameters:
strategy:
type: parallel

View File

@ -0,0 +1,17 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
def pytest_addoption(parser):
parser.addoption("--dir", help="Base directory for tasks discovery.")

View File

@ -0,0 +1,4 @@
pytest
networkx
jsonschema
yaml

View File

@ -0,0 +1,6 @@
#current tasks will not pass
- id: primary-controller
requires: [controller]
- id: controller
type: group
requires: [primary-controller]

View File

@ -0,0 +1,96 @@
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import jsonschema
import networkx as nx
import pytest
import yaml
TASK_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'required': ['type', 'id'],
'properties': {
'id': {'type': 'string'},
'type': {'enum': ['puppet', 'shell', 'group', 'stage'],
'type': 'string'},
'parameters': {'type': 'object'},
'required_for': {'type': 'array'},
'requires': {'type': 'array'}}}
TASKS_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'array',
'items': TASK_SCHEMA}
def get_files(base_dir, patterns=('tasks.yaml',)):
for root, dirs, files in os.walk(base_dir):
for file_name in files:
if file_name in patterns:
yield os.path.join(root, file_name)
@pytest.fixture
def tasks(request):
tasks = []
for file_path in get_files(request.config.getoption('dir')):
with open(file_path) as f:
tasks.extend(yaml.load(f.read()))
return tasks
@pytest.fixture
def graph(tasks):
graph = nx.DiGraph()
for task in tasks:
graph.add_node(task['id'], **task)
if 'required_for' in task:
for req in task['required_for']:
graph.add_edge(task['id'], req)
if 'requires' in task:
for req in task['requires']:
graph.add_edge(req, task['id'])
if 'groups' in task:
for req in task['groups']:
graph.add_edge(task['id'], req)
if 'tasks' in task:
for req in task['tasks']:
graph.add_edge(req, task['id'])
if 'stage' in task:
graph.add_edge(task['id'], task['stage'])
return graph
def test_schema(tasks):
checker = jsonschema.FormatChecker()
jsonschema.validate(tasks, TASKS_SCHEMA, format_checker=checker)
def test_for_cycles_in_graph(graph):
#todo(dshulyak) show where cycle is
dag = nx.is_directed_acyclic_graph(graph)
assert dag, 'Graph is not acyclic.'
def test_not_empty(graph):
for node_name, node in graph.node.items():
assert node != {}, "{0} should not be an empty".format(node_name)