Added data serialisation for master node resources

* Introduced new configuration parser driver
* All drives should be placed in drivers folder
* Master node data are serialised for cluster object

Change-Id: I4ab4b54530272a76337357ce981e2144fb67fd71
This commit is contained in:
Dmitry Ukov 2016-09-23 18:29:47 +03:00
parent 78fec444ad
commit 5a11df2194
7 changed files with 68 additions and 12 deletions

View File

View File

@ -0,0 +1,28 @@
# 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 yaml
from nailgun.logger import logger
class YamlConfig(object):
def __init__(self, config_file, resource_name):
with open(config_file) as cfg:
self.config = yaml.load(cfg)
self.config_name = resource_name
logger.debug("Initalized Config {0}.".
format(config_file))
def to_config_dict(self):
return self.config

View File

@ -52,12 +52,12 @@ class OpenStackConfigPipeline(BasePipeline):
GitRepo.checkout(repo)
repo_path = os.path.join(const.REPOS_DIR, repo.repo_name)
resource_mapping = ExternalGit.ext_settings['resource_mapping']
resource_mapping.pop('master_config', {})
exts_list = utils.get_file_exts_list(resource_mapping)
global_config = utils.get_config_hash(repo_path,
resource_mapping,
exts=exts_list)
# Read config for overrides
# Overrides file should contain following mapping
# - role:config_file_dir
@ -103,6 +103,24 @@ class OpenStackConfigPipeline(BasePipeline):
logger.info("Node {0} config from git {1}".format(uid, common))
return node_data
@classmethod
def process_deployment_for_cluster(self, cluster, data):
repo = GitRepo.get_by_cluster_id(cluster.id)
if not repo:
return data
GitRepo.checkout(repo)
repo_path = os.path.join(const.REPOS_DIR, repo.repo_name)
resource_mapping = ExternalGit.ext_settings['resource_mapping']
master_config_mapping = resource_mapping.pop('master_config', {})
master_config = utils.get_config_hash(
repo_path,
{'master_config': master_config_mapping},
exts=['yaml']
)
data['master_config'] = master_config
return data
# TODO(dukov) Remove decorator extension management is available
@utils.register_extension(u'fuel_external_git')

View File

@ -62,3 +62,7 @@ resource_mapping:
nova_paste_api_ini:
alias: nova-api-paste.ini
path: /etc/nova/api-paste.ini
master_config:
alias: master_config.yaml
path: ""
driver: 'fuel_external_git.drivers.yaml_driver.YamlConfig'

View File

@ -12,7 +12,7 @@
import os
from fuel_external_git.openstack_config import OpenStackConfig
from fuel_external_git.drivers.openstack_config import OpenStackConfig
from fuel_external_git.tests import base

View File

@ -33,19 +33,25 @@ def get_config_hash(file_dir, resource_mapping, exts=['conf']):
"Directory {} not found. Returning emty dict".format(file_dir))
return {}
cfg2drv = {}
for resource, params in resource_mapping.items():
drv = params.get(
'driver',
'fuel_external_git.drivers.openstack_config.OpenStackConfig'
)
cfg2drv[params['alias']] = {'drv': drv, 'resource': resource}
conf_files = [conf for conf in os.listdir(file_dir)
if conf.split('.')[-1] in exts]
for conf_file in conf_files:
resource_name = None
driver_str = 'fuel_external_git.openstack_config.OpenStackConfig'
for resource, params in resource_mapping.items():
if params['alias'] == conf_file:
resource_name = resource
driver_str = params.get('driver', driver_str)
break
drv_class = importutils.import_class(driver_str)
config = drv_class(os.path.join(file_dir, conf_file), resource_name)
res[config.config_name] = config.to_config_dict()
if conf_file in cfg2drv.keys():
drv_class = importutils.import_class(cfg2drv[conf_file]['drv'])
config = drv_class(
os.path.join(file_dir, conf_file),
cfg2drv[conf_file]['resource']
)
res[config.config_name] = config.to_config_dict()
return res