Exemple #1
0
def open_movies():
    choices = list(values)

    for x in range(len(hosts)):
        one_client = SSHClient('client' + str(x))
        prompt = "Type "
        for v in choices:
            prompt += v + ", "
        prompt = prompt[:-2]
        prompt += " :"
        choice = get_valid_input(prompt)
        choices.remove(choice.lower())
        num = random.randint(0, 2)
        command = "~/dbuscontrol.sh stop"
        one_client.exec_command(command)
        command = "omxplayer /mnt/usb/media/" + choice + "/mov_" + str(
            num) + ".mp4 --aspect-mode=stretch --loop"
        one_client.exec_command(command)
        print("Opening a " + choice + " movie, number " + str(num) +
              " on client " + str(x) + "!")
    time.sleep(15)
    print("done playing movie")
    cmds = [
        "~/dbuscontrol.sh stop", "sleep 2",
        "omxplayer /mnt/usb/media/intro.mp4 --aspect-mode=stretch --loop"
    ]
    for cmd in cmds:
        client.run_command(cmd, stop_on_errors=False)
    next = raw_input("Hit return to continue or 'Q' to quit:")
    if next == "Q":
        print("quitting")
    else:
        open_movies()
Exemple #2
0
 def test_ssh_client_shell(self):
     """Test that running command sans shell works as expected
     and that shell commands fail accordingly"""
     client = SSHClient(self.host,
                        port=self.listen_port,
                        pkey=self.user_key)
     channel, host, stdout, stderr, stdin = client.exec_command(
         self.fake_cmd, use_shell=False)
     output = list(client.read_output_buffer(stdout))
     stderr = list(stderr)
     expected = []
     exit_code = channel.recv_exit_status()
     self.assertEqual(expected,
                      output,
                      msg="Got unexpected command output - %s" % (output, ))
     self.assertTrue(
         exit_code == 127,
         msg="Expected cmd not found error code 127, got %s instead" %
         (exit_code, ))
     channel, host, stdout, stderr, stdin = client.exec_command(
         'id', use_shell=False)
     output = list(client.read_output_buffer(stdout))
     exit_code = channel.recv_exit_status()
     self.assertTrue(output,
                     msg="Got no output from cmd executed without shell")
     self.assertTrue(
         exit_code == 0,
         msg="Cmd executed with shell failed with error code %s" %
         (exit_code, ))
     del client
def open_movie(choice, clientID):
    one_client = SSHClient(hosts[clientID])
    num = random.randint(0, 2)
    command = "~/dbuscontrol.sh stop"
    one_client.exec_command(command)
    command = "omxplayer /mnt/usb/media/" + choice + "/mov_" + str(
        num) + ".mp4 --aspect-mode=stretch --loop"
    one_client.exec_command(command)
    print("Opening a " + choice + " movie, number " + str(num) + " on " +
          hosts[clientID] + "!")
Exemple #4
0
def test():
    """Perform ls and copy file with SSHClient on localhost"""
    client = SSHClient('localhost')
    channel, host, stdout, stderr = client.exec_command('ls -ltrh')
    for line in stdout:
        pprint(line.strip())
    client.copy_file('../test', 'test_dir/test')
Exemple #5
0
def test():
    """Perform ls and copy file with SSHClient on localhost"""
    client = SSHClient('localhost')
    channel, host, stdout, stderr = client.exec_command('ls -ltrh')
    for line in stdout:
        print line.strip()
    client.copy_file('../test', 'test_dir/test')
Exemple #6
0
 def test_ssh_client_utf_encoding(self):
     """Test that unicode output works"""
     client = SSHClient(self.host, port=self.listen_port,
                        pkey=self.user_key)
     expected = [u'é']
     cmd = u"echo 'é'"
     channel, host, stdout, stderr, stdin = client.exec_command(cmd)
     output = list(stdout)
     self.assertEqual(expected, output,
                      msg="Got unexpected unicode output %s - expected %s" % (
                          output, expected,))
     del client
Exemple #7
0
 def test_ssh_client_shell(self):
     """Test that running command sans shell works as expected
     and that shell commands fail accordingly"""
     client = SSHClient(self.host, port=self.listen_port,
                        pkey=self.user_key)
     channel, host, stdout, stderr, stdin = client.exec_command(self.fake_cmd, use_shell=False)
     output = list(stdout)
     stderr = list(stderr)
     expected = []
     exit_code = channel.recv_exit_status()
     self.assertEqual(expected, output,
                      msg = "Got unexpected command output - %s" % (output,))
     self.assertTrue(exit_code == 127,
                     msg="Expected cmd not found error code 127, got %s instead" % (
                         exit_code,))
     channel, host, stdout, stderr, stdin = client.exec_command('id', use_shell=False)
     output = list(stdout)
     exit_code = channel.recv_exit_status()
     self.assertTrue(output,
                     msg="Got no output from cmd executed without shell")
     self.assertTrue(exit_code==0,
                     msg="Cmd executed with shell failed with error code %s" % (
                         exit_code,))
     del client
 def test_ssh_agent_authentication(self):
     """Test authentication via SSH agent.
     Do not provide public key to use when creating SSHClient,
     instead override the client's agent with our own fake SSH agent,
     add our to key to agent and try to login to server.
     Key should be automatically picked up from the overriden agent"""
     agent = FakeAgent()
     agent.add_key(USER_KEY)
     client = SSHClient(self.host, port=self.listen_port, _agent=agent)
     channel, host, stdout, stderr = client.exec_command(self.fake_cmd)
     channel.close()
     output = list(stdout)
     stderr = list(stderr)
     expected = [self.fake_resp]
     self.assertEqual(expected, output, msg="Got unexpected command output - %s" % (output,))
     del client
Exemple #9
0
 def test_ssh_agent_authentication(self):
     """Test authentication via SSH agent.
     Do not provide public key to use when creating SSHClient,
     instead override the client's agent with our own fake SSH agent,
     add our to key to agent and try to login to server.
     Key should be automatically picked up from the overriden agent"""
     agent = FakeAgent()
     agent.add_key(USER_KEY)
     client = SSHClient(self.host, port=self.listen_port, agent=agent)
     channel, host, stdout, stderr = client.exec_command(self.fake_cmd)
     output = list(stdout)
     stderr = list(stderr)
     expected = [self.fake_resp]
     self.assertEqual(expected,
                      output,
                      msg="Got unexpected command output - %s" % (output, ))
     del client