Skip to content

Commit a424baf

Browse files
潘佳瑶ob-robot
潘佳瑶
authored andcommitted
ocp installer upgrade precheck
1 parent c6016be commit a424baf

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Diff for: service/handler/rsa_handler.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,15 @@ def decrypt_private_key(self, text):
4040
decrypt_data = cipher.decrypt(encrypt_data, None)
4141
return decrypt_data.decode('utf-8')
4242
except (ValueError, TypeError) as e:
43-
self.obd.stdio.error("password decrypt failed, reason: %s" % e)
43+
self.obd.stdio.error("password decrypt failed, reason: %s" % e)
4444
raise Exception('rsa decryption an exception occurred: %s' % e)
45+
46+
def encrypt_public_key(self, text):
47+
try:
48+
cipher = PKCS1_v1_5.new(self.public_key)
49+
encrypt_data = cipher.encrypt(text.encode())
50+
encrypt_base64 = base64.b64encode(encrypt_data)
51+
return encrypt_base64.decode('utf-8')
52+
except ValueError as e:
53+
self.obd.stdio.error("password encrypt failed, reason: %s" % e)
54+
raise Exception('rsa encryption an exception occurred: %s' % e)

Diff for: service/handler/service_info_handler.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def generate_config(self, cluster_name):
165165
if res:
166166
log.get_logger().info("found ocp docker")
167167
home_path = "/home/{0}/ocp-server".format(self.context['upgrade_user']) if self.context['upgrade_user'] != 'root' else "/root/ocp-server"
168-
auth = Auth(user=username, port=ssh_port, password=password)
168+
auth = Auth(user=username, port=ssh_port, password=RSAHandler().encrypt_public_key(password) if password else password)
169169
jdbc_username = self.context['connection_info'][cluster_name].user
170170
user_name = jdbc_username.split('@')[0]
171171
tenant_name = jdbc_username.split('@')[1].split('#')[0] if '#' in jdbc_username else jdbc_username.split('@')[1]
@@ -177,20 +177,17 @@ def generate_config(self, cluster_name):
177177
self.context['monitor']['tenant_name'] = monitor_tenant_name
178178
monitor_tenant_username = monitor_user.split('@')[0]
179179
monitor_tenant_user = TenantUser(tenant_name=monitor_tenant_name, user_name=monitor_tenant_username, user_database=monitor_database)
180-
monitor_tenant = TenantConfig(name=monitor_tenant_user, password=monitor_password)
181-
ocp_server = OcpServer(component='ocp-server-ce', metadb=self.context['connection_info'][cluster_name], meta_tenant=meta_tenant, monitor_tenant=monitor_tenant, admin_password='********',
180+
monitor_tenant = TenantConfig(name=monitor_tenant_user, password=RSAHandler().encrypt_public_key(monitor_password))
181+
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('********'),
182182
home_path=home_path, servers=servers, port=server_port, memory_size=memory_xmx)
183183
components = OcpComponentConfig(ocpserver=ocp_server)
184184
data = OCPDeploymnetConfig(auth=auth, components=components)
185185

186186
ocp_handler = OcpHandler()
187-
try:
188-
cluster_config_yaml_path = ocp_handler.create_ocp_config_path(data)
189-
log.get_logger().info('upgrade path: %s' % cluster_config_yaml_path)
190-
deployment_id = ocp_handler.create_ocp_deployment(cluster_name, cluster_config_yaml_path)
191-
log.get_logger().info('upgrade id: %s' % deployment_id)
192-
except Exception as ex:
193-
log.get_logger().error(ex)
187+
cluster_config_yaml_path = ocp_handler.create_ocp_config_path(data)
188+
log.get_logger().info('upgrade path: %s' % cluster_config_yaml_path)
189+
deployment_id = ocp_handler.create_ocp_deployment(cluster_name, cluster_config_yaml_path)
190+
log.get_logger().info('upgrade id: %s' % deployment_id)
194191

195192
def create_ocp_info(self, cluster_name):
196193
deploy = self.obd.deploy_manager.get_deploy_config(cluster_name)

Diff for: workflows/ocp-server/4.2.1/start.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from __future__ import absolute_import, division, print_function
1717

1818
import const
19-
19+
import os
2020

2121
def start(plugin_context, workflow, *args, **kwargs):
2222
repositories = plugin_context.repositories
@@ -27,7 +27,14 @@ def start(plugin_context, workflow, *args, **kwargs):
2727
workflow.add_with_component_version_kwargs(const.STAGE_FIRST, 'general', '0.1', {'new_clients': clients}, 'chown_dir')
2828
if not plugin_context.cluster_config.depends:
2929
workflow.add_with_kwargs(const.STAGE_FIRST, {'need_connect': False}, 'cursor_check')
30-
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')
30+
cluster_config = plugin_context.cluster_config
31+
server_config = cluster_config.get_server_conf(cluster_config.servers[0])
32+
client = clients[cluster_config.servers[0]]
33+
bootstrap_path = os.path.join(server_config['home_path'], '.bootstrapped')
34+
cmd = 'ls %s' % bootstrap_path
35+
source_option = getattr(plugin_context.options, 'source_option', None)
36+
if not(source_option == 'upgrade' or client.execute_command(cmd)):
37+
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')
3138
workflow.add(const.STAGE_FIRST, 'start', 'health_check')
3239
workflow.add(const.STAGE_FIRST, 'stop_pre')
3340
workflow.add_with_component(const.STAGE_FIRST, 'general', 'stop')

0 commit comments

Comments
 (0)