def _load_pkg_svccfg(self): """Load package system service options from a file. :return: dict, package system service descriptor """ fpath = getattr(self._istor_nodes, ISTOR_NODE.PKGREPO).joinpath( self._pkg_id.pkg_id, cr_const.PKG_SVCCFG_FPATH.format(pkg_name=self._pkg_id.pkg_name)) try: pkg_svccfg = cr_utl.rc_load_ini( fpath, emheading='Package service descriptor', render=True, context=self._context) except cr_exc.RCNotFoundError: pkg_svccfg = {} return pkg_svccfg
def get_cluster_conf(istor_cfg_dpath: Path, **cmd_opts): """"Get a collection of DC/OS cluster configuration options. :param istor_cfg_dpath: Path, absolute path to the DC/OS configuration directory within the local DC/OS installation storage :return: dict, configparser.ConfigParser.read_dict() compatible data """ # Load cluster configuration file fpath = Path(cmd_opts.get(CLI_CMDOPT.DCOS_CLUSTERCFGPATH)) # Unblock irrelevant local operations if str(fpath) == 'NOP': return {} if not fpath.is_absolute(): if istor_cfg_dpath.exists(): fpath = istor_cfg_dpath.joinpath(fpath) else: fpath = Path('.').resolve().joinpath(fpath) cluster_conf = cr_utl.rc_load_ini(fpath, emheading='Cluster setup descriptor') # CLI options take precedence, if any. # list(tuple('ipaddr', 'port')) cli_master_priv_ipaddrs = [ ipaddr.partition(':')[::2] for ipaddr in cmd_opts.get(CLI_CMDOPT.MASTER_PRIVIPADDR, '').split(' ') if ipaddr != '' ] mnode_sects = [ sect for sect in cluster_conf if sect.startswith('master-node') ] # iterator(tuple('ipaddr', 'port'), str) change_map = zip(cli_master_priv_ipaddrs, mnode_sects) for item in change_map: if item[0][0]: cluster_conf[item[1]]['privateipaddr'] = item[0][0] if item[0][1]: try: port = int(item[0][1]) except (ValueError, TypeError): port = cm_const.ZK_CLIENTPORT_DFT port = (port if 0 < port < 65536 else cm_const.ZK_CLIENTPORT_DFT) cluster_conf[item[1]]['zookeeperclientport'] = port # Add extra 'master-node' sections, if CLI provides extra arguments extra_cli_items = cli_master_priv_ipaddrs[len(mnode_sects):] for n, item in enumerate(extra_cli_items): if item[0]: # TODO: Implement collision tolerance for section names. cluster_conf[f'master-node-extra{n}'] = {} cluster_conf[f'master-node-extra{n}']['privateipaddr'] = (item[0]) if item[1]: try: port = int(item[1]) except (ValueError, TypeError): port = cm_const.ZK_CLIENTPORT_DFT port = (port if 0 < port < 65536 else cm_const.ZK_CLIENTPORT_DFT) cluster_conf[f'master-node-extra{n}'][ 'zookeeperclientport'] = port # DC/OS storage distribution parameters cli_dstor_url = cmd_opts.get(CLI_CMDOPT.DSTOR_URL) cli_dstor_pkgrepo_path = cmd_opts.get(CLI_CMDOPT.DSTOR_PKGREPOPATH) cli_dstor_pkglist_path = cmd_opts.get(CLI_CMDOPT.DSTOR_PKGLISTPATH) cli_dstor_dcoscfg_path = cmd_opts.get(CLI_CMDOPT.DSTOR_DCOSCFGPATH) if not cluster_conf.get('distribution-storage'): cluster_conf['distribution-storage'] = {} if cli_dstor_url: cluster_conf['distribution-storage']['rooturl'] = cli_dstor_url if cli_dstor_pkgrepo_path: cluster_conf['distribution-storage']['pkgrepopath'] = ( cli_dstor_pkgrepo_path) if cli_dstor_pkglist_path: cluster_conf['distribution-storage']['pkglistpath'] = ( cli_dstor_pkglist_path) if cli_dstor_dcoscfg_path: cluster_conf['distribution-storage']['dcoscfgpath'] = ( cli_dstor_dcoscfg_path) # Local parameters of DC/OS node cli_local_priv_ipaddr = cmd_opts.get(CLI_CMDOPT.LOCAL_PRIVIPADDR) if not cluster_conf.get('local'): cluster_conf['local'] = {} if cli_local_priv_ipaddr: cluster_conf['local']['privateipaddr'] = cli_local_priv_ipaddr return cluster_conf
def test_rc_load_ini_should_provide_valid_content(mock_cfg_parser, *args): """Check does rc_load_ini output equal ConfigParser.items.""" mock_cfg_parser().items.return_value = [('itm', [('key', 'val')])] data = utils.rc_load_ini(Path()) assert data == {'itm': {'key': 'val'}}
def test_rc_load_ini_template_should_return_dict(mock_template, *args): """Check ini transformation to dict.""" mock_template().render.return_value = '[DEFAULT] \n key: val' ini = utils.rc_load_ini(Path(), render=True) assert ini == {'DEFAULT': {'key': 'val'}}
def _load_svc_conf(self): """Load package system service options from a file.""" fpath = self.pkgrepo_dpath.joinpath(str(self.pkg_id), self._svc_cfg_fpath) return cr_utl.rc_load_ini(fpath, emheading='Package svc descriptor')
def _load_pkg_ini(self): """Load package initialization/pre-install options from a file.""" fpath = self.pkgrepo_dpath.joinpath(str(self.pkg_id), self._pkg_ini_fpath) return cr_utl.rc_load_ini(fpath, emheading='Package ini descriptor')
def get_cluster_conf(self): """"Get a collection of DC/OS cluster configuration options. :return: dict, configparser.ConfigParser.read_dict() compatible data """ # TODO: Functionality implemented in this method needs to be reused # in other application parts (e.g. CmdConfigUpgrade) and so, it # has been arranged as a standalone function get_cluster_conf(). # Thus the CmdConfigSetup is to be moved to use that standalone # function instead of this method to avoid massive code # duplication. # Load cluster configuration file fpath = Path(self.cmd_opts.get(CLI_CMDOPT.DCOS_CLUSTERCFGPATH)) # Unblock irrelevant local operations if str(fpath) == 'NOP': self.cluster_conf_nop = True LOG.info(f'{self.msg_src}: cluster_conf: NOP') return {} if not fpath.is_absolute(): if self.inst_storage.cfg_dpath.exists(): fpath = self.inst_storage.cfg_dpath.joinpath(fpath) else: fpath = Path('.').resolve().joinpath(fpath) cluster_conf = cr_utl.rc_load_ini(fpath, emheading='Cluster setup descriptor') # CLI options take precedence, if any. # list(tuple('ipaddr', 'port')) cli_master_priv_ipaddrs = [ ipaddr.partition(':')[::2] for ipaddr in self.cmd_opts.get( CLI_CMDOPT.MASTER_PRIVIPADDR, '').split(' ') if ipaddr != '' ] mnode_sects = [ sect for sect in cluster_conf if sect.startswith('master-node') ] # iterator(tuple('ipaddr', 'port'), str) change_map = zip(cli_master_priv_ipaddrs, mnode_sects) for item in change_map: if item[0][0]: cluster_conf[item[1]]['privateipaddr'] = item[0][0] if item[0][1]: try: port = int(item[0][1]) except (ValueError, TypeError): port = cm_const.ZK_CLIENTPORT_DFT port = (port if 0 < port < 65536 else cm_const.ZK_CLIENTPORT_DFT) cluster_conf[item[1]]['zookeeperclientport'] = port # Add extra 'master-node' sections, if CLI provides extra arguments extra_cli_items = cli_master_priv_ipaddrs[len(mnode_sects):] for n, item in enumerate(extra_cli_items): if item[0]: # TODO: Implement collision tolerance for section names. cluster_conf[f'master-node-extra{n}'] = {} cluster_conf[f'master-node-extra{n}']['privateipaddr'] = ( item[0]) if item[1]: try: port = int(item[1]) except (ValueError, TypeError): port = cm_const.ZK_CLIENTPORT_DFT port = (port if 0 < port < 65536 else cm_const.ZK_CLIENTPORT_DFT) cluster_conf[f'master-node-extra{n}'][ 'zookeeperclientport'] = port # DC/OS storage distribution parameters cli_dstor_url = self.cmd_opts.get(CLI_CMDOPT.DSTOR_URL) cli_dstor_pkgrepo_path = self.cmd_opts.get( CLI_CMDOPT.DSTOR_PKGREPOPATH) cli_dstor_pkglist_path = self.cmd_opts.get( CLI_CMDOPT.DSTOR_PKGLISTPATH) cli_dstor_dcoscfg_path = self.cmd_opts.get( CLI_CMDOPT.DSTOR_DCOSCFGPATH) if not cluster_conf.get('distribution-storage'): cluster_conf['distribution-storage'] = {} if cli_dstor_url: cluster_conf['distribution-storage']['rooturl'] = cli_dstor_url if cli_dstor_pkgrepo_path: cluster_conf['distribution-storage']['pkgrepopath'] = ( cli_dstor_pkgrepo_path) if cli_dstor_pkglist_path: cluster_conf['distribution-storage']['pkglistpath'] = ( cli_dstor_pkglist_path) if cli_dstor_dcoscfg_path: cluster_conf['distribution-storage']['dcoscfgpath'] = ( cli_dstor_dcoscfg_path) # Local parameters of DC/OS node cli_local_priv_ipaddr = self.cmd_opts.get(CLI_CMDOPT.LOCAL_PRIVIPADDR) if not cluster_conf.get('local'): cluster_conf['local'] = {} if cli_local_priv_ipaddr: cluster_conf['local']['privateipaddr'] = cli_local_priv_ipaddr return cluster_conf