Fix Clustrix tests

Now MDBCI is responsible for Clustrix installation
as well as license processing.
Clustrix version is hardcoded now
(until MDBCI fix for finding latest version)
This commit is contained in:
Timofey Turenko 2020-10-21 23:31:43 +03:00
parent badca4f611
commit 3546b716c5
3 changed files with 33 additions and 168 deletions

View File

@ -15,10 +15,6 @@
/**
* @file clustrix_nodes.h - work with Clustrix setup
*
* ~/.config/mdbci/clustrix_license file have to contain SQL
* which setups license to the Clustrix node
*
* TODO: move functionality of install_clustrix() to MDBCI
*/
#include <cerrno>
@ -26,10 +22,6 @@
#include <maxtest/mariadb_nodes.hh>
#include <maxtest/nodes.hh>
#define CLUSTRIX_DEPS_YUM "yum install -y bzip2 wget screen ntp ntpdate vim htop mdadm"
#define WGET_CLUSTRIX "wget http://files.clustrix.com/releases/software/clustrix-9.1.4.el7.tar.bz2"
#define UNPACK_CLUSTRIX "tar xvjf clustrix-9.1.4.el7.tar.bz2"
#define INSTALL_CLUSTRIX "cd clustrix-9.1.4.el7; sudo ./clxnode_install.py --yes --force"
class Clustrix_nodes : public Mariadb_nodes
{

View File

@ -20,58 +20,6 @@ int Clustrix_nodes::prepare_server(int m)
{
int rv = 1;
int ec;
char* clustrix_rpm = ssh_node_output(m, "rpm -qa | grep clustrix-clxnode", true, &ec);
if (strstr(clustrix_rpm, "clustrix-clxnode") == NULL)
{
char* str1 = nullptr;
char* str2 = nullptr;
char* str3 = nullptr;
char* str4 = nullptr;
str1 = ssh_node_output(m, CLUSTRIX_DEPS_YUM, true, &ec);
if (ec == 0)
{
printf("Installed clustrix dependencies on node %d.\n", m);
str2 = ssh_node_output(m, WGET_CLUSTRIX, false, &ec);
if (ec == 0)
{
printf("Wgot Clustrix installation package on node %d.\n", m);
str3 = ssh_node_output(m, UNPACK_CLUSTRIX, false, &ec);
if (ec == 0)
{
printf("Unpacked Clustrix package on node %d.\n", m);
str4 = ssh_node_output(m, INSTALL_CLUSTRIX, false, &ec);
if (ec == 0)
{
printf("Successfully installed Clustrix on node %d.\n", m);
}
else
{
printf("Error: Could not install Clustrix package on node %d: %s\n", m, str4);
}
}
else
{
printf("Error: Could not unpack Clustrix package on node %d: %s\n", m, str3);
}
}
else
{
printf("Error: Could not wget Clustrix installation package on node %d: %s\n", m, str2);
}
}
else
{
printf("Error: Could not install Clustrix dependencies on node %d: %s\n", m, str1);
}
free(str4);
free(str3);
free(str2);
free(str1);
}
free(clustrix_rpm);
bool running = false;
@ -180,119 +128,28 @@ int Clustrix_nodes::prepare_server(int m)
return rv;
}
namespace
{
using std::string;
bool license_is_valid(const std::string& license)
{
static const std::regex regex("\"expiration\":\"[^\"]+\"");
bool is_valid = false;
std::smatch match;
if (std::regex_search(license, match, regex))
{
if (match.size() == 1)
{
string s = match[0].str();
s = s.substr(14, 10); // We expect something like '"expiration":"2019-08-21 00:00:00"'
if (s.length() == 10) // '2019-08-21' (excluding quotes)
{
int year = atoi(s.substr(0, 4).c_str()); // 2019
int month = atoi(s.substr(5, 2).c_str()); // 08
int day = atoi(s.substr(8, 2).c_str()); // 21
time_t timestamp = time(NULL);
struct tm now;
localtime_r(&timestamp, &now);
now.tm_year += 1900;
now.tm_mon += 1;
if (year >= now.tm_year
&& (month > now.tm_mon || (month == now.tm_mon && day >= now.tm_mday)))
{
is_valid = true;
}
else
{
printf("ERROR: The date is %d-%d-%d, but the license in the license file "
"is valid only until %d-%d-%d.\n",
now.tm_year, now.tm_mon, now.tm_mday,
year, month, day);
}
}
else
{
printf("ERROR: The value of the key 'expiration' does not appear to be valid.\n");
}
}
else
{
printf("ERROR: The license in the license file either does not contain an "
"'expiration' key or then it contains several.\n");
}
}
else
{
printf("ERROR: The license file does not seem to contain a valid license.\n");
}
return is_valid;
}
}
int Clustrix_nodes::start_replication()
{
int rv = 1;
std::string lic_filename = std::string(getenv("HOME"))
+ std::string("/.config/mdbci/clustrix_license");
std::ifstream lic_file;
lic_file.open(lic_filename.c_str());
if (lic_file.is_open())
std::string cluster_setup_sql = std::string("ALTER CLUSTER ADD '")
+ std::string(IP_private[1])
+ std::string("'");
for (int i = 2; i < N; i++)
{
printf("Using license file '%s'.\n", lic_filename.c_str());
std::stringstream ss;
ss << lic_file.rdbuf();
std::string clustrix_license = ss.str();
lic_file.close();
if (license_is_valid(clustrix_license))
{
execute_query_all_nodes(clustrix_license.c_str());
std::string cluster_setup_sql = std::string("ALTER CLUSTER ADD '")
+ std::string(IP_private[1])
cluster_setup_sql += std::string(",'")
+ std::string(IP_private[i])
+ std::string("'");
for (int i = 2; i < N; i++)
{
cluster_setup_sql += std::string(",'")
+ std::string(IP_private[i])
+ std::string("'");
}
connect();
execute_query(nodes[0], "%s", cluster_setup_sql.c_str());
close_connections();
}
connect();
execute_query(nodes[0], "%s", cluster_setup_sql.c_str());
close_connections();
rv = 0;
rv = 0;
}
}
else
{
printf("ERROR: The Clustrix license file '%s' does not exist. "
"It must contain a string \"set global license='{...}';\" using which the "
"Clustrix license can be set.\n",
lic_filename.c_str());
}
return rv;
}

View File

@ -363,7 +363,11 @@
"memory_size" : "16192",
"labels" : [
"CLUSTRIX_BACKEND"
]
],
"product" : {
"name" : "clustrix",
"version" : "5.3.11_13"
}
},
"clustrix_001" :
@ -373,7 +377,11 @@
"memory_size" : "16192",
"labels" : [
"CLUSTRIX_BACKEND"
]
],
"product" : {
"name" : "clustrix",
"version" : "5.3.11_13"
}
},
"clustrix_002" :
@ -383,7 +391,11 @@
"memory_size" : "16192",
"labels" : [
"CLUSTRIX_BACKEND"
]
],
"product" : {
"name" : "clustrix",
"version" : "5.3.11_13"
}
},
"clustrix_003" :
@ -393,6 +405,10 @@
"box" : "${clustrix_box}",
"labels" : [
"CLUSTRIX_BACKEND"
]
],
"product" : {
"name" : "clustrix",
"version" : "5.3.11_13"
}
}
}