From 9518705bffe3f736a749bcada74e029fe4fc7c69 Mon Sep 17 00:00:00 2001 From: Liapkovich Date: Wed, 29 Jan 2025 16:00:27 +0100 Subject: [PATCH] refactor(manager): refactor ScyllaManagerTool.add_cluster function Changes: - Updated docstring to contain relevant information about cluster add command `sctool cluster add`. Removed the part that describes command flags which can be retrieved from official docs (links attached). - Removed useless or added some extra empty lines to improve code readability. - Removed `client_encrypt` condition from client encryption 'if-else' block since its duplication. --- sdcm/mgmt/cli.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/sdcm/mgmt/cli.py b/sdcm/mgmt/cli.py index e32a837975..2352625039 100644 --- a/sdcm/mgmt/cli.py +++ b/sdcm/mgmt/cli.py @@ -1053,33 +1053,19 @@ def add_cluster(self, name, host=None, db_cluster=None, client_encrypt=None, dis Add a cluster to manager Usage: - sctool cluster add [flags] - - Flags: - -h, --help help for add - --host string hostname or IP of one of the cluster nodes - -n, --name alias alias you can give to your cluster - --ssl-user-cert-file path path to client certificate when using client/server encryption with require_client_auth enabled - --ssl-user-key-file path path to key associated with ssl-user-cert-file - - Global Flags: - --api-url URL URL of Scylla Manager server (default "https://127.0.0.1:5443/api/v1") - -c, --cluster name target cluster name or ID + sctool cluster add --host [--name ] [--auth-token ] [flags] Scylla Docs: - https://docs.scylladb.com/operating-scylla/manager/1.4/add-a-cluster/ - https://docs.scylladb.com/operating-scylla/manager/1.4/sctool/#cluster-add - - + https://manager.docs.scylladb.com/stable/add-a-cluster.html + https://manager.docs.scylladb.com/stable/sctool#cluster-add """ # pylint: disable=too-many-locals - if not any([host, db_cluster]): raise ScyllaManagerError("Neither host or db_cluster parameter were given to Manager add_cluster") + host = host or self.get_cluster_hosts_ip(db_cluster=db_cluster)[0] - # FIXME: if cluster already added, print a warning, but not fail - cmd = 'cluster add --host={} --name={} --auth-token {}'.format( - host, name, auth_token) + + cmd = 'cluster add --host {} --name {} --auth-token {}'.format(host, name, auth_token) if force_non_ssl_session_port: cmd += " --force-non-ssl-session-port" @@ -1091,17 +1077,20 @@ def add_cluster(self, name, host=None, db_cluster=None, client_encrypt=None, dis "fail since not using client-encryption parameters.") else: # check if scylla-node has client-encrypt db_node, _ip = self.get_cluster_hosts_with_ips(db_cluster=db_cluster)[0] - if client_encrypt or db_node.is_client_encrypt: + if db_node.is_client_encrypt: cmd += " --ssl-user-cert-file {} --ssl-user-key-file {}".format(SSL_USER_CERT_FILE, SSL_USER_KEY_FILE) + if credentials: username, password = credentials cmd += f" --username {username} --password {password}" + res_cluster_add = self.sctool.run(cmd, parse_table_res=False) if not res_cluster_add or 'Cluster added' not in res_cluster_add.stderr: raise ScyllaManagerError("Encountered an error on 'sctool cluster add' command response: {}".format( res_cluster_add)) cluster_id = res_cluster_add.stdout.split('\n')[0] + # return ManagerCluster instance with the manager's new cluster-id manager_cluster = self.clusterClass(manager_node=self.manager_node, cluster_id=cluster_id, client_encrypt=client_encrypt)