Ejemplo n.º 1
0
 def testDeletedNotIncluded(self):
     self.e2.delete()
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 2)
     self.assertNotIn(clusto.Adjacency(
         parent_id=ANY, parent_name='p2', parent_type='pool',
         child_id=ANY, child_name='e2', child_type='entity'
     ), adj_map)
Ejemplo n.º 2
0
 def testRemovedNotIncluded(self):
     self.p1.remove(self.p2)
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 2)
     self.assertNotIn(clusto.Adjacency(
         parent_id=ANY, parent_name='p1', parent_type='pool',
         child_id=ANY, child_name='p2', child_type='pool'
     ), adj_map)
Ejemplo n.º 3
0
 def testRemovedNotIncluded(self):
     self.p1.remove(self.p2)
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 2)
     self.assertNotIn(
         clusto.Adjacency(parent_id=ANY,
                          parent_name='p1',
                          parent_type='pool',
                          child_id=ANY,
                          child_name='p2',
                          child_type='pool'), adj_map)
Ejemplo n.º 4
0
 def testDeletedNotIncluded(self):
     self.e2.delete()
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 2)
     self.assertNotIn(
         clusto.Adjacency(parent_id=ANY,
                          parent_name='p2',
                          parent_type='pool',
                          child_id=ANY,
                          child_name='e2',
                          child_type='entity'), adj_map)
Ejemplo n.º 5
0
    def populate_pools_and_datacenters(self):
        seen = set()

        forward_map = collections.defaultdict(set)

        # we're building a reverse map from (parent_type, object) to
        # parents. Remember that.
        #
        # unfortunately, this is just a DG (not a tree or even an DAG),
        # so we can't just do a depth-first-search with path retention here
        # to build the map of parents. We'll do one pass against clusto to
        # build a shallow map of all parent-child relationships, then
        # flatten it to get transitive parent relationships, then reverse it.
        #
        # yay.
        relationships = adjacency_map()
        for row in relationships:
            if row.parent_type not in self.CONTEXT_TYPES:
                continue
            root_name = ContextKey(row.parent_type, row.parent_name)
            child_name = ContextKey(row.child_type, row.child_name)
            forward_map[root_name].add(child_name)

        # now flatten it
        transitive_contents = {}
        for pool_or_datacenter, contents in forward_map.iteritems():
            recursive_contents = set()
            seen = set()
            work_queue = list(contents)
            while work_queue:
                t = work_queue.pop(0)
                if t in seen:
                    continue
                seen.add(t)
                if t in forward_map:
                    work_queue.extend(forward_map[t])
                    recursive_contents.add(t)
                else:
                    recursive_contents.add(t)
            transitive_contents[pool_or_datacenter] = recursive_contents

        results = dict(
            (typ, collections.defaultdict(set))
            for typ
            in self.CONTEXT_TYPES
        )

        # finally, reverse it
        for parent, children in transitive_contents.iteritems():
            for child in children:
                results[parent.item_type][child].add(parent)

        self.context_dict = results
Ejemplo n.º 6
0
 def testAdjacencyMap(self):
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 3)
     self.assertIn(clusto.Adjacency(
         parent_id=ANY, parent_name='p1', parent_type='pool',
         child_id=ANY, child_name='p2', child_type='pool'
     ), adj_map)
     self.assertIn(clusto.Adjacency(
         parent_id=ANY, parent_name='p1', parent_type='pool',
         child_id=ANY, child_name='e1', child_type='entity'
     ), adj_map)
     self.assertIn(clusto.Adjacency(
         parent_id=ANY, parent_name='p2', parent_type='pool',
         child_id=ANY, child_name='e2', child_type='entity'
     ), adj_map)
Ejemplo n.º 7
0
 def testAdjacencyMap(self):
     adj_map = clusto.adjacency_map()
     self.assertEquals(len(adj_map), 3)
     self.assertIn(
         clusto.Adjacency(parent_id=ANY,
                          parent_name='p1',
                          parent_type='pool',
                          child_id=ANY,
                          child_name='p2',
                          child_type='pool'), adj_map)
     self.assertIn(
         clusto.Adjacency(parent_id=ANY,
                          parent_name='p1',
                          parent_type='pool',
                          child_id=ANY,
                          child_name='e1',
                          child_type='entity'), adj_map)
     self.assertIn(
         clusto.Adjacency(parent_id=ANY,
                          parent_name='p2',
                          parent_type='pool',
                          child_id=ANY,
                          child_name='e2',
                          child_type='entity'), adj_map)