Empty fields processed correctly in plugin adapters
Before this patch all empty but existing plugin metadata properties was removed from output as well as `tasks` field that was not respecting not null constraint at DB level. As a minor patch payload missing InvalidFileFormat error was added. Change-Id: I6a21e347fefb7a9a30be562b7fb3e4a8c5c61a36 Partial-Bug: 1616722 Closes-Bug: 1626855
This commit is contained in:
parent
1e4875938e
commit
c910f056a9
|
@ -20,6 +20,7 @@ from .api import *
|
|||
from .deployment import *
|
||||
from .disk import *
|
||||
from .extension import *
|
||||
from .files import *
|
||||
from .mongodb import *
|
||||
from .network import *
|
||||
from .network_template import *
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# 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 .base import NailgunException
|
||||
|
||||
|
||||
class InvalidFileFormat(NailgunException):
|
||||
message = "Invalid file format: {}, supported formats are: {}"
|
||||
|
||||
def __init__(self, path, supported_formats, *args, **kwargs):
|
||||
super(InvalidFileFormat, self).__init__(*args, **kwargs)
|
||||
self.message = self.message.format(path, ', '.join(supported_formats))
|
|
@ -38,6 +38,16 @@ class Plugin(NailgunObject):
|
|||
|
||||
@classmethod
|
||||
def create(cls, data):
|
||||
"""Create plugin.
|
||||
|
||||
WARNING: don't pass keys with none to non nullable fields.
|
||||
|
||||
:param data: data
|
||||
:type data: dict
|
||||
|
||||
:return: plugin instance
|
||||
:rtype: models.Plugin
|
||||
"""
|
||||
graphs = {}
|
||||
for graph in data.pop("graphs", []):
|
||||
graphs[graph.pop('type')] = graph
|
||||
|
|
|
@ -48,11 +48,8 @@ class PluginAdapterBase(object):
|
|||
def attributes_processors(self):
|
||||
return {
|
||||
'attributes_metadata':
|
||||
lambda data:
|
||||
(data.get('attributes', None) or {})
|
||||
if data else data,
|
||||
'tasks':
|
||||
lambda data: data or []
|
||||
lambda data: (data or {}).get('attributes', {}),
|
||||
'tasks': lambda data: data or []
|
||||
}
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -66,17 +63,24 @@ class PluginAdapterBase(object):
|
|||
:rtype: dict
|
||||
"""
|
||||
data_tree, report = self.loader.load()
|
||||
|
||||
if report.is_failed():
|
||||
logger.error(report.render())
|
||||
logger.error('Problem with loading plugin {0}'.format(
|
||||
self.plugin_path))
|
||||
return data_tree
|
||||
|
||||
for field in data_tree:
|
||||
if field in self.attributes_processors:
|
||||
data_tree[field] = \
|
||||
self.attributes_processors[field](data_tree.get(field))
|
||||
|
||||
data_tree = {k: v for k, v in six.iteritems(data_tree) if v}
|
||||
data_tree = {
|
||||
k: v
|
||||
for k, v in six.iteritems(data_tree)
|
||||
if v is not None
|
||||
}
|
||||
|
||||
return data_tree
|
||||
|
||||
@property
|
||||
|
@ -321,6 +325,7 @@ class PluginAdapterV1(PluginAdapterBase):
|
|||
if isinstance(role, list) and 'controller' in role:
|
||||
role.append('primary-controller')
|
||||
return tasks
|
||||
return []
|
||||
|
||||
def get_tasks(self):
|
||||
tasks = self.plugin.tasks
|
||||
|
|
Loading…
Reference in New Issue