class TestServerUninstall(BaseProductTestCase): def setUp(self): super(TestServerUninstall, self).setUp() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_uninstall(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) cmd_output = self.run_prestoadmin('server uninstall', raise_error=False).splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop()[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def assert_uninstalled_dirs_removed(self, container): self.installer.assert_uninstalled(container) self.assert_path_removed(container, '/etc/presto') self.assert_path_removed(container, '/usr/lib/presto') self.assert_path_removed(container, '/var/lib/presto') self.assert_path_removed(container, '/usr/shared/doc/presto') self.assert_path_removed(container, '/etc/init.d/presto') def test_uninstall_twice(self): self.test_uninstall() output = self.run_prestoadmin('server uninstall', raise_error=False) with open(os.path.join(LOCAL_RESOURCES_DIR, 'uninstall_twice.txt'), 'r') as f: expected = f.read() self.assertEqualIgnoringOrder(expected, output) def test_uninstall_lost_host(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) self.cluster.stop_host(self.cluster.slaves[0]) expected = self.down_node_connection_error( self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall', raise_error=False) self.assertRegexpMatches(cmd_output, expected) for container in [ self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2] ]: self.assert_uninstalled_dirs_removed(container)
class TestServerUninstall(BaseProductTestCase): def setUp(self): super(TestServerUninstall, self).setUp() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_uninstall(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) cmd_output = self.run_prestoadmin( 'server uninstall', raise_error=False).splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop()[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def assert_uninstalled_dirs_removed(self, container): self.installer.assert_uninstalled(container) self.assert_path_removed(container, '/etc/presto') self.assert_path_removed(container, '/usr/lib/presto') self.assert_path_removed(container, '/var/lib/presto') self.assert_path_removed(container, '/usr/shared/doc/presto') self.assert_path_removed(container, '/etc/init.d/presto') def test_uninstall_twice(self): self.test_uninstall() output = self.run_prestoadmin('server uninstall', raise_error=False) with open(os.path.join(LOCAL_RESOURCES_DIR, 'uninstall_twice.txt'), 'r') as f: expected = f.read() self.assertEqualIgnoringOrder(expected, output) def test_uninstall_lost_host(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) self.cluster.stop_host( self.cluster.slaves[0]) expected = self.down_node_connection_error( self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall', raise_error=False) self.assertRegexpMatches(cmd_output, expected) for container in [self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2]]: self.assert_uninstalled_dirs_removed(container)
def test_install_fails_java_not_found(self): installer = StandalonePrestoInstaller(self) with relocate_jdk_directory(self.cluster, '/usr'): self.upload_topology() cmd_output = installer.install(pa_raise_error=False) actual = cmd_output.splitlines() num_failures = 0 for line in enumerate(actual): if str(line).find('Error: Required Java version' ' could not be found') != -1: num_failures += 1 self.assertEqual(4, num_failures) for container in self.cluster.all_hosts(): installer.assert_uninstalled(container)
def test_install_fails_java8_not_found(self): installer = StandalonePrestoInstaller(self) with relocate_jdk_directory(self.cluster, '/usr'): self.upload_topology() cmd_output = installer.install(pa_raise_error=False) actual = cmd_output.splitlines() num_failures = 0 for line in enumerate(actual): if str(line).find('Error: Required Java version' ' could not be found') != -1: num_failures += 1 self.assertEqual(4, num_failures) for container in self.cluster.all_hosts(): installer.assert_uninstalled(container)
def test_install_failure_without_java8_home(self): installer = StandalonePrestoInstaller(self, dummy=True) for container in self.cluster.all_hosts(): self.cluster.exec_cmd_on_host(container, "mv /usr/java/jdk1.8.0_40 /usr/") self.upload_topology() cmd_output = installer.install(pa_raise_error=False) actual = cmd_output.splitlines() num_failures = 0 for line in enumerate(actual): if str(line).find("Error: Required Java version" " could not be found") != -1: num_failures += 1 self.assertEqual(4, num_failures) for container in self.cluster.all_hosts(): installer.assert_uninstalled(container, dummy=True)
class TestServerUninstall(BaseProductTestCase): def setUp(self): super(TestServerUninstall, self).setUp() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_uninstall(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) self.run_prestoadmin( 'server uninstall', raise_error=False).splitlines() self.assert_stopped(process_per_host) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def assert_uninstalled_dirs_removed(self, container): self.installer.assert_uninstalled(container) self.assert_path_removed(container, '/usr/lib/presto') self.assert_path_removed(container, '/var/lib/presto') self.assert_path_removed(container, '/usr/shared/doc/presto') self.assert_path_removed(container, '/etc/init.d/presto') def test_uninstall_lost_host(self): self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PRESTO_CLUSTER) self.cluster.stop_host( self.cluster.slaves[0]) expected = self.down_node_connection_error( self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall', raise_error=False) self.assertRegexpMatches(cmd_output, expected) for container in [self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2]]: self.assert_uninstalled_dirs_removed(container)
class TestPackageInstall(BaseProductTestCase): def setUp(self): super(TestPackageInstall, self).setUp() self.setup_cluster(self.PA_ONLY_CLUSTER) self.upload_topology() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_package_install(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install ' '/mnt/presto-admin/%(rpm)s', rpm=rpm_name) for container in self.cluster.all_hosts(): self.installer.assert_installed(self, container, msg=output) def test_install_coord_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) for slave in self.cluster.slaves: self.installer.assert_uninstalled(slave, msg=output) def test_install_worker_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(slave1)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_workers_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/' '%(rpm)s -H %(slave1)s,%(slave2)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_exclude_coord(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/' '%(rpm)s -x %(master)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.master, msg=output) for slave in self.cluster.slaves: self.installer.assert_installed(self, slave, msg=output) def test_install_exclude_worker(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/' '%(rpm)s -x %(slave1)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_exclude_workers(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/' '%(rpm)s -x %(slave1)s,%(slave2)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_invalid_path(self): rpm_name = self.installer.copy_presto_rpm_to_master() cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin' '/invalid-path/presto.rpm', rpm=rpm_name) error = '\nFatal error: [%s] error: ' \ '/mnt/presto-admin/invalid-path/presto.rpm: open failed: ' \ 'No such file or directory\n\nAborting.\n' expected = '' for host in self.cluster.all_internal_hosts(): expected += error % host self.assertEqualIgnoringOrder(cmd_output, expected) def test_install_no_path_arg(self): self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install', raise_error=False) self.assertEqual( output, 'Incorrect number of arguments to task.\n\n' 'Displaying detailed information for task ' '\'package install\':\n\n' ' Install the rpm package on the cluster\n' ' \n Args:\n' ' local_path: Absolute path to the rpm' ' to be installed\n ' '--nodeps (optional): Flag to indicate if ' 'rpm install\n' ' should ignore c' 'hecking package dependencies. Equivalent\n' ' to adding --nodeps flag to rpm ' '-i.\n\n') def test_install_already_installed(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H ' '%(master)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name) expected = self.escape_for_regex( self.replace_keywords( """ Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'package install ' '/etc/opt/prestoadmin/config.json') error = """ Fatal error: \[%s\] error: (/etc/opt/prestoadmin/config.json: )?not an rpm \ package Aborting. """ expected = '' for host in self.cluster.all_internal_hosts(): expected += error % host self.assertRegexpMatchesLineByLine(cmd_output.splitlines(), expected.splitlines()) @docker_only def test_install_rpm_with_missing_jdk(self): rpm_name = self.installer.copy_presto_rpm_to_master( rpm_dir=prestoadmin.main_dir, rpm_name=self.installer.presto_rpm_filename) self.cluster.exec_cmd_on_host(self.cluster.master, 'rpm -e jdk1.8.0_40-1.8.0_40-fcs') self.assertRaisesRegexp( OSError, 'package jdk1.8.0_40-1.8.0_40-fcs is not ' 'installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q jdk1.8.0_40-1.8.0_40-fcs') cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name) self.assertRegexpMatchesLineByLine( cmd_output.splitlines(), self.jdk_not_found_error_message(rpm_name).splitlines()) def jdk_not_found_error_message(self, rpm_name): with open(os.path.join(LOCAL_RESOURCES_DIR, 'jdk_not_found.txt')) as f: jdk_not_found_error = f.read() return self.escape_for_regex( self.replace_keywords(jdk_not_found_error, **self.installer.get_keywords(rpm_name))) @docker_only def test_install_rpm_missing_dependency(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host(self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name) expected = self.replace_keywords( """ Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s --nodeps', rpm=rpm_name) expected = 'Deploying rpm on %(host)s...\n' \ 'Package deployed successfully on: %(host)s\n' \ 'Package installed successfully on: %(host)s' \ % {'host': self.cluster.internal_master} self.assertEqualIgnoringOrder(expected, cmd_output)
class TestPackageInstall(BaseProductTestCase): def setUp(self): super(TestPackageInstall, self).setUp() self.setup_cluster(NoHadoopBareImageProvider(), self.PA_ONLY_CLUSTER) self.upload_topology() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_package_install(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install ' '/mnt/presto-admin/%(rpm)s', rpm=rpm_name) for container in self.cluster.all_hosts(): self.installer.assert_installed(self, container, msg=output) def test_install_coord_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) for slave in self.cluster.slaves: self.installer.assert_uninstalled(slave, msg=output) def test_install_worker_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(slave1)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_workers_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install /mnt/presto-admin/' '%(rpm)s -H %(slave1)s,%(slave2)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_exclude_coord(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install /mnt/presto-admin/' '%(rpm)s -x %(master)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.master, msg=output) for slave in self.cluster.slaves: self.installer.assert_installed(self, slave, msg=output) def test_install_exclude_worker(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install /mnt/presto-admin/' '%(rpm)s -x %(slave1)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_exclude_workers(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install /mnt/presto-admin/' '%(rpm)s -x %(slave1)s,%(slave2)s', rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_invalid_path(self): rpm_name = self.installer.copy_presto_rpm_to_master() cmd_output = self.run_prestoadmin('package install /mnt/presto-admin' '/invalid-path/presto.rpm', rpm=rpm_name, raise_error=False) error = '\nFatal error: [%s] error: ' \ '/mnt/presto-admin/invalid-path/presto.rpm: open failed: ' \ 'No such file or directory\n\nAborting.\n' expected = '' for host in self.cluster.all_internal_hosts(): expected += error % host self.assertEqualIgnoringOrder(cmd_output, expected) def test_install_no_path_arg(self): self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install', raise_error=False) self.assertEqual(output, 'Incorrect number of arguments to task.\n\n' 'Displaying detailed information for task ' '\'package install\':\n\n' ' Install the rpm package on the cluster\n' ' \n Args:\n' ' local_path: Absolute path to the rpm' ' to be installed\n ' '--nodeps (optional): Flag to indicate if ' 'rpm install\n' ' should ignore c' 'hecking package dependencies. Equivalent\n' ' to adding --nodeps flag to rpm ' '-i.\n\n') def test_install_already_installed(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.run_prestoadmin('package install /mnt/presto-admin/%(rpm)s -H ' '%(master)s', rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name, raise_error=False) expected = self.escape_for_regex(self.replace_keywords(""" Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'package install ' '/etc/opt/prestoadmin/config.json', raise_error=False) error = """ Fatal error: \[%s\] error: (/etc/opt/prestoadmin/config.json: )?not an rpm \ package Aborting. """ expected = '' for host in self.cluster.all_internal_hosts(): expected += error % host self.assertRegexpMatchesLineByLine(cmd_output.splitlines(), expected.splitlines()) @docker_only def test_install_rpm_missing_dependency(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host( self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s', rpm=rpm_name, raise_error=False) expected = self.replace_keywords(""" Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install /mnt/presto-admin/%(rpm)s -H %(master)s --nodeps', rpm=rpm_name ) expected = 'Deploying rpm on %(host)s...\n' \ 'Package deployed successfully on: %(host)s\n' \ 'Package installed successfully on: %(host)s' \ % {'host': self.cluster.internal_master} self.assertEqualIgnoringOrder(expected, cmd_output)
class TestServerUninstall(BaseProductTestCase): def setUp(self): super(TestServerUninstall, self).setUp() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_uninstall(self): self.setup_cluster(self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) cmd_output = self.run_prestoadmin('server uninstall').splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop()[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def assert_uninstalled_dirs_removed(self, container): self.installer.assert_uninstalled(container) self.assert_path_removed(container, '/etc/presto') self.assert_path_removed(container, '/usr/lib/presto') self.assert_path_removed(container, '/var/lib/presto') self.assert_path_removed(container, '/usr/shared/doc/presto') self.assert_path_removed(container, '/etc/init.d/presto') def test_uninstall_when_server_down(self): self.setup_cluster(self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.run_prestoadmin('server stop -H %s' % self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall').splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop( not_running=[self.cluster.internal_slaves[0]])[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def test_uninstall_twice(self): self.test_uninstall() output = self.run_prestoadmin('server uninstall') with open(os.path.join(LOCAL_RESOURCES_DIR, 'uninstall_twice.txt'), 'r') as f: expected = f.read() self.assertEqualIgnoringOrder(expected, output) def test_uninstall_lost_host(self): self.setup_cluster(self.PA_ONLY_CLUSTER) pa_installer = PrestoadminInstaller(self) pa_installer.install() topology = { "coordinator": self.cluster.internal_slaves[0], "workers": [ self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2] ] } self.upload_topology(topology) self.installer.install() start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) down_node = self.cluster.internal_slaves[0] self.cluster.stop_host(self.cluster.slaves[0]) expected = self.down_node_connection_error( self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall') self.assertRegexpMatches(cmd_output, expected) process_per_active_host = [] for host, pid in process_per_host: if host not in down_node: process_per_active_host.append((host, pid)) self.assert_stopped(process_per_active_host) for container in [ self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2] ]: self.assert_uninstalled_dirs_removed(container) def test_uninstall_with_dir_readonly(self): self.setup_cluster(self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) 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) uninstalled_hosts = self.cluster.all_hosts()[:] uninstalled_hosts.remove(self.cluster.master) for container in uninstalled_hosts: self.assert_uninstalled_dirs_removed(container) self.installer.assert_installed(self, container=self.cluster.master) @docker_only def test_uninstall_as_non_sudo(self): self.setup_cluster(self.PA_ONLY_CLUSTER) self.upload_topology() self.installer.install(dummy=True) script = './presto-admin server uninstall -u testuser -p testpass' 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() self.assertEqualIgnoringOrder(expected, output)
class TestPackageInstall(BaseProductTestCase): def setUp(self): super(TestPackageInstall, self).setUp() self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PA_CLUSTER) self.upload_topology() self.installer = StandalonePrestoInstaller(self) def tearDown(self): self._assert_uninstall() super(TestPackageInstall, self).tearDown() def _assert_uninstall(self): output = self.run_prestoadmin('package uninstall presto-server-rpm --force') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) @attr('smoketest') def test_package_installer(self): rpm_name = self.installer.copy_presto_rpm_to_master() # install output = self.run_prestoadmin('package install %(rpm)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) for container in self.cluster.all_hosts(): self.installer.assert_installed(self, container, msg=output) # uninstall output = self.run_prestoadmin('package uninstall presto-server-rpm') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) def test_install_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() # install onto master and slave2 output = self.run_prestoadmin('package install %(rpm)s -H %(master)s,%(slave2)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) # uninstall on slave2 output = self.run_prestoadmin('package uninstall presto-server-rpm -H %(slave2)s') self.installer.assert_installed(self, self.cluster.master, msg=output) for container in self.cluster.slaves: self.installer.assert_uninstalled(container, msg=output) # uninstall on rest output = self.run_prestoadmin('package uninstall presto-server-rpm --force') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) def test_install_exclude_nodes(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin('package install %(rpm)s -x %(master)s,%(slave2)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) # install self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) # uninstall output = self.run_prestoadmin('package uninstall presto-server-rpm -x %(master)s,%(slave2)s') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) # skip this tests as it depends on OS package names @attr('quarantine') @docker_only def test_install_rpm_missing_dependency(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host( self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install %(rpm)s -H %(master)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name), raise_error=False) expected = self.replace_keywords(""" Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'quarantine') @docker_only def test_install_rpm_with_nodeps(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host( self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install %(rpm)s -H %(master)s --nodeps', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name) ) expected = 'Deploying rpm on %(host)s...\n' \ 'Package deployed successfully on: %(host)s\n' \ 'Package installed successfully on: %(host)s' \ % {'host': self.cluster.internal_master} self.assertEqualIgnoringOrder(expected, cmd_output)
class TestServerUninstall(BaseProductTestCase): def setUp(self): super(TestServerUninstall, self).setUp() self.installer = StandalonePrestoInstaller(self) @attr('smoketest') def test_uninstall(self): self.setup_cluster(NoHadoopBareImageProvider(), self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) cmd_output = self.run_prestoadmin( 'server uninstall', raise_error=False).splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop()[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def assert_uninstalled_dirs_removed(self, container): self.installer.assert_uninstalled(container) self.assert_path_removed(container, '/etc/presto') self.assert_path_removed(container, '/usr/lib/presto') self.assert_path_removed(container, '/var/lib/presto') self.assert_path_removed(container, '/usr/shared/doc/presto') self.assert_path_removed(container, '/etc/init.d/presto') def test_uninstall_when_server_down(self): self.setup_cluster(NoHadoopBareImageProvider(), self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.run_prestoadmin('server stop -H %s' % self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall').splitlines() self.assert_stopped(process_per_host) expected = uninstall_output + self.expected_stop( not_running=[self.cluster.internal_slaves[0]])[:] self.assertRegexpMatchesLineByLine(cmd_output, expected) for container in self.cluster.all_hosts(): self.assert_uninstalled_dirs_removed(container) def test_uninstall_twice(self): self.test_uninstall() output = self.run_prestoadmin('server uninstall', raise_error=False) with open(os.path.join(LOCAL_RESOURCES_DIR, 'uninstall_twice.txt'), 'r') as f: expected = f.read() self.assertEqualIgnoringOrder(expected, output) def test_uninstall_lost_host(self): self.setup_cluster(NoHadoopBareImageProvider(), self.PA_ONLY_CLUSTER) pa_installer = PrestoadminInstaller(self) pa_installer.install() topology = {"coordinator": self.cluster.internal_slaves[0], "workers": [self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2]]} self.upload_topology(topology) self.installer.install() start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) down_node = self.cluster.internal_slaves[0] self.cluster.stop_host( self.cluster.slaves[0]) expected = self.down_node_connection_error( self.cluster.internal_slaves[0]) cmd_output = self.run_prestoadmin('server uninstall', raise_error=False) self.assertRegexpMatches(cmd_output, expected) process_per_active_host = [] for host, pid in process_per_host: if host not in down_node: process_per_active_host.append((host, pid)) self.assert_stopped(process_per_active_host) for container in [self.cluster.internal_master, self.cluster.internal_slaves[1], self.cluster.internal_slaves[2]]: self.assert_uninstalled_dirs_removed(container) def test_uninstall_with_dir_readonly(self): self.setup_cluster(NoHadoopBareImageProvider(), self.STANDALONE_PRESTO_CLUSTER) start_output = self.run_prestoadmin('server start') process_per_host = self.get_process_per_host(start_output.splitlines()) self.assert_started(process_per_host) self.run_script_from_prestoadmin_dir("chmod 500 -R /usr/lib/presto") self.run_prestoadmin('server uninstall', raise_error=False) # 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) uninstalled_hosts = self.cluster.all_hosts()[:] uninstalled_hosts.remove(self.cluster.master) for container in uninstalled_hosts: self.assert_uninstalled_dirs_removed(container) self.installer.assert_installed(self, container=self.cluster.master) @docker_only def test_uninstall_as_non_sudo(self): self.setup_cluster(NoHadoopBareImageProvider(), self.PA_ONLY_CLUSTER) self.upload_topology() self.installer.install() script = './presto-admin server uninstall -u testuser -p testpass' 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() self.assertEqualIgnoringOrder(expected, output)
class TestPackageInstall(BaseProductTestCase): def setUp(self): super(TestPackageInstall, self).setUp() self.setup_cluster(NoHadoopBareImageProvider(), STANDALONE_PA_CLUSTER) self.upload_topology() self.installer = StandalonePrestoInstaller(self) def tearDown(self): self._assert_uninstall() super(TestPackageInstall, self).tearDown() def _assert_uninstall(self): output = self.run_prestoadmin( 'package uninstall presto-server-rpm --force') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) @attr('smoketest') def test_package_installer(self): rpm_name = self.installer.copy_presto_rpm_to_master() # install output = self.run_prestoadmin('package install %(rpm)s', rpm=os.path.join( self.cluster.rpm_cache_dir, rpm_name)) for container in self.cluster.all_hosts(): self.installer.assert_installed(self, container, msg=output) # uninstall output = self.run_prestoadmin('package uninstall presto-server-rpm') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) def test_install_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() # install onto master and slave2 output = self.run_prestoadmin( 'package install %(rpm)s -H %(master)s,%(slave2)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) # uninstall on slave2 output = self.run_prestoadmin( 'package uninstall presto-server-rpm -H %(slave2)s') self.installer.assert_installed(self, self.cluster.master, msg=output) for container in self.cluster.slaves: self.installer.assert_uninstalled(container, msg=output) # uninstall on rest output = self.run_prestoadmin( 'package uninstall presto-server-rpm --force') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) def test_install_exclude_nodes(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( 'package install %(rpm)s -x %(master)s,%(slave2)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) # install self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) # uninstall output = self.run_prestoadmin( 'package uninstall presto-server-rpm -x %(master)s,%(slave2)s') for container in self.cluster.all_hosts(): self.installer.assert_uninstalled(container, msg=output) # skip this tests as it depends on OS package names @attr('quarantine') @docker_only def test_install_rpm_missing_dependency(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host(self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install %(rpm)s -H %(master)s', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name), raise_error=False) expected = self.replace_keywords( """ Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'quarantine') @docker_only def test_install_rpm_with_nodeps(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host(self.cluster.master, 'rpm -e --nodeps python-2.6.6') self.assertRaisesRegexp(OSError, 'package python-2.6.6 is not installed', self.cluster.exec_cmd_on_host, self.cluster.master, 'rpm -q python-2.6.6') cmd_output = self.run_prestoadmin( 'package install %(rpm)s -H %(master)s --nodeps', rpm=os.path.join(self.cluster.rpm_cache_dir, rpm_name)) expected = 'Deploying rpm on %(host)s...\n' \ 'Package deployed successfully on: %(host)s\n' \ 'Package installed successfully on: %(host)s' \ % {'host': self.cluster.internal_master} self.assertEqualIgnoringOrder(expected, cmd_output)
class TestPackageInstall(BaseProductTestCase): def setUp(self): super(TestPackageInstall, self).setUp() self.setup_cluster(self.PA_ONLY_CLUSTER) self.upload_topology() self.installer = StandalonePrestoInstaller(self) @attr("smoketest") def test_package_install(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install " "/mnt/presto-admin/%(rpm)s", rpm=rpm_name) for container in self.cluster.all_hosts(): self.installer.assert_installed(self, container, msg=output) def test_install_coord_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install /mnt/presto-admin/%(rpm)s -H %(master)s", rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) for slave in self.cluster.slaves: self.installer.assert_uninstalled(slave, msg=output) def test_install_worker_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install /mnt/presto-admin/%(rpm)s -H %(slave1)s", rpm=rpm_name) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_workers_using_dash_h(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( "package install /mnt/presto-admin/" "%(rpm)s -H %(slave1)s,%(slave2)s", rpm=rpm_name ) self.installer.assert_installed(self, self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_uninstalled(self.cluster.master, msg=output) self.installer.assert_uninstalled(self.cluster.slaves[2], msg=output) def test_install_exclude_coord(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install /mnt/presto-admin/" "%(rpm)s -x %(master)s", rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.master, msg=output) for slave in self.cluster.slaves: self.installer.assert_installed(self, slave, msg=output) def test_install_exclude_worker(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install /mnt/presto-admin/" "%(rpm)s -x %(slave1)s", rpm=rpm_name) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_installed(self, self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_exclude_workers(self): rpm_name = self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin( "package install /mnt/presto-admin/" "%(rpm)s -x %(slave1)s,%(slave2)s", rpm=rpm_name ) self.installer.assert_uninstalled(self.cluster.slaves[0], msg=output) self.installer.assert_uninstalled(self.cluster.slaves[1], msg=output) self.installer.assert_installed(self, self.cluster.master, msg=output) self.installer.assert_installed(self, self.cluster.slaves[2], msg=output) def test_install_invalid_path(self): rpm_name = self.installer.copy_presto_rpm_to_master() cmd_output = self.run_prestoadmin("package install /mnt/presto-admin" "/invalid-path/presto.rpm", rpm=rpm_name) error = ( "\nFatal error: [%s] error: " "/mnt/presto-admin/invalid-path/presto.rpm: open failed: " "No such file or directory\n\nAborting.\n" ) expected = "" for host in self.cluster.all_internal_hosts(): expected += error % host self.assertEqualIgnoringOrder(cmd_output, expected) def test_install_no_path_arg(self): self.installer.copy_presto_rpm_to_master() output = self.run_prestoadmin("package install", raise_error=False) self.assertEqual( output, "Incorrect number of arguments to task.\n\n" "Displaying detailed information for task " "'package install':\n\n" " Install the rpm package on the cluster\n" " \n Args:\n" " local_path: Absolute path to the rpm" " to be installed\n " "--nodeps (optional): Flag to indicate if " "rpm install\n" " should ignore c" "hecking package dependencies. Equivalent\n" " to adding --nodeps flag to rpm " "-i.\n\n", ) def test_install_already_installed(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.run_prestoadmin("package install /mnt/presto-admin/%(rpm)s -H " "%(master)s", rpm=rpm_name) self.installer.assert_installed(self, self.cluster.master) cmd_output = self.run_prestoadmin("package install /mnt/presto-admin/%(rpm)s -H %(master)s", rpm=rpm_name) expected = self.escape_for_regex( self.replace_keywords( """ Fatal error: [%(master)s] sudo() received nonzero return code 1 while \ executing! Requested: rpm -i /opt/prestoadmin/packages/%(rpm)s Executed: sudo -S -p 'sudo password:'******'sudo password:' /bin/bash -l -c "rpm -i \ /opt/prestoadmin/packages/%(rpm)s" Aborting. Deploying rpm on %(master)s... Package deployed successfully on: %(master)s [%(master)s] out: error: Failed dependencies: [%(master)s] out: python >= 2.4 is needed by %(rpm_basename)s [%(master)s] out: """, **self.installer.get_keywords(rpm_name) ) self.assertRegexpMatchesLineByLine(cmd_output.splitlines(), self.escape_for_regex(expected).splitlines()) @docker_only def test_install_rpm_with_nodeps(self): rpm_name = self.installer.copy_presto_rpm_to_master() self.cluster.exec_cmd_on_host(self.cluster.master, "rpm -e --nodeps python-2.6.6") self.assertRaisesRegexp( OSError, "package python-2.6.6 is not installed", self.cluster.exec_cmd_on_host, self.cluster.master, "rpm -q python-2.6.6", ) cmd_output = self.run_prestoadmin( "package install /mnt/presto-admin/%(rpm)s -H %(master)s --nodeps", rpm=rpm_name ) expected = ( "Deploying rpm on %(host)s...\n" "Package deployed successfully on: %(host)s\n" "Package installed successfully on: %(host)s" % {"host": self.cluster.internal_master} ) self.assertEqualIgnoringOrder(expected, cmd_output)