diff options
Diffstat (limited to 'tests/file_source.py')
-rw-r--r-- | tests/file_source.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/file_source.py b/tests/file_source.py new file mode 100644 index 0000000..79bb234 --- /dev/null +++ b/tests/file_source.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# Authors: Radostin Stoyanov <rstoyanov1@gmail.com> +# +# Copyright (C) 2017 Radostin Stoyanov +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +""" +Regression tests which aim to exercise the creation of root file system +with FileSource. +""" + +import unittest + +from . import mock +from . import virt_bootstrap +from . import ImageAccessor +from . import NOT_ROOT + + +# pylint: disable=invalid-name +class TestDirFileSource(ImageAccessor): + """ + Ensures that files from rootfs tarball are extracted correctly. + """ + def call_bootstrap(self): + """ + Execute the bootstrap() method of virt_bootstrap. + """ + virt_bootstrap.bootstrap( + uri=self.tar_file, + dest=self.dest_dir, + fmt='dir', + progress_cb=mock.Mock(), + uid_map=self.uid_map, + gid_map=self.gid_map, + root_password=self.root_password + ) + + def test_dir_extract_rootfs(self): + """ + Extract rootfs from each dummy tarfile. + """ + self.call_bootstrap() + self.check_rootfs(skip_ownership=NOT_ROOT) + + @unittest.skipIf(NOT_ROOT, "Root privileges required") + def test_dir_ownership_mapping(self): + """ + Ensures that UID/GID mapping for extracted root file system are applied + correctly. + """ + self.uid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + self.gid_map = [[1000, 2000, 10], [0, 1000, 10], [500, 500, 10]] + self.call_bootstrap() + self.apply_mapping() + self.check_rootfs() + + def test_dir_setting_root_password(self): + """ + Ensures that the root password is set correctly when FileSource is used + with fmt='dir'. + """ + self.root_password = 'my secret root password' + self.call_bootstrap() + self.validate_shadow_file() |