v2v: -o rhv-upload: split vmcheck out of precheck

Split the VM existance check out of the precheck script to a new vmcheck
script, and invoke that in #prepare_targets.  Invoke the precheck script
in #precheck, as now it can be run with only values of command line
options.

This does not change which checks are performed; however, an invalid
cluster name will make virt-v2v fail way earlier (even before connecting
to the source).

(cherry picked from commit 6499fdc199)
This commit is contained in:
Pino Toscano
2019-09-12 13:19:48 +02:00
committed by Richard W.M. Jones
parent fed5b4195b
commit fb5e3592a9
6 changed files with 111 additions and 17 deletions

View File

@@ -26,7 +26,8 @@ BUILT_SOURCES = \
config.ml \
output_rhv_upload_createvm_source.ml \
output_rhv_upload_plugin_source.ml \
output_rhv_upload_precheck_source.ml
output_rhv_upload_precheck_source.ml \
output_rhv_upload_vmcheck_source.ml
EXTRA_DIST = \
$(SOURCES_MLI) $(SOURCES_ML) $(SOURCES_C) \
@@ -36,6 +37,7 @@ EXTRA_DIST = \
rhv-upload-createvm.py \
rhv-upload-plugin.py \
rhv-upload-precheck.py \
rhv-upload-vmcheck.py \
v2v_unit_tests.ml \
virt-v2v.pod \
virt-v2v-copy-to-local.pod \
@@ -87,6 +89,7 @@ SOURCES_MLI = \
output_rhv_upload_createvm_source.mli \
output_rhv_upload_plugin_source.mli \
output_rhv_upload_precheck_source.mli \
output_rhv_upload_vmcheck_source.mli \
output_vdsm.mli \
parse_ova.mli \
parse_ovf_from_ova.mli \
@@ -152,6 +155,7 @@ SOURCES_ML = \
output_rhv_upload_createvm_source.ml \
output_rhv_upload_plugin_source.ml \
output_rhv_upload_precheck_source.ml \
output_rhv_upload_vmcheck_source.ml \
output_rhv_upload.ml \
output_vdsm.ml \
output_openstack.ml \
@@ -173,6 +177,8 @@ output_rhv_upload_plugin_source.ml: $(srcdir)/rhv-upload-plugin.py
$(srcdir)/embed.sh code $^ $@
output_rhv_upload_precheck_source.ml: $(srcdir)/rhv-upload-precheck.py
$(srcdir)/embed.sh code $^ $@
output_rhv_upload_vmcheck_source.ml: $(srcdir)/rhv-upload-vmcheck.py
$(srcdir)/embed.sh code $^ $@
if HAVE_OCAML

View File

@@ -94,10 +94,13 @@ class output_rhv_upload output_alloc output_conn
let diskid_file_of_id id = tmpdir // sprintf "diskid.%d" id in
(* Create Python scripts for precheck, plugin and create VM. *)
(* Create Python scripts for precheck, vmcheck, plugin and create VM. *)
let precheck_script =
Python_script.create ~name:"rhv-upload-precheck.py"
Output_rhv_upload_precheck_source.code in
let vmcheck_script =
Python_script.create ~name:"rhv-upload-vmcheck.py"
Output_rhv_upload_vmcheck_source.code in
let plugin_script =
Python_script.create ~name:"rhv-upload-plugin.py"
Output_rhv_upload_plugin_source.code in
@@ -230,6 +233,9 @@ object
error_unless_nbdkit_working ();
error_unless_nbdkit_python_plugin_working ();
error_unless_output_alloc_sparse ();
(* Python code prechecks. *)
if Python_script.run_command precheck_script json_params [] <> 0 then
error (f_"failed server prechecks, see earlier errors");
if have_selinux then
error_unless_nbdkit_compiled_with_selinux ()
@@ -251,11 +257,11 @@ object
let json_params =
("output_name", JSON.String output_name) :: json_params in
(* Python code prechecks. These can't run in #precheck because
(* Check that the VM does not exist. This can't run in #precheck because
* we need to know the name of the virtual machine.
*)
if Python_script.run_command precheck_script json_params [] <> 0 then
error (f_"failed server prechecks, see earlier errors");
if Python_script.run_command vmcheck_script json_params [] <> 0 then
error (f_"failed vmchecks, see earlier errors");
(* Create an nbdkit instance for each disk and set the
* target URI to point to the NBD socket.

View File

@@ -1,5 +1,5 @@
(* virt-v2v
* Copyright (C) 2018 Red Hat Inc.
* Copyright (C) 2019 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -0,0 +1,19 @@
(* virt-v2v
* Copyright (C) 2018 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
val code : string

View File

@@ -1,6 +1,6 @@
# -*- python -*-
# oVirt or RHV pre-upload checks used by virt-v2v -o rhv-upload
# Copyright (C) 2018 Red Hat Inc.
# Copyright (C) 2018-2019 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -60,16 +60,6 @@ connection = sdk.Connection(
system_service = connection.system_service()
# Find if a virtual machine already exists with that name.
vms_service = system_service.vms_service()
vms = vms_service.list(
search = ("name=%s" % params['output_name']),
)
if len(vms) > 0:
vm = vms[0]
raise RuntimeError("VM already exists with name %s, id %s" %
(params['output_name'], vm.id))
# Check whether the specified cluster exists.
clusters_service = system_service.clusters_service()
clusters = clusters_service.list(

73
v2v/rhv-upload-vmcheck.py Normal file
View File

@@ -0,0 +1,73 @@
# -*- python -*-
# oVirt or RHV VM existance check used by virt-v2v -o rhv-upload
# Copyright (C) 2018-2019 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import json
import logging
import sys
import time
from http.client import HTTPSConnection
from urllib.parse import urlparse
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
# Parameters are passed in via a JSON doc from the OCaml code.
# Because this Python code ships embedded inside virt-v2v there
# is no formal API here.
params = None
if len(sys.argv) != 2:
raise RuntimeError("incorrect number of parameters")
# Parameters are passed in via a JSON document.
with open(sys.argv[1], 'r') as fp:
params = json.load(fp)
# What is passed in is a password file, read the actual password.
with open(params['output_password'], 'r') as fp:
output_password = fp.read()
output_password = output_password.rstrip()
# Parse out the username from the output_conn URL.
parsed = urlparse(params['output_conn'])
username = parsed.username or "admin@internal"
# Connect to the server.
connection = sdk.Connection(
url = params['output_conn'],
username = username,
password = output_password,
ca_file = params['rhv_cafile'],
log = logging.getLogger(),
insecure = params['insecure'],
)
system_service = connection.system_service()
# Find if a virtual machine already exists with that name.
vms_service = system_service.vms_service()
vms = vms_service.list(
search = ("name=%s" % params['output_name']),
)
if len(vms) > 0:
vm = vms[0]
raise RuntimeError("VM already exists with name %s, id %s" %
(params['output_name'], vm.id))
# Otherwise everything is OK, exit with no error.