<s> """<STR_LIT>""" <EOL> import fnmatch <EOL> import os <EOL> import urllib <EOL> import prestoadmin <EOL> from tests . base_installer import BaseInstaller <EOL> from tests . docker_cluster import DockerCluster <EOL> from tests . product . mode_installers import StandaloneModeInstaller <EOL> from tests . product . prestoadmin_installer import PrestoadminInstaller <EOL> from tests . product . topology_installer import TopologyInstaller <EOL> RPM_BASENAME = r'<STR_LIT>' <EOL> PRESTO_RPM_GLOB = r'<STR_LIT>' <EOL> PACKAGE_NAME = '<STR_LIT>' <EOL> class StandalonePrestoInstaller ( BaseInstaller ) : <EOL> def __init__ ( self , testcase , rpm_location = None ) : <EOL> if rpm_location : <EOL> self . rpm_dir , self . rpm_name = rpm_location <EOL> else : <EOL> self . rpm_dir , self . rpm_name = self . _detect_presto_rpm ( ) <EOL> self . testcase = testcase <EOL> @ staticmethod <EOL> def get_dependencies ( ) : <EOL> return [ PrestoadminInstaller , StandaloneModeInstaller , <EOL> TopologyInstaller ] <EOL> def install ( self , extra_configs = None , coordinator = None , <EOL> pa_raise_error = True ) : <EOL> cluster = self . testcase . cluster <EOL> rpm_name = self . copy_presto_rpm_to_master ( cluster = cluster ) <EOL> self . testcase . write_test_configs ( cluster , extra_configs , coordinator ) <EOL> cmd_output = self . testcase . run_prestoadmin ( <EOL> '<STR_LIT>' + os . path . join ( cluster . mount_dir , rpm_name ) , <EOL> cluster = cluster , raise_error = pa_raise_error <EOL> ) <EOL> return cmd_output <EOL> def get_keywords ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . rpm_name , <EOL> '<STR_LIT>' : RPM_BASENAME , <EOL> } <EOL> @ staticmethod <EOL> def assert_installed ( testcase , container = None , msg = None , cluster = None ) : <EOL> if not cluster : <EOL> cluster = testcase . cluster <EOL> if not container : <EOL> container = cluster . get_master ( ) <EOL> try : <EOL> check_rpm = cluster . exec_cmd_on_host ( <EOL> container , '<STR_LIT>' % ( PACKAGE_NAME , ) ) <EOL> testcase . assertRegexpMatches ( <EOL> check_rpm , RPM_BASENAME + '<STR_LIT:\n>' , msg = msg <EOL> ) <EOL> except OSError as e : <EOL> if isinstance ( testcase . cluster , DockerCluster ) : <EOL> cluster . client . commit ( cluster . master , '<STR_LIT>' ) <EOL> cluster . client . commit ( cluster . slaves [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> cluster . client . commit ( cluster . slaves [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> cluster . client . commit ( cluster . slaves [ <NUM_LIT:2> ] , '<STR_LIT>' ) <EOL> if msg : <EOL> error_message = e . strerror + '<STR_LIT:\n>' + msg <EOL> else : <EOL> error_message = e . strerror <EOL> testcase . fail ( msg = error_message ) <EOL> def copy_presto_rpm_to_master ( self , cluster = None ) : <EOL> if not cluster : <EOL> cluster = self . testcase . cluster <EOL> rpm_path = os . path . join ( self . rpm_dir , self . rpm_name ) <EOL> try : <EOL> cluster . copy_to_host ( rpm_path , cluster . master ) <EOL> self . _check_if_corrupted_rpm ( self . rpm_name , cluster ) <EOL> except OSError : <EOL> print '<STR_LIT>' <EOL> StandalonePrestoInstaller . _download_rpm ( ) <EOL> cluster . copy_to_host ( rpm_path , cluster . master ) <EOL> self . _check_if_corrupted_rpm ( self . rpm_name , cluster ) <EOL> return self . rpm_name <EOL> @ staticmethod <EOL> def _download_rpm ( ) : <EOL> rpm_filename = '<STR_LIT>' <EOL> rpm_path = os . path . join ( prestoadmin . main_dir , <EOL> rpm_filename ) <EOL> urllib . urlretrieve ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , rpm_path ) <EOL> return rpm_filename <EOL> @ staticmethod <EOL> def _detect_presto_rpm ( ) : <EOL> """<STR_LIT>""" <EOL> rpm_names = fnmatch . filter ( os . listdir ( prestoadmin . main_dir ) , <EOL> PRESTO_RPM_GLOB ) <EOL> if rpm_names : <EOL> rpm_name = sorted ( rpm_names ) [ - <NUM_LIT:1> ] <EOL> else : <EOL> try : <EOL> rpm_name = StandalonePrestoInstaller . _download_rpm ( ) <EOL> except : <EOL> rpm_name = StandalonePrestoInstaller . _download_rpm ( ) <EOL> return prestoadmin . main_dir , rpm_name <EOL> @ staticmethod <EOL> def _check_if_corrupted_rpm ( rpm_name , cluster ) : <EOL> cluster . exec_cmd_on_host ( <EOL> cluster . master , '<STR_LIT>' + <EOL> os . path . join ( cluster . mount_dir , rpm_name ) <EOL> ) <EOL> def assert_uninstalled ( self , container , msg = None ) : <EOL> failure_msg = '<STR_LIT>' % ( PACKAGE_NAME , ) <EOL> rpm_cmd = '<STR_LIT>' % ( PACKAGE_NAME , ) <EOL> self . testcase . assertRaisesRegexp ( <EOL> OSError , <EOL> failure_msg , <EOL> self . testcase . cluster . exec_cmd_on_host , container , <EOL> rpm_cmd , msg = msg ) </s>
