MXS-2900 Clean up test config file and label handling
This commit is contained in:
		@ -1,30 +0,0 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
struct labels_table_t
 | 
			
		||||
{
 | 
			
		||||
    std::string test_label;
 | 
			
		||||
    std::string mdbci_label;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const labels_table_t labels_table [] __attribute__((unused)) =
 | 
			
		||||
{
 | 
			
		||||
    {"REPL_BACKEND", "REPL_BACKEND"},
 | 
			
		||||
    {"BIG_REPL_BACKEND", "BIG_REPL_BACKEND"},
 | 
			
		||||
    {"GALERA_BACKEND", "GALERA_BACKEND"},
 | 
			
		||||
    {"TWO_MAXSCALES", "SECOND_MAXSCALE"},
 | 
			
		||||
    {"COLUMNSTORE_BACKEND", "COLUMNSTORE_BACKEND"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief get_mdbci_lables Finds all MDBCI labels which are needed by test
 | 
			
		||||
 * Every test has a number of labels defined in the CMakeLists.txt,
 | 
			
		||||
 * some of these lables defines which nodes (virtual machines) are needed
 | 
			
		||||
 * for this particular test. Function finds such labels and forms labels string
 | 
			
		||||
 * in the 'mdbci up' command format
 | 
			
		||||
 * @param labels_string All lables from CMakeLists.txt
 | 
			
		||||
 * @return Labels string in the 'mdbci up' --labels parameter format
 | 
			
		||||
 */
 | 
			
		||||
std::string get_mdbci_lables(const char * labels_string);
 | 
			
		||||
@ -89,11 +89,6 @@ public:
 | 
			
		||||
     */
 | 
			
		||||
    int global_result;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief test_name Neme of the test
 | 
			
		||||
     */
 | 
			
		||||
    char* test_name;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief galera Mariadb_nodes object containing references to Galera setuo
 | 
			
		||||
     */
 | 
			
		||||
@ -282,21 +277,6 @@ public:
 | 
			
		||||
     */
 | 
			
		||||
    bool use_ipv6;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief template_name Name of maxscale.cnf template
 | 
			
		||||
     */
 | 
			
		||||
    const char * template_name;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief labels 'LABELS' string from CMakeLists.txt
 | 
			
		||||
     */
 | 
			
		||||
    const char * labels;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief mdbci_labels labels to be passed to MDBCI
 | 
			
		||||
     */
 | 
			
		||||
    std::string mdbci_labels;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @brief configured_labels List of lables for which nodes are configured
 | 
			
		||||
     */
 | 
			
		||||
@ -627,7 +607,7 @@ public:
 | 
			
		||||
     *
 | 
			
		||||
     * @param dest Destination file name for actual configuration file
 | 
			
		||||
     */
 | 
			
		||||
    void process_template(int m, const char* src, const char* dest = "/etc/maxscale.cnf");
 | 
			
		||||
    void process_template(int m, const std::string& src, const char* dest = "/etc/maxscale.cnf");
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute a MaxCtrl command
 | 
			
		||||
@ -697,13 +677,21 @@ private:
 | 
			
		||||
    void report_result(const char* format, va_list argp);
 | 
			
		||||
    void copy_one_mariadb_log(Mariadb_nodes* nrepl, int i, std::string filename);
 | 
			
		||||
 | 
			
		||||
    void set_template_and_labels();
 | 
			
		||||
    void set_mdbci_labels();
 | 
			
		||||
 | 
			
		||||
    bool too_many_maxscales() const
 | 
			
		||||
    {
 | 
			
		||||
        return maxscales->N < 2
 | 
			
		||||
               && mdbci_labels.find("SECOND_MAXSCALE") != std::string::npos;
 | 
			
		||||
               && m_mdbci_labels.find("SECOND_MAXSCALE") != std::string::npos;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::vector<std::function<void(void)>> m_on_destroy;
 | 
			
		||||
 | 
			
		||||
    std::string m_test_name;       /**< Test name */
 | 
			
		||||
    std::string m_config_template; /**< MaxScale config file template used by test */
 | 
			
		||||
    std::string m_labels;          /**< Test labels */
 | 
			
		||||
    std::string m_mdbci_labels;    /**< Labels for MDBCI */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -729,19 +717,3 @@ void* log_copy_thread(void* ptr);
 | 
			
		||||
 * @return String form comparison of status sets
 | 
			
		||||
 */
 | 
			
		||||
std::string dump_status(const StringSet& current, const StringSet& expected);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief get_template_name Returns the name of maxscale.cnf template to use for given test
 | 
			
		||||
 * @param test_name Name of the test
 | 
			
		||||
 * @param labels pointer to string for storing all test labels
 | 
			
		||||
 * @return Name of maxscale.cnf file template
 | 
			
		||||
 */
 | 
			
		||||
const char* get_template_name(char* test_name, const char**labels);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief readenv_and_set_default Read enviromental variable and set default values if
 | 
			
		||||
 * variable is not defined
 | 
			
		||||
 * @param name Name of the environmental variable
 | 
			
		||||
 * @param defaultenv Default values to be set
 | 
			
		||||
 * @return Envaronmental variable value
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@ -1,24 +1,43 @@
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "labels_table.h"
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
#include "testconnections.h"
 | 
			
		||||
 | 
			
		||||
std::string get_mdbci_lables(const char *labels_string)
 | 
			
		||||
namespace
 | 
			
		||||
{
 | 
			
		||||
    std::string mdbci_labels("MAXSCALE");
 | 
			
		||||
struct labels_table_t
 | 
			
		||||
{
 | 
			
		||||
    std::string test_label;
 | 
			
		||||
    std::string mdbci_label;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const labels_table_t labels_table[] =
 | 
			
		||||
{
 | 
			
		||||
    {"REPL_BACKEND", "REPL_BACKEND"},
 | 
			
		||||
    {"BIG_REPL_BACKEND", "BIG_REPL_BACKEND"},
 | 
			
		||||
    {"GALERA_BACKEND", "GALERA_BACKEND"},
 | 
			
		||||
    {"TWO_MAXSCALES", "SECOND_MAXSCALE"},
 | 
			
		||||
    {"COLUMNSTORE_BACKEND", "COLUMNSTORE_BACKEND"},
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * Generate MDBCI labels required by test. Every test has a number of labels defined in CMakeLists.txt.
 | 
			
		||||
 * Some of these labels define which nodes (virtual machines) are needed for this particular test.
 | 
			
		||||
 * This function generates the equivalent labels for the 'mdbci up'-command.
 | 
			
		||||
 */
 | 
			
		||||
void TestConnections::set_mdbci_labels()
 | 
			
		||||
{
 | 
			
		||||
    std::string mdbci_labels_str("MAXSCALE");
 | 
			
		||||
    for (size_t i = 0; i < sizeof(labels_table) / sizeof(labels_table_t); i++)
 | 
			
		||||
    {
 | 
			
		||||
        std::string test_label = std::string(";") + labels_table[i].test_label;
 | 
			
		||||
        if (strstr(labels_string, test_label.c_str()))
 | 
			
		||||
        std::string test_label = ";" + labels_table[i].test_label;
 | 
			
		||||
        if (m_labels.find(test_label) != std::string::npos)
 | 
			
		||||
        {
 | 
			
		||||
            mdbci_labels += "," + labels_table[i].mdbci_label;
 | 
			
		||||
            mdbci_labels_str += "," + labels_table[i].mdbci_label;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (TestConnections::verbose)
 | 
			
		||||
    {
 | 
			
		||||
        printf("mdbci labels %s\n", mdbci_labels.c_str());
 | 
			
		||||
        printf("mdbci labels %s\n", mdbci_labels_str.c_str());
 | 
			
		||||
    }
 | 
			
		||||
    return mdbci_labels;
 | 
			
		||||
    m_mdbci_labels = mdbci_labels_str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,12 +20,12 @@
 | 
			
		||||
#include "sql_t1.h"
 | 
			
		||||
#include "testconnections.h"
 | 
			
		||||
#include "test_info.hh"
 | 
			
		||||
#include "labels_table.h"
 | 
			
		||||
#include "envv.h"
 | 
			
		||||
 | 
			
		||||
using namespace mxb;
 | 
			
		||||
using std::cout;
 | 
			
		||||
using std::endl;
 | 
			
		||||
using std::string;
 | 
			
		||||
 | 
			
		||||
namespace maxscale
 | 
			
		||||
{
 | 
			
		||||
@ -258,30 +258,15 @@ TestConnections::TestConnections(int argc, char* argv[])
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (optind < argc)
 | 
			
		||||
    {
 | 
			
		||||
        test_name = argv[optind];
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        test_name = basename(argv[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const char* labels_string = "";
 | 
			
		||||
    template_name = get_template_name(test_name, &labels_string);
 | 
			
		||||
    tprintf("testname: '%s', template: '%s'", test_name, template_name);
 | 
			
		||||
    labels = strstr(labels_string, "LABELS;");
 | 
			
		||||
    if (!labels)
 | 
			
		||||
    {
 | 
			
		||||
        labels = (char* ) "LABELS;REPL_BACKEND";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mdbci_labels = get_mdbci_lables(labels);
 | 
			
		||||
    m_test_name = (optind < argc) ? argv[optind] : basename(argv[0]);
 | 
			
		||||
    set_template_and_labels();
 | 
			
		||||
    tprintf("testname: '%s', template: '%s'", m_test_name.c_str(), m_config_template.c_str());
 | 
			
		||||
    set_mdbci_labels();
 | 
			
		||||
 | 
			
		||||
    std::string delimiter = std::string (",");
 | 
			
		||||
    size_t pos_start = 0, pos_end, delim_len = delimiter.length();
 | 
			
		||||
    std::string label;
 | 
			
		||||
    std::string mdbci_labels_c = mdbci_labels + delimiter;
 | 
			
		||||
    std::string mdbci_labels_c = m_mdbci_labels + delimiter;
 | 
			
		||||
 | 
			
		||||
    bool mdbci_call_needed = false;
 | 
			
		||||
 | 
			
		||||
@ -309,7 +294,7 @@ TestConnections::TestConnections(int argc, char* argv[])
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (mdbci_labels.find(std::string("REPL_BACKEND")) == std::string::npos)
 | 
			
		||||
    if (m_mdbci_labels.find(std::string("REPL_BACKEND")) == std::string::npos)
 | 
			
		||||
    {
 | 
			
		||||
        no_repl = true;
 | 
			
		||||
        if (verbose)
 | 
			
		||||
@ -318,7 +303,7 @@ TestConnections::TestConnections(int argc, char* argv[])
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (mdbci_labels.find(std::string("GALERA_BACKEND")) == std::string::npos)
 | 
			
		||||
    if (m_mdbci_labels.find(std::string("GALERA_BACKEND")) == std::string::npos)
 | 
			
		||||
    {
 | 
			
		||||
        no_galera = true;
 | 
			
		||||
        if (verbose)
 | 
			
		||||
@ -492,7 +477,7 @@ TestConnections::TestConnections(int argc, char* argv[])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    char str[1024];
 | 
			
		||||
    sprintf(str, "mkdir -p LOGS/%s", test_name);
 | 
			
		||||
    sprintf(str, "mkdir -p LOGS/%s", m_test_name.c_str());
 | 
			
		||||
    system(str);
 | 
			
		||||
 | 
			
		||||
    timeout = 999999999;
 | 
			
		||||
@ -700,34 +685,47 @@ void TestConnections::print_env()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* get_template_name(char* test_name, const char** labels)
 | 
			
		||||
/**
 | 
			
		||||
 * Set config template file and test labels.
 | 
			
		||||
 */
 | 
			
		||||
void TestConnections::set_template_and_labels()
 | 
			
		||||
{
 | 
			
		||||
    const TestDefinition* found = nullptr;
 | 
			
		||||
    for (int i = 0; test_definitions[i].name; i++)
 | 
			
		||||
    {
 | 
			
		||||
        auto* test = &test_definitions[i];
 | 
			
		||||
        if (strcmp(test->name, test_name) == 0)
 | 
			
		||||
        if (test->name == m_test_name)
 | 
			
		||||
        {
 | 
			
		||||
            found = test;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    string labels_string;
 | 
			
		||||
    if (found)
 | 
			
		||||
    {
 | 
			
		||||
        *labels = found->labels;
 | 
			
		||||
        return found->config_template;
 | 
			
		||||
        labels_string = found->labels;
 | 
			
		||||
        m_config_template = found->config_template;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        printf("Failed to find configuration template for test '%s', using default template '%s'.\n",
 | 
			
		||||
               test_name, default_template);
 | 
			
		||||
        return default_template;
 | 
			
		||||
               m_test_name.c_str(), default_template);
 | 
			
		||||
        m_config_template = default_template;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto labels_pos = labels_string.find("LABELS;");
 | 
			
		||||
    if (labels_pos != string::npos)
 | 
			
		||||
    {
 | 
			
		||||
        m_labels = labels_string.substr(labels_pos);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        m_labels = "LABELS;REPL_BACKEND";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TestConnections::process_template(int m, const char* template_name, const char* dest)
 | 
			
		||||
void TestConnections::process_template(int m, const string& template_name, const char* dest)
 | 
			
		||||
{
 | 
			
		||||
    struct stat stb;
 | 
			
		||||
    char str[4096];
 | 
			
		||||
@ -735,7 +733,7 @@ void TestConnections::process_template(int m, const char* template_name, const c
 | 
			
		||||
 | 
			
		||||
    char extended_template_file[1024];
 | 
			
		||||
 | 
			
		||||
    sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name);
 | 
			
		||||
    sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name.c_str());
 | 
			
		||||
    sprintf(extended_template_file, "%s.%03d", template_file, m);
 | 
			
		||||
 | 
			
		||||
    if (stat((char*)extended_template_file, &stb) == 0)
 | 
			
		||||
@ -834,7 +832,7 @@ void TestConnections::init_maxscales()
 | 
			
		||||
 | 
			
		||||
void TestConnections::init_maxscale(int m)
 | 
			
		||||
{
 | 
			
		||||
    process_template(m, template_name, maxscales->access_homedir[m]);
 | 
			
		||||
    process_template(m, m_config_template, maxscales->access_homedir[m]);
 | 
			
		||||
    if (maxscales->ssh_node_f(m, true, "test -d %s/certs", maxscales->access_homedir[m]))
 | 
			
		||||
    {
 | 
			
		||||
        tprintf("SSL certificates not found, copying to maxscale");
 | 
			
		||||
@ -911,7 +909,7 @@ int TestConnections::copy_mariadb_logs(Mariadb_nodes* nrepl,
 | 
			
		||||
            if (strcmp(nrepl->IP[i], "127.0.0.1") != 0)
 | 
			
		||||
            {
 | 
			
		||||
                char str[4096];
 | 
			
		||||
                sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i);
 | 
			
		||||
                sprintf(str, "LOGS/%s/%s%d_mariadb_log", m_test_name.c_str(), prefix, i);
 | 
			
		||||
                threads.emplace_back(&TestConnections::copy_one_mariadb_log, this, nrepl, i, str);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -925,7 +923,7 @@ int TestConnections::copy_all_logs()
 | 
			
		||||
    set_timeout(300);
 | 
			
		||||
 | 
			
		||||
    char str[PATH_MAX + 1];
 | 
			
		||||
    sprintf(str, "mkdir -p LOGS/%s", test_name);
 | 
			
		||||
    sprintf(str, "mkdir -p LOGS/%s", m_test_name.c_str());
 | 
			
		||||
    system(str);
 | 
			
		||||
 | 
			
		||||
    std::vector<std::thread> threads;
 | 
			
		||||
@ -957,11 +955,11 @@ int TestConnections::copy_maxscale_logs(double timestamp)
 | 
			
		||||
    char sys[1024];
 | 
			
		||||
    if (timestamp == 0)
 | 
			
		||||
    {
 | 
			
		||||
        sprintf(log_dir, "LOGS/%s", test_name);
 | 
			
		||||
        sprintf(log_dir, "LOGS/%s", m_test_name.c_str());
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        sprintf(log_dir, "LOGS/%s/%04f", test_name, timestamp);
 | 
			
		||||
        sprintf(log_dir, "LOGS/%s/%04f", m_test_name.c_str(), timestamp);
 | 
			
		||||
    }
 | 
			
		||||
    for (int i = 0; i < maxscales->N; i++)
 | 
			
		||||
    {
 | 
			
		||||
@ -2210,7 +2208,7 @@ int TestConnections::call_mdbci(const char * options)
 | 
			
		||||
    if (system((std::string("mdbci up ") +
 | 
			
		||||
                std::string(mdbci_config_name) +
 | 
			
		||||
                std::string(" --labels ") +
 | 
			
		||||
                mdbci_labels +
 | 
			
		||||
                m_mdbci_labels +
 | 
			
		||||
                std::string(" ") +
 | 
			
		||||
                std::string(options)).c_str() ))
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user