def create_cluster(region, request): """A fixture to create clusters via the API client, and clean them up in case of test failure.""" factory = ClustersFactory(delete_logs_on_success=request.config.getoption( "delete_logs_on_success")) def _create_cluster(client, cluster_name, config): # Create cluster with initial configuration with open(config, encoding="utf-8") as config_file: config_contents = config_file.read() body = CreateClusterRequestContent( cluster_name=cluster_name, cluster_configuration=config_contents) response = client.create_cluster(body, region=region) cluster = Cluster(name=cluster_name, config_file=config, ssh_key=request.config.getoption("key_path"), region=region) factory.register_cluster(cluster) return cluster, response yield _create_cluster if not request.config.getoption("no_delete"): try: test_passed = request.node.rep_call.passed except AttributeError: test_passed = False factory.destroy_all_clusters(test_passed=test_passed)
def clusters_factory(request): """ Define a fixture to manage the creation and destruction of clusters. The configs used to create clusters are dumped to output_dir/clusters_configs/{test_name}.config """ factory = ClustersFactory() def _cluster_factory(cluster_config): cluster_config = _write_cluster_config_to_outdir( request, cluster_config) cluster = Cluster( name=request.config.getoption("cluster") if request.config.getoption("cluster") else "integ-tests-{0}{1}{2}".format( random_alphanumeric(), "-" if request.config.getoption("stackname_suffix") else "", request.config.getoption("stackname_suffix"), ), config_file=cluster_config, ssh_key=request.config.getoption("key_path"), ) if not request.config.getoption("cluster"): factory.create_cluster(cluster) return cluster yield _cluster_factory if not request.config.getoption("no_delete"): factory.destroy_all_clusters()
def clusters_factory(request): """ Define a fixture to manage the creation and destruction of clusters. The configs used to create clusters are dumped to output_dir/clusters_configs/{test_name}.config """ factory = ClustersFactory(keep_logs_on_failure=request.config.getoption("keep_logs_on_cluster_failure")) def _cluster_factory(cluster_config, extra_args=None, raise_on_error=True): cluster_config = _write_cluster_config_to_outdir(request, cluster_config) cluster = Cluster( name=request.config.getoption("cluster") if request.config.getoption("cluster") else "integ-tests-{0}{1}{2}".format( random_alphanumeric(), "-" if request.config.getoption("stackname_suffix") else "", request.config.getoption("stackname_suffix"), ), config_file=cluster_config, ssh_key=request.config.getoption("key_path"), ) if not request.config.getoption("cluster"): factory.create_cluster(cluster, extra_args=extra_args, raise_on_error=raise_on_error) return cluster yield _cluster_factory if not request.config.getoption("no_delete"): factory.destroy_all_clusters( keep_logs=request.config.getoption("keep_logs_on_test_failure") and request.node.rep_call.failed )
def clusters_factory(request): """ Define a fixture to manage the creation and destruction of clusters. The configs used to create clusters are dumped to output_dir/clusters_configs/{test_name}.config """ factory = ClustersFactory() def _cluster_factory(cluster_config): cluster_config = _write_cluster_config_to_outdir( request, cluster_config) cluster = Cluster( name="integ-tests-" + random_alphanumeric(), config_file=cluster_config, ssh_key=request.config.getoption("key_path"), ) factory.create_cluster(cluster) return cluster yield _cluster_factory factory.destroy_all_clusters()