Ejemplo n.º 1
0
    def testHaNode(self):
        """test failover servers"""
        fs = FileSystem('nonreg')
        srv = Server('foo1', ['foo1@tcp'])
        tgt = Target(fs, srv, 0, '/dev/null')
        self.assertEqual(tgt.server, srv)
        self.assertEqual(len(tgt.failservers), 0)

        # Could not switch to an undefined failnode
        self.assertFalse(tgt.failover(NodeSet("foo1")))
        self.assertEqual(tgt.server, srv)

        # Add a failserver and switch to it
        foo2 = Server('foo2', ['foo2@tcp'])
        tgt.add_server(foo2)
        self.assertEqual(list(tgt.failservers), [foo2])
        self.assertTrue(tgt.failover(NodeSet("foo2")))
        self.assertEqual(tgt.server, foo2)

        # Add a 2nd failserver and switch to it
        foo3 = Server('foo3', ['foo3@tcp'])
        tgt.add_server(foo3)
        self.assertEqual(list(tgt.failservers), [foo2, foo3])
        self.assertTrue(tgt.failover(NodeSet("foo3")))
        self.assertEqual(tgt.server, foo3)

        # Switch with more than 1 candidate but only one exist
        self.assertTrue(tgt.failover(NodeSet("bar,foo2")))
        self.assertEqual(tgt.server, foo2)

        # Could not switch if more than one node matches
        self.assertRaises(ComponentError, Target.failover, tgt,
                          NodeSet("foo[2,3]"))
Ejemplo n.º 2
0
    def testHaNode(self):
        """test failover servers"""
        fs = FileSystem('nonreg')
        srv = Server('foo1', ['foo1@tcp'])
        tgt = Target(fs, srv, 0, '/dev/null')
        self.assertEqual(tgt.server, srv)
        self.assertEqual(len(tgt.failservers), 0)

        # Could not switch to an undefined failnode
        self.assertFalse(tgt.failover(NodeSet("foo1")))
        self.assertEqual(tgt.server, srv)

        # Add a failserver and switch to it
        foo2 = Server('foo2', ['foo2@tcp'])
        tgt.add_server(foo2)
        self.assertEqual(list(tgt.failservers), [ foo2 ])
        self.assertTrue(tgt.failover(NodeSet("foo2")))
        self.assertEqual(tgt.server, foo2)

        # Add a 2nd failserver and switch to it
        foo3 = Server('foo3', ['foo3@tcp'])
        tgt.add_server(foo3)
        self.assertEqual(list(tgt.failservers), [ foo2, foo3 ])
        self.assertTrue(tgt.failover(NodeSet("foo3")))
        self.assertEqual(tgt.server, foo3)

        # Switch with more than 1 candidate but only one exist
        self.assertTrue(tgt.failover(NodeSet("bar,foo2")))
        self.assertEqual(tgt.server, foo2)

        # Could not switch if more than one node matches
        self.assertRaises(ComponentError, Target.failover, tgt,
                          NodeSet("foo[2,3]"))
Ejemplo n.º 3
0
 def testAllServers(self):
     """test ComponentGroup.allservers()"""
     fs = FileSystem('comp')
     grp = ComponentGroup()
     grp.add(Target(fs, Server('foo1', ['foo1@tcp']), 0, '/dev/sda'))
     comp = Target(fs, Server('foo2', ['foo2@tcp']), 1, '/dev/sda')
     grp.add(comp)
     comp.add_server(Server('foo3', ['foo3@tcp0']))
     self.assertEqual(str(grp.allservers()), "foo[1-3]")
Ejemplo n.º 4
0
 def testAllServers(self):
     """test ComponentGroup.allservers()"""
     fs = FileSystem('comp')
     grp = ComponentGroup()
     grp.add(Target(fs, Server('foo1', ['foo1@tcp']), 0, '/dev/sda'))
     comp = Target(fs, Server('foo2', ['foo2@tcp']), 1, '/dev/sda')
     grp.add(comp)
     comp.add_server(Server('foo3', ['foo3@tcp0']))
     self.assertEqual(str(grp.allservers()), "foo[1-3]")
Ejemplo n.º 5
0
 def test_group_by_all_servers(self):
     """test ComponentGroup.groupbyallservers()"""
     fs = FileSystem('comp')
     grp = ComponentGroup()
     srv1 = Server('foo1', ['foo1@tcp'])
     srv2 = Server('foo2', ['foo2@tcp'])
     comp1 = Target(fs, srv1, 0, '/dev/sda')
     comp1.add_server(srv2)
     grp.add(comp1)
     comp2 = Target(fs, srv2, 1, '/dev/sdb')
     comp2.add_server(srv1)
     grp.add(comp2)
     comp3 = Target(fs, srv1, 2, '/dev/sdc')
     comp3.add_server(srv2)
     grp.add(comp3)
     comp4 = Target(fs, srv2, 3, '/dev/sdd')
     comp4.add_server(srv1)
     grp.add(comp4)
     key = lambda c: c.TYPE
     results = [[srv, sorted(comps, key=key)] for srv, comps in grp.groupbyallservers()]
     self.assertEqual(len(results), 2)
     self.assertTrue([srv1, [comp1, comp2, comp3, comp4]] in results)
     self.assertTrue([srv2, [comp1, comp2, comp3, comp4]] in results)
Ejemplo n.º 6
0
 def test_group_by_all_servers(self):
     """test ComponentGroup.groupbyallservers()"""
     fs = FileSystem('comp')
     grp = ComponentGroup()
     srv1 = Server('foo1', ['foo1@tcp'])
     srv2 = Server('foo2', ['foo2@tcp'])
     comp1 = Target(fs, srv1, 0, '/dev/sda')
     comp1.add_server(srv2)
     grp.add(comp1)
     comp2 = Target(fs, srv2, 1, '/dev/sdb')
     comp2.add_server(srv1)
     grp.add(comp2)
     comp3 = Target(fs, srv1, 2, '/dev/sdc')
     comp3.add_server(srv2)
     grp.add(comp3)
     comp4 = Target(fs, srv2, 3, '/dev/sdd')
     comp4.add_server(srv1)
     grp.add(comp4)
     key = lambda c: c.TYPE
     results = [[srv, sorted(comps, key=key)] for srv, comps in grp.groupbyallservers()]
     self.assertEqual(len(results), 2)
     self.assertTrue([srv1, [comp1, comp2, comp3, comp4]] in results)
     self.assertTrue([srv2, [comp1, comp2, comp3, comp4]] in results)