2015-04-01 16:07:51 +03:00
# Copyright (C) 2013, 2015 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
import os
2020-09-03 19:03:38 +03:00
import tempfile
2013-03-18 01:06:52 +04:00
2013-04-11 03:48:07 +04:00
from tests import utils
2013-03-18 01:06:52 +04:00
2013-07-03 02:30:46 +04:00
from virtinst import Cloner
2013-03-18 01:06:52 +04:00
2020-09-09 00:48:40 +03:00
CLI_XMLDIR = utils . DATADIR + " /cli/virtclone/ "
2013-03-18 01:06:52 +04:00
2020-09-03 19:03:38 +03:00
def test_clone_unmanaged ( ) :
"""
Test that unmanaged storage duplication via the clone wizard
actually copies data
"""
xmlpath = CLI_XMLDIR + " clone-disk.xml "
2020-09-04 18:13:29 +03:00
conn = utils . URIs . open_testdefault_cached ( )
2020-09-03 19:03:38 +03:00
xml = open ( xmlpath ) . read ( )
2013-03-18 01:06:52 +04:00
2020-09-03 19:03:38 +03:00
tmp1 = tempfile . NamedTemporaryFile ( )
tmp2 = tempfile . NamedTemporaryFile ( )
inp1 = os . path . abspath ( __file__ )
inp2 = xmlpath
2013-03-18 01:06:52 +04:00
2020-09-03 19:03:38 +03:00
xml = xml . replace ( " /tmp/__virtinst_cli_exist1.img " , inp1 )
xml = xml . replace ( " /tmp/__virtinst_cli_exist2.img " , inp2 )
cloner = Cloner ( conn , src_xml = xml )
2013-04-13 22:34:52 +04:00
2020-09-04 21:13:52 +03:00
diskinfos = cloner . get_nonshare_diskinfos ( )
2020-09-03 19:03:38 +03:00
assert len ( diskinfos ) == 2
2020-09-04 21:13:52 +03:00
diskinfos [ 0 ] . set_new_path ( tmp1 . name , False )
diskinfos [ 1 ] . set_new_path ( tmp2 . name , False )
2013-03-18 01:06:52 +04:00
2020-09-03 19:03:38 +03:00
cloner . prepare ( )
cloner . start_duplicate ( None )
2013-03-18 01:06:52 +04:00
2020-09-03 19:03:38 +03:00
assert open ( tmp1 . name ) . read ( ) == open ( inp1 ) . read ( )
assert open ( tmp2 . name ) . read ( ) == open ( inp2 ) . read ( )
2020-09-05 15:51:31 +03:00
def test_generate_name ( ) :
conn = utils . URIs . open_testdriver_cached ( )
def _g ( n ) :
return Cloner . generate_clone_name ( conn , n )
assert _g ( " test " ) == " test-clone1 "
assert _g ( " test-clone-simple " ) == " test-clone-simple-clone "
assert _g ( " test-clone-simple-clone " ) == " test-clone-simple-clone1 "
assert _g ( " test-clone-simple-clone5 " ) == " test-clone-simple-clone6 "