def systemd_run(unit_name, cgroup_slice, *args): return commands.execCmd( cmdutils.systemd_run( args, unit=unit_name, slice=cgroup_slice, accounting=_ACCOUNTING, ))
def _dhclient(self): # Ask dhclient to stop any dhclient running for the device if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)): kill_dhclient(self.iface, self.family) cmd = [self.DHCLIENT.cmd, '-%s' % self.family, '-1', '-pf', self.pidFile, '-lf', self.leaseFile, self.iface] cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup) rc, out, err = execCmd(cmd) return rc, out, err
def systemd_run(unit_name, cgroup_slice, *args): return commands.execCmd( cmdutils.systemd_run( args, unit=unit_name, slice=cgroup_slice, accounting=_ACCOUNTING, ) )
def _dhclient(self): # Ask dhclient to stop any dhclient running for the device if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)): kill_dhclient(self.iface, self.family) cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf', self.pidFile, '-lf', self.leaseFile, self.iface] if not self.default_route: # Instruct Fedora/EL's dhclient-script not to set gateway on iface cmd += ['-e', 'DEFROUTE=no'] if self.duid_source_file and supports_duid_file(): cmd += ['-df', self.duid_source_file] cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup) return execCmd(cmd)
def _dhclient(self): # Ask dhclient to stop any dhclient running for the device if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)): kill_dhclient(self.iface, self.family) cmd = [self.DHCLIENT.cmd, '-%s' % self.family, '-1', '-pf', self.pidFile, '-lf', self.leaseFile, self.iface] if not self.default_route: # Instruct Fedora/EL's dhclient-script not to set gateway on iface cmd += ['-e', 'DEFROUTE=no'] if self.duid_source_file: cmd += ['-df', self.duid_source_file] cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup) return execCmd(cmd)
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP): """Bring up an interface""" cmd = [constants.EXT_IFUP, iface_name] if cgroup is not None: cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup) rc, out, err = utils.execCmd(cmd, raw=False) if rc != 0: # In /etc/sysconfig/network-scripts/ifup* the last line usually # contains the error reason. raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else '')
def mount(self, mntOpts=None, vfstype=None, timeout=None, cgroup=None): cmd = [constants.EXT_MOUNT] if vfstype is not None: cmd.extend(("-t", vfstype)) if mntOpts: cmd.extend(("-o", mntOpts)) cmd.extend((self.fs_spec, self.fs_file)) if cgroup: cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup) return self._runcmd(cmd, timeout)
def _dhclient(self): if linkiface.exists(self.iface): kill(self.iface, self.family) address.flush(self.iface, family=self.family) cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf', self.pidFile, '-lf', self.leaseFile] if not self.default_route: # Instruct Fedora/EL's dhclient-script not to set gateway on iface cmd += ['-e', 'DEFROUTE=no'] if self.duid_source_file and supports_duid_file(): cmd += ['-df', self.duid_source_file] cmd += [self.iface] cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup) return execCmd(cmd)
def test_accounting(self): accounting = ( cmdutils.Accounting.CPU, cmdutils.Accounting.Memory, cmdutils.Accounting.BlockIO, ) cmd = cmdutils.systemd_run(['a', 'b'], accounting=accounting) res = [ constants.EXT_SYSTEMD_RUN, '--property=CPUAccounting=1', '--property=MemoryAccounting=1', '--property=BlockIOAccounting=1', 'a', 'b', ] self.assertEqual(cmd, res)
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP): """Bring up an interface""" cmd = [constants.EXT_IFUP, iface_name] if cgroup is not None: # TODO: We set unique uuid for every run to not use the same unit twice # and prevent systemd_run race (BZ#1259468). This uuid could be dropped # when BZ#1272368 will be solved or when we use systemd >= v220. cmd = cmdutils.systemd_run(cmd, scope=True, unit=uuid.uuid4(), slice=cgroup) rc, out, err = utils.execCmd(cmd, raw=False) if rc != 0: # In /etc/sysconfig/network-scripts/ifup* the last line usually # contains the error reason. raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else "")
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP): """Bring up an interface""" cmd = [constants.EXT_IFUP, iface_name] if cgroup is not None: # TODO: We set unique uuid for every run to not use the same unit twice # and prevent systemd_run race (BZ#1259468). This uuid could be dropped # when BZ#1272368 will be solved or when we use systemd >= v220. cmd = cmdutils.systemd_run(cmd, scope=True, unit=uuid.uuid4(), slice=cgroup) rc, out, err = utils.execCmd(cmd, raw=False) if rc != 0: # In /etc/sysconfig/network-scripts/ifup* the last line usually # contains the error reason. raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else '')
def _mount(fs_spec, fs_file, mntOpts=None, vfstype=None, timeout=None, cgroup=None): """ Called from supervdsm for running the mount command as root. """ cmd = [constants.EXT_MOUNT] if vfstype is not None: cmd.extend(("-t", vfstype)) if mntOpts: cmd.extend(("-o", mntOpts)) cmd.extend((fs_spec, fs_file)) if cgroup: cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup) _runcmd(cmd, timeout)
def test_unit(self): cmd = cmdutils.systemd_run(['a', 'b'], unit='unit') res = [constants.EXT_SYSTEMD_RUN, '--unit=unit', 'a', 'b'] self.assertEqual(cmd, res)
def test_scope(self): cmd = cmdutils.systemd_run(["a", "b"], scope=True) res = [constants.EXT_SYSTEMD_RUN, "--scope", "a", "b"] self.assertEqual(cmd, res)
def test_unit(self): cmd = cmdutils.systemd_run(["a", "b"], unit="unit") res = [constants.EXT_SYSTEMD_RUN, "--unit=unit", "a", "b"] self.assertEqual(cmd, res)
def test_slice(self): cmd = cmdutils.systemd_run(['a', 'b'], slice='slice') res = [constants.EXT_SYSTEMD_RUN, '--slice=slice', 'a', 'b'] self.assertEqual(cmd, res)
def test_scope(self): cmd = cmdutils.systemd_run(['a', 'b'], scope=True) res = [constants.EXT_SYSTEMD_RUN, '--scope', 'a', 'b'] self.assertEqual(cmd, res)
def test_defaults(self): cmd = cmdutils.systemd_run(['a', 'b']) res = [constants.EXT_SYSTEMD_RUN, 'a', 'b'] self.assertEqual(cmd, res)
def test_slice(self): cmd = cmdutils.systemd_run(["a", "b"], slice="slice") res = [constants.EXT_SYSTEMD_RUN, "--slice=slice", "a", "b"] self.assertEqual(cmd, res)