Skip to content
Snippets Groups Projects
Commit 301a1b35 authored by Jiří Ježek's avatar Jiří Ježek
Browse files

Merge branch 'fix/ssh_conntection_hypervisors' into 'master'

Fix ssh connection

See merge request !46
parents ee7d3da7 bdbbf7a2
No related branches found
No related tags found
1 merge request!46Fix ssh connection
Pipeline #551303 waiting for manual action with stages
in 26 seconds
......@@ -50,7 +50,7 @@ ostack-einfra_cz-project-migration: &migration-job
- ci/install-ssh-private-key-configuration.sh "${SSH_PRIVATE_KEY_HYPERVISORS}" ci/ssh_configuration
- eval "$(ssh-agent)"
script:
- ci/project-migrator.py --source-openrc="${SRC_CLOUD_OSTACK_RC_FILE}_${PROJECT_DOMAIN_NAME}" --destination-openrc="${DST_CLOUD_OSTACK_RC_FILE}_${PROJECT_DOMAIN_NAME}" --project-name="${PROJECT_NAME}" --validation-a-source-server-id="${VALIDATION_SERVER_ID}" --ceph-migrator-sshkeyfile="${MIGRATOR_SSH_KEY_FILE}" --hypervisor-sshkeyfile="${SSH_PRIVATE_KEY_HYPERVISORS}" --explicit-server-names="${MIGRATE_EXPLICIT_SERVER_NAMES}" --explicit-volume-names="${MIGRATE_EXPLICIT_VOLUME_NAMES}" ${PROJECT_MIGRATOR_EXTRA_ARGS}
- ci/project-migrator.py --source-openrc="${SRC_CLOUD_OSTACK_RC_FILE}_${PROJECT_DOMAIN_NAME}" --destination-openrc="${DST_CLOUD_OSTACK_RC_FILE}_${PROJECT_DOMAIN_NAME}" --project-name="${PROJECT_NAME}" --validation-a-source-server-id="${VALIDATION_SERVER_ID}" --ceph-migrator-sshkeyfile="${MIGRATOR_SSH_KEY_FILE}" --explicit-server-names="${MIGRATE_EXPLICIT_SERVER_NAMES}" --explicit-volume-names="${MIGRATE_EXPLICIT_VOLUME_NAMES}" ${PROJECT_MIGRATOR_EXTRA_ARGS}
after_script:
- zip -P ${MIGRATION_ARCHIVE_PASSWORD} migration-archive.zip *.dump *.log
- rm -f *.dump *.log
......
......@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.9.12] - 2024-12-11
### Fix
- Fixed ssh connection to hypervisors (G1 and G2)
- Removed argument --hypervisor-sshkeyfile and it is not used anymore as it uses default ssh key that is created in gitlab ci
## [1.9.11] - 2024-12-10
### Added
- Mapping for `a3.*nvidia-t4` flavors (incomplete).
......
......@@ -197,12 +197,11 @@ def remote_cmd_exec(hostname, username, key_filename, command):
print("Error:", e)
return None, None, e
def remote_cmd_exec_ssh(hostname, username, key_filename, command):
def remote_cmd_exec_ssh(hostname, username, command):
"""Executes a remote command using OpenSSH client and returns stdout, stderr, and exit-code or Exception"""
# Construct the SSH command to be executed
ssh_command = [
"ssh",
"-i", key_filename, # Identify file (private key)
f"{username}@{hostname}", # Connect to the host with the given username
command # The command to execute remotely
]
......@@ -327,8 +326,7 @@ def copy_ephemeral_disks_over_ssh(args, destination_project_conn, diskfile_paths
mkdir_command = f'sudo mkdir {args.destination_hypervisor_ephemeral_tmp}'
chown_tmp = f'sudo chown {args.destination_hypervisor_login_user}:{args.destination_hypervisor_login_user} {args.destination_hypervisor_ephemeral_tmp}'
prepare_tmp_command = f'{mkdir_command}; {chown_tmp}'
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user,
args.hypervisor_sshkeyfile.name, prepare_tmp_command)
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user, prepare_tmp_command)
for diskfile_path in diskfile_paths.values():
if not diskfile_path:
......@@ -336,7 +334,6 @@ def copy_ephemeral_disks_over_ssh(args, destination_project_conn, diskfile_paths
diskfile_name = os.path.basename(diskfile_path)
scp_command = [
'scp', '-A',
'-o', f'IdentityFile={args.hypervisor_sshkeyfile.name}',
'-o', 'StrictHostKeyChecking=no',
f"{args.source_hypervisor_login_user}@{source_hypervisor_ip}:{diskfile_path}",
f"{args.destination_hypervisor_login_user}@{destination_hypervisor_ip}:{args.destination_hypervisor_ephemeral_tmp}{i_destination_server.id}{diskfile_name}"
......@@ -362,21 +359,18 @@ def copy_ephemeral_disks_over_ssh(args, destination_project_conn, diskfile_paths
# Validate checksums
checks_result = compare_checksums(args, source_hypervisor_ip, destination_hypervisor_ip, diskfile_path, tmp_path)
if checks_result:
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user,
args.hypervisor_sshkeyfile.name, complete_command)
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user, complete_command)
log_or_assert(args, "F.46 checksum of migrated ephemeral disk is correct", reply_ecode == 0)
else:
remove_command = f"rm -f {tmp_path}"
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user,
args.hypervisor_sshkeyfile.name, remove_command)
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user, remove_command)
args.logger.warning(f"Migration of ephemeral disk {diskfile_path} was not sucessfull, due to different checksum."
f"File {tmp_path} on {destination_hypervisor_ip} hypervisor was removed!")
# Remove temporary directory
rmdir_command = f'sudo rmdir {args.destination_hypervisor_ephemeral_tmp}'
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user,
args.hypervisor_sshkeyfile.name, rmdir_command)
_, _, reply_ecode = remote_cmd_exec_ssh(destination_hypervisor_ip, args.destination_hypervisor_login_user, rmdir_command)
# start server in source cloud (if necessary)
restore_server_status_callback['func'](**restore_server_status_callback['args'])
# destination VM start, wait for ACTIVE
......@@ -424,12 +418,10 @@ def compare_checksums(args, source_address, destination_address, source_file, de
"""Compares checksums between source and destination ephemeral disks"""
source_command = f'sha256sum {source_file}'
destination_command = f'sha256sum {destination_file}'
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(source_address, args.ceph_migrator_user,
args.hypervisor_sshkeyfile.name, source_command)
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(source_address, args.ceph_migrator_user, source_command)
log_or_assert(args, "F.44 source checkum was obtained successfully", reply_ecode == 0)
source_checksum = reply_stdout.split()[0]
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(destination_address, args.destination_hypervisor_login_user,
args.hypervisor_sshkeyfile.name, destination_command)
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(destination_address, args.destination_hypervisor_login_user, destination_command)
log_or_assert(args, "F.45 destination checkum was obtained successfully", reply_ecode == 0)
destination_checksum = reply_stdout.split()[0]
return source_checksum == destination_checksum
\ No newline at end of file
......@@ -911,8 +911,7 @@ def restore_source_server_status(args, source_project_conn, source_server_detail
def get_ephemeral_disk_path(args,i_source_server_detail, source_hypervisor_ip):
"""Get ephemeral disk name, if no one exist returns None"""
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(source_hypervisor_ip, args.ceph_migrator_user,
args.hypervisor_sshkeyfile.name, 'virsh dumpxml ' + i_source_server_detail.id )
reply_stdout, _, reply_ecode = remote_cmd_exec_ssh(source_hypervisor_ip, args.ceph_migrator_user, 'virsh dumpxml ' + i_source_server_detail.id )
assert reply_ecode == 0, "Virsh dumpxml obtained successfully"
d_dumpxml = xmltodict.parse(reply_stdout)
return get_disk_paths_from_xml(d_dumpxml)
......
......@@ -400,9 +400,6 @@ if __name__ == "__main__":
clib.BLOCK_STORAGE_VOLUME_MIGRATION_MODE_VMOFF_SNAP_CLONE_FLATTEN_CLEANUP_VMON],
help='(Optional) Mode which determines order of steps performed during volume migration (steps G.05-G.17, F34).')
AP.add_argument('--hypervisor-sshkeyfile', default=None, type=argparse.FileType('r'),
help='OpenStack hypervisor SSH keyfile')
AP.add_argument('--source-hypervisor-login-user', default='root',
help='Source OpenStack hypervisor login user')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment