def test_exclude_path(self):
        testtree = generate_testtree1(current_uid, current_gid)

        with fake_testtree(testtree) as (fake_chown, _, fake_listdir,
                                         fake_stat, _, _, _):
            manager = NovaStatedirOwnershipManager(
                '/var/lib/nova',
                exclude_paths=[
                    'instances/foo/bar',
                    '/var/lib/nova/instances/foo/removeddir'
                ])
            manager.run()
            self.assertIn('/var/lib/nova/instances/foo/bar',
                          manager.exclude_paths)
            self.assertIn('/var/lib/nova/instances/foo/removeddir',
                          manager.exclude_paths)
            self.assertNotIn(mock.call('/var/lib/nova/instances/foo/bar'),
                             fake_stat.call_args_list)
            self.assertNotIn(mock.call('/var/lib/nova/instances/foo/bar'),
                             fake_chown.call_args_list)
            self.assertNotIn(
                mock.call('/var/lib/nova/instances/foo/removeddir'),
                fake_stat.call_args_list)
            self.assertNotIn(
                mock.call('/var/lib/nova/instances/foo/removeddir'),
                fake_chown.call_args_list)
            self.assertNotIn(
                mock.call('/var/lib/nova/instances/foo/removeddir'),
                fake_listdir.call_args_list)
Beispiel #2
0
    def test_upgrade_marker_id_change(self):
        other_uid = current_uid + 1
        other_gid = current_gid + 1
        testtree = generate_testtree2(other_uid, other_gid, other_uid,
                                      other_gid)

        # Determine which paths should change uid/gid
        expected_changes = {}
        for k, v in six.iteritems(testtree):
            if k == '/var/lib/nova/upgrade_marker':
                # Ignore the marker, it should be deleted
                continue
            if k == '/var/lib/_nova_secontext':
                # Ignore, outside tree
                continue
            v = v['stat']
            if v.st_uid == other_uid or v.st_gid == other_gid:
                expected_changes[k] = (
                    current_uid if v.st_uid == other_uid else v.st_uid,
                    current_gid if v.st_gid == other_gid else v.st_gid)

        with fake_testtree(testtree) as (_, _, _, _, fake_unlink, _, _):
            NovaStatedirOwnershipManager('/var/lib/nova').run()
            for fn, expected in six.iteritems(expected_changes):
                assert_ids(testtree, fn, expected[0], expected[1])
            fake_unlink.assert_called_with('/var/lib/nova/upgrade_marker')
    def test_upgrade_marker_no_id_change(self):
        testtree = generate_testtree2(current_uid, current_gid, current_uid,
                                      current_gid)

        with fake_testtree(testtree) as (fake_chown, _, _, _, fake_unlink):
            NovaStatedirOwnershipManager('/var/lib/nova').run()
            fake_chown.assert_not_called()
            fake_unlink.assert_called_with('/var/lib/nova/upgrade_marker')
    def test_upgrade_marker_no_id_change(self):
        testtree = generate_testtree2(current_uid, current_gid, current_uid,
                                      current_gid)

        with fake_testtree(testtree) as (fake_chown, _, _, _, fake_unlink, _,
                                         _):
            NovaStatedirOwnershipManager('/var/lib/nova').run()
            fake_chown.assert_called_once_with(
                '/var/lib/nova/instances/foo/removeddir2', 100, -1)
            fake_unlink.assert_called_with('/var/lib/nova/upgrade_marker')
    def test_no_upgrade_marker(self):
        testtree = generate_testtree1(current_uid, current_gid)

        with fake_testtree(testtree) as (fake_chown, _, _, _, _, _, fake_lsetfilecon):
            NovaStatedirOwnershipManager('/var/lib/nova').run()
            fake_chown.assert_called_once_with('/var/lib/nova/instances/foo/removeddir2', 100, -1)
            fake_lsetfilecon.assert_any_call('/var/lib/nova', 'newcontext')
            fake_lsetfilecon.assert_any_call('/var/lib/nova/instances/foo', 'newcontext')
            chcon_paths = [x[0][0] for x in fake_lsetfilecon.call_args_list]
            self.assertNotIn('/var/lib/nova/instances/foo/bar', chcon_paths)
    def test_no_upgrade_marker(self):
        testtree = generate_testtree1(current_uid, current_gid)

        with fake_testtree(testtree) as (fake_chown, _, _, _, _):
            NovaStatedirOwnershipManager('/var/lib/nova').run()
            fake_chown.assert_not_called()