LGTM, thanks
On Wed, Aug 27, 2014 at 10:17 PM, Yuto KAWAMURA(kawamuray) < [email protected]> wrote: > Add the _GetCgroupInstanceParamPath function which returns the path of > the specified cgroup parameter file and change the > _GetCgroupInstanceValue to use this function. > With this patch, "subsystem" argument for this function was removed > because it can be determined by the param_name argument. > > Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]> > --- > lib/hypervisor/hv_lxc.py | 33 > ++++++++++++++++++---------- > test/py/ganeti.hypervisor.hv_lxc_unittest.py | 4 ++-- > 2 files changed, 24 insertions(+), 13 deletions(-) > > diff --git a/lib/hypervisor/hv_lxc.py b/lib/hypervisor/hv_lxc.py > index 52007b5..96b71fc 100644 > --- a/lib/hypervisor/hv_lxc.py > +++ b/lib/hypervisor/hv_lxc.py > @@ -298,22 +298,35 @@ class LXCHypervisor(hv_base.BaseHypervisor): > return utils.PathJoin(subsys_dir, base_group, "lxc", instance_name) > > @classmethod > - def _GetCgroupInstanceValue(cls, instance_name, subsystem, param): > + def _GetCgroupInstanceParamPath(cls, instance_name, param_name): > + """Return the path of the specified cgroup parameter file. > + > + @type instance_name: string > + @param instance_name: instance name > + @type param_name: string > + @param param_name: cgroup subsystem parameter name > + @rtype string > + @return path of the cgroup subsystem parameter file > + > + """ > + subsystem = param_name.split(".", 1)[0] > + subsys_dir = cls._GetCgroupInstanceSubsysDir(instance_name, subsystem) > + return utils.PathJoin(subsys_dir, param_name) > + > + @classmethod > + def _GetCgroupInstanceValue(cls, instance_name, param_name): > """Return the value of the specified cgroup parameter. > > @type instance_name: string > @param instance_name: instance name > - @type subsystem: string > - @param subsystem: cgroup subsystem name > - @type param: string > - @param param: cgroup subsystem parameter name > + @type param_name: string > + @param param_name: cgroup subsystem parameter name > @rtype string > @return value read from cgroup subsystem fs > > """ > - subsys_dir = cls._GetCgroupInstanceSubsysDir(instance_name, subsystem) > - param_file = utils.PathJoin(subsys_dir, param) > - return utils.ReadFile(param_file).rstrip("\n") > + param_path = cls._GetCgroupInstanceParamPath(instance_name, > param_name) > + return utils.ReadFile(param_path).rstrip("\n") > > @classmethod > def _GetCgroupCpuList(cls, instance_name): > @@ -321,8 +334,7 @@ class LXCHypervisor(hv_base.BaseHypervisor): > > """ > try: > - cpumask = cls._GetCgroupInstanceValue(instance_name, > - "cpuset", "cpuset.cpus") > + cpumask = cls._GetCgroupInstanceValue(instance_name, "cpuset.cpus") > except EnvironmentError, err: > raise errors.HypervisorError("Getting CPU list for instance" > " %s failed: %s" % (instance_name, > err)) > @@ -336,7 +348,6 @@ class LXCHypervisor(hv_base.BaseHypervisor): > """ > try: > mem_limit = cls._GetCgroupInstanceValue(instance_name, > - "memory", > "memory.limit_in_bytes") > mem_limit = int(mem_limit) > except EnvironmentError: > diff --git a/test/py/ganeti.hypervisor.hv_lxc_unittest.py b/test/py/ > ganeti.hypervisor.hv_lxc_unittest.py > index 2285046..df7309d 100755 > --- a/test/py/ganeti.hypervisor.hv_lxc_unittest.py > +++ b/test/py/ganeti.hypervisor.hv_lxc_unittest.py > @@ -171,12 +171,12 @@ class TestCgroupReadData(LXCHypervisorTestCase): > def testGetCgroupInstanceValue(self, getdir_mock): > getdir_mock.return_value = utils.PathJoin(self.cgroot, "memory", > "lxc", > "instance1") > - self.assertEqual(self.hv._GetCgroupInstanceValue("instance1", > "memory", > + self.assertEqual(self.hv._GetCgroupInstanceValue("instance1", > > "memory.limit_in_bytes"), > "128") > getdir_mock.return_value = utils.PathJoin(self.cgroot, "cpuset", > "some_group", "lxc", > "instance1") > - self.assertEqual(self.hv._GetCgroupInstanceValue("instance1", > "cpuset", > + self.assertEqual(self.hv._GetCgroupInstanceValue("instance1", > "cpuset.cpus"), > "0-1") > > -- > 2.0.4 > > Hrvoje Ribicic Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370
