Skip to content

Commit

Permalink
ocp installer upgrade precheck
Browse files Browse the repository at this point in the history
  • Loading branch information
潘佳瑶 authored and ob-robot committed Feb 17, 2025
1 parent c6016be commit a424baf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
12 changes: 11 additions & 1 deletion service/handler/rsa_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,15 @@ def decrypt_private_key(self, text):
decrypt_data = cipher.decrypt(encrypt_data, None)
return decrypt_data.decode('utf-8')
except (ValueError, TypeError) as e:
self.obd.stdio.error("password decrypt failed, reason: %s" % e)
self.obd.stdio.error("password decrypt failed, reason: %s" % e)
raise Exception('rsa decryption an exception occurred: %s' % e)

def encrypt_public_key(self, text):
try:
cipher = PKCS1_v1_5.new(self.public_key)
encrypt_data = cipher.encrypt(text.encode())
encrypt_base64 = base64.b64encode(encrypt_data)
return encrypt_base64.decode('utf-8')
except ValueError as e:
self.obd.stdio.error("password encrypt failed, reason: %s" % e)
raise Exception('rsa encryption an exception occurred: %s' % e)
17 changes: 7 additions & 10 deletions service/handler/service_info_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def generate_config(self, cluster_name):
if res:
log.get_logger().info("found ocp docker")
home_path = "/home/{0}/ocp-server".format(self.context['upgrade_user']) if self.context['upgrade_user'] != 'root' else "/root/ocp-server"
auth = Auth(user=username, port=ssh_port, password=password)
auth = Auth(user=username, port=ssh_port, password=RSAHandler().encrypt_public_key(password) if password else password)
jdbc_username = self.context['connection_info'][cluster_name].user
user_name = jdbc_username.split('@')[0]
tenant_name = jdbc_username.split('@')[1].split('#')[0] if '#' in jdbc_username else jdbc_username.split('@')[1]
Expand All @@ -177,20 +177,17 @@ def generate_config(self, cluster_name):
self.context['monitor']['tenant_name'] = monitor_tenant_name
monitor_tenant_username = monitor_user.split('@')[0]
monitor_tenant_user = TenantUser(tenant_name=monitor_tenant_name, user_name=monitor_tenant_username, user_database=monitor_database)
monitor_tenant = TenantConfig(name=monitor_tenant_user, password=monitor_password)
ocp_server = OcpServer(component='ocp-server-ce', metadb=self.context['connection_info'][cluster_name], meta_tenant=meta_tenant, monitor_tenant=monitor_tenant, admin_password='********',
monitor_tenant = TenantConfig(name=monitor_tenant_user, password=RSAHandler().encrypt_public_key(monitor_password))
ocp_server = OcpServer(component='ocp-server-ce', metadb=self.context['connection_info'][cluster_name], meta_tenant=meta_tenant, monitor_tenant=monitor_tenant, admin_password=RSAHandler().encrypt_public_key('********'),
home_path=home_path, servers=servers, port=server_port, memory_size=memory_xmx)
components = OcpComponentConfig(ocpserver=ocp_server)
data = OCPDeploymnetConfig(auth=auth, components=components)

ocp_handler = OcpHandler()
try:
cluster_config_yaml_path = ocp_handler.create_ocp_config_path(data)
log.get_logger().info('upgrade path: %s' % cluster_config_yaml_path)
deployment_id = ocp_handler.create_ocp_deployment(cluster_name, cluster_config_yaml_path)
log.get_logger().info('upgrade id: %s' % deployment_id)
except Exception as ex:
log.get_logger().error(ex)
cluster_config_yaml_path = ocp_handler.create_ocp_config_path(data)
log.get_logger().info('upgrade path: %s' % cluster_config_yaml_path)
deployment_id = ocp_handler.create_ocp_deployment(cluster_name, cluster_config_yaml_path)
log.get_logger().info('upgrade id: %s' % deployment_id)

def create_ocp_info(self, cluster_name):
deploy = self.obd.deploy_manager.get_deploy_config(cluster_name)
Expand Down
11 changes: 9 additions & 2 deletions workflows/ocp-server/4.2.1/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import absolute_import, division, print_function

import const

import os

def start(plugin_context, workflow, *args, **kwargs):
repositories = plugin_context.repositories
Expand All @@ -27,7 +27,14 @@ def start(plugin_context, workflow, *args, **kwargs):
workflow.add_with_component_version_kwargs(const.STAGE_FIRST, 'general', '0.1', {'new_clients': clients}, 'chown_dir')
if not plugin_context.cluster_config.depends:
workflow.add_with_kwargs(const.STAGE_FIRST, {'need_connect': False}, 'cursor_check')
workflow.add_with_component_version_kwargs(const.STAGE_FIRST, const.COMP_OB_CE if const.COMP_OB_CE in repository_name else const.COMP_OB, '4.0.0.0', {'scale_out_component': const.COMP_OCP_SERVER_CE}, 'connect', 'create_tenant', 'create_user', 'import_time_zone')
cluster_config = plugin_context.cluster_config
server_config = cluster_config.get_server_conf(cluster_config.servers[0])
client = clients[cluster_config.servers[0]]
bootstrap_path = os.path.join(server_config['home_path'], '.bootstrapped')
cmd = 'ls %s' % bootstrap_path
source_option = getattr(plugin_context.options, 'source_option', None)
if not(source_option == 'upgrade' or client.execute_command(cmd)):
workflow.add_with_component_version_kwargs(const.STAGE_FIRST, const.COMP_OB_CE if const.COMP_OB_CE in repository_name else const.COMP_OB, '4.0.0.0', {'scale_out_component': const.COMP_OCP_SERVER_CE}, 'connect', 'create_tenant', 'create_user', 'import_time_zone')
workflow.add(const.STAGE_FIRST, 'start', 'health_check')
workflow.add(const.STAGE_FIRST, 'stop_pre')
workflow.add_with_component(const.STAGE_FIRST, 'general', 'stop')
Expand Down

0 comments on commit a424baf

Please sign in to comment.