def test_get_all_hosts(self): """ Getting all hosts """ for backend_dict in self.backends: #create a minion with relevant backens m = Minions("*", **backend_dict) #create some groups and hosts into that Minion m.group_class.add_group("group1") m.group_class.add_hosts_to_group_glob("group1", "[0-9]") hosts = m.get_all_hosts() assert compare_arrays(hosts, self.current_minions) == True #now test with grouping m = Minions("[1][0-9];@group1:*", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(20)) == True m = Minions("[1][0-5];@group1:[5-9]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(5, 16)) == True #do some testing about exclude string m = Minions("*", exclude_spec="[1-9][0-9]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(10)) == True m = Minions("[1][0-5];@group1:[5-9]", exclude_spec="[1][3-5];@group1:[5-7]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(8, 13)) == True
def test_get_all_hosts(self): """ Getting all hosts """ for backend_dict in self.backends: # create a minion with relevant backens m = Minions("*", **backend_dict) # create some groups and hosts into that Minion m.group_class.add_group("group1") m.group_class.add_hosts_to_group_glob("group1", "[0-9]") hosts = m.get_all_hosts() assert compare_arrays(hosts, self.current_minions) == True # now test with grouping m = Minions("[1][0-9];@group1:*", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(20)) == True m = Minions("[1][0-5];@group1:[5-9]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(5, 16)) == True # do some testing about exclude string m = Minions("*", exclude_spec="[1-9][0-9]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(10)) == True m = Minions("[1][0-5];@group1:[5-9]", exclude_spec="[1][3-5];@group1:[5-7]", **backend_dict) hosts = m.get_all_hosts() assert compare_arrays(hosts, range(8, 13)) == True
def _get_host_grep_modules(self, server_spec): """ In cases when user doesnt supply the module list we have to consider that all of the modules are chosen so that method will return a list of them """ from func.overlord.client import Minions,Overlord #insetad of getting all of the modules we consider #that all of machines has the same modules ... host_modules = {} #FIXME: we need to change this to create a dict of hostname->modules # so we only call module.grep on systems that report it. things like # virt/hardware aren't available on all guests m = Minions(server_spec) hosts = m.get_all_hosts() if not hosts: raise Exception("No minions on system!") for host in hosts: fc = Overlord(host, noglobs=True) module_methods = fc.system.inventory() for module in module_methods: # searching for "grep"? meta if "grep" in module_methods[module]: if not host_modules.has_key(host): host_modules[host] = [] host_modules[host].append(module) return host_modules
def _get_modules(self): """ In cases when user doesnt supply the module list we have to consider that all of the modules are chosen so that method will return a list of them """ from func.overlord.client import Minions,Overlord #insetad of getting all of the modules we consider #that all of machines has the same modules ... m = Minions("*") hosts = m.get_all_hosts() if hosts: fc = Overlord(hosts[0], noglobs=True) return fc.system.list_modules() else: raise Exception("No minions on system !")