Exemplo n.º 1
0
 def get_ssh_connection(self):
     if self.use_password:
         return get_ssh_connection(self.cluster.hostname,
                                   self.username,
                                   password=self.password,
                                   port=self.cluster.port)
     else:
         user = type(self.user).objects.get(id=self.user.id)
         private = StringIO(user.private_key)
         return get_ssh_connection(self.cluster.hostname,
                                   self.username,
                                   key=private,
                                   port=self.cluster.port)
Exemplo n.º 2
0
 def get_ssh_connection(self):
     if self.use_password:
         return get_ssh_connection(self.cluster.hostname,
                                   self.username,
                                   password=self.password,
                                   port=self.cluster.port)
     else:
         user = type(self.user).objects.get(id=self.user.id)
         private = StringIO(user.private_key)
         return get_ssh_connection(self.cluster.hostname,
                                   self.username,
                                   key=private,
                                   port=self.cluster.port)
Exemplo n.º 3
0
 def test_get_ssh_key(self):
     test_path = os.path.join(settings.MEDIA_ROOT, "tests")
     with open(os.path.join(test_path, "id_rsa"), 'r') as key:
         ssh = get_ssh_connection("localhost", "vagrant",
                                  key=key, port=2222)
         with ssh:
             pass
Exemplo n.º 4
0
    def test_get_ssh_password(self, mock_ssh):
        ssh = get_ssh_connection("localhost", "vagrant",
                                 password="******", port=2222)

        mock_connect = mock_ssh.mock_calls[-1]
        self.assertEqual(mock_connect[1][0], SERVER['hostname'])
        self.assertEqual(mock_connect[2]['password'], SERVER['password'])
        self.assertEqual(mock_connect[2]['username'], SERVER['username'])
        self.assertEqual(mock_connect[2]['port'], SERVER['port'])
        with ssh:
            pass
Exemplo n.º 5
0
 def test_get_ssh_key(self, mock_ssh, mock_paramiko):
     test_path = os.path.join(settings.MEDIA_ROOT, "tests")
     with open(os.path.join(test_path, "id_rsa"), 'r') as key:
         ssh = get_ssh_connection("localhost", "vagrant",
                                  key=key, port=2222)
         mock_paramiko.RSAKey.from_private_key.assert_called_once()
         mock_connect = mock_ssh.mock_calls[-1]
         self.assertEqual(mock_connect[1][0], SERVER['hostname'])
         self.assertEqual(mock_connect[2]['username'], SERVER['username'])
         self.assertEqual(mock_connect[2]['port'], SERVER['port'])
         with ssh:
             pass
Exemplo n.º 6
0
    def test_get_ssh_password(self, mock_ssh):
        ssh = get_ssh_connection("localhost",
                                 "vagrant",
                                 password="******",
                                 port=2222)

        mock_connect = mock_ssh.mock_calls[-1]
        self.assertEqual(mock_connect[1][0], SERVER['hostname'])
        self.assertEqual(mock_connect[2]['password'], SERVER['password'])
        self.assertEqual(mock_connect[2]['username'], SERVER['username'])
        self.assertEqual(mock_connect[2]['port'], SERVER['port'])
        with ssh:
            pass
Exemplo n.º 7
0
 def test_get_ssh_key(self, mock_ssh, mock_paramiko):
     test_path = os.path.join(settings.MEDIA_ROOT, "tests")
     with open(os.path.join(test_path, "id_rsa"), 'r') as key:
         ssh = get_ssh_connection("localhost",
                                  "vagrant",
                                  key=key,
                                  port=2222)
         mock_paramiko.RSAKey.from_private_key.assert_called_once()
         mock_connect = mock_ssh.mock_calls[-1]
         self.assertEqual(mock_connect[1][0], SERVER['hostname'])
         self.assertEqual(mock_connect[2]['username'], SERVER['username'])
         self.assertEqual(mock_connect[2]['port'], SERVER['port'])
         with ssh:
             pass
Exemplo n.º 8
0
 def test_get_ssh_error(self):
     with self.assertRaises(Exception):
         get_ssh_connection("localhost", "username")
Exemplo n.º 9
0
 def test_get_ssh_password(self):
     ssh = get_ssh_connection("localhost", "vagrant",
                              password="******", port=2222)
     with ssh:
         pass
Exemplo n.º 10
0
 def test_get_ssh_error(self):
     with self.assertRaises(Exception):
         get_ssh_connection("localhost", "username")