Skip to content

Commit

Permalink
Added support to password auth with key pair
Browse files Browse the repository at this point in the history
This commit adds support to login to system
with password authentication when key pair
is also specified, for some images without
cloud-init properly configured.

Change-Id: Ib9288f22a0e785062bc4870d5b972fde65880418
  • Loading branch information
Zhongcheng Lao committed Jan 16, 2015
1 parent b3ea58b commit 07393f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 4 additions & 2 deletions rally/benchmark/scenarios/vm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def wait_for_ping(self, server_ip):
timeout=120
)

def run_command(self, server_ip, port, username, interpreter, script):
def run_command(self, server_ip, port, username, password,
interpreter, script):
"""Run command via SSH on server.
Create SSH connection for server, wait for server to become
Expand All @@ -61,7 +62,8 @@ def run_command(self, server_ip, port, username, interpreter, script):
"""
self.wait_for_ping(server_ip)
ssh = sshutils.SSH(username, server_ip, port=port,
pkey=self.context["user"]["keypair"]["private"])
pkey=self.context["user"]["keypair"]["private"],
password=password)

self.wait_for_ssh(ssh)
return self.run_action(ssh, interpreter, script)
Expand Down
5 changes: 4 additions & 1 deletion rally/benchmark/scenarios/vm/vmtasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, *args, **kwargs):
"keypair": {}, "allow_ssh": {}})
def boot_runcommand_delete(self, image, flavor,
script, interpreter, username,
password=None,
volume_args=None,
fixed_network="private",
floating_network="public",
Expand All @@ -62,6 +63,7 @@ def boot_runcommand_delete(self, image, flavor,
metric names to values (see the sample script below)
:param interpreter: The shell interpreter to use when running script
:param username: User to SSH to instance as
:param password: Password on SSH authentication
:param volume_args: volume args when boot VM from volume
:param fixed_network: Network where instance is part of
:param floating_network: External network used to get floating ip from
Expand Down Expand Up @@ -99,7 +101,8 @@ def boot_runcommand_delete(self, image, flavor,
server_ip = fixed_ip

code, out, err = self.run_command(server_ip, port,
username, interpreter, script)
username, password,
interpreter, script)

if code:
raise exceptions.ScriptError(
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/benchmark/scenarios/vm/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ def test_run_command(self, mock_ssh_class, mock_wait_ping,

vm_scenario = utils.VMScenario()
vm_scenario.context = {"user": {"keypair": {"private": "ssh"}}}
vm_scenario.run_command("1.2.3.4", 22, "username", "int", "script")
vm_scenario.run_command("1.2.3.4", 22, "username",
'password', "int", "script")

mock_wait_ping.assert_called_once_with("1.2.3.4")
mock_ssh_class.assert_called_once_with("username", "1.2.3.4", port=22,
pkey="ssh")
pkey="ssh",
password='password')
mock_ssh_instance.wait.assert_called_once_with()
mock_run_action.assert_called_once_with(mock_ssh_instance,
"int", "script")
Expand Down
15 changes: 9 additions & 6 deletions tests/unit/benchmark/scenarios/vm/test_vmtasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def test_boot_runcommand_delete(self, mock_json_loads):
scenario.boot_runcommand_delete(
"image_id", "flavour_id", "script_path", "interpreter",
fixed_network='private', floating_network='public',
volume_args={'size': 10}, username="username", ip_version=4,
volume_args={'size': 10}, username="username",
password='password', ip_version=4,
port=22, use_floatingip=True, force_delete=False, fakearg="f")

# Assertions
Expand All @@ -77,7 +78,7 @@ def test_boot_runcommand_delete(self, mock_json_loads):
scenario._associate_floating_ip.assert_called_once_with(
fake_server, fake_floating_ip)
scenario.run_command.assert_called_once_with(
fake_floating_ip.ip, 22, 'username',
fake_floating_ip.ip, 22, 'username', 'password',
"interpreter", "script_path")

mock_json_loads.assert_called_once_with('stdout')
Expand Down Expand Up @@ -125,6 +126,7 @@ def test_boot_runcommand_delete_fails(self, mock_json_loads):
"image_id", "flavour_id", "script_path",
"interpreter", fixed_network='private',
floating_network='public', username="username",
password='password',
ip_version=4, port=22, use_floatingip=True,
force_delete=False, fakearg="f")

Expand All @@ -138,7 +140,7 @@ def test_boot_runcommand_delete_fails(self, mock_json_loads):
scenario._associate_floating_ip.assert_called_once_with(
fake_server, fake_floating_ip)
scenario.run_command.assert_called_once_with(
fake_floating_ip.ip, 22, 'username',
fake_floating_ip.ip, 22, 'username', 'password',
"interpreter", "script_path")

@mock.patch("json.loads")
Expand Down Expand Up @@ -180,6 +182,7 @@ def test_boot_runcommand_delete_valueerror_fails(self, mock_json_loads):
"image_id", "flavour_id", "script_path",
"interpreter", fixed_network='private',
floating_network='public', username="username",
password='password',
ip_version=4, port=22, use_floatingip=True,
force_delete=False, fakearg="f")

Expand All @@ -193,7 +196,7 @@ def test_boot_runcommand_delete_valueerror_fails(self, mock_json_loads):
scenario._associate_floating_ip.assert_called_once_with(
fake_server, fake_floating_ip)
scenario.run_command.assert_called_once_with(
fake_floating_ip.ip, 22, 'username',
fake_floating_ip.ip, 22, 'username', 'password',
"interpreter", "script_path")

@mock.patch("json.loads")
Expand All @@ -220,7 +223,7 @@ def test_boot_runcommand_delete_no_floating_ip(self, mock_json_loads):
scenario.boot_runcommand_delete(
"image_id", "flavour_id", "script_path", "interpreter",
fixed_network='private', floating_network='public',
username="username", ip_version=4,
username="username", password='password', ip_version=4,
port=22, use_floatingip=False, force_delete=False, fakearg="f")

# Assertions
Expand All @@ -230,7 +233,7 @@ def test_boot_runcommand_delete_no_floating_ip(self, mock_json_loads):

scenario.run_command.assert_called_once_with(
fake_server.addresses['private'][0]['addr'], 22, 'username',
"interpreter", "script_path")
'password', "interpreter", "script_path")

mock_json_loads.assert_called_once_with('stdout')

Expand Down

0 comments on commit 07393f6

Please sign in to comment.