Example #1
0
 def __init__(self, server, port, service, krb5ccname=None):
     if krb5ccname == None and not 'KRB5CCAME' in environ:
         raise RemctlError, 'no token'
     self.server = server
     self.port = port
     self.service = service
     self.remctl = remctl.Remctl()
Example #2
0
 def test_full_failure(self):
     # type: () -> None
     r = remctl.Remctl("localhost", 14373, self.principal)
     r.command(["test", "bad-command"])
     type, data, stream, status, error = r.output()
     self.assertEqual(type, "error")
     self.assertEqual(data, b"Unknown command")
     self.assertEqual(error, 5)
Example #3
0
 def test_source_ip(self):
     # type: () -> None
     r = remctl.Remctl()
     r.set_source_ip("127.0.0.1")
     r.open("127.0.0.1", 14373, self.principal)
     r.set_source_ip("::1")
     pattern = "(cannot connect to|unknown host) .*"
     try:
         r.open("127.0.0.1", 14373, self.principal)
     except remctl.RemctlError as error:
         self.assertTrue(re.compile(pattern).match(str(error)))
Example #4
0
 def test_timeout(self):
     # type: () -> None
     r = remctl.Remctl()
     r.set_timeout(1)
     r.open("127.0.0.1", 14373, self.principal)
     r.command(["test", "sleep"])
     try:
         type, data, stream, status, error = r.output()
         assert "output unexpectedly succeeded"
     except remctl.RemctlError:
         self.assertEqual(r.error(), "error receiving token: timed out")
     r.close()
Example #5
0
 def test_full_success(self):
     # type: () -> None
     r = remctl.Remctl()
     r.open("localhost", 14373, self.principal)
     r.command(["test", "test"])
     type, data, stream, status, error = r.output()
     self.assertEqual(type, "output")
     self.assertEqual(data, b"hello world\n")
     self.assertEqual(stream, 1)
     type, data, stream, status, error = r.output()
     self.assertEqual(type, "status")
     self.assertEqual(status, 0)
     type, data, stream, status, error = r.output()
     self.assertEqual(type, "done")
     r.noop()
     r.close()
Example #6
0
 def test_ccache(self):
     # type: () -> None
     r = remctl.Remctl()
     os.environ["KRB5CCNAME"] = "nonexistent-file"
     try:
         r.open("localhost", 14373, self.principal)
         self.fail("open without ticket cache succeeded")
     except remctl.RemctlError:
         pass
     okay = False
     try:
         r.set_ccache("tests/tmp/krb5cc_test")
         okay = True
     except remctl.RemctlError:
         pass
     if okay:
         r.open("localhost", 14373, self.principal)
     r.close()
Example #7
0
 def test_full_errors(self):
     # type: () -> None
     r = remctl.Remctl()
     try:
         r.open("localhost", "foo")
     except TypeError as error:
         self.assertEqual(str(error), "port must be a number: 'foo'")
     try:
         r.open("localhost", -1)
     except ValueError as error:
         self.assertEqual(str(error), "invalid port number: -1")
     pattern = "cannot connect to localhost \\(port 14444\\): .*"
     try:
         r.open("localhost", 14444)
     except remctl.RemctlError as error:
         self.assertTrue(re.compile(pattern).match(str(error)))
     self.assertTrue(re.compile(pattern).match(r.error()))
     try:
         r.command(["test", "test"])
     except remctl.RemctlNotOpenedError as error:
         self.assertEqual(str(error), "no currently open connection")
     r.open("localhost", 14373, self.principal)
     try:
         r.command("test")
     except TypeError as error:
         self.assertEqual(
             str(error), "command must be a sequence or iterator"
         )
     try:
         r.command([])
     except ValueError as error:
         self.assertEqual(str(error), "command must not be empty")
     r.close()
     try:
         r.output()
     except remctl.RemctlNotOpenedError as error:
         self.assertEqual(str(error), "no currently open connection")
     self.assertEqual(r.error(), "no currently open connection")
Example #8
0
#!/usr/bin/env python2

import remctl
import sys

# this exists because remctl is a python2 library apparently and not a python3 one.
# if I am wrong about this please nuke it and uncomment the code in swipedlib.py

remctlHost = 'gomes.acm.jhu.edu'
remctlPrinc = 'host/gomes.trinidad.acm.jhu.edu'

try:
    message = sys.argv[1]
    if message != '':
        command = ('announce', 'door', message)
        object = remctl.Remctl(remctlHost, 4373, remctlPrinc)
        object.command(command)
except IndexError:
    pass