Skip to content

Commit

Permalink
Add test that presto is started as presto user
Browse files Browse the repository at this point in the history
* Make sure that the user of server's pid is presto
* change run_prestoadmin_script to run_script_from_prestoadmin_dir and
  extend to be able to run on other hosts than master

Testing: make lint, ran test, sandbox with all tests and new RPM
  • Loading branch information
cawallin committed Sep 23, 2015
1 parent 30cf206 commit fe8663a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
12 changes: 8 additions & 4 deletions tests/product/base_product_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,21 @@ def run_prestoadmin(self, command, raise_error=True, cluster=None):
raise_error=raise_error
)

def run_prestoadmin_script(self, script_contents, **kwargs):
def run_script_from_prestoadmin_dir(self, script_contents, host='',
**kwargs):
if not host:
host = self.cluster.master

script_contents = self.replace_keywords(script_contents,
**kwargs)
temp_script = '/opt/prestoadmin/tmp.sh'
self.cluster.write_content_to_host(
'#!/bin/bash\ncd /opt/prestoadmin\n%s' % script_contents,
temp_script, self.cluster.master)
temp_script, host)
self.cluster.exec_cmd_on_host(
self.cluster.master, 'chmod +x %s' % temp_script)
host, 'chmod +x %s' % temp_script)
return self.cluster.exec_cmd_on_host(
self.cluster.master, temp_script)
host, temp_script)

def assert_path_exists(self, host, file_path):
self.cluster.exec_cmd_on_host(
Expand Down
14 changes: 7 additions & 7 deletions tests/product/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_passwordless_ssh_authentication(self):
# Passwordless SSH as root, but specify -I
# We need to do it as a script because docker_py doesn't support
# redirecting stdin.
command_output = self.run_prestoadmin_script(
command_output = self.run_script_from_prestoadmin_dir(
'echo "password" | ./presto-admin connector add -I')

self.assertEqualIgnoringOrder(
Expand All @@ -120,7 +120,7 @@ def test_passwordless_ssh_authentication(self):
# Passwordless SSH as app-admin, specify -I
non_root_sudo_warning = self.non_root_sudo_warning_message()

command_output = self.run_prestoadmin_script(
command_output = self.run_script_from_prestoadmin_dir(
'echo "password" | ./presto-admin connector add -I -u app-admin')
self.assertEqualIgnoringOrder(
self.success_output + self.interactive_text +
Expand All @@ -134,7 +134,7 @@ def test_passwordless_ssh_authentication(self):

# Passwordless SSH as app-admin, but specify wrong password with -I
parallel_password_failure = self.parallel_password_failure_message()
command_output = self.run_prestoadmin_script(
command_output = self.run_script_from_prestoadmin_dir(
'echo "asdf" | ./presto-admin connector add -I -u app-admin')
self.assertEqualIgnoringOrder(parallel_password_failure +
self.interactive_text, command_output)
Expand All @@ -146,7 +146,7 @@ def test_passwordless_ssh_authentication(self):
command_output)

# Passwordless SSH as root, in serial mode
command_output = self.run_prestoadmin_script(
command_output = self.run_script_from_prestoadmin_dir(
'./presto-admin connector add --serial')
self.assertEqualIgnoringOrder(
self.success_output, command_output)
Expand All @@ -161,7 +161,7 @@ def test_no_passwordless_ssh_authentication(self):
# This is needed because the test for
# No passwordless SSH, -I correct -u app-admin,
# was giving Device not a stream error in jenkins
self.run_prestoadmin_script(
self.run_script_from_prestoadmin_dir(
'echo "password" | ./presto-admin connector add -I')

for host in self.cluster.all_hosts():
Expand All @@ -185,7 +185,7 @@ def test_no_passwordless_ssh_authentication(self):

# No passwordless SSH, -I correct -u app-admin
non_root_sudo_warning = self.non_root_sudo_warning_message()
command_output = self.run_prestoadmin_script(
command_output = self.run_script_from_prestoadmin_dir(
'echo "password" | ./presto-admin connector add -I -u app-admin')
self.assertEqualIgnoringOrder(
self.success_output + self.interactive_text +
Expand Down Expand Up @@ -234,4 +234,4 @@ def setup_for_connector_add(self):
'echo \'connector.name=tpch\' ' \
'>> /etc/opt/prestoadmin/connectors/' \
'tpch.properties\n'
self.run_prestoadmin_script(connector_script)
self.run_script_from_prestoadmin_dir(connector_script)
6 changes: 3 additions & 3 deletions tests/product/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_connector_add_wrong_permissions(self):
# test add connector without read permissions on file
script = 'chmod 600 /etc/opt/prestoadmin/connectors/tpch.properties;' \
' su app-admin -c "./presto-admin connector add tpch"'
output = self.run_prestoadmin_script(script)
output = self.run_script_from_prestoadmin_dir(script)
with open(os.path.join(LOCAL_RESOURCES_DIR,
'connector_permissions_warning.txt'), 'r') as f:
expected = f.read() % \
Expand All @@ -77,7 +77,7 @@ def test_connector_add_wrong_permissions(self):
# test add connector directory without read permissions on directory
script = 'chmod 600 /etc/opt/prestoadmin/connectors; ' \
'su app-admin -c "./presto-admin connector add"'
output = self.run_prestoadmin_script(script)
output = self.run_script_from_prestoadmin_dir(script)
permission_error = '\nWarning: [slave3] Permission denied\n\n\n' \
'Warning: [slave2] Permission denied\n\n\n' \
'Warning: [slave1] Permission denied\n\n\n' \
Expand All @@ -90,7 +90,7 @@ def test_connector_add_wrong_permissions(self):
not_found_error = self.fatal_error(
'Configuration for connector tpch not found')
self.assertRaisesRegexp(OSError, not_found_error,
self.run_prestoadmin_script, script)
self.run_script_from_prestoadmin_dir, script)

def test_connector_add(self):
self.setup_cluster('presto')
Expand Down
13 changes: 13 additions & 0 deletions tests/product/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ def test_start_restart_config_file_error(self):
self.assert_simple_server_restart(expected_restart,
expected_stop=expected_stop)

def test_started_with_presto_user(self):
# note, will only work with 0.115t RPM
self.setup_cluster('presto')
start_output = self.run_prestoadmin('server start').splitlines()
process_per_host = self.get_process_per_host(start_output)

for host, pid in process_per_host:
user_for_pid = self.run_script_from_prestoadmin_dir(
'uid=$(awk \'/^Uid:/{print $2}\' /proc/%s/status);'
'getent passwd "$uid" | awk -F: \'{print $1}\'' % pid,
host)
self.assertEqual(user_for_pid.strip(), 'presto')

def assert_simple_start_stop(self, expected_start, expected_stop):
cmd_output = self.run_prestoadmin('server start')
cmd_output = cmd_output.splitlines()
Expand Down
6 changes: 3 additions & 3 deletions tests/product/test_server_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_install_interactive_with_hostnames(self):
self.copy_presto_rpm_to_master()
self.write_test_configs(self.cluster)

cmd_output = self.run_prestoadmin_script(
cmd_output = self.run_script_from_prestoadmin_dir(
'echo -e "root\n22\n%(master)s\n%(slave1)s\n" | '
'./presto-admin server install /mnt/presto-admin/%(rpm)s ')

Expand Down Expand Up @@ -366,7 +366,7 @@ def test_install_interactive_with_ips(self):
'master_ip': ips[self.cluster.master],
'slave1_ip': ips[self.cluster.slaves[0]]
}
cmd_output = self.run_prestoadmin_script(
cmd_output = self.run_script_from_prestoadmin_dir(
'echo -e "root\n22\n%(master_ip)s\n%(slave1_ip)s\n" | '
'./presto-admin server install /mnt/presto-admin/%(rpm)s ',
**additional_keywords).splitlines()
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_install_with_no_perm_to_local_path(self):
for host in self.cluster.all_internal_hosts():
expected += error_msg % {'host': host,
'rpm': self.presto_rpm_filename}
actual = self.run_prestoadmin_script(script)
actual = self.run_script_from_prestoadmin_dir(script)
self.assertEqualIgnoringOrder(actual, expected)

def test_install_twice(self):
Expand Down
24 changes: 18 additions & 6 deletions tests/product/test_server_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,27 @@ def test_uninstall_with_dir_readonly(self):
process_per_host = self.get_process_per_host(start_output.splitlines())
self.assert_started(process_per_host)

self.run_prestoadmin_script("chmod 500 -R /usr/lib/presto")
cmd_output = self.run_prestoadmin('server uninstall').splitlines()
self.run_script_from_prestoadmin_dir("chmod 500 -R /usr/lib/presto")
self.run_prestoadmin('server uninstall').splitlines()

# The master node was not able to be stopped or uninstalled because
# the permissions of the directory were changed such that the
# stop command can't run
pid_to_remove = None
for (host, pid) in process_per_host:
if host == self.cluster.internal_master:
pid_to_remove = pid
process_per_host.remove((self.cluster.internal_master, pid_to_remove))
self.assert_stopped(process_per_host)
expected = uninstall_output + self.expected_stop()[:]
self.assertRegexpMatchesLineByLine(cmd_output, expected)

for container in self.cluster.all_hosts():
uninstalled_hosts = self.cluster.all_hosts()[:]
uninstalled_hosts.remove(self.cluster.master)

for container in uninstalled_hosts:
self.assert_uninstalled_dirs_removed(container)

self.assert_installed(self.cluster.master)

@docker_only
def test_uninstall_as_non_sudo(self):
self.setup_cluster()
Expand All @@ -130,7 +142,7 @@ def test_uninstall_as_non_sudo(self):
self.server_install()

script = './presto-admin server uninstall -u testuser -p testpass'
output = self.run_prestoadmin_script(script)
output = self.run_script_from_prestoadmin_dir(script)
with open(os.path.join(LOCAL_RESOURCES_DIR, 'non_sudo_uninstall.txt'),
'r') as f:
expected = f.read()
Expand Down

0 comments on commit fe8663a

Please sign in to comment.