Beispiel #1
0
    def test_14_restore_ld(self, mock_copyto, mock_size, mock_path,
                           mock_gcl, mock_msg):
        """Test14 ElfPatcher().restore_ld()."""
        mock_msg.level = 0
        mock_size.return_value = -1
        mock_path.return_value = "/some_contdir"
        mock_gcl.return_value = ""
        elfp = ElfPatcher(self.local, self.contid)
        self.assertFalse(elfp.restore_ld())

        mock_size.return_value = 20
        mock_copyto.return_value = True
        mock_path.return_value = "/some_contdir"
        mock_gcl.return_value = ""
        elfp = ElfPatcher(self.local, self.contid)
        self.assertTrue(elfp.restore_ld())
Beispiel #2
0
    def set_mode(self, xmode, force=False):
        """Set execution mode"""
        status = False
        prev_xmode = self.get_mode()
        elfpatcher = ElfPatcher(self.localrepo, self.container_id)
        filebind = FileBind(self.localrepo, self.container_id)
        futil_croot = FileUtil(self.container_orig_root)
        orig_path = futil_croot.getdata('r').strip()
        if xmode not in self.valid_modes:
            Msg().err("Error: invalid execmode:", xmode)
            return status

        if not (force or xmode != prev_xmode):
            return True

        if prev_xmode[0] in ('R', 'S') and xmode[0] != 'R':
            filebind.restore()

        if xmode[0] == 'F':
            if force or prev_xmode[0] in ("P", "R", "S"):
                futil_cont = FileUtil(self.container_root)
                status = (futil_cont.links_conv(force, True, orig_path)
                          and elfpatcher.get_ld_libdirs(force))

        if xmode in ('P1', 'P2', 'F1', 'R1', 'R2', 'R3', 'S1'):
            if prev_xmode in ('P1', 'P2', 'F1', 'R1', 'R2', 'R3', 'S1'):
                status = True
            elif force or prev_xmode in ("F2", "F3", "F4"):
                status = ((elfpatcher.restore_ld() or force)
                          and elfpatcher.restore_binaries())
            if xmode[0] == 'R':
                filebind.setup()
        elif xmode in ("F2", ):
            if force or prev_xmode in ("F3", "F4"):
                status = elfpatcher.restore_binaries()
            if force or prev_xmode in ('P1', 'P2', 'F1', 'R1', 'R2', 'R3',
                                       'S1'):
                status = elfpatcher.patch_ld()
        elif xmode in ("F3", "F4"):
            if force or prev_xmode in ('P1', 'P2', 'F1', 'F2', 'R1', 'R2',
                                       'R3', 'S1'):
                status = (elfpatcher.patch_ld()
                          and elfpatcher.patch_binaries())
            elif prev_xmode in ("F3", "F4"):
                status = True

        if xmode[0] in ("P", "R", "S"):
            if force or (status and prev_xmode.startswith("F")):
                futil = FileUtil(self.container_root)
                status = futil.links_conv(force, False, orig_path)

        if status or force:
            futil = FileUtil(self.container_execmode)
            status = futil.putdata(xmode, "w")

        if status or force:
            futil = FileUtil(self.container_orig_root)
            status = futil.putdata(os.path.realpath(self.container_root), "w")

        if (not status) and (not force):
            Msg().err("Error: container setup failed")

        return bool(status)