diff options
author | Szilard Cserey <szilard.cserey@ericsson.com> | 2015-08-18 19:47:50 +0200 |
---|---|---|
committer | Szilard Cserey <szilard.cserey@ericsson.com> | 2015-09-16 11:33:23 +0200 |
commit | 49aacd62348d7edf91c5b9bbd40d31708610e1e5 (patch) | |
tree | 0dc637b67d2c56ea71c995ca26113df6c81ce16f /fuel/deploy/cloud | |
parent | 54f12d2bdd72ae12061ebf62c5b70f357850c411 (diff) |
Autodeployer support for ODL Plugin installation + Fuel 6.1
- Opendaylight plugin installation
- Adapting Autodeployer to Fuel 6.1
- restarting blades that couldn't be discovered Fuel in time
BGS-87 Autodeployment restarts blade if that has not been discovered by Fuel
BGS-90 Fuel 6.1 and Opendaylight Fuel plugin install support for Autodeployer
Change-Id: I83aab3f8caf368a70fd3f2b67c7ba1b6191993c6
Signed-off-by: Szilard Cserey <szilard.cserey@ericsson.com>
Diffstat (limited to 'fuel/deploy/cloud')
-rw-r--r-- | fuel/deploy/cloud/configure_environment.py | 41 | ||||
-rw-r--r-- | fuel/deploy/cloud/configure_network.py | 15 | ||||
-rw-r--r-- | fuel/deploy/cloud/configure_nodes.py | 34 | ||||
-rw-r--r-- | fuel/deploy/cloud/configure_settings.py | 12 | ||||
-rw-r--r-- | fuel/deploy/cloud/deploy.py | 201 | ||||
-rw-r--r-- | fuel/deploy/cloud/deployment.py | 87 |
6 files changed, 208 insertions, 182 deletions
diff --git a/fuel/deploy/cloud/configure_environment.py b/fuel/deploy/cloud/configure_environment.py index d0037d7..2d68c1b 100644 --- a/fuel/deploy/cloud/configure_environment.py +++ b/fuel/deploy/cloud/configure_environment.py @@ -1,6 +1,13 @@ +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + import common -import os -import shutil from configure_settings import ConfigureSettings from configure_network import ConfigureNetwork @@ -14,6 +21,9 @@ exec_cmd = common.exec_cmd parse = common.parse err = common.err log = common.log +delete = common.delete +create_dir_if_not_exists = common.create_dir_if_not_exists + class ConfigureEnvironment(object): @@ -21,7 +31,6 @@ class ConfigureEnvironment(object): self.env_id = None self.dea = dea self.yaml_config_dir = yaml_config_dir - self.env_name = self.dea.get_property('environment_name') self.release_id = release_id self.node_id_roles_dict = node_id_roles_dict self.required_networks = [] @@ -36,21 +45,20 @@ class ConfigureEnvironment(object): def configure_environment(self): log('Configure environment') - if os.path.exists(self.yaml_config_dir): - log('Deleting existing config directory %s' % self.yaml_config_dir) - shutil.rmtree(self.yaml_config_dir) - log('Creating new config directory %s' % self.yaml_config_dir) - os.makedirs(self.yaml_config_dir) - - mode = self.dea.get_property('environment_mode') + delete(self.yaml_config_dir) + create_dir_if_not_exists(self.yaml_config_dir) + env_name = self.dea.get_env_name() + env_mode = self.dea.get_env_mode() + env_net_segment_type = self.dea.get_env_net_segment_type() log('Creating environment %s release %s, mode %s, network-mode neutron' - ', net-segment-type vlan' % (self.env_name, self.release_id, mode)) + ', net-segment-type %s' + % (env_name, self.release_id, env_mode, env_net_segment_type)) exec_cmd('fuel env create --name %s --release %s --mode %s ' - '--network-mode neutron --net-segment-type vlan' - % (self.env_name, self.release_id, mode)) + '--network-mode neutron --net-segment-type %s' + % (env_name, self.release_id, env_mode, env_net_segment_type)) - if not self.env_exists(self.env_name): - err('Failed to create environment %s' % self.env_name) + if not self.env_exists(env_name): + err('Failed to create environment %s' % env_name) self.config_settings() self.config_network() self.config_nodes() @@ -68,6 +76,3 @@ class ConfigureEnvironment(object): nodes = ConfigureNodes(self.yaml_config_dir, self.env_id, self.node_id_roles_dict, self.dea) nodes.config_nodes() - - - diff --git a/fuel/deploy/cloud/configure_network.py b/fuel/deploy/cloud/configure_network.py index 295eb90..0027894 100644 --- a/fuel/deploy/cloud/configure_network.py +++ b/fuel/deploy/cloud/configure_network.py @@ -1,3 +1,13 @@ +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + + import common import yaml import io @@ -11,6 +21,8 @@ parse = common.parse err = common.err check_file_exists = common.check_file_exists log = common.log +backup = common.backup + class ConfigureNetwork(object): @@ -41,6 +53,7 @@ class ConfigureNetwork(object): network_yaml = ('%s/network_%s.yaml' % (self.yaml_config_dir, self.env_id)) check_file_exists(network_yaml) + backup(network_yaml) network_config = self.dea.get_property('network') @@ -58,4 +71,4 @@ class ConfigureNetwork(object): network.update(net_id[network['name']]) with io.open(network_yaml, 'w') as stream: - yaml.dump(network_config, stream, default_flow_style=False)
\ No newline at end of file + yaml.dump(network_config, stream, default_flow_style=False) diff --git a/fuel/deploy/cloud/configure_nodes.py b/fuel/deploy/cloud/configure_nodes.py index a2f2a10..06199d2 100644 --- a/fuel/deploy/cloud/configure_nodes.py +++ b/fuel/deploy/cloud/configure_nodes.py @@ -1,3 +1,13 @@ +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + + import common import yaml import io @@ -12,6 +22,7 @@ parse = common.parse err = common.err check_file_exists = common.check_file_exists log = common.log +backup = common.backup class ConfigureNodes(object): @@ -39,18 +50,18 @@ class ConfigureNodes(object): def modify_node_network_schemes(self, node_id, roles_blade): log('Modify network transformations for node %s' % node_id) type = self.dea.get_node_property(roles_blade[1], 'transformations') - transformations = self.dea.get_transformations(type) - - for node_file in glob.glob('%s/deployment_%s/*_%s.yaml' - % (self.yaml_config_dir, self.env_id, - node_id)): + transformations = self.dea.get_property(type) + deployment_dir = '%s/deployment_%s' % ( + self.yaml_config_dir, self.env_id) + backup(deployment_dir) + for node_file in glob.glob(deployment_dir + '/*_%s.yaml' % node_id): with io.open(node_file) as stream: - node = yaml.load(stream) + node = yaml.load(stream) - node['network_scheme']['transformations'] = transformations + node['network_scheme'].update(transformations) with io.open(node_file, 'w') as stream: - yaml.dump(node, stream, default_flow_style=False) + yaml.dump(node, stream, default_flow_style=False) def download_deployment_config(self): log('Download deployment config for environment %s' % self.env_id) @@ -77,6 +88,7 @@ class ConfigureNodes(object): interface_yaml = ('%s/node_%s/interfaces.yaml' % (self.yaml_config_dir, node_id)) check_file_exists(interface_yaml) + backup(interface_yaml) with io.open(interface_yaml) as stream: interfaces = yaml.load(stream) @@ -84,10 +96,10 @@ class ConfigureNodes(object): net_name_id = {} for interface in interfaces: for network in interface['assigned_networks']: - net_name_id[network['name']] = network['id'] + net_name_id[network['name']] = network['id'] type = self.dea.get_node_property(roles_blade[1], 'interfaces') - interface_config = self.dea.get_interfaces(type) + interface_config = self.dea.get_property(type) for interface in interfaces: interface['assigned_networks'] = [] @@ -99,4 +111,4 @@ class ConfigureNodes(object): interface['assigned_networks'].append(net) with io.open(interface_yaml, 'w') as stream: - yaml.dump(interfaces, stream, default_flow_style=False)
\ No newline at end of file + yaml.dump(interfaces, stream, default_flow_style=False) diff --git a/fuel/deploy/cloud/configure_settings.py b/fuel/deploy/cloud/configure_settings.py index ac0afdc..fa918fd 100644 --- a/fuel/deploy/cloud/configure_settings.py +++ b/fuel/deploy/cloud/configure_settings.py @@ -1,3 +1,12 @@ +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + import common import yaml import io @@ -11,6 +20,8 @@ parse = common.parse err = common.err check_file_exists = common.check_file_exists log = common.log +backup = common.backup + class ConfigureSettings(object): @@ -40,6 +51,7 @@ class ConfigureSettings(object): settings_yaml = ('%s/settings_%s.yaml' % (self.yaml_config_dir, self.env_id)) check_file_exists(settings_yaml) + backup(settings_yaml) settings = self.dea.get_property('settings') diff --git a/fuel/deploy/cloud/deploy.py b/fuel/deploy/cloud/deploy.py index c423834..1534f0b 100644 --- a/fuel/deploy/cloud/deploy.py +++ b/fuel/deploy/cloud/deploy.py @@ -1,7 +1,17 @@ -import time +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + + +import os import yaml import io -import sys +import glob import common from dea import DeploymentEnvironmentAdapter @@ -22,173 +32,94 @@ log = common.log commafy = common.commafy ArgParser = common.ArgParser + class Deploy(object): - def __init__(self, dea_file, macs_file): + def __init__(self, dea_file, blade_node_file, plugins_dir, + no_health_check): self.dea = DeploymentEnvironmentAdapter(dea_file) - self.macs_file = macs_file + self.blade_node_file = blade_node_file + self.plugins_dir = plugins_dir + self.no_health_check = no_health_check self.macs_per_blade = {} self.blades = self.dea.get_node_ids() - self.node_ids_dict = {} - self.node_id_roles_dict = {} - self.supported_release = None + self.blade_node_dict = {} + self.node_roles_dict = {} self.env_id = None - self.wanted_release = self.dea.get_wanted_release() - - def cleanup_fuel_environments(self, env_list): - WAIT_LOOP = 60 - SLEEP_TIME = 10 - for env in env_list: - log('Deleting environment %s' % env[E['id']]) - exec_cmd('fuel env --env %s --delete' % env[E['id']]) - all_env_erased = False - for i in range(WAIT_LOOP): - env_list = parse(exec_cmd('fuel env list')) - if env_list: - time.sleep(SLEEP_TIME) - else: - all_env_erased = True - break - if not all_env_erased: - err('Could not erase these environments %s' - % [(env[E['id']], env[E['status']]) for env in env_list]) - - def cleanup_fuel_nodes(self, node_list): - for node in node_list: - if node[N['status']] == 'discover': - log('Deleting node %s' % node[N['id']]) - exec_cmd('fuel node --node-id %s --delete-from-db' - % node[N['id']]) - exec_cmd('cobbler system remove --name node-%s' - % node[N['id']], False) - - def check_previous_installation(self): - log('Check previous installation') - env_list = parse(exec_cmd('fuel env list')) - if env_list: - self.cleanup_fuel_environments(env_list) - node_list = parse(exec_cmd('fuel node list')) - if node_list: - self.cleanup_fuel_nodes(node_list) - - def check_supported_release(self): - log('Check supported release: %s' % self.wanted_release) - release_list = parse(exec_cmd('fuel release -l')) - for release in release_list: - if release[R['name']] == self.wanted_release: - self.supported_release = release - break - if not self.supported_release: - err('This Fuel does not contain the following release: %s' - % self.wanted_release) - - def check_prerequisites(self): - log('Check prerequisites') - self.check_supported_release() - self.check_previous_installation() - - def get_mac_addresses(self): - with io.open(self.macs_file, 'r') as stream: - self.macs_per_blade = yaml.load(stream) - - def find_mac_in_dict(self, mac): - for blade, mac_list in self.macs_per_blade.iteritems(): - if mac in mac_list: - return blade - - def all_blades_discovered(self): - for blade, node_id in self.node_ids_dict.iteritems(): - if not node_id: - return False - return True - - def not_discovered_blades_summary(self): - summary = '' - for blade, node_id in self.node_ids_dict.iteritems(): - if not node_id: - summary += '\n[blade %s]' % blade - return summary - - def node_discovery(self, node_list, discovered_macs): - for node in node_list: - if (node[N['status']] == 'discover' and - node[N['online']] == 'True' and - node[N['mac']] not in discovered_macs): - discovered_macs.append(node[N['mac']]) - blade = self.find_mac_in_dict(node[N['mac']]) - if blade: - log('Blade %s discovered as Node %s with MAC %s' - % (blade, node[N['id']], node[N['mac']])) - self.node_ids_dict[blade] = node[N['id']] - - def discovery_waiting_loop(self, discovered_macs): - WAIT_LOOP = 320 - SLEEP_TIME = 10 - all_discovered = False - for i in range(WAIT_LOOP): - node_list = parse(exec_cmd('fuel node list')) - if node_list: - self.node_discovery(node_list, discovered_macs) - if self.all_blades_discovered(): - all_discovered = True - break - else: - time.sleep(SLEEP_TIME) - return all_discovered - - def wait_for_discovered_blades(self): - log('Wait for discovered blades') - discovered_macs = [] - for blade in self.blades: - self.node_ids_dict[blade] = None - all_discovered = self.discovery_waiting_loop(discovered_macs) - if not all_discovered: - err('Not all blades have been discovered: %s' - % self.not_discovered_blades_summary()) + self.wanted_release = self.dea.get_property('wanted_release') + + def get_blade_node_mapping(self): + with io.open(self.blade_node_file, 'r') as stream: + self.blade_node_dict = yaml.load(stream) def assign_roles_to_cluster_node_ids(self): - self.node_id_roles_dict = {} - for blade, node_id in self.node_ids_dict.iteritems(): + self.node_roles_dict = {} + for blade, node in self.blade_node_dict.iteritems(): roles = commafy(self.dea.get_node_role(blade)) - self.node_id_roles_dict[node_id] = (roles, blade) + self.node_roles_dict[node] = (roles, blade) def configure_environment(self): + release_list = parse(exec_cmd('fuel release -l')) + for release in release_list: + if release[R['name']] == self.wanted_release: + break config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR, - self.supported_release[R['id']], - self.node_id_roles_dict) + release[R['id']], + self.node_roles_dict) config_env.configure_environment() self.env_id = config_env.env_id def deploy_cloud(self): dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id, - self.node_id_roles_dict) + self.node_roles_dict, self.no_health_check) dep.deploy() + def install_plugins(self): + log('Installing Fuel Plugins') + if self.plugins_dir and os.path.isdir(self.plugins_dir): + for f in glob.glob('%s/*.rpm' % self.plugins_dir): + log('Found plugin %s, installing ...' % f) + r, c = exec_cmd('fuel plugins --install %s' % f, False) + if c > 0 and 'does not update installed package' not in r: + err('Installation of Fuel Plugin %s failed' % f) + def deploy(self): - self.get_mac_addresses() - self.check_prerequisites() - self.wait_for_discovered_blades() + + self.install_plugins() + + self.get_blade_node_mapping() + self.assign_roles_to_cluster_node_ids() + self.configure_environment() + self.deploy_cloud() + def parse_arguments(): parser = ArgParser(prog='python %s' % __file__) + parser.add_argument('-nh', dest='no_health_check', action='store_true', + default=False, + help='Don\'t run health check after deployment') parser.add_argument('dea_file', action='store', help='Deployment Environment Adapter: dea.yaml') - parser.add_argument('macs_file', action='store', - help='Blade MAC addresses: macs.yaml') + parser.add_argument('blade_node_file', action='store', + help='Blade Node mapping: blade_node.yaml') + parser.add_argument('plugins_dir', nargs='?', action='store', + help='Plugins directory') args = parser.parse_args() check_file_exists(args.dea_file) - check_file_exists(args.macs_file) - return (args.dea_file, args.macs_file) + check_file_exists(args.blade_node_file) + return (args.dea_file, args.blade_node_file, args.plugins_dir, + args.no_health_check) + def main(): - dea_file, macs_file = parse_arguments() + dea_file, blade_node_file, plugins_dir, no_health_check = parse_arguments() - deploy = Deploy(dea_file, macs_file) + deploy = Deploy(dea_file, blade_node_file, plugins_dir, no_health_check) deploy.deploy() if __name__ == '__main__': - main()
\ No newline at end of file + main() diff --git a/fuel/deploy/cloud/deployment.py b/fuel/deploy/cloud/deployment.py index 0054c5b..43bd4b6 100644 --- a/fuel/deploy/cloud/deployment.py +++ b/fuel/deploy/cloud/deployment.py @@ -1,3 +1,13 @@ +############################################################################### +# Copyright (c) 2015 Ericsson AB and others. +# szilard.cserey@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + + import common import os import shutil @@ -15,20 +25,26 @@ run_proc = common.run_proc parse = common.parse err = common.err log = common.log +literal_unicode = common.literal_unicode +literal_unicode_representer = common.literal_unicode_representer +yaml.add_representer(literal_unicode, literal_unicode_representer) +backup = common.backup class Deployment(object): - def __init__(self, dea, yaml_config_dir, env_id, node_id_roles_dict): + def __init__(self, dea, yaml_config_dir, env_id, node_id_roles_dict, + no_health_check): self.dea = dea self.yaml_config_dir = yaml_config_dir self.env_id = env_id self.node_id_roles_dict = node_id_roles_dict + self.no_health_check = no_health_check def download_deployment_info(self): log('Download deployment info for environment %s' % self.env_id) - deployment_dir = '%s/deployment_%s' \ - % (self.yaml_config_dir, self.env_id) + deployment_dir = ('%s/deployment_%s' + % (self.yaml_config_dir, self.env_id)) if os.path.exists(deployment_dir): shutil.rmtree(deployment_dir) exec_cmd('fuel deployment --env %s --download --dir %s' @@ -39,21 +55,54 @@ class Deployment(object): exec_cmd('fuel --env %s deployment --upload --dir %s' % (self.env_id, self.yaml_config_dir)) + def __update_opnfv_dict(self, opnfv_dict, key, node_type, val): + if val: + if key not in opnfv_dict: + opnfv_dict.update({key: {}}) + opnfv_dict[key].update({node_type: val}) + def config_opnfv(self): log('Configure OPNFV settings on environment %s' % self.env_id) - opnfv_compute = self.dea.get_opnfv('compute') - opnfv_controller = self.dea.get_opnfv('controller') self.download_deployment_info() + + opnfv = {'opnfv': {}} + dns_list = self.dea.get_dns_list() + host_list = self.dea.get_hosts() + + ntp_list_for_controller = '' + for ntp in self.dea.get_ntp_list(): + ntp_list_for_controller += 'server %s\n' % ntp + + ntp_list_for_compute = '' + for controller_file in glob.glob( + '%s/deployment_%s/*controller*.yaml' + % (self.yaml_config_dir, self.env_id)): + with io.open(controller_file) as stream: + controller = yaml.load(stream) + ntp_list_for_compute += 'server %s\n' % controller['fqdn'] + + self.__update_opnfv_dict( + opnfv['opnfv'], 'dns', 'controller', dns_list[:]) + self.__update_opnfv_dict( + opnfv['opnfv'], 'dns', 'compute', dns_list[:]) + self.__update_opnfv_dict( + opnfv['opnfv'], 'ntp', 'controller', + literal_unicode(ntp_list_for_controller)) + self.__update_opnfv_dict( + opnfv['opnfv'], 'ntp', 'compute', + literal_unicode(ntp_list_for_compute)) + + if host_list: + opnfv['opnfv'].update({'hosts': host_list}) + for node_file in glob.glob('%s/deployment_%s/*.yaml' % (self.yaml_config_dir, self.env_id)): - with io.open(node_file) as stream: - node = yaml.load(stream) - if node['role'] == 'compute': - node.update(opnfv_compute) - else: - node.update(opnfv_controller) - with io.open(node_file, 'w') as stream: - yaml.dump(node, stream, default_flow_style=False) + with io.open(node_file) as stream: + node = yaml.load(stream) + node.update(opnfv) + with io.open(node_file, 'w') as stream: + yaml.dump(node, stream, default_flow_style=False) + self.upload_deployment_info() def run_deploy(self): @@ -103,11 +152,15 @@ class Deployment(object): def health_check(self): log('Now running sanity and smoke health checks') - log(exec_cmd('fuel health --env %s --check sanity,smoke --force' - % self.env_id)) - + r = exec_cmd('fuel health --env %s --check sanity,smoke --force' + % self.env_id) + log(r) + if 'failure' in r: + err('Healthcheck failed!') + def deploy(self): self.config_opnfv() self.run_deploy() self.verify_node_status() - self.health_check()
\ No newline at end of file + if not self.no_health_check: + self.health_check() |