def setup_cluster(self, bare_image_provider, cluster_type):
        try:
            installers = self._cluster_types[cluster_type]
        except __HOLE__:
            self.fail(
                '%s is not a valid cluster type. Valid cluster types are %s' %
                (cluster_type, ', '.join(self._cluster_types.keys())))

        config_filename = ConfigurableCluster.check_for_cluster_config()

        if config_filename:
            self.cluster = ConfigurableCluster.start_bare_cluster(
                config_filename, self,
                StandalonePrestoInstaller.assert_installed)
        else:
            try:
                self.cluster = DockerCluster.start_existing_images(
                    bare_image_provider, cluster_type)
                if self.cluster:
                    self._apply_post_install_hooks(installers)
                    self._update_replacement_keywords(installers)
                    return
                self.cluster = DockerCluster.start_bare_cluster(
                    bare_image_provider)
            except DockerClusterException as e:
                self.fail(e.msg)

        self._run_installers(installers)

        if isinstance(self.cluster, DockerCluster):
            self.cluster.commit_images(bare_image_provider, cluster_type)
dataset/ETHPy150Open prestodb/presto-admin/tests/product/base_product_case.py/BaseProductTestCase.setup_cluster