Skip to content

Commit

Permalink
clean version working
Browse files Browse the repository at this point in the history
  • Loading branch information
szachovy committed Jul 14, 2024
1 parent 255d9b8 commit e22646b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 40 deletions.
2 changes: 0 additions & 2 deletions services/mysql-mgmt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,3 @@ RUN \
chmod \
744 \
/usr/bin/envsubst

ENTRYPOINT [ "/opt/entrypoint.sh" ]
18 changes: 9 additions & 9 deletions services/mysql-mgmt/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ version: "3.8"
services:
initcontainer:
build: "/opt/superset-cluster/mysql-mgmt"
image: "mysql-mgmt"
entrypoint: [ "/opt/entrypoint.sh" ]
container_name: "mysql-mgmt-initcontainer"
network_mode: "host"
restart: "no"
environment:
- "IS_PRIMARY_MGMT_NODE=${IS_PRIMARY_MGMT_NODE}"
- "VIRTUAL_IP_ADDRESS=${VIRTUAL_IP_ADDRESS}"
- "NETWORK_INTERFACE=${NETWORK_INTERFACE}"
- "PRIMARY_MYSQL_NODE=${PRIMARY_MYSQL_NODE}"
- "SECONDARY_FIRST_MYSQL_NODE=${SECONDARY_FIRST_MYSQL_NODE}"
- "SECONDARY_SECOND_MYSQL_NODE=${SECONDARY_SECOND_MYSQL_NODE}"
IS_PRIMARY_MGMT_NODE: "${IS_PRIMARY_MGMT_NODE}"
VIRTUAL_IP_ADDRESS: "${VIRTUAL_IP_ADDRESS}"
NETWORK_INTERFACE: "${NETWORK_INTERFACE}"
PRIMARY_MYSQL_NODE: "${PRIMARY_MYSQL_NODE}"
SECONDARY_FIRST_MYSQL_NODE: "${SECONDARY_FIRST_MYSQL_NODE}"
SECONDARY_SECOND_MYSQL_NODE: "${SECONDARY_SECOND_MYSQL_NODE}"
volumes:
- "initcontainer_generated:/opt/initcontainer"

maincontainer:
image: "mysql-mgmt"
command: "keepalived --use-file /opt/initcontainer/keepalived.conf && mysqlrouter --config /opt/initcontainer/mysql_router/mysqlrouter.conf"
entrypoint: [ "sh", "-c", "keepalived --use-file /opt/initcontainer/keepalived.conf && mysqlrouter --config /opt/initcontainer/mysql_router/mysqlrouter.conf" ]
container_name: "mysql-mgmt"
restart: "always"
hostname: "${HOSTNAME}"
environment:
- "PRIMARY_MYSQL_NODE=${PRIMARY_MYSQL_NODE}"
network_mode: "host"
privileged: true
volumes:
Expand Down
7 changes: 7 additions & 0 deletions services/mysql-mgmt/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ export SECONDARY_SECOND_MYSQL_NODE="${6}"

cd /opt/superset-cluster/mysql-mgmt
docker compose up initcontainer && docker compose up maincontainer --detach

export IS_PRIMARY_MGMT_NODE="true"
export VIRTUAL_IP_ADDRESS="172.18.0.8"
export NETWORK_INTERFACE="eth0"
export PRIMARY_MYSQL_NODE="node-1"
export SECONDARY_FIRST_MYSQL_NODE="node-2"
export SECONDARY_SECOND_MYSQL_NODE="node-3"
18 changes: 9 additions & 9 deletions services/mysql-mgmt/superset-user.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE USER `superset` IDENTIFIED BY `mysql`;
CREATE USER IF NOT EXISTS 'superset'@'%' IDENTIFIED BY 'mysql';
CREATE DATABASE IF NOT EXISTS `superset`;
GRANT ALL PRIVILEGES ON `superset`.* TO `superset`;
GRANT INSERT ON `mysql_innodb_cluster_metadata`.* TO `superset`;
GRANT SELECT ON `performance_schema`.* TO `superset` WITH GRANT OPTION;
GRANT CREATE USER ON *.* TO `superset`;
GRANT SELECT, EXECUTE ON `mysql_innodb_cluster_metadata`.* TO `superset` WITH GRANT OPTION;
GRANT INSERT, UPDATE, DELETE ON `mysql_innodb_cluster_metadata.routers` TO `superset` WITH GRANT OPTION;
GRANT INSERT, UPDATE, DELETE ON `mysql_innodb_cluster_metadata.v2_routers` TO `superset` WITH GRANT OPTION;
GRANT SELECT ON `mysql.user` TO `superset`;
GRANT ALL PRIVILEGES ON `superset`.* TO 'superset'@'%';
GRANT INSERT ON `mysql_innodb_cluster_metadata`.* TO 'superset'@'%';
GRANT SELECT ON `performance_schema`.* TO 'superset'@'%' WITH GRANT OPTION;
GRANT CREATE USER ON *.* TO 'superset'@'%';
GRANT SELECT, EXECUTE ON `mysql_innodb_cluster_metadata`.* TO 'superset'@'%' WITH GRANT OPTION;
GRANT INSERT, UPDATE, DELETE ON `mysql_innodb_cluster_metadata`.`routers` TO 'superset'@'%' WITH GRANT OPTION;
GRANT INSERT, UPDATE, DELETE ON `mysql_innodb_cluster_metadata`.`v2_routers` TO 'superset'@'%' WITH GRANT OPTION;
GRANT SELECT ON `mysql`.`user` TO 'superset'@'%';
1 change: 0 additions & 1 deletion src/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
network_interface: "eth0"
virtual_ip_address: "172.18.0.10"
mgmt_hostname: "mysql-mgmt"
mysql_user: "root"
redis_hostname: "redis"
Expand Down
8 changes: 5 additions & 3 deletions tests/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ resource "null_resource" "generate_ansible_group_vars" {
mkdir $(dirname $GROUP_VARS_FILE)
cp $DEFAULTS_FILE $GROUP_VARS_FILE
{
echo "virtual_ip_address: \"$VIRTUAL_IP_ADDRESS\""
echo "mysql_password: \"mysql\""
echo "superset_password: \"admin\""
echo "node_prefix: \"$NODE_PREFIX\""
} >> $GROUP_VARS_FILE
EOT

environment = {
DEFAULTS_FILE = "../../src/defaults.yml"
GROUP_VARS_FILE = "../testsuite/group_vars/testing.yml"
NODE_PREFIX = "${var.node_prefix}"
DEFAULTS_FILE = "../../src/defaults.yml"
GROUP_VARS_FILE = "../testsuite/group_vars/testing.yml"
NODE_PREFIX = "${var.node_prefix}"
VIRTUAL_IP_ADDRESS = cidrhost("${var.subnet}", "${8}")
}
}

Expand Down
11 changes: 6 additions & 5 deletions tests/testsuite/roles/testing/files/functional_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@


class MgmtNodeFunctionalTests(container_connection.ContainerUtilities, metaclass=data_structures.Overlay):
def __init__(self, mgmt_hostname: str, mysql_user: str, mysql_password: str, node_prefix: str, after_disaster: bool) -> None:
def __init__(self, mgmt_hostname: str, mysql_user: str, mysql_password: str, virtual_ip_address: str, node_prefix: str, after_disaster: bool) -> None:
super().__init__(node=mgmt_hostname)
self.mysql_user: str = mysql_user
self.mysql_password: str = mysql_password
self.virtual_ip_address: str = virtual_ip_address
self.mgmt_primary_node: str = f"{node_prefix}-0"
self.mgmt_secondary_node: str = f"{node_prefix}-5"
self.mysql_primary_node: str = f"{node_prefix}-1"
Expand All @@ -17,7 +18,7 @@ def __init__(self, mgmt_hostname: str, mysql_user: str, mysql_password: str, nod

@data_structures.Overlay.post_init_hook
def status_cluster(self):
cluster_status_output: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@172.18.0.10:6446 --execute \"dba.getCluster(\'superset\').status();\"")
cluster_status_output: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@{self.virtual_ip_address}:6446 --execute \"dba.getCluster(\'superset\').status();\"")
if self.after_disaster:
assert self.find_in_the_output(cluster_status_output, b'"status": "OK_NO_TOLERANCE_PARTIAL"'), 'The MySQL InnoDB cluster desired state after disaster is unappropriate'
else:
Expand All @@ -26,20 +27,20 @@ def status_cluster(self):

@data_structures.Overlay.post_init_hook
def status_routers(self):
routers_status_output: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@172.18.0.10:6446 --execute \"dba.getCluster(\'superset\').listRouters();\"")
routers_status_output: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@{self.virtual_ip_address}:6446 --execute \"dba.getCluster(\'superset\').listRouters();\"")
assert (self.find_in_the_output(routers_status_output, f'{self.mgmt_primary_node}'.encode()) and self.find_in_the_output(routers_status_output, f'{self.mgmt_secondary_node}'.encode())), f'MySQL Mgmt routers are offline or not attached, expected {self.mgmt_primary_node} and {self.mgmt_secondary_node} to be visible from the superset cluster'

@data_structures.Overlay.post_init_hook
def status_swarm(self):
if not self.after_disaster:
swarm_info = self.info()['Swarm']
assert swarm_info['LocalNodeState'] == 'active', 'The Swarm node has not been activated'
assert swarm_info['ControlAvailable'] is False, f'The 172.18.0.10 is not supposed to be a Swarm manager, but it is'
assert swarm_info['ControlAvailable'] is False, f'The {self.virtual_ip_address} is not supposed to be a Swarm manager, but it is'

def check_after_disaster(self):
if self.after_disaster:
try:
new_mysql_primary_node: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@172.18.0.10:6446 --sql --execute \"SELECT @@hostname;\"")
new_mysql_primary_node: bytes = self.run_command_on_the_container(f"mysqlsh --interactive --uri {self.mysql_user}:{self.mysql_password}@{self.virtual_ip_address}:6446 --sql --execute \"SELECT @@hostname;\"")
if not self.find_in_the_output(new_mysql_primary_node, self.mysql_secondary_nodes[0].encode('utf-8')):
if not self.find_in_the_output(new_mysql_primary_node, self.mysql_secondary_nodes[1].encode('utf-8')):
raise AssertionError(f'After stopping {self.mysql_primary_node}, one of {self.mysql_secondary_nodes} was expected to be selected as the new primary. Selection process failed with the output: {new_mysql_primary_node}')
Expand Down
10 changes: 5 additions & 5 deletions tests/testsuite/roles/testing/files/functional_superset.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def find_processed_queries(self) -> bool | AssertionError:


class SupersetNodeFunctionalTests(container_connection.ContainerUtilities, metaclass=data_structures.Overlay):
def __init__(self, node_prefix: str, mysql_user: str, mysql_password: str, redis_hostname: str, redis_port: int, celery_sql_lab_task_annotations: str, celery_broker: str, superset_hostname: str, database_name: str, superset_password: str) -> None:
def __init__(self, node_prefix: str, mysql_user: str, mysql_password: str, redis_hostname: str, redis_port: int, celery_sql_lab_task_annotations: str, celery_broker: str, superset_hostname: str, database_name: str, superset_password: str, virtual_ip_address: str) -> None:
super().__init__(node=superset_hostname)
self.celery: typing.Type = Celery(superset_hostname, celery_broker, celery_sql_lab_task_annotations, node_prefix)
self.redis: typing.Type = Redis(superset_hostname, redis_hostname, redis_port, node_prefix)
Expand All @@ -66,7 +66,7 @@ def __init__(self, node_prefix: str, mysql_user: str, mysql_password: str, redis
self.superset_hostname: str = superset_hostname
self.database_name: str = database_name
self.superset_password: str = superset_password
self.mgmt_primary_node: str = "172.18.0.10"
self.virtual_ip_address: str = virtual_ip_address
self.superset_node: str = f"{node_prefix}-4"
self.api_default_url: str = "http://localhost:8088/api/v1"
self.api_authorization_header: str = f"Authorization: Bearer {self.login_to_superset_api()}"
Expand Down Expand Up @@ -97,9 +97,9 @@ def login_to_superset(self) -> dict[str, str] | AssertionError:

@data_structures.Overlay.post_init_hook
def status_database(self) -> None | AssertionError:
payload: str = f'{{"database_name": "MySQL", "sqlalchemy_uri": "mysql+mysqlconnector://{self.mysql_user}:{self.mysql_password}@{self.find_node_ip(self.mgmt_primary_node)}:6446/{self.database_name}", "impersonate_user": false}}'
payload: str = f'{{"database_name": "MySQL", "sqlalchemy_uri": "mysql+mysqlconnector://{self.mysql_user}:{self.mysql_password}@{self.virtual_ip_address}:6446/{self.database_name}", "impersonate_user": false}}'
test_database_connection: bytes = self.run_command_on_the_container(f"curl --silent {self.api_default_url}/database/test_connection/ --header 'Content-Type: application/json' --header '{self.api_authorization_header}' --header '{self.api_csrf_header}' --header '{self.api_session_header}' --data '{payload}'")
assert self.find_in_the_output(test_database_connection, b'{"message":"OK"}'), f'Could not connect to the {self.database_name} on {self.mgmt_primary_node} port 6446, the database is either down or not configured according to the given SQL Alchemy URI'
assert self.find_in_the_output(test_database_connection, b'{"message":"OK"}'), f'Could not connect to the {self.database_name} on {self.virtual_ip_address} port 6446, the database is either down or not configured according to the given SQL Alchemy URI'

@data_structures.Overlay.post_init_hook
def status_datasets(self) -> None | AssertionError:
Expand All @@ -118,7 +118,7 @@ def status_swarm(self) -> None | AssertionError:
# assert swarm_info['Nodes'] == 3, f'The Swarm is expected to consist of 3 nodes instead of {swarm_info["Nodes"]} in the pool.'

def create_database_connection(self) -> int | AssertionError:
payload: str = f'{{"engine": "mysql", "configuration_method": "sqlalchemy_form", "database_name": "MySQL", "sqlalchemy_uri": "mysql+mysqlconnector://{self.mysql_user}:{self.mysql_password}@{self.find_node_ip(self.mgmt_primary_node)}:6446/{self.database_name}"}}'
payload: str = f'{{"engine": "mysql", "configuration_method": "sqlalchemy_form", "database_name": "MySQL", "sqlalchemy_uri": "mysql+mysqlconnector://{self.mysql_user}:{self.mysql_password}@{self.virtual_ip_address}:6446/{self.database_name}"}}'
mysql_connect: bytes = self.run_command_on_the_container(f"curl --silent {self.api_default_url}/database/ --header 'Content-Type: application/json' --header '{self.api_authorization_header}' --header '{self.api_session_header}' --header '{self.api_csrf_header}' --data '{payload}'")
assert not self.find_in_the_output(mysql_connect, b'"message"'), f'Could not create database from API: {mysql_connect}'
return self.decode_command_output(mysql_connect).get('id')
Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/roles/testing/tasks/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
celery_broker=\"{{ celery_broker }}\",
superset_hostname=\"{{ superset_hostname }}\",
database_name=\"{{ database_name }}\",
superset_password=\"{{ superset_password }}\"
superset_password=\"{{ superset_password }}\",
virtual_ip_address=\"{{ virtual_ip_address }}\",
);
database_id = superset_functional.create_database_connection();
query_dttm = superset_functional.run_query(database_id);
Expand All @@ -31,6 +32,7 @@
mgmt_hostname=\"{{ mgmt_hostname }}\",
mysql_user=\"{{ mysql_user }}\",
mysql_password=\"{{ mysql_password }}\",
virtual_ip_address=\"{{ virtual_ip_address }}\",
node_prefix=\"{{ node_prefix }}\",
after_disaster=False
);'"
Expand All @@ -56,6 +58,7 @@
mgmt_hostname=\"{{ mgmt_hostname }}\",
mysql_user=\"{{ mysql_user }}\",
mysql_password=\"{{ mysql_password }}\",
virtual_ip_address=\"{{ virtual_ip_address }}\",
node_prefix=\"{{ node_prefix }}\",
after_disaster=True
);
Expand Down
5 changes: 0 additions & 5 deletions tests/testsuite/roles/testing/tasks/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@
sleep 60
args:
executable: /bin/bash
register: end_to_end_output

- name: Display the output
ansible.builtin.debug:
var: end_to_end_output.stdout

0 comments on commit e22646b

Please sign in to comment.