Sync environment_config.yaml for plugins < 3.0.0
By a mistake environment_config.yaml and tasks.yaml are not synced into db for plugins with package version lower than 3.0.0 Change-Id: If0af10c1ccfa6696cbedd27df8357bc3cb642aa8 Closes-bug: #1587134
This commit is contained in:
parent
2637149229
commit
6ced755542
|
@ -63,6 +63,13 @@ class PluginAdapterBase(object):
|
|||
metadata = self._load_config(metadata_file_path) or {}
|
||||
Plugin.update(self.plugin, metadata)
|
||||
|
||||
db_config_metadata_mapping = {
|
||||
'attributes_metadata': self.environment_config_name,
|
||||
'tasks': self.task_config_name
|
||||
}
|
||||
|
||||
self._update_plugin(db_config_metadata_mapping)
|
||||
|
||||
def _load_config(self, config):
|
||||
if os.access(config, os.R_OK):
|
||||
with open(config, "r") as conf:
|
||||
|
@ -75,6 +82,21 @@ class PluginAdapterBase(object):
|
|||
else:
|
||||
logger.warning("Config {0} is not readable.".format(config))
|
||||
|
||||
def _update_plugin(self, mapping):
|
||||
data_to_update = {}
|
||||
|
||||
for attribute, config in six.iteritems(mapping):
|
||||
config_file_path = os.path.join(self.plugin_path, config)
|
||||
attribute_data = self._load_config(config_file_path)
|
||||
# Plugin columns have constraints for nullable data, so
|
||||
# we need to check it
|
||||
if attribute_data:
|
||||
if attribute == 'attributes_metadata':
|
||||
attribute_data = attribute_data['attributes']
|
||||
data_to_update[attribute] = attribute_data
|
||||
|
||||
Plugin.update(self.plugin, data_to_update)
|
||||
|
||||
def _load_tasks(self, config):
|
||||
data = self._load_config(config)
|
||||
for item in data:
|
||||
|
@ -259,31 +281,14 @@ class PluginAdapterV3(PluginAdapterV2):
|
|||
super(PluginAdapterV3, self).sync_metadata_to_db()
|
||||
|
||||
db_config_metadata_mapping = {
|
||||
'attributes_metadata': self.environment_config_name,
|
||||
'roles_metadata': self.node_roles_config_name,
|
||||
'volumes_metadata': self.volumes_config_name,
|
||||
'network_roles_metadata': self.network_roles_config_name,
|
||||
'deployment_tasks': self.deployment_tasks_config_name,
|
||||
'tasks': self.task_config_name
|
||||
}
|
||||
|
||||
self._update_plugin(db_config_metadata_mapping)
|
||||
|
||||
def _update_plugin(self, mapping):
|
||||
data_to_update = {}
|
||||
|
||||
for attribute, config in six.iteritems(mapping):
|
||||
config_file_path = os.path.join(self.plugin_path, config)
|
||||
attribute_data = self._load_config(config_file_path)
|
||||
# Plugin columns have constraints for nullable data, so
|
||||
# we need to check it
|
||||
if attribute_data:
|
||||
if attribute == 'attributes_metadata':
|
||||
attribute_data = attribute_data['attributes']
|
||||
data_to_update[attribute] = attribute_data
|
||||
|
||||
Plugin.update(self.plugin, data_to_update)
|
||||
|
||||
|
||||
class PluginAdapterV4(PluginAdapterV3):
|
||||
"""Plugin wrapper class for package version 4.0.0"""
|
||||
|
|
|
@ -277,6 +277,10 @@ class TestPluginsApi(BasePluginTest):
|
|||
"label": "label"
|
||||
}
|
||||
}, **self.sample_plugin)
|
||||
|
||||
self.mocked_metadata['environment_config.yaml'] = {
|
||||
'attributes': sample['attributes_metadata']
|
||||
}
|
||||
self.create_plugin(sample=sample).json_body
|
||||
cluster = self.create_cluster()
|
||||
editable = self.default_attributes(cluster).json_body['editable']
|
||||
|
|
|
@ -144,10 +144,18 @@ class TestPluginBase(base.BaseTestCase):
|
|||
|
||||
def test_sync_metadata_to_db(self):
|
||||
plugin_metadata = self.env.get_default_plugin_metadata()
|
||||
attributes_metadata = self.env.get_default_plugin_env_config()
|
||||
tasks = self.env.get_default_plugin_tasks()
|
||||
|
||||
mocked_metadata = {
|
||||
self._find_path('metadata'): plugin_metadata,
|
||||
self._find_path('environment_config'): attributes_metadata,
|
||||
self._find_path('tasks'): tasks,
|
||||
}
|
||||
|
||||
with mock.patch.object(
|
||||
self.plugin_adapter, '_load_config') as load_conf:
|
||||
load_conf.return_value = plugin_metadata
|
||||
load_conf.side_effect = lambda key: mocked_metadata[key]
|
||||
self.plugin_adapter.sync_metadata_to_db()
|
||||
|
||||
for key, val in six.iteritems(plugin_metadata):
|
||||
|
|
Loading…
Reference in New Issue