def _process_dependencies(self): services_map = utils.get_deploy_components_info() deps_map = utils.get_dependencies_map(services_map) new_deps = [] for dep in self.dependencies: new_deps.extend(utils.extend_dependency(dep, deps_map, {}, {})) self.dependencies = new_deps
def validate(components, types): if not types: types = ["service-def"] for validation_type in set(types): if validation_type == "service-def": component_map = utils.get_deploy_components_info() service_validation.validate_service_definitions( component_map, components) else: raise RuntimeError( "Unexpected validation type: '{}'".format(validation_type))
def get_deps_map(components_map=None): """Returns dependencies map.""" components_map = components_map or utils.get_deploy_components_info() deps_map = {} for service_name, service_map in components_map.items(): deps_map[service_name] = Node( service_name, 'service', _parse_service_deps(service_map['service_content'])) deps_map.update( _parse_pre_and_post_deps(service_map['service_content'])) return deps_map
def get_deps_graph(components_map=None): """Returns dependencies map.""" components_map = components_map or utils.get_deploy_components_info() deps_graph = {} for service_name, service in components_map.items(): deps_graph[service_name] = set() containers = service['service_content']['service']['containers'] for cont in containers: for cmd in itertools.chain( cont.get('pre', []), [cont.get('daemon', [])], cont.get('post', [])): for dep in cmd.get('dependencies', ()): deps_graph[service_name].add(dep.partition("/")[0]) return deps_graph
def validate(components, types): if not types: types = ["service-def", "dockerfiles"] for validation_type in set(types): if validation_type == "service-def": component_map = utils.get_deploy_components_info() service_validation.validate_service_definitions(component_map, components) service_validation.validate_service_versions(component_map, components) elif validation_type == "dockerfiles": dockerfiles.validate() else: raise RuntimeError( "Unexpected validation type: '{}'".format(validation_type) )
def take_action(self, parsed_args): if CONF.repositories.clone: do_fetch() config.load_component_defaults() # only these two are being implicitly passed CONF.action._update( dry_run=parsed_args.dry_run, export_dir=parsed_args.export_dir, ) components_map = utils.get_deploy_components_info() components = parsed_args.components if components: components = set(components) validation_service.validate_service_definitions( components_map, components) deploy.deploy_components(components_map, components)
def take_action(self, parsed_args): self._fetch_repos() config.load_component_defaults() # only these two are being implicitly passed CONF.action._update( dry_run=parsed_args.dry_run, export_dir=parsed_args.export_dir, ) components_map = utils.get_deploy_components_info() components = parsed_args.components if components: components = set(components) validation_service.validate_service_definitions( components_map, components) validation_service.validate_service_versions( components_map, components) deploy.deploy_components(components_map, components)
def test_get_deploy_components_info_with_custom_context(self): custom_params = { "configs": { "service_name": "keystone", "db_root_password": "******", "keystone_db_name": "keystone_db_name_custom", "keystone_db_username": "******", "keystone_db_password": "******", "openstack_user_password": "******", "openstack_user_name": "os_user_name_custom", "openstack_project_name": "os_project_name_custom", "openstack_role_name": "os_role_name_custom", "keystone_admin_port": "keystone_admin_port_custom", "keystone_public_port": "keystone_public_port_custom" } } conf = config._yaml.AttrDict() conf._merge(custom_params) conf._merge(config._REAL_CONF) config._REAL_CONF = conf base_dir = os.path.dirname(__file__) self.conf.repositories.path = os.path.join(base_dir, "test_repo_dir") self.conf.repositories.repos = [{"name": "component"}] config.load_component_defaults() res = utils.get_deploy_components_info( rendering_context=custom_params["configs"] )["keystone"]["service_content"] with open( os.path.join(base_dir, "service-rendered-example-custom.yaml")) as f: expected = yaml.load(f) self.assertDictEqual(expected, res)
def test_get_deploy_components_info_with_default_context(self): default_params = { "configs": { "service_name": "keystone", "db_root_password": "******", "keystone_db_name": "keystone_db_name_default", "keystone_db_username": "******", "keystone_db_password": "******", "openstack_user_password": "******", "openstack_user_name": "os_user_name_default", "openstack_project_name": "os_project_name_default", "openstack_role_name": "os_role_name_default", "keystone_admin_port": "keystone_admin_port_default", "keystone_public_port": "keystone_public_port_default" } } conf = config._yaml.AttrDict() conf._merge(default_params) conf._merge(config._REAL_CONF) config._REAL_CONF = conf base_dir = os.path.dirname(__file__) self.conf.repositories.path = os.path.join(base_dir, "test_repo_dir") self.conf.repositories.repos = [{"name": "component"}] res = ( utils.get_deploy_components_info()["keystone"]["service_content"] ) print(yaml.dump(res, default_flow_style=False)) with open(os.path.join(base_dir, "service-rendered-example-default.yaml")) as f: expected = yaml.load(f) self.assertDictEqual(expected, res)
def test_get_deploy_components_info_with_default_context(self): default_params = { "configs": { "service_name": "keystone", "db_root_password": "******", "keystone_db_name": "keystone_db_name_default", "keystone_db_username": "******", "keystone_db_password": "******", "openstack_user_password": "******", "openstack_user_name": "os_user_name_default", "openstack_project_name": "os_project_name_default", "openstack_role_name": "os_role_name_default", "keystone_admin_port": "keystone_admin_port_default", "keystone_public_port": "keystone_public_port_default" } } conf = config._yaml.AttrDict() conf._merge(default_params) conf._merge(config._REAL_CONF) config._REAL_CONF = conf base_dir = os.path.dirname(__file__) self.conf.repositories.path = os.path.join(base_dir, "test_repo_dir") self.conf.repositories.repos = [{"name": "component"}] res = ( utils.get_deploy_components_info()["keystone"]["service_content"]) print(yaml.dump(res, default_flow_style=False)) with open( os.path.join(base_dir, "service-rendered-example-default.yaml")) as f: expected = yaml.load(f) self.assertDictEqual(expected, res)
def show_dep(components): components_map = utils.get_deploy_components_info() base_validation.validate_components_names(set(components), components_map) deps = get_deps(components, components_map) print(" ".join(deps))