Beispiel #1
0
 def data(self):
     self.p1 = Pool('p1')
     self.p2 = Pool('p2')
     self.e1 = Entity('e1')
     self.e2 = Entity('e2')
     self.p1.insert(self.e1)
     self.p2.insert(self.e2)
     self.p1.insert(self.p2)
Beispiel #2
0
 def data(self):
     self.p1 = Pool('p1')
     self.p2 = Pool('p2')
     self.e1 = Entity('e1')
     self.e2 = Entity('e2')
     self.p1.insert(self.e1)
     self.p2.insert(self.e2)
     self.p1.insert(self.p2)
Beispiel #3
0
    def testParents(self):

        class OtherDriver(Driver):
            _clusto_type = 'otherdriver'
            _driver_name = 'otherdriver'


        p1 = Pool('toppool')
        d1 = Pool('grandparent')
        d1a = Pool('othergrandparent')
        d1b = OtherDriver('anothergrandparent')
        d2 = Driver('parent')
        d3 = Driver('child')

        d1b.add_attr('foo', 'someval')
        p1.insert(d1a)
        d1b.insert(d2)
        d1a.insert(d2)
        d1.insert(d2)
        d2.insert(d3)

        self.assertEqual(sorted([d1,d1a, p1]),
                         sorted(d3.parents(clusto_types=[Pool], search_parents=True)))

        self.assertEqual([d2],
                         d3.parents())

        self.assertEqual(['someval'],
                         d3.attr_values('foo', merge_container_attrs=True))
Beispiel #4
0
class TestAdjacencyMap(testbase.ClustoTestBase):
    def data(self):
        self.p1 = Pool('p1')
        self.p2 = Pool('p2')
        self.e1 = Entity('e1')
        self.e2 = Entity('e2')
        self.p1.insert(self.e1)
        self.p2.insert(self.e2)
        self.p1.insert(self.p2)

    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)

    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)

    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)
Beispiel #5
0
    def testChildrenContents(self):

        p1 = Pool('p1')
        p2 = Pool('p2')

        d1 = Driver('d1')
        d2 = Driver('d2')

        p1.insert(d1)
        p2.insert(d2)
        p2.insert(p1)

        self.assertEqual(sorted([p1, d1, d2]),
                         sorted(p2.contents(search_children=True)))
Beispiel #6
0
    def testMultipleGrandchildrenContents(self):
        p1 = Pool('p1')
        p2 = Pool('p2')

        d1 = Driver('d1')
        d2 = Driver('d2')
        d3 = Driver('d3')

        p2.insert(d1)
        p2.insert(d2)
        p2.insert(d3)

        p1.insert(p2)

        self.assertEqual(sorted([p2, d1, d2, d3]),
                         sorted(p1.contents(search_children=True)))
Beispiel #7
0
    def testChildrenContents(self):

        p1 = Pool('p1')
        p2 = Pool('p2')

        d1 = Driver('d1')
        d2 = Driver('d2')

        p1.insert(d1)
        p2.insert(d2)
        p2.insert(p1)

        self.assertEqual(sorted([p1,d1,d2]),
                         sorted(p2.contents(search_children=True)))
Beispiel #8
0
class TestAdjacencyMap(testbase.ClustoTestBase):
    def data(self):
        self.p1 = Pool('p1')
        self.p2 = Pool('p2')
        self.e1 = Entity('e1')
        self.e2 = Entity('e2')
        self.p1.insert(self.e1)
        self.p2.insert(self.e2)
        self.p1.insert(self.p2)

    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)

    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)

    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)
Beispiel #9
0
    def testSiblings(self):

        d1 = Driver('d1')
        d2 = Driver('d2')
        d3 = Driver('d3')
        d4 = Driver('d4')
        d5 = Driver('d5')
        d6 = Driver('d6')
        d7 = Driver('d7')
        d8 = Driver('d8')

        db = Pool('db')
        web = Pool('web')
        dev = Pool('dev')
        prod = Pool('prod')
        alpha = Pool('alpha')
        beta = Pool('beta')

        db.set_attr('pooltype', 'role')
        web.set_attr('pooltype', 'role')

        db.insert(d1)
        db.insert(d2)
        db.insert(d3)
        db.insert(d7)
        db.insert(d8)

        web.insert(d4)
        web.insert(d5)
        web.insert(d6)
        web.insert(d7)

        map(prod.insert, [d1,d2,d4,d5])

        map(dev.insert, [d3,d6,d7,d8])

        map(alpha.insert, [d7, d8])
        map(beta.insert, [d3,d6])


        self.assertEquals(sorted([d2]),
                          sorted(d1.siblings()))

        self.assertEquals(sorted(d3.siblings()),
                          sorted([]))

        self.assertEquals(sorted(d3.siblings(parent_filter=lambda x: not x.attr_values('pooltype', 'role'),
                                             additional_pools=[web])),
                          sorted([d6]))

        self.assertEquals(sorted(d7.siblings(parent_filter=lambda x: not x.attr_values('pooltype', 'role'),
                                             additional_pools=[db])),
                          sorted([d8]))
Beispiel #10
0
    def testGetEntities(self):

        d1 = Driver('d1')
        dv1 = Device('dv1')
        Location('l1')
        BasicDatacenter('dc1')


        namelist = ['e1', 'e2', 'dv1']

        self.assertEqual(sorted([n.name
                                 for n in clusto.get_entities(names=namelist)]),
                         sorted(namelist))

        dl = [Driver]
        self.assertEqual(sorted([n.name
                                 for n in clusto.get_entities(clusto_drivers=dl)]),
                         sorted(['d1','e1','e2','e3']))


        tl = [Location, BasicDatacenter]
        self.assertEqual(sorted([n.name
                                 for n in clusto.get_entities(clusto_types=tl)]),
                         sorted(['l1','dc1']))

        p1 = Pool('p1')
        p2 = Pool('p2')
        p3 = Pool('p3')
        p4 = Pool('p4')

        s1 = BasicServer('s1')
        s2 = BasicServer('s2')
        s3 = BasicServer('s3')

        p1.insert(s1)
        p1.insert(s2)

        p2.insert(s2)
        p2.insert(s3)
        p2.insert(d1)

        p3.insert(s3)
        p3.insert(d1)
        p3.insert(s1)

        p4.insert(p3)


        self.assertEqual(sorted([s2,s3]),
                         sorted(clusto.get_from_pools(pools=[p2],
                                                      clusto_types=[BasicServer])))

        self.assertEqual(sorted([s2]),
                         sorted(clusto.get_from_pools(pools=[p2, 'p1'],
                                                      clusto_types=[BasicServer])))
        self.assertEqual(sorted([s3]),
                         sorted(clusto.get_from_pools(pools=['p2', 'p3'],
                                                      clusto_types=[BasicServer])))

        self.assertEqual(sorted([s1]),
                         sorted(clusto.get_from_pools(pools=['p4', 'p1'],
                                                      clusto_types=[BasicServer])))
Beispiel #11
0
    def testSiblings(self):

        d1 = Driver('d1')
        d2 = Driver('d2')
        d3 = Driver('d3')
        d4 = Driver('d4')
        d5 = Driver('d5')
        d6 = Driver('d6')
        d7 = Driver('d7')
        d8 = Driver('d8')

        db = Pool('db')
        web = Pool('web')
        dev = Pool('dev')
        prod = Pool('prod')
        alpha = Pool('alpha')
        beta = Pool('beta')

        db.set_attr('pooltype', 'role')
        web.set_attr('pooltype', 'role')

        db.insert(d1)
        db.insert(d2)
        db.insert(d3)
        db.insert(d7)
        db.insert(d8)

        web.insert(d4)
        web.insert(d5)
        web.insert(d6)
        web.insert(d7)

        map(prod.insert, [d1, d2, d4, d5])

        map(dev.insert, [d3, d6, d7, d8])

        map(alpha.insert, [d7, d8])
        map(beta.insert, [d3, d6])

        self.assertEquals(sorted([d2]), sorted(d1.siblings()))

        self.assertEquals(sorted(d3.siblings()), sorted([]))

        self.assertEquals(
            sorted(
                d3.siblings(parent_filter=lambda x: not x.attr_values(
                    'pooltype', 'role'),
                            additional_pools=[web])), sorted([d6]))

        self.assertEquals(
            sorted(
                d7.siblings(parent_filter=lambda x: not x.attr_values(
                    'pooltype', 'role'),
                            additional_pools=[db])), sorted([d8]))
Beispiel #12
0
    def testGetEntities(self):

        d1 = Driver('d1')
        dv1 = Device('dv1')
        Location('l1')
        BasicDatacenter('dc1')

        namelist = ['e1', 'e2', 'dv1']

        self.assertEqual(
            sorted([n.name for n in clusto.get_entities(names=namelist)]),
            sorted(namelist))

        dl = [Driver]
        self.assertEqual(
            sorted([n.name for n in clusto.get_entities(clusto_drivers=dl)]),
            sorted(['d1', 'e1', 'e2', 'e3']))

        tl = [Location, BasicDatacenter]
        self.assertEqual(
            sorted([n.name for n in clusto.get_entities(clusto_types=tl)]),
            sorted(['l1', 'dc1']))

        p1 = Pool('p1')
        p2 = Pool('p2')
        p3 = Pool('p3')
        p4 = Pool('p4')

        s1 = BasicServer('s1')
        s2 = BasicServer('s2')
        s3 = BasicServer('s3')

        p1.insert(s1)
        p1.insert(s2)

        p2.insert(s2)
        p2.insert(s3)
        p2.insert(d1)

        p3.insert(s3)
        p3.insert(d1)
        p3.insert(s1)

        p4.insert(p3)

        self.assertEqual(
            sorted([s2, s3]),
            sorted(
                clusto.get_from_pools(pools=[p2], clusto_types=[BasicServer])))

        self.assertEqual(
            sorted([s2]),
            sorted(
                clusto.get_from_pools(pools=[p2, 'p1'],
                                      clusto_types=[BasicServer])))
        self.assertEqual(
            sorted([s3]),
            sorted(
                clusto.get_from_pools(pools=['p2', 'p3'],
                                      clusto_types=[BasicServer])))

        self.assertEqual(
            sorted([s1]),
            sorted(
                clusto.get_from_pools(pools=['p4', 'p1'],
                                      clusto_types=[BasicServer])))
Beispiel #13
0
    def testParents(self):
        class OtherDriver(Driver):
            _clusto_type = 'otherdriver'
            _driver_name = 'otherdriver'

        p1 = Pool('toppool')
        d1 = Pool('grandparent')
        d1a = Pool('othergrandparent')
        d1b = OtherDriver('anothergrandparent')
        d2 = Driver('parent')
        d3 = Driver('child')

        d1b.add_attr('foo', 'someval')
        p1.insert(d1a)
        d1b.insert(d2)
        d1a.insert(d2)
        d1.insert(d2)
        d2.insert(d3)

        self.assertEqual(
            sorted([d1, d1a, p1]),
            sorted(d3.parents(clusto_types=[Pool], search_parents=True)))

        self.assertEqual([d2], d3.parents())

        self.assertEqual(['someval'],
                         d3.attr_values('foo', merge_container_attrs=True))
Beispiel #14
0
    def testMultipleGrandchildrenContents(self):
        p1 = Pool('p1')
        p2 = Pool('p2')

        d1 = Driver('d1')
        d2 = Driver('d2')
        d3 = Driver('d3')

        p2.insert(d1)
        p2.insert(d2)
        p2.insert(d3)

        p1.insert(p2)

        self.assertEqual(sorted([p2, d1, d2, d3]),
                         sorted(p1.contents(search_children=True)))