Пример #1
0
 def _build_cloner(self):
     conn = self.conn.get_backend()
     orig_name = self.vm.get_name()
     new_name = self.widget("clone-new-name").get_text()
     cloner = Cloner(conn, src_name=orig_name)
     if new_name:
         cloner.set_clone_name(new_name)
     return cloner
Пример #2
0
    def _clone(self,
               filebase,
               disks=None,
               force_list=None,
               skip_list=None,
               compare=True,
               conn=None,
               clone_disks_file=None):
        """Helper for comparing clone input/output from 2 xml files"""
        infile = os.path.join(clonexml_dir, filebase + "-in.xml")
        in_content = utils.read_file(infile)

        if not conn:
            conn = utils.URIs.open_testdriver_cached()
        cloneobj = Cloner(conn)
        cloneobj.original_xml = in_content
        for force in force_list or []:
            cloneobj.force_target = force
        for skip in skip_list or []:
            cloneobj.skip_target = skip

        cloneobj = self._default_clone_values(cloneobj, disks)

        if compare:
            self._clone_compare(cloneobj,
                                filebase,
                                clone_disks_file=clone_disks_file)
            self._clone_define(filebase)
        else:
            cloneobj.setup_original()
            cloneobj.setup_clone()
Пример #3
0
    def build_new_clone_design(self, new_name=None):
        design = Cloner(self.conn.get_backend())
        design.original_guest = self.orig_vm.get_name()
        if not new_name:
            new_name = design.generate_clone_name()
        design.clone_name = new_name

        # Erase any clone_policy from the original design, so that we
        # get the entire device list.
        design.clone_policy = []
        return design
Пример #4
0
    def _clone(self, filebase, disks=None, force_list=None,
               skip_list=None, compare=True, conn=None,
               clone_disks_file=None):
        """Helper for comparing clone input/output from 2 xml files"""
        infile = os.path.join(clonexml_dir, filebase + "-in.xml")
        in_content = open(infile).read()

        if not conn:
            conn = utils.URIs.open_testdriver_cached()
        cloneobj = Cloner(conn)
        cloneobj.original_xml = in_content
        for force in force_list or []:
            cloneobj.force_target = force
        for skip in skip_list or []:
            cloneobj.skip_target = skip

        cloneobj = self._default_clone_values(cloneobj, disks)

        if compare:
            self._clone_compare(cloneobj, filebase,
                                clone_disks_file=clone_disks_file)
            self._clone_define(filebase)
        else:
            cloneobj.setup_original()
            cloneobj.setup_clone()
Пример #5
0
    def notestCloneGuestLookup(self):
        """Test using a vm name lookup for cloning"""
        for base in clone_files:
            infile = os.path.join(clonexml_dir, base + "-in.xml")

            vm = None
            try:
                vm = conn.defineXML(utils.read_file(infile))

                cloneobj = Cloner(conn)
                cloneobj.original_guest = ORIG_NAME

                cloneobj = self._default_clone_values(cloneobj)
                self._clone_compare(cloneobj, base)
            finally:
                if vm:
                    vm.undefine()
Пример #6
0
    def notestCloneGuestLookup(self):
        """Test using a vm name lookup for cloning"""
        for base in clone_files:
            infile = os.path.join(clonexml_dir, base + "-in.xml")

            vm = None
            try:
                vm = conn.defineXML(utils.read_file(infile))

                cloneobj = Cloner(conn)
                cloneobj.original_guest = ORIG_NAME

                cloneobj = self._default_clone_values(cloneobj)
                self._clone_compare(cloneobj, base)
            finally:
                if vm:
                    vm.undefine()
Пример #7
0
def test_clone_unmanaged():
    """
    Test that unmanaged storage duplication via the clone wizard
    actually copies data
    """
    xmlpath = CLI_XMLDIR + "clone-disk.xml"
    conn = utils.URIs.open_testdefault_cached()
    xml = open(xmlpath).read()

    tmp1 = tempfile.NamedTemporaryFile()
    tmp2 = tempfile.NamedTemporaryFile()
    inp1 = os.path.abspath(__file__)
    inp2 = xmlpath

    xml = xml.replace("/tmp/__virtinst_cli_exist1.img", inp1)
    xml = xml.replace("/tmp/__virtinst_cli_exist2.img", inp2)
    cloner = Cloner(conn, src_xml=xml)

    diskinfos = cloner.get_nonshare_diskinfos()
    assert len(diskinfos) == 2
    diskinfos[0].set_new_path(tmp1.name, False)
    diskinfos[1].set_new_path(tmp2.name, False)

    cloner.prepare()
    cloner.start_duplicate(None)

    assert open(tmp1.name).read() == open(inp1).read()
    assert open(tmp2.name).read() == open(inp2).read()
Пример #8
0
    def build_new_clone_design(self, new_name=None):
        design = Cloner(self.conn.get_backend())
        design.original_guest = self.vm.get_name()
        if not new_name:
            new_name = design.generate_clone_name()
        design.clone_name = new_name

        # Erase any clone_policy from the original design, so that we
        # get the entire device list.
        design.clone_policy = []
        return design
Пример #9
0
    def _clone_helper(self, filebase, disks=None, force_list=None,
                      skip_list=None, compare=True, useconn=None):
        """Helper for comparing clone input/output from 2 xml files"""
        infile = os.path.join(clonexml_dir, filebase + "-in.xml")
        in_content = utils.read_file(infile)

        cloneobj = Cloner(useconn or conn)
        cloneobj.original_xml = in_content
        for force in force_list or []:
            cloneobj.force_target = force
        for skip in skip_list or []:
            cloneobj.skip_target = skip

        cloneobj = self._default_clone_values(cloneobj, disks)

        if compare:
            self._clone_compare(cloneobj, filebase)
            self._clone_define(filebase)
        else:
            cloneobj.setup()
Пример #10
0
 def _g(n):
     return Cloner.generate_clone_name(conn, n)
Пример #11
0
    def testCloneMisc(self):
        conn = utils.URIs.open_testdriver_cached()

        with self.assertRaises(RuntimeError) as err:
            cloner = Cloner(conn)
            # Add this bit here for coverage testing
            cloner.clone_xml = None
            cloner.setup_original()
        self.assertTrue("Original guest name or XML" in str(err.exception))

        with self.assertRaises(RuntimeError) as err:
            cloner = Cloner(conn)
            cloner.original_guest = "test-snapshots"
            cloner.setup_original()
        self.assertTrue("must be shutoff" in str(err.exception))

        with self.assertRaises(ValueError) as err:
            cloner = Cloner(conn)
            cloner.original_guest = "test-clone-simple"
            cloner.setup_original()
            cloner.setup_clone()
        self.assertTrue("More disks to clone" in str(err.exception))

        cloner = Cloner(conn)
        self.assertEqual(cloner.generate_clone_name("test-clone5"),
                         "test-clone6")
Пример #12
0
 def _reset_generated_path(self):
     self._generated_path = Cloner.generate_clone_disk_path(
         self._orig_disk.conn, self._orig_vm_name, self._new_vm_name,
         self._orig_disk.get_source_path())