예제 #1
0
    def on_delete_request(self, rsrc_id):
        instance_id = rsrc_id
        apps_group = cgutils.apps_group_name(self._cgroup_prefix)
        cgrp = os.path.join(apps_group, instance_id)

        with lc.LogContext(_LOGGER, rsrc_id,
                           adapter_cls=lc.ContainerAdapter) as log:
            self._unregister_oom_handler(cgrp)

            log.info('Deleting cgroups: %s:%s', self.SUBSYSTEMS, cgrp)
            for subsystem in self.SUBSYSTEMS:
                cgutils.delete(subsystem, cgrp)

        # Recalculate the cgroup hard limits on remaining apps
        #
        # TODO: commented out until proper fix implemented.
        #
        # expunged = cgutils.reset_memory_limit_in_bytes()
        # for expunged_uniq_name in expunged:
        #     exp_app_dir = os.path.join(tm_env.apps_dir, expunged_uniq_name)
        #     with open(os.path.join(exp_app_dir,
        #                            'services', 'finished'), 'w') as f:
        #         f.write('oom')
        #     exp_cgrp = os.path.join('treadmill', 'apps', expunged_uniq_name)
        #     cgutils.kill_apps_in_cgroup('memory', exp_cgrp,
        #                                 delete_cgrp=False)

        return True
예제 #2
0
    def on_delete_request(self, rsrc_id):
        instance_id = rsrc_id
        apps_group = cgutils.apps_group_name(self._cgroup_prefix)
        cgrp = os.path.join(apps_group, instance_id)

        with lc.LogContext(_LOGGER, rsrc_id,
                           adapter_cls=lc.ContainerAdapter) as log:
            self._unregister_oom_handler(cgrp)

            log.info('Deleting cgroups: %s:%s', self.SUBSYSTEMS, cgrp)
            for subsystem in self.SUBSYSTEMS:
                cgutils.delete(subsystem, cgrp)

        return True
예제 #3
0
    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'))

        cgutils.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)),
        ])