def test_help(self):
     """Test help output :
        -h
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-h')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("""check_carp_by_ssh""")
 def test_version(self):
     """Test version output :
        -V
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-V')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("check_carp_by_ssh.py v%s"
                                  % check_carp_by_ssh.PLUGIN_VERSION)
 def test_bad_argument2(self):
     """Test bad argument:
         -1 192.168.1.10 -c 172.16.1.2
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-1')
     sys.argv.append('192.168.1.10')
     sys.argv.append('-c')
     sys.argv.append('172.16.1.2')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("Argument `cross_ip_2' is missing !")
 def test_bad_argument1(self):
     """Test bad argument:
         -1 192.168.1.10 -3 192.168.1.11 -c 172.16.1.2
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-1')
     sys.argv.append('192.168.1.10')
     sys.argv.append('-3')
     sys.argv.append('192.168.1.11')
     sys.argv.append('-c')
     sys.argv.append('172.16.1.2')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("option -3 not recognized")
 def test_check4(self):
     """Test check4 :
         -1 192.168.1.14 -2 192.168.1.15 -c 172.16.1.2
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-1')
     sys.argv.append('192.168.1.14')
     sys.argv.append('-2')
     sys.argv.append('192.168.1.15')
     sys.argv.append('-c')
     sys.argv.append('172.16.1.2')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 2)
         output = out.getvalue().strip()
         assert output.startswith("CARP ERROR - Interfaces in MASTER state are on the two hosts")
 def test_check3(self):
     """Test check3 :
         -1 192.168.1.13 -2 192.168.1.11 -c 172.16.1.2
     """ 
     sys.argv = [sys.argv[0]]
     sys.argv.append('-1')
     sys.argv.append('192.168.1.13')
     sys.argv.append('-2')
     sys.argv.append('192.168.1.11')
     sys.argv.append('-c')
     sys.argv.append('172.16.1.2')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 2)
         output = out.getvalue().strip()
         assert output.startswith("CARP ERROR - Plugin can get status of interfaces: ")
 def test_check1(self):
     """Test check1 :
         -1 192.168.1.10 -2 192.168.1.11 -c 172.16.1.2
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-1')
     sys.argv.append('192.168.1.10')
     sys.argv.append('-2')
     sys.argv.append('192.168.1.11')
     sys.argv.append('-c')
     sys.argv.append('172.16.1.2')
     try:
         out = StringIO()
         sys.stdout = out
         check_carp_by_ssh.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 0)
         output = out.getvalue().strip()
         assert output.startswith("CARP OK - Master cross ip: 192.168.1.10"
                                  " - Backup cross ip: 192.168.1.11"
                                  " - 3 interfaces up")