← Back to team overview

curtin-dev team mailing list archive

Re: [Merge] ~mitchellaugustin/curtin:namespace_chroot_fix into curtin:master

 

A few tweaks and I think this is good for merge.  I think I want to squash these commits down to 1, so make sure please the Commit Message listed on the MP is the one you want for that.

Quirks of how curtin CI works means that the final check happens once I mark the MP as a whole approved, so I apologize in advance if that discovers some problem.

Diff comments:

> diff --git a/curtin/util.py b/curtin/util.py
> index 53e2035..e8a8b1e 100644
> --- a/curtin/util.py
> +++ b/curtin/util.py
> @@ -767,6 +778,16 @@ class ChrootableTarget(object):
>                      self.rc_tmp = None
>                  raise
>  
> +        # Symlink true to ischroot since we may be in separate PID

Tweak comment please, still talks about symlinking

> +        # namespace, which can throw off ischroot
> +        true_mount_path = paths.target_path(self.target, '/usr/bin/true')
> +        ischroot_mount_path = paths.target_path(self.target,
> +                                                '/usr/bin/ischroot')
> +        true_exists = os.path.isfile(true_mount_path)
> +        if true_exists and do_mount(true_mount_path, ischroot_mount_path,
> +                                    opts='--bind'):
> +            self.umounts.append(ischroot_mount_path)
> +
>          return self
>  
>      def __exit__(self, etype, value, trace):
> diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
> index 4e268f0..4801f7c 100644
> --- a/tests/unittests/test_util.py
> +++ b/tests/unittests/test_util.py
> @@ -627,6 +627,67 @@ class TestChrootableTargetMounts(CiTestCase):
>          self.assertEqual(sorted(my_mounts), sorted(in_chroot.mounts))
>  
>  
> +class TestChrootableTargetIsChrootBehavior(CiTestCase):
> +    """Test ChrootableTargets handle ischroot behavior correctly
> +
> +    The test checks to make sure that, in a ChrootableTarget:
> +        a) /usr/bin/ischroot is bind-mounted to the /usr/bin/true
> +        inside the target (i.e. it appears in ChrootableTarget.umounts)
> +        b) The content of /usr/bin/ischroot inside the target actually is
> +        identical to that of /usr/bin/true within the target
> +
> +        Assumptions:
> +        - /usr/bin/true exists inside the target. (If it does not,
> +        util.py does not attempt this bind mount)
> +
> +        Notes:
> +        - This test ignores any attempts to bind-mount anything other
> +        than files, as such mounts are out-of-scope for this test.
> +        """
> +
> +    def setUp(self):
> +        super(TestChrootableTargetIsChrootBehavior, self).setUp()
> +        self.target = self.tmp_dir()
> +        self.truebin = os.path.join(self.target, 'usr/bin/true')
> +        self.ischrootbin = os.path.join(self.target, 'usr/bin/ischroot')
> +        os.makedirs(os.path.dirname(self.truebin))
> +        self.add_patch('curtin.util.do_mount', 'm_do_mount')
> +        self.add_patch('curtin.util.subp', 'm_subp')

Can delete this add_patch of m_subp I think

> +        self.true_content = "true"
> +        self.ischroot_content = "ischroot"
> +        self.umounts = []
> +        util.write_file(self.truebin, self.true_content)
> +        util.write_file(self.ischrootbin, self.ischroot_content)
> +
> +    def mymount(self, src, dst, opts):
> +        print('mymount(src=%s dst=%s, opts=%s)' % (src, dst, opts))
> +        if dst not in self.umounts:
> +            self.umounts.append(dst)
> +        else:
> +            return False
> +
> +        if os.path.isfile(src):
> +            util.write_file(dst, util.load_file(src))
> +        else:
> +            print("Ignoring non-file bind mounts for this test")
> +        return True
> +
> +    def test_chrootable_target_binds_ischroot_true(self):
> +        target_ischroot = os.path.join(self.target, 'usr/bin/ischroot')
> +
> +        self.m_do_mount.side_effect = self.mymount
> +        with util.ChrootableTarget(self.target) as chroot:
> +            self.assertTrue(target_ischroot in chroot.umounts)
> +
> +    def test_chrootable_target_bind_ischroot_true_value(self):
> +        target_ischroot = os.path.join(self.target, 'usr/bin/ischroot')
> +
> +        self.m_do_mount.side_effect = self.mymount
> +        with util.ChrootableTarget(self.target):
> +            target_ischroot_file = util.load_file(target_ischroot)
> +            self.assertEqual(self.true_content, target_ischroot_file)
> +
> +
>  class TestChrootableTargetResolvConf(CiTestCase):
>      """Test ChrootableTargets handles target /etc/resolv.conf gracefully"""
>  


-- 
https://code.launchpad.net/~mitchellaugustin/curtin/+git/curtin/+merge/460960
Your team curtin developers is subscribed to branch curtin:master.



Follow ups

References