Exemple #1
0
    def test_create_with_password(self):
        """
        Initialize object with password.

        Just to have better coverage, initialize the object
        with the 'password' value instead of the 'key'.
        """
        conn_params = {
            'hostname': 'dummy.host.org',
            'username': '******',
            'password': '******'
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            'username': '******',
            'password': '******',
            'allow_agent': False,
            'hostname': 'dummy.host.org',
            'look_for_keys': False,
            'port': 22
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
Exemple #2
0
    def test_key_material_argument(self):
        path = os.path.join(os.path.dirname(__file__), "fixtures", "misc",
                            "test_rsa.key")

        with open(path, "r") as fp:
            private_key = fp.read()

        conn_params = {
            "hostname": "dummy.host.org",
            "username": "******",
            "key_material": private_key,
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key))
        expected_conn = {
            "username": "******",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "pkey": pkey,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg("Connecting to server")
    def test_key_material_argument(self):
        path = os.path.join(os.path.dirname(__file__), 'fixtures', 'misc',
                            'test_rsa.key')

        with open(path, 'r') as fp:
            private_key = fp.read()

        conn_params = {
            'hostname': 'dummy.host.org',
            'username': '******',
            'key_material': private_key
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key))
        expected_conn = {
            'username': '******',
            'allow_agent': False,
            'hostname': 'dummy.host.org',
            'look_for_keys': False,
            'pkey': pkey,
            'port': 22
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_password_protected_key_valid_password_provided(self):
        path = os.path.join(os.path.dirname(__file__), 'fixtures', 'misc',
                            'test_rsa_2048b_pass_foobar.key')

        # Supplied as key_material
        with open(path, 'r') as fp:
            private_key = fp.read()

        conn_params = {
            'hostname': 'dummy.host.org',
            'username': '******',
            'key_material': private_key,
            'password': '******'
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())

        conn_params = {
            'hostname': 'dummy.host.org',
            'username': '******',
            'key_files': path,
            'password': '******'
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())
Exemple #5
0
    def test_password_protected_key_valid_password_provided(self):
        path = os.path.join(
            os.path.dirname(__file__),
            "fixtures",
            "misc",
            "test_rsa_2048b_pass_foobar.key",
        )

        # Supplied as key_material
        with open(path, "r") as fp:
            private_key = fp.read()

        conn_params = {
            "hostname": "dummy.host.org",
            "username": "******",
            "key_material": private_key,
            "password": "******",
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())

        conn_params = {
            "hostname": "dummy.host.org",
            "username": "******",
            "key_files": path,
            "password": "******",
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())
    def test_deprecated_key_argument(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'key': 'id_rsa'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'key_filename': 'id_rsa',
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_create_with_password(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'password': '******'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'password': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_deprecated_key_argument(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'key': 'id_rsa'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'key_filename': 'id_rsa',
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_create_with_password(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'password': '******'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'password': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_create_without_credentials(self):
        """
        Initialize object with no credentials.

        Just to have better coverage, initialize the object
        without 'password' neither 'key'.
        """
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'hostname': 'dummy.host.org',
                         'allow_agent': True,
                         'look_for_keys': True,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
    def test_create_without_credentials(self):
        """
        Initialize object with no credentials.

        Just to have better coverage, initialize the object
        without 'password' neither 'key'.
        """
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'hostname': 'dummy.host.org',
                         'allow_agent': True,
                         'look_for_keys': True,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
Exemple #12
0
    def test_deprecated_key_argument(self):
        conn_params = {
            "hostname": "dummy.host.org",
            "username": "******",
            "key": "id_rsa",
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "******",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "key_filename": "id_rsa",
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg("Connecting to server")
Exemple #13
0
    def test_create_without_credentials(self):
        """
        Initialize object with no credentials.

        Just to have better coverage, initialize the object
        without 'password' neither 'key'.
        """
        conn_params = {"hostname": "dummy.host.org", "username": "******"}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "******",
            "hostname": "dummy.host.org",
            "allow_agent": True,
            "look_for_keys": True,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
    def test_create_with_password(self):
        """
        Initialize object with password.

        Just to have better coverage, initialize the object
        with the 'password' value instead of the 'key'.
        """
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'password': '******'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': '******',
                         'password': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
Exemple #15
0
    def test_key_material_argument(self):
        path = os.path.join(os.path.dirname(__file__),
                            'fixtures', 'misc', 'dummy_rsa')

        with open(path, 'r') as fp:
            private_key = fp.read()

        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******',
                       'key_material': private_key}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key))
        expected_conn = {'username': '******',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'pkey': pkey,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
        self.assertLogMsg('Connecting to server')
    def test_ed25519_key_type(self):
        path = os.path.join(os.path.dirname(__file__), 'fixtures', 'misc',
                            'test_ed25519.key')

        # Supplied as key_material
        with open(path, 'r') as fp:
            private_key = fp.read()

        conn_params = {
            'hostname': 'dummy.host.org',
            'username': '******',
            'key_material': private_key
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())
Exemple #17
0
    def test_ed25519_key_type(self):
        path = os.path.join(os.path.dirname(__file__), "fixtures", "misc",
                            "test_ed25519.key")

        # Supplied as key_material
        with open(path, "r") as fp:
            private_key = fp.read()

        conn_params = {
            "hostname": "dummy.host.org",
            "username": "******",
            "key_material": private_key,
        }

        mock = ParamikoSSHClient(**conn_params)
        self.assertTrue(mock.connect())
Exemple #18
0
node = driver.deploy_node(name=nodeName,
                          ex_blockdevicemappings=my_mapping,
                          image=image,
                          size=size,
                          ex_security_groups=[nodeName],
                          auth=pk,
                          ssh_username="******",
                          ssh_key=private_key_file,
                          deploy=sd)

# on Windows, libcloud doesn't run the deploy script to change the password, so we try it manually here
sshclient = ParamikoSSHClient(node.public_ips[0],
                              username="******",
                              key=private_key_file,
                              timeout=300)
res1 = sshclient.connect()
res2 = sshclient.run(passwd_change_cmd)

# allow remote access (RDP) by modifying the security group
driver.ex_authorize_security_group(nodeName,
                                   3389,
                                   3389,
                                   cidr_ip='0.0.0.0/0',
                                   protocol='tcp')

print(
    "REMnux Instance Ready to use, IP address: %s  RDP password for the 'remnux' user is %s"
    % (node.public_ips[0], newPass))
print("For SSH access use this command: ssh -i %s remnux@%s" %
      (private_key_file, node.public_ips[0]))