summaryrefslogtreecommitdiffstats
path: root/tests/file_source.py
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-08-26 21:41:52 +0100
committerRadostin Stoyanov <rstoyanov1@gmail.com>2017-08-28 15:57:16 +0100
commit186bf4860e963d58a1779b1898985d4d13211286 (patch)
tree51c04c8b7e378245de6b39a82c364aea8ba52ebf /tests/file_source.py
parenta48353f83374c37480c98c463363873b95058e5f (diff)
downloadvirt-bootstrap.git-186bf4860e963d58a1779b1898985d4d13211286.tar.gz
virt-bootstrap.git-186bf4860e963d58a1779b1898985d4d13211286.tar.xz
virt-bootstrap.git-186bf4860e963d58a1779b1898985d4d13211286.zip
Add regression tests
These tests aim to verify the output of virt-bootstrap by creating tar archives which contain dummy root file system and call the function bootstrap(). The check the extracted root file system.
Diffstat (limited to 'tests/file_source.py')
-rw-r--r--tests/file_source.py78
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()