def test_paralel_map(self): lst = [1, 2, 3, 4, 5] res = utils.parallel_map(lambda x: x * 2, lst) expected = list([x * 2 for x in lst]) self.assertEqual(res, expected) res = utils.parallel_map(lambda x: x * 2, lst, workers=2) expected = list([x * 2 for x in lst]) self.assertEqual(res, expected)
def test_paralel_map(self): lst = [1, 2, 3, 4, 5] res = utils.parallel_map(lambda x: x * 2, lst) expected = list(map(lambda x: x * 2, lst)) self.assertEqual(res, expected) res = utils.parallel_map(lambda x: x * 2, lst, workers=2) expected = list(map(lambda x: x * 2, lst)) self.assertEqual(res, expected)
def __call__(self, subnet_uuid=None, **kwargs): super(FixSubnets, self).__call__(**kwargs) self.session = Context().session self.subnet_uuid = subnet_uuid ipam = Resource( 'network-ipam', fq_name='default-domain:default-project:default-network-ipam', fetch=True) to_check = [(vn.uuid, subnet.get('subnet_uuid'), subnet) for vn in ipam.back_refs.virtual_network for subnet in vn.get('attr', {}).get('ipam_subnets', [])] to_fix = parallel_map(self.chk, to_check, workers=50) if not self.dry_run and not self.check: parallel_map(self.fix, to_fix, workers=50)
def __call__(self, public_fqname=None, **kwargs): super(FixFIPLocks, self).__call__(**kwargs) self.public_fqname = public_fqname public_vn = Resource('virtual-network', fq_name=public_fqname, fetch=True) subnets = [] for s in public_vn['network_ipam_refs'][0]['attr']['ipam_subnets']: subnets.append( IPNetwork( '%s/%s' % (s['subnet']['ip_prefix'], s['subnet']['ip_prefix_len']))) parallel_map(self._check_fip, self.resources, args=(subnets, ), workers=50)
def _check_resource_refs(self, uuid, values): ref_attrs = ('ref:', 'backref:', 'children:', 'parent:') to_check = [] for key, _ in values.items(): if key.startswith(ref_attrs): to_check.append(key) results = parallel_map(self._check_ref, to_check, args=(uuid, ), workers=20) return any(results)
def __call__(self): self.kclient = kclient.Client(session=Context().session) parallel_map(self._check, Collection('project', fetch=True), workers=50)
def __call__(self, exclude=None, **kwargs): super(CleanRT, self).__call__(**kwargs) self.exclude = exclude parallel_map(self._check_rt, self.resources, workers=50)
def __call__(self, paths=None, **kwargs): super(CleanSIScheduling, self).__call__(**kwargs) parallel_map(self._check_si, self.resources, workers=50)