def __init__(self, conf, uuid, namespace=None, service=None, pids_path=None, default_cmd_callback=None, cmd_addl_env=None, pid_file=None): self.conf = conf self.uuid = uuid self.namespace = namespace self.default_cmd_callback = default_cmd_callback self.cmd_addl_env = cmd_addl_env self.pids_path = pids_path or self.conf.external_pids self.pid_file = pid_file if service: self.service_pid_fname = 'pid.' + service self.service = service else: self.service_pid_fname = 'pid' self.service = 'default-service' utils.ensure_dir(os.path.dirname(self.get_pid_file_name()))
def __init__(self, conf, network, process_monitor, version=None, plugin=None): super(DhcpLocalProcess, self).__init__(conf, network, process_monitor, version, plugin) self.confs_dir = self.get_confs_dir(conf) self.network_conf_dir = os.path.join(self.confs_dir, network.id) utils.ensure_dir(self.network_conf_dir)
def enable(self): """Enables DHCP for this network by spawning a local process.""" if self.active: self.restart() elif self._enable_dhcp(): utils.ensure_dir(self.network_conf_dir) self.interface_name = cfg.CONF.symcpe.dhcp_interface self.spawn_process()
def _get_state_file_path(self, loadbalancer_id, kind, ensure_state_dir=True): """Returns the file name for a given kind of config file.""" confs_dir = os.path.abspath(os.path.normpath(self.state_path)) conf_dir = os.path.join(confs_dir, loadbalancer_id) if ensure_state_dir: linux_utils.ensure_dir(conf_dir) return os.path.join(conf_dir, kind)
def enable(self): """Enables DHCP for this network by spawning a local process.""" if self.active: self.restart() elif self._enable_dhcp(): utils.ensure_dir(self.network_conf_dir) interface_name = self.device_manager.setup(self.network) self.interface_name = interface_name self.spawn_process()
def get_pid_file_name(self, ensure_pids_dir=False): """Returns the file name for a given kind of config file.""" if self.pid_file: if ensure_pids_dir: utils.ensure_dir(os.path.dirname(self.pid_file)) return self.pid_file else: return utils.get_conf_file_name(self.pids_path, self.uuid, self.service_pid_fname, ensure_pids_dir)
def start(self): fmt = self.process_name + "--%Y-%m-%d--%H%M%S.log" log_dir = os.path.join(DEFAULT_LOG_DIR, self.test_name) utils.ensure_dir(log_dir) cmd = [spawn.find_executable(self.exec_name), '--log-dir', log_dir, '--log-file', timeutils.strtime(fmt=fmt)] for filename in self.config_filenames: cmd += ['--config-file', filename] self.process = async_process.AsyncProcess(cmd) self.process.start(block=True)
def __init__(self, host=None): super(DhcpAgent, self).__init__(host=host) self.needs_resync_reasons = collections.defaultdict(list) self.conf = cfg.CONF self.cache = NetworkCache() self.dhcp_driver_cls = importutils.import_class(self.conf.dhcp_driver) ctx = context.get_admin_context_without_session() self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, ctx, self.conf.use_namespaces) # create dhcp dir to store dhcp info dhcp_dir = os.path.dirname("/%s/dhcp/" % self.conf.state_path) linux_utils.ensure_dir(dhcp_dir) self.dhcp_version = self.dhcp_driver_cls.check_version() self._populate_networks_cache() self._process_monitor = external_process.ProcessMonitor( config=self.conf, resource_type='dhcp')
def test_ensure_dir_not_exist(self, makedirs, isdir): utils.ensure_dir('/the') isdir.assert_called_once_with('/the') makedirs.assert_called_once_with('/the', 0o755)
def test_ensure_dir_no_fail_if_exists(self, makedirs): error = OSError() error.errno = errno.EEXIST makedirs.side_effect = error utils.ensure_dir("/etc/create/concurrently")
def test_ensure_dir_calls_makedirs(self, makedirs): utils.ensure_dir("/etc/create/directory") makedirs.assert_called_once_with("/etc/create/directory", 0o755)
def test_ensure_dir_exist(self, makedirs, isdir): utils.ensure_dir('/the') isdir.assert_called_once_with('/the') self.assertFalse(makedirs.called)
def ensure_pids_dir(self): utils.ensure_dir(os.path.dirname(self.get_pid_file_name()))
def _init_ha_conf_path(self): ha_full_path = os.path.dirname("/%s/" % self.conf.ha_confs_path) agent_utils.ensure_dir(ha_full_path)
def get_full_config_file_path(self, filename, ensure_conf_dir=True): conf_dir = self.get_conf_dir() if ensure_conf_dir: utils.ensure_dir(conf_dir) return os.path.join(conf_dir, filename)
def test_ensure_dir_no_fail_if_exists(self, path_exists, makedirs): error = OSError() error.errno = errno.EEXIST makedirs.side_effect = error utils.ensure_dir("/etc/create/concurrently")