def test_delete(self): """Tests cgroup deletion.""" cgroups_dir = os.path.join(self.root, 'cgroups') treadmill.cgroups.get_mountpoint.return_value = cgroups_dir group = os.path.join('treadmill', 'apps', 'test1') # Create a directory for the cgroup os.makedirs(os.path.join(cgroups_dir, group)) cgroups.delete('cpu', group) os.rmdir.assert_called_once_with(os.path.join(cgroups_dir, group))
def delete(system, group): """ safely delete cgroup path """ fullpath = cgroups.makepath(system, group) for (dirname, _subdirs, _files) in os.walk(fullpath, topdown=False): cgrp = cgroups.extractpath(dirname, system) # free empty memory before the cgroups is destroyed if system == 'memory': memory_force_empty(cgrp) try: cgroups.delete(system, cgrp) except OSError as err: _LOGGER.exception('Unable remove cgroup %s %s, %r', system, cgrp, err) raise err
def test_delete_rec(self): """Tests recursive cgroup deletion.""" cgroups_dir = os.path.join(self.root, 'cgroups') treadmill.cgroups.get_mountpoint.return_value = cgroups_dir group = os.path.join('treadmill', 'apps', 'test1') # Create a directory and subdirs for the cgroup os.makedirs(os.path.join(cgroups_dir, group, 'foo', 'bar', 'baz')) cgroups.delete('cpu', group) os.rmdir.assert_has_calls([ mock.call(os.path.join(cgroups_dir, group, 'foo/bar/baz')), mock.call(os.path.join(cgroups_dir, group, 'foo/bar')), mock.call(os.path.join(cgroups_dir, group, 'foo')), mock.call(os.path.join(cgroups_dir, group)), ])