Added new plugin version with node & nic attributes support

* Added new plugin version supported by Fuel >= v9.0
* Added validation for node/nic/bond plugin node's attributes

Change-Id: I3e059940b910e67cca9b02a4d29179fa985414ff
Implements: blueprint nics-and-nodes-attributes-via-plugin
This commit is contained in:
Elena Kosareva 2016-09-22 11:36:57 +03:00
parent 2ce77d627e
commit 6dbc520503
32 changed files with 1205 additions and 4 deletions

View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

View File

@ -0,0 +1,4 @@
fuel_plugin_example_v5
======================
Plugin description

View File

@ -0,0 +1,18 @@
# This file contains additional bond attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
attribute_a:
label: "Bond attribute A"
description: "Some description"
type: "text"
value: ""
restrictions:
- condition: "settings:common.libvirt_type.value != 'kvm'"
action: "hide"
attribute_b:
label: "Bond attribute B"
description: "Some description"
type: "checkbox"
value: false

View File

@ -0,0 +1,17 @@
# This file contains wizard components descriptions that are pretty similar to
# the `environment_config.yaml`.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/component-registry
# - https://specs.openstack.org/openstack/fuel-specs/specs/8.0/component-registry.html
- name: additional_service:service_plugin_v5_component
label: "Title for service_plugin_v5_component component."
description: "Description for service_plugin_v5_component component."
compatible:
- name: "hypervisor:xxx"
requires:
- name: "hypervisor:xxx"
message: "service_plugin_v5_component requires XXX compute."
incompatible:
- name: "network:neutron:*"
message: "service_plugin_v5_component incompatible with Neutron network."

View File

@ -0,0 +1,14 @@
# This puppet manifest creates example file in /tmp folder.
notice('PLUGIN: fuel_plugin_example_v5 - deploy.pp')
class fuel_plugin_example_v5 {
file { '/tmp/fuel_plugin_example_v5_puppet':
owner => 'root',
group => 'root',
mode => 0644,
content => "fuel_plugin_example_v5\n",
}
}
class {'fuel_plugin_example_v5': }

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -eux
# It's a script which deploys your plugin
echo fuel_plugin_example_v5 > /tmp/fuel_plugin_example_v5_sh
OS_NAME=''
if grep -i CentOS /etc/issue.net >/dev/null; then
OS_NAME='centos';
elif grep -i Ubuntu /etc/issue.net >/dev/null; then
OS_NAME='ubuntu';
fi
function install_package {
if [ $OS_NAME == 'ubuntu' ]; then
apt-get install -y --force-yes -o 'APT::Get::AllowUnauthenticated=1' fuel-simple-service
elif [ $OS_NAME == 'centos' ]; then
yum install -y fuel-simple-service
fi
}
install_package
fuel-simple-service.py &

View File

@ -0,0 +1,46 @@
- id: fuel_plugin_example_v5
type: group
role: [fuel_plugin_example_v5]
tasks:
- hiera
- globals
required_for: [deploy_end]
requires: [deploy_start]
parameters:
strategy:
type: parallel
- id: fuel_plugin_example_v5-controller-deployment
type: puppet
version: 2.0.0
groups: [primary-controller, controller]
required_for: [connectivity_tests, deploy_end]
requires: [netconfig, deploy_start]
parameters:
puppet_manifest: "deploy.pp"
puppet_modules: "."
timeout: 3600
- id: fuel_plugin_example_v5-deployment
type: puppet
version: 2.0.0
groups: [fuel_plugin_example_v5]
required_for: [deploy_end]
requires: [deploy_start]
parameters:
puppet_manifest: "deploy.pp"
puppet_modules: "."
timeout: 3600
retries: 10
- id: fuel_plugin_example_v5-post-deployment-sh
type: shell
version: 2.0.0
role: [fuel_plugin_example_v5]
required_for: [post_deployment_end]
requires: [post_deployment_start]
parameters:
cmd: bash deploy.sh
retries: 3
interval: 20
timeout: 180

View File

@ -0,0 +1,15 @@
# This file describes additional attributes that will appear on the Settings
# tab of the Fuel web UI. When the environment is deployed, these attributes
# are passed to the task executor so that the data is available
# in the /etc/astute.yaml file on each target node and can be accessed from
# your bash or puppet scripts.
attributes:
metadata:
group: 'other'
fuel_plugin_example_v5_text:
value: 'Set default value'
label: 'Text field'
description: 'Description for text field'
weight: 25
type: "text"

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from wsgiref.simple_server import make_server
def web_app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain')]
start_response(status, headers)
return open('/etc/astute.yaml').read()
def start_server(host, port):
httpd = make_server(host, port, web_app)
print 'Started server 8234'
httpd.serve_forever()
def main():
start_server('', 8234)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,40 @@
# Plugin name
name: fuel_plugin_example_v5
# Human-readable name for your plugin
title: Title for fuel_plugin_example_v5 plugin
# Plugin version
version: '1.0.0'
# Description
description: Please describe your plugin here
# Minimum required fuel version
fuel_version: ['9.0', '10.0']
# Specify license of your plugin
licenses: ['Apache License Version 2.0']
# Specify author or company name
authors: ['Specify author or company name']
# A link to the plugin's page
homepage: 'https://github.com/openstack/fuel-plugins'
# Specify a group which your plugin implements, possible options:
# network, storage, storage::cinder, storage::glance, hypervisor,
# equipment
groups: []
# Change `false` to `true` if the plugin can be installed in the environment
# after the deployment.
is_hotpluggable: false
# The plugin is compatible with releases in the list
releases:
- os: ubuntu
version: mitaka-9.0
mode: ['ha']
deployment_scripts_path: deployment_scripts/
repository_path: repositories/ubuntu
- os: ubuntu
version: newton-10.0
mode: ['ha']
deployment_scripts_path: deployment_scripts/
repository_path: repositories/ubuntu
# Version of plugin package
package_version: '5.0.0'

View File

@ -0,0 +1,24 @@
# `network_roles.yaml` file is used to declare VIP addresses and link
# them with networks and nodes.
# Unique network role name
- id: "fuel_plugin_example_v5_network_role"
# Role mapping to network
default_mapping: "public"
properties:
# Should be true if network role requires subnet being set
subnet: true
# Should be true if network role requires gateway being set
gateway: false
# List of VIPs to be allocated
vip:
# Unique VIP name
- name: "vip_name"
# Optional linux namespace for VIP
namespace: "haproxy"
# Optional alias so VIP can be queried via API
alias: "vip_name"
# Optional node role list to map VIP to (defaults to
# primary-controller and controller)
node_roles:
- "fuel_plugin_example_v5_role"

View File

@ -0,0 +1,18 @@
# This file contains additional nic attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
attribute_a:
label: "NIC attribute A"
description: "Some description"
type: "text"
value: ""
restrictions:
- condition: "settings:common.libvirt_type.value != 'kvm'"
action: "hide"
attribute_b:
label: "NIC attribute B"
description: "Some description"
type: "checkbox"
value: false

View File

@ -0,0 +1,25 @@
# This file contains additional node's attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
plugin_section_a:
metadata:
group: "some_new_section"
label: "Section A"
restrictions:
- condition: "settings:common.libvirt_type.value != 'kvm'"
action: "hide"
attribute_a:
label: "Node attribute A for section A"
description: "Some description"
type: "text"
value: ""
restrictions:
- condition: "false"
action: "hide"
attribute_b:
label: "Node attribute B for section A"
description: "Some description"
type: "checkbox"
value: ""

View File

@ -0,0 +1,6 @@
fuel_plugin_example_v5:
name: "Set here the name for the role. This name will be displayed in the Fuel web UI."
description: "Write description for your role"
has_primary: false # whether has primary role or not
public_ip_required: false # whether requires public net or not
weight: 100 # weight that will be used for ordering on fuel ui

View File

@ -0,0 +1,21 @@
#!/bin/bash
set -eux
command -v fpm >/dev/null 2>&1 || {
echo >&2 "Install 'fpm' to build this plugin. Aborting."; exit 1;
}
ruby -e "require 'fpm'" 2>&1 || {
echo >&2 "'Fpm' binary file is present, but gem seems to be broken! Aborting."; exit 1;
}
ROOT=$(dirname `readlink -f $0`)
UBUNTU_REPO_PATH=$ROOT/repositories/ubuntu
CENTOS_REPO_PATH=$ROOT/repositories/centos
rm -f $UBUNTU_REPO_PATH/*.deb
rm -f $CENTOS_REPO_PATH/*.rpm
fpm -t deb -p $UBUNTU_REPO_PATH -n fuel-simple-service -v 5.0.0 -s dir $ROOT/fuel-simple-service.py=/usr/bin/fuel-simple-service.py
fpm -t rpm -p $CENTOS_REPO_PATH -n fuel-simple-service -v 5.0.0 -s dir $ROOT/fuel-simple-service.py=/usr/bin/fuel-simple-service.py

View File

@ -0,0 +1,6 @@
# Set here new volumes for your role
volumes: []
volumes_roles_mapping:
fuel_plugin_example_v5_role:
# Default role mapping
- {allocate_size: "min", id: "os"}

View File

@ -19,4 +19,5 @@ from fuel_plugin_builder.actions.build import BuildPluginV1
from fuel_plugin_builder.actions.build import BuildPluginV2
from fuel_plugin_builder.actions.build import BuildPluginV3
from fuel_plugin_builder.actions.build import BuildPluginV4
from fuel_plugin_builder.actions.build import BuildPluginV5
from fuel_plugin_builder.actions.build import make_builder

View File

@ -269,6 +269,10 @@ class BuildPluginV4(BuildPluginV3):
pass
class BuildPluginV5(BuildPluginV4):
pass
def make_builder(plugin_path):
"""Creates build object.

View File

@ -0,0 +1,15 @@
# This file contains additional bond attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
attribute_a:
label: "Bond attribute A"
description: "Some description"
type: "text"
value: ""
attribute_b:
label: "Bond attribute B"
description: "Some description"
type: "checkbox"
value: false

View File

@ -0,0 +1,38 @@
# Plugin name
name: ${plugin_name}
# Human-readable name for your plugin
title: Title for ${plugin_name} plugin
# Plugin version
version: '1.0.0'
# Description
description: Please describe your plugin here
# Required fuel version
fuel_version: ['9.0', '10.0']
# Specify license of your plugin
licenses: ['Apache License Version 2.0']
# Specify author or company name
authors: ['Specify author or company name']
# A link to the plugin's page
homepage: 'https://github.com/stackforge/fuel-plugins'
# Specify a group which your plugin implements, possible options:
# network, storage, storage::cinder, storage::glance, hypervisor
groups: []
# Change `false` to `true` if the plugin can be installed in the environment
# after the deployment.
is_hotpluggable: false
# The plugin is compatible with releases in the list
releases:
- os: ubuntu
version: mitaka-9.0
mode: ['ha']
deployment_scripts_path: deployment_scripts/
repository_path: repositories/ubuntu
- os: ubuntu
version: newton-10.0
mode: ['ha']
deployment_scripts_path: deployment_scripts/
repository_path: repositories/ubuntu
# Version of plugin package
package_version: '5.0.0'

View File

@ -0,0 +1,15 @@
# This file contains additional nic attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
attribute_a:
label: "NIC attribute A"
description: "Some description"
type: "text"
value: ""
attribute_b:
label: "NIC attribute B"
description: "Some description"
type: "checkbox"
value: false

View File

@ -0,0 +1,19 @@
# This file contains additional node's attributes provided by plugin.
# Please, take a look at following link for the details:
# - https://blueprints.launchpad.net/fuel/+spec/nics-and-nodes-attributes-via-plugin
# - https://specs.openstack.org/openstack/fuel-specs/specs/10.0/nics-and-nodes-attributes-via-plugin.html
plugin_section_a:
metadata:
group: "some_new_section"
label: "Section A"
attribute_a:
label: "Node attribute A for section A"
description: "Some description"
type: "text"
value: ""
attribute_b:
label: "Node attribute B for section A"
description: "Some description"
type: "checkbox"
value: ""

View File

@ -27,6 +27,7 @@ class TestValidatorV4(TestValidatorV3):
__test__ = True
validator_class = ValidatorV4
schema_class = SchemaV4
package_version = '4.0.0'
def setUp(self):
super(TestValidatorV4, self).setUp()
@ -34,7 +35,7 @@ class TestValidatorV4(TestValidatorV3):
'name': 'plugin_name-12',
'title': 'plugin_name-12',
'version': '1.2.3',
'package_version': '4.0.0',
'package_version': self.package_version,
'description': 'Description',
'fuel_version': ['8.0.0'],
'licenses': ['Apache', 'BSD'],
@ -106,7 +107,7 @@ class TestValidatorV4(TestValidatorV3):
'name': 'plugin_name-12',
'title': 'plugin_name-12',
'version': '1.2.3',
'package_version': '4.0.0',
'package_version': self.package_version,
'description': 'Description',
'fuel_version': ['8.0.0'],
'licenses': ['Apache', 'BSD'],

View File

@ -0,0 +1,452 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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 mock
from fuel_plugin_builder import errors
from fuel_plugin_builder.tests.test_validator_v4 import TestValidatorV4
from fuel_plugin_builder.validators.schemas import SchemaV5
from fuel_plugin_builder.validators.validator_v5 import ValidatorV5
class TestValidatorV5(TestValidatorV4):
__test__ = True
validator_class = ValidatorV5
schema_class = SchemaV5
package_version = '5.0.0'
def setUp(self):
super(TestValidatorV5, self).setUp()
def test_check_schemas(self):
mocked_methods = [
'check_metadata_schema',
'check_env_config_attrs',
'check_tasks_schema',
'check_deployment_tasks_schema',
'check_network_roles_schema',
'check_node_roles_schema',
'check_volumes_schema',
'check_components_schema',
'check_node_attributes_schema'
]
self.mock_methods(self.validator, mocked_methods)
self.mock_methods(
self.validator,
['validate_file_by_schema', 'check_interface_attributes_schema']
)
self.validator.check_schemas()
self.assertEqual(
[mock.call(self.validator.bond_config_path),
mock.call(self.validator.nic_config_path)],
self.validator.check_interface_attributes_schema.call_args_list)
for method in mocked_methods:
getattr(self.validator, method).assert_called_once_with()
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_compatibility_failed(self, utils_mock):
fuel_version_checks = (
(['8.0', '9.0', '10.0']),
(['6.1', '7.0', '8.0']),
(['6.0', '6.1', '7.0']),
(['6.1', '7.0']),
)
for fuel_version in fuel_version_checks:
mock_data = {
'fuel_version': fuel_version,
'package_version': '5.0.0'}
err_msg = 'Current plugin format 5.0.0 is not compatible with ' \
'{0} Fuel release. Fuel version must be 9.0 or higher.' \
' Please remove {0} version from metadata.yaml file or' \
' downgrade package_version.'.format(fuel_version[0])
self.check_raised_exception(
utils_mock, mock_data,
err_msg, self.validator.check_compatibility)
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_compatibility_passed(self, utils_mock):
utils_mock.parse_yaml.return_value = {
'fuel_version': ['9.0', '9.1', '9.2', '10.0'],
'package_version': '5.0.0'}
self.validator.check_compatibility()
@mock.patch('fuel_plugin_builder.validators.base.utils.exists')
def test_check_interface_attributes_schema_validation_no_file(self,
exists_mock):
mocked_methods = ['validate_schema']
self.mock_methods(self.validator, mocked_methods)
exists_mock.return_value = False
self.validator.check_interface_attributes_schema(mock.ANY)
self.assertFalse(self.validator.validate_schema.called)
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_interface_attributes_schema_validation_failed(self,
utils_mock):
data_sets = [
{
'123': {
'label': 'Attribute without type',
'description': 'Attribute without type',
'value': ''
}
},
{
'attribute_without_label': {
'description': 'Attribute without label',
'type': 'text',
'value': 'attribute_value'
}
}, {
'attribute_without_value': {
'label': 'Attribute without value',
'description': 'Attribute without value',
'type': 'text',
}
},
{
'attribute-1': {
'description': 'Attribute with wrong label type',
'label': 123,
'type': 'checkbox',
}
},
{
'attribute-2': {
'label': 'Attribute with wrong type type',
'type': [],
}
},
{
'attribute-3': {
'label': 'Attribute with wrong description type',
'type': 'text',
'description': False
}
},
{
'attribute-4': {
'label': 'Attribute with wrong restrictions type',
'type': 'text',
'restrictions': {}
}
},
{
'label': 'Missed attribute name. Wrong level nesting.',
'type': 'text',
'value': ''
},
{
'extra_level': {
'attribute_name': {
'label': 'Attribute with extra nesting level',
'type': 'text',
'value': ''
}
}
},
{
'uns@pported_letters=!n_attr_name*': {
'label': 'Attribute with wrong name',
'type': 'text',
'value': ''
}
},
['wrong interface attributes object type']
]
for data in data_sets:
utils_mock.parse_yaml.return_value = data
self.assertRaises(errors.ValidationError,
self.validator.check_interface_attributes_schema,
mock.ANY)
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_interface_attributes_schema_validation_passed(self,
utils_mock):
data_sets = [
{
'123': {
'label': 'Attribute with min required fields',
'type': 'text',
'value': ''
}
},
{
'Attribute_1': {
'label': 'Attribute with restrictions & complex value',
'description': 'Some attribute description',
'type': 'text',
'value': {'key1': ['val_1', 'val_2']},
'restrictions': [
{
'condition': 'false',
'action': 'disable'
}
]
},
'attribute-2': {
'label': 'Attribute with additional fields',
'type': 'number',
'description': 'Some attribute description',
'value': 10,
'min': 0
},
'metadata': {
'label': 'Some metadata'
}
}
]
for data in data_sets:
utils_mock.parse_yaml.return_value = data
self.validator.check_interface_attributes_schema('nic_config_path')
@mock.patch('fuel_plugin_builder.validators.base.utils.exists')
def test_check_node_attributes_schema_validation_no_file(self,
exists_mock):
mocked_methods = ['validate_schema']
self.mock_methods(self.validator, mocked_methods)
exists_mock.return_value = False
self.validator.check_node_attributes_schema()
self.assertFalse(self.validator.validate_schema.called)
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_node_attributes_schema_validation_failed(self, utils_mock):
data_sets = [
{
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'123': {
'label': 'Attribute without type',
'description': 'Attribute without type',
'value': ''
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute_without_label': {
'description': 'Attribute without label',
'type': 'text',
'value': 'attribute_value'
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute_without_value': {
'label': 'Attribute without value',
'description': 'Attribute without value',
'type': 'text',
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute-1': {
'description': 'Attribute with wrong label type',
'label': 123,
'type': 'checkbox',
'value': ''
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute-2': {
'label': 'Attribute with wrong type type',
'type': [],
'value': ''
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute-3': {
'label': 'Attribute with wrong description type',
'type': 'text',
'value': '',
'description': False
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute-4': {
'label': 'Attribute with wrong restrictions type',
'type': 'text',
'value': '',
'restrictions': {}
}
}
}, {
'plugin_section': {
'metadata': {
'group': 'Metadata without label'
},
'attribute_a': {
'label': 'Some label',
'type': 'text',
'value': '',
}
}
}, {
'plugin_section': {
'metadata': {
'label': None,
'group': 'Metadata with wrong label type'
},
'attribute_a': {
'label': 'Some label',
'type': 'text',
'value': '',
}
}
}, {
'plugin_section': {
'metadata': {
'label': None,
'group': 'Metadata with wrong restriction type',
'restrictions': 'restrictions'
},
'attribute_a': {
'label': 'Some label',
'type': 'text',
'value': '',
}
}
}, {
'metadata': {
'label': 'Some label'
},
'attribute': {
'label': 'Missed plugin section. Wrong level nesting.',
'type': 'text',
'value': ''
}
}, {
'extra_level': {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'attribute-4': {
'label': 'Attribute with extra nesting level',
'type': 'text',
'value': ''
}
}
}
}, {
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'uns@pported_letters=!n_attr_name*': {
'label': 'Attribute with wrong name',
'type': 'text',
'value': ''
}
}
}, {
'uns@pported_letters=!n_section_name': {
'metadata': {
'label': 'Some label'
},
'attribute': {
'label': 'Attribute with wrong name',
'type': 'text',
'value': ''
}
}
},
['wrong interface attributes object type']
]
for data in data_sets:
utils_mock.parse_yaml.return_value = data
self.assertRaises(errors.ValidationError,
self.validator.check_node_attributes_schema)
@mock.patch('fuel_plugin_builder.validators.base.utils')
def test_check_node_attributes_schema_validation_passed(self, utils_mock):
data_sets = [
{
'plugin_section': {
'metadata': {
'label': 'Some label'
},
'123': {
'label': 'Attribute with min required fields',
'type': 'text',
'value': ''
}
},
'plugin_section123': {
'Attribute_1': {
'label': 'Attribute with restrictions & complex value',
'description': 'Some attribute description',
'type': 'text',
'value': {'key1': ['val_1', 'val_2']},
'restrictions': [
{
'condition': 'false',
'action': 'disable'
}
]
},
'attribute-2': {
'label': 'Attribute with additional fields',
'type': 'number',
'description': 'Some attribute description',
'value': 10,
'min': 0
},
'metadata': {
'label': 'Metadata with extra field & restrictions',
'restrictions': [
{
'condition': 'false',
'action': 'disable'
}
],
'group': 'group A'
}
}
}
]
for data in data_sets:
utils_mock.parse_yaml.return_value = data
self.validator.check_node_attributes_schema()

View File

@ -20,6 +20,7 @@ from fuel_plugin_builder.validators import ValidatorV1
from fuel_plugin_builder.validators import ValidatorV2
from fuel_plugin_builder.validators import ValidatorV3
from fuel_plugin_builder.validators import ValidatorV4
from fuel_plugin_builder.validators import ValidatorV5
from fuel_plugin_builder.version_mapping import get_plugin_for_version
@ -60,6 +61,18 @@ class TestVersionMapping(BaseTestCase):
'templates/v4/plugin_data/'])
self.assertEqual(result['validator'], ValidatorV4)
def test_get_plugin_for_version_5(self):
result = get_plugin_for_version('5.0.0')
self.assertEqual(result['version'], '5.0.0')
self.assertEqual(
result['templates'],
[
'templates/base',
'templates/v3/plugin_data/',
'templates/v4/plugin_data/',
'templates/v5/plugin_data/'])
self.assertEqual(result['validator'], ValidatorV5)
def test_get_plugin_for_version_raises_error(self):
with self.assertRaisesRegexp(errors.WrongPackageVersionError,
'Wrong package version "2999"'):

View File

@ -19,4 +19,5 @@ from fuel_plugin_builder.validators.validator_v1 import ValidatorV1
from fuel_plugin_builder.validators.validator_v2 import ValidatorV2
from fuel_plugin_builder.validators.validator_v3 import ValidatorV3
from fuel_plugin_builder.validators.validator_v4 import ValidatorV4
from fuel_plugin_builder.validators.validator_v5 import ValidatorV5
from fuel_plugin_builder.validators.base import LegacyBaseValidator

View File

@ -20,3 +20,4 @@ from fuel_plugin_builder.validators.schemas.v1 import SchemaV1
from fuel_plugin_builder.validators.schemas.v2 import SchemaV2
from fuel_plugin_builder.validators.schemas.v3 import SchemaV3
from fuel_plugin_builder.validators.schemas.v4 import SchemaV4
from fuel_plugin_builder.validators.schemas.v5 import SchemaV5

View File

@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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.
from fuel_plugin_builder.validators.schemas import SchemaV4
class SchemaV5(SchemaV4):
@property
def package_version(self):
return {'enum': ['5.0.0']}
@property
def node_attributes_schema(self):
return {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'patternProperties': {
'^[0-9a-zA-Z_-]+$': {"$ref": "#/definitions/attrItem"}
},
"definitions": {
"attrItem": self.node_nic_attributes_schema
},
"additionalProperties": False
}
@property
def node_nic_attributes_schema(self):
return {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'properties': {
'metadata': self.node_nic_metadata_items
},
'patternProperties': {
'^(?!metadata)[0-9a-zA-Z_-]+$': self.node_nic_attribute_items
},
"additionalProperties": False
}
@property
def node_nic_attribute_items(self):
return {
'type': 'object',
'required': ['type', 'label', 'value'],
'properties': {
'label': {'type': 'string'},
'description': {'type': 'string'},
'type': {'type': 'string'},
'value': {},
'restrictions': self.restrictions
}
}
@property
def node_nic_metadata_items(self):
return {
'type': 'object',
'required': ['label'],
'properties': {
'label': {'type': 'string'},
'restrictions': self.restrictions
}
}

View File

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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.
from os.path import join as join_path
from fuel_plugin_builder.validators.schemas import SchemaV5
from fuel_plugin_builder.validators import ValidatorV4
class ValidatorV5(ValidatorV4):
schema = SchemaV5()
def __init__(self, *args, **kwargs):
super(ValidatorV5, self).__init__(*args, **kwargs)
self.bond_config_path = join_path(self.plugin_path, 'bond_config.yaml')
self.nic_config_path = join_path(self.plugin_path, 'nic_config.yaml')
self.node_config_path = join_path(self.plugin_path, 'node_config.yaml')
@property
def basic_version(self):
return '9.0'
def check_schemas(self):
super(ValidatorV5, self).check_schemas()
self.check_node_attributes_schema()
self.check_interface_attributes_schema(self.bond_config_path)
self.check_interface_attributes_schema(self.nic_config_path)
def check_node_attributes_schema(self):
self.validate_file_by_schema(self.schema.node_attributes_schema,
self.node_config_path,
allow_not_exists=True)
def check_interface_attributes_schema(self, file_path):
self.validate_file_by_schema(self.schema.node_nic_attributes_schema,
file_path,
allow_not_exists=True)

View File

@ -20,7 +20,7 @@ from fuel_plugin_builder import errors
from fuel_plugin_builder import utils
latest_version = '4.0.0'
latest_version = '5.0.0'
def get_mapping():
@ -47,7 +47,15 @@ def get_mapping():
'templates/v3/plugin_data/',
'templates/v4/plugin_data/'],
'validator': validators.ValidatorV4,
'builder': build.BuildPluginV4}]
'builder': build.BuildPluginV4},
{'version': '5.0.0',
'templates': [
'templates/base',
'templates/v3/plugin_data/',
'templates/v4/plugin_data/',
'templates/v5/plugin_data/'],
'validator': validators.ValidatorV5,
'builder': build.BuildPluginV5}]
def get_plugin_for_version(version):