def tune(self, tuning_model, comps=None, **kwargs): """Tune server.""" comps = (comps or self.components).managed() actions = ActionGroup() for server, srvcomps in comps.groupbyserver(): if server.is_local(): actions.add( server.tune(tuning_model, srvcomps, self.fs_name, **kwargs)) else: act = self._proxy_action('tune', server.hostname, srvcomps, **kwargs) if tuning_model.filename: copy = Install(server.hostname, self, tuning_model.filename, comps=srvcomps, **kwargs) act.depends_on(copy) actions.add(copy) actions.add(act) # Run local actions and FSProxyAction actions.launch() self._run_actions() # Check actions status and return MOUNTED if no error return self._check_errors([MOUNTED], None, actions)
def test_group_dep_error(self): """A ok group which depends on an error group is on error""" grp1 = ActionGroup() act1 = TestAction('/bin/false') grp1.add(act1) grp2 = ActionGroup() act2 = TestAction('/bin/true') grp2.add(act2) grp2.depends_on(grp1) grp2.launch() task_self().run() self.assertEqual(act1.status(), ACT_ERROR) self.assertEqual(grp1.status(), ACT_ERROR) self.assertEqual(act2.status(), ACT_WAITING) self.assertEqual(grp2.status(), ACT_ERROR)
def test_group_dep_ok(self): """A ok group which depends on an ok group is ok""" grp1 = ActionGroup() act1 = TestAction('/bin/true') grp1.add(act1) grp2 = ActionGroup() act2 = TestAction('/bin/true') grp2.add(act2) grp1.depends_on(grp2) grp1.launch() task_self().run() self.assertEqual(act1.status(), ACT_OK) self.assertEqual(grp1.status(), ACT_OK) self.assertEqual(act2.status(), ACT_OK) self.assertEqual(grp2.status(), ACT_OK)
def test_one_dep_after_error(self): """An action with an error group dependency is on error""" act = TestAction('/bin/true') self.grp = ActionGroup() act1 = TestAction('/bin/false') self.grp.add(act1) act.depends_on(self.grp) act.launch() task_self().run() self.assertEqual(act1.status(), ACT_ERROR) self.assertEqual(self.grp.status(), ACT_ERROR) self.assertEqual(act.status(), ACT_ERROR)
def test_two_deps_after_error(self): """2 ok actions with an error group dependency are on error""" dep1 = TestAction('/bin/true') dep2 = TestAction('/bin/true') self.grp = ActionGroup() act1 = TestAction('/bin/false') self.grp.add(act1) dep1.depends_on(self.grp) dep2.depends_on(self.grp) dep1.launch() task_self().run() self.assertEqual(act1.status(), ACT_ERROR) self.assertEqual(self.grp.status(), ACT_ERROR) self.assertEqual(dep1.status(), ACT_ERROR) self.assertEqual(dep2.status(), ACT_ERROR)
def _prepare(self, action, comps=None, groupby=None, reverse=False, need_unload=False, tunings=None, allservers=False, **kwargs): """ Instanciate all actions for the component list and but them in a graph of ActionGroup(). Action could be local or proxy actions. Components list is filtered, based on action name. """ graph = ActionGroup() comps = comps or self.components first_comps = None last_comps = None localsrv = None modules = set() localcomps = None if groupby: iterable = comps.groupby(attr=groupby, reverse=reverse) else: iterable = [(None, comps)] # Iterate over targets, grouping them by start order and server. for _order, comps in iterable: graph.add(ActionGroup()) compgrp = ActionGroup() proxygrp = ActionGroup() for srv, comps in comps.groupbyserver(allservers=allservers): if srv.action_enabled is True: if srv.is_local(): localsrv = srv localcomps = comps for comp in comps: compgrp.add(getattr(comp, action)(**kwargs)) else: act = self._proxy_action(action, srv.hostname, comps, **kwargs) if tunings and tunings.filename: copy = Install(srv.hostname, self, tunings.filename, comps=comps, **kwargs) act.depends_on(copy) proxygrp.add(copy) proxygrp.add(act) if len(compgrp) > 0: graph[-1].add(compgrp) # Keep track of first comp group if first_comps is None: first_comps = compgrp first_comps.parent = graph[-1] # Keep track of last comp group last_comps = compgrp last_comps.parent = graph[-1] # Build module loading list, if needed for comp_action in compgrp: modules.update(comp_action.needed_modules()) if len(proxygrp) > 0: graph[-1].add(proxygrp) # Add module loading, if needed. if first_comps is not None and len(modules) > 0: modgrp = ActionGroup() for module in modules: modgrp.add(localsrv.load_modules(modname=module, **kwargs)) # Serialize modules loading actions modgrp.sequential() first_comps.parent.add(modgrp) first_comps.depends_on(modgrp) # Apply tuning to last component group, if needed if tunings is not None and last_comps is not None: tune = localsrv.tune(tunings, localcomps, self.fs_name, **kwargs) last_comps.parent.add(tune) tune.depends_on(last_comps) # Add module unloading to last component group, if needed. if need_unload and last_comps is not None: unload = localsrv.unload_modules(**kwargs) last_comps.parent.add(unload) unload.depends_on(last_comps) # Join the different part together graph.sequential() return graph
def setUp(self): self.grp = ActionGroup()