Esempio n. 1
0
 def test_delete(self, mock_path, mock_command):
     mock_path.return_value = False
     root = RootInit('root_dir')
     root.delete()
     mock_command.assert_called_once_with(
         ['rm', '-r', '-f', 'root_dir']
     )
Esempio n. 2
0
    def __init__(
        self, xml_state, root_dir, allow_existing=False
    ):
        """
        Setup and host bind new root system at given root_dir directory
        """
        log.info('Setup root directory: %s', root_dir)
        root = RootInit(
            root_dir, allow_existing
        )
        root.create()
        image_uri = xml_state.get_derived_from_image_uri()
        if image_uri:
            root_import = RootImport(
                root_dir, image_uri, xml_state.build_type.get_image()
            )
            root_import.sync_data()
        root_bind = RootBind(
            root
        )
        root_bind.setup_intermediate_config()
        root_bind.mount_kernel_file_systems()
        root_bind.mount_shared_directory()

        self.xml_state = xml_state
        self.profiles = xml_state.profiles
        self.root_bind = root_bind

        # A list of Uri references is stored inside of the System instance
        # in order to delay the Uri destructors until the System instance
        # dies. This is needed to keep bind mounted Uri locations alive
        # for System operations
        self.uri_list = []
Esempio n. 3
0
    def __init__(self, xml_state, root_dir, allow_existing=False):
        """
        Setup and host bind new root system at given root_dir directory
        """
        log.info('Setup root directory: %s', root_dir)
        root = RootInit(root_dir, allow_existing)
        root.create()
        image_uri = xml_state.get_derived_from_image_uri()
        if image_uri:
            root_import = RootImport(root_dir, image_uri,
                                     xml_state.build_type.get_image())
            root_import.sync_data()
        root_bind = RootBind(root)
        root_bind.setup_intermediate_config()
        root_bind.mount_kernel_file_systems()
        root_bind.mount_shared_directory()

        self.xml_state = xml_state
        self.profiles = xml_state.profiles
        self.root_bind = root_bind

        # A list of Uri references is stored inside of the System instance
        # in order to delay the Uri destructors until the System instance
        # dies. This is needed to keep bind mounted Uri locations alive
        # for System operations
        self.uri_list = []
Esempio n. 4
0
 def test_create_raises_error(self, mock_command, mock_temp, mock_data_sync,
                              mock_rmtree, mock_symlink, mock_chwon,
                              mock_makedirs, mock_path):
     mock_path.return_value = False
     mock_temp.return_value = 'tmpdir'
     mock_data_sync.side_effect = Exception
     root = RootInit('root_dir')
     root.create()
Esempio n. 5
0
    def test_create(
        self, mock_Path_create, mock_Temporary, mock_data_sync,
        mock_copy, mock_create, mock_makedev,
        mock_symlink, mock_chwon, mock_makedirs,
        mock_path
    ):
        data_sync = Mock()
        mock_data_sync.return_value = data_sync
        mock_makedev.return_value = 'makedev'
        mock_path_return = [
            True, True, True, True, False, False,
            False, False, False, False, False
        ]

        def path_exists(self):
            return mock_path_return.pop()

        mock_path.side_effect = path_exists

        mock_path.return_value = False
        mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir'
        root = RootInit('root_dir', True)
        assert root.create() is None
        assert mock_makedirs.call_args_list == [
            call('tmpdir/var/cache/kiwi'),
            call('tmpdir/dev/pts'),
            call('tmpdir/proc'),
            call('tmpdir/etc/sysconfig'),
            call('tmpdir/run'),
            call('tmpdir/sys'),
            call('tmpdir/var')
        ]
        assert mock_chwon.call_args_list == [
            call('tmpdir/var/cache/kiwi', 0, 0),
            call('tmpdir/dev/pts', 0, 0),
            call('tmpdir/proc', 0, 0),
            call('tmpdir/etc/sysconfig', 0, 0),
            call('tmpdir/run', 0, 0),
            call('tmpdir/sys', 0, 0),
            call('tmpdir/var', 0, 0)
        ]
        assert mock_symlink.call_args_list == [
            call('/proc/self/fd', 'tmpdir/dev/fd'),
            call('fd/2', 'tmpdir/dev/stderr'),
            call('fd/0', 'tmpdir/dev/stdin'),
            call('fd/1', 'tmpdir/dev/stdout')
        ]
        mock_data_sync.assert_called_once_with(
            'tmpdir/', 'root_dir'
        )
        data_sync.sync_data.assert_called_once_with(
            options=['-a', '--ignore-existing']
        )

        mock_copy.assert_called_once_with(
            '/.buildenv', 'root_dir'
        )
        mock_create.assert_called_once_with('root_dir')
Esempio n. 6
0
 def test_create_raises_error(
     self, mock_temp, mock_data_sync, mock_rmtree, mock_symlink,
     mock_mknod, mock_chwon, mock_makedirs, mock_path
 ):
     mock_path.return_value = False
     mock_temp.return_value = 'tmpdir'
     mock_data_sync.side_effect = Exception
     root = RootInit('root_dir')
     root.create()
Esempio n. 7
0
 def test_create_raises_error(self, mock_Path_create, mock_Temporary,
                              mock_data_sync, mock_symlink, mock_chwon,
                              mock_makedirs, mock_path):
     mock_path.return_value = False
     mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir'
     mock_data_sync.side_effect = Exception
     root = RootInit('root_dir')
     with raises(KiwiRootInitCreationError):
         root.create()
Esempio n. 8
0
 def import_repositories_marked_as_imageinclude(self):
     """
     Those <repository> sections which are marked with the
     imageinclude attribute should be permanently added to
     the image repository configuration
     """
     repository_sections = \
         self.xml_state.get_repository_sections_used_in_image()
     root = RootInit(root_dir=self.root_dir, allow_existing=True)
     repo = Repository(RootBind(root), self.xml_state.get_package_manager())
     repo.use_default_location()
     for xml_repo in repository_sections:
         repo_type = xml_repo.get_type()
         repo_source = xml_repo.get_source().get_path()
         repo_user = xml_repo.get_username()
         repo_secret = xml_repo.get_password()
         repo_alias = xml_repo.get_alias()
         repo_priority = xml_repo.get_priority()
         repo_dist = xml_repo.get_distribution()
         repo_components = xml_repo.get_components()
         repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
         repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
         uri = Uri(repo_source, repo_type)
         repo_source_translated = uri.translate(
             check_build_environment=False)
         if not repo_alias:
             repo_alias = uri.alias()
         log.info('Setting up image repository %s', repo_source)
         log.info('--> Type: %s', repo_type)
         log.info('--> Translated: %s', repo_source_translated)
         log.info('--> Alias: %s', repo_alias)
         repo.add_repo(repo_alias, repo_source_translated, repo_type,
                       repo_priority, repo_dist, repo_components, repo_user,
                       repo_secret, uri.credentials_file_name(),
                       repo_repository_gpgcheck, repo_package_gpgcheck)
Esempio n. 9
0
    def __init__(
        self, xml_state, root_dir, allow_existing=False
    ):
        """
        Setup and host bind new root system at given root_dir directory
        """
        log.info('Setup root directory: %s', root_dir)
        if not log.getLogLevel() == logging.DEBUG and not log.get_logfile():
            self.issue_message = dedent('''
                {headline}: {reason}

                Further details to clarify the error might have been
                reported earlier in the package manager log information
                and did not get exposed to the caller. Thus if the above
                message is not clear on the error please call kiwi with
                the --debug or --logfile option.
            ''')
        else:
            self.issue_message = '{headline}: {reason}'
        root = RootInit(
            root_dir, allow_existing
        )
        root.create()
        image_uri = xml_state.get_derived_from_image_uri()
        if image_uri:
            root_import = RootImport.new(
                root_dir, image_uri, xml_state.build_type.get_image()
            )
            root_import.sync_data()
        root_bind = RootBind(
            root
        )
        root_bind.setup_intermediate_config()
        root_bind.mount_kernel_file_systems()
        root_bind.mount_shared_directory()

        self.xml_state = xml_state
        self.profiles = xml_state.profiles
        self.root_bind = root_bind

        # A list of Uri references is stored inside of the System instance
        # in order to delay the Uri destructors until the System instance
        # dies. This is needed to keep bind mounted Uri locations alive
        # for System operations
        self.uri_list = []
Esempio n. 10
0
 def test_init_raises_error(self, mock_path):
     mock_path.return_value = True
     with raises(KiwiRootDirExists):
         RootInit('root_dir')
Esempio n. 11
0
 def test_delete(self, mock_path, mock_wipe):
     mock_path.return_value = False
     root = RootInit('root_dir')
     root.delete()
     mock_wipe.assert_called_once_with('root_dir')
Esempio n. 12
0
 def test_create(
     self, mock_command, mock_temp, mock_data_sync, mock_rmtree,
     mock_makedev, mock_symlink, mock_mknod, mock_chwon, mock_makedirs,
     mock_path
 ):
     data_sync = mock.Mock()
     mock_data_sync.return_value = data_sync
     mock_makedev.return_value = 'makedev'
     mock_path.return_value = True
     mock_temp.return_value = 'tmpdir'
     root = RootInit('root_dir', True)
     root.create()
     assert mock_makedirs.call_args_list == [
         call('tmpdir/dev/pts'),
         call('tmpdir/proc'),
         call('tmpdir/etc/sysconfig'),
         call('tmpdir/var/cache'),
         call('tmpdir/run'),
         call('tmpdir/sys')
     ]
     assert mock_chwon.call_args_list == [
         call('tmpdir/dev/pts', 0, 0),
         call('tmpdir/proc', 0, 0),
         call('tmpdir/etc/sysconfig', 0, 0),
         call('tmpdir/var/cache', 0, 0),
         call('tmpdir/run', 0, 0),
         call('tmpdir/sys', 0, 0)
     ]
     assert mock_mknod.call_args_list == [
         call('tmpdir/dev/null', 8630, 'makedev'),
         call('tmpdir/dev/zero', 8630, 'makedev'),
         call('tmpdir/dev/full', 8594, 'makedev'),
         call('tmpdir/dev/random', 8630, 'makedev'),
         call('tmpdir/dev/urandom', 8612, 'makedev'),
         call('tmpdir/dev/tty', 8630, 'makedev'),
         call('tmpdir/dev/ptmx', 8630, 'makedev'),
         call('tmpdir/dev/loop0', 24992, 'makedev'),
         call('tmpdir/dev/loop1', 24992, 'makedev'),
         call('tmpdir/dev/loop2', 24992, 'makedev'),
         call('tmpdir/dev/loop3', 25014, 'makedev'),
         call('tmpdir/dev/loop4', 25014, 'makedev')
     ]
     assert mock_symlink.call_args_list == [
         call('/proc/self/fd', 'tmpdir/dev/fd'),
         call('fd/2', 'tmpdir/dev/stderr'),
         call('fd/0', 'tmpdir/dev/stdin'),
         call('fd/1', 'tmpdir/dev/stdout'),
         call('/run', 'tmpdir/var/run')
     ]
     assert mock_command.call_args_list == [
         call([
             'cp',
             '/var/adm/fillup-templates/group.aaa_base',
             'tmpdir/etc/group'
         ]),
         call([
             'cp',
              '/var/adm/fillup-templates/passwd.aaa_base',
             'tmpdir/etc/passwd'
         ]),
         call([
             'cp',
             '/var/adm/fillup-templates/sysconfig.proxy',
             'tmpdir/etc/sysconfig/proxy'
         ])
     ]
     mock_data_sync.assert_called_once_with(
         'tmpdir/', 'root_dir'
     )
     data_sync.sync_data.assert_called_once_with(
         options=['-a', '--ignore-existing']
     )
     mock_rmtree.assert_called_once_with(
         'tmpdir', ignore_errors=True
     )
Esempio n. 13
0
 def test_init_raises_error(self, mock_path):
     mock_path.return_value = True
     RootInit('root_dir')
Esempio n. 14
0
    def test_create(
        self, mock_command, mock_temp, mock_data_sync, mock_rmtree, mock_copy,
        mock_makedev, mock_symlink, mock_chwon, mock_makedirs,
        mock_path
    ):
        data_sync = mock.Mock()
        mock_data_sync.return_value = data_sync
        mock_makedev.return_value = 'makedev'
        mock_path_return = [
            True, True, True, True, False, False, False, False, False, False, False
        ]

        def path_exists(self):
            return mock_path_return.pop()

        mock_path.side_effect = path_exists

        mock_path.return_value = False
        mock_temp.return_value = 'tmpdir'
        root = RootInit('root_dir', True)
        root.create()
        assert mock_makedirs.call_args_list == [
            call('tmpdir/var/cache/kiwi'),
            call('tmpdir/dev/pts'),
            call('tmpdir/proc'),
            call('tmpdir/etc/sysconfig'),
            call('tmpdir/run'),
            call('tmpdir/sys'),
            call('tmpdir/var')
        ]
        assert mock_chwon.call_args_list == [
            call('tmpdir/var/cache/kiwi', 0, 0),
            call('tmpdir/dev/pts', 0, 0),
            call('tmpdir/proc', 0, 0),
            call('tmpdir/etc/sysconfig', 0, 0),
            call('tmpdir/run', 0, 0),
            call('tmpdir/sys', 0, 0),
            call('tmpdir/var', 0, 0)
        ]
        assert mock_symlink.call_args_list == [
            call('/proc/self/fd', 'tmpdir/dev/fd'),
            call('fd/2', 'tmpdir/dev/stderr'),
            call('fd/0', 'tmpdir/dev/stdin'),
            call('fd/1', 'tmpdir/dev/stdout'),
            call('/run', 'tmpdir/var/run')
        ]
        assert mock_command.call_args_list == [
            call(['mkdir', '-p', 'root_dir']),
            call([
                'cp',
                '/var/adm/fillup-templates/group.aaa_base',
                'tmpdir/etc/group'
            ]),
            call([
                'cp',
                '/var/adm/fillup-templates/passwd.aaa_base',
                'tmpdir/etc/passwd'
            ]),
            call([
                'cp',
                '/var/adm/fillup-templates/sysconfig.proxy',
                'tmpdir/etc/sysconfig/proxy'
            ])
        ]
        mock_data_sync.assert_called_once_with(
            'tmpdir/', 'root_dir'
        )
        data_sync.sync_data.assert_called_once_with(
            options=['-a', '--ignore-existing']
        )
        mock_rmtree.assert_called_once_with(
            'tmpdir', ignore_errors=True
        )

        mock_copy.assert_called_once_with(
            '/.buildenv', 'root_dir'
        )
Esempio n. 15
0
 def test_create(self, mock_path, mock_command):
     mock_path.return_value = False
     root = RootInit('root_dir')
     mock_path.return_value = True
     root.create()
     assert mock_command.called
Esempio n. 16
0
 def test_create_raises_error(self, mock_path, mock_command):
     mock_path.return_value = False
     mock_command.side_effect = KiwiRootInitCreationError('some-error')
     root = RootInit('root_dir')
     root.create()
Esempio n. 17
0
    def test_create(self, mock_command, mock_temp, mock_data_sync, mock_rmtree,
                    mock_copy, mock_makedev, mock_symlink, mock_chwon,
                    mock_makedirs, mock_path):
        data_sync = mock.Mock()
        mock_data_sync.return_value = data_sync
        mock_makedev.return_value = 'makedev'
        mock_path_return = [
            True, True, True, True, False, False, False, False, False, False,
            False
        ]

        def path_exists(self):
            return mock_path_return.pop()

        mock_path.side_effect = path_exists

        mock_path.return_value = False
        mock_temp.return_value = 'tmpdir'
        root = RootInit('root_dir', True)
        root.create()
        assert mock_makedirs.call_args_list == [
            call('tmpdir/var/cache/kiwi'),
            call('tmpdir/dev/pts'),
            call('tmpdir/proc'),
            call('tmpdir/etc/sysconfig'),
            call('tmpdir/run'),
            call('tmpdir/sys'),
            call('tmpdir/var')
        ]
        assert mock_chwon.call_args_list == [
            call('tmpdir/var/cache/kiwi', 0, 0),
            call('tmpdir/dev/pts', 0, 0),
            call('tmpdir/proc', 0, 0),
            call('tmpdir/etc/sysconfig', 0, 0),
            call('tmpdir/run', 0, 0),
            call('tmpdir/sys', 0, 0),
            call('tmpdir/var', 0, 0)
        ]
        assert mock_symlink.call_args_list == [
            call('/proc/self/fd', 'tmpdir/dev/fd'),
            call('fd/2', 'tmpdir/dev/stderr'),
            call('fd/0', 'tmpdir/dev/stdin'),
            call('fd/1', 'tmpdir/dev/stdout'),
            call('/run', 'tmpdir/var/run')
        ]
        assert mock_command.call_args_list == [
            call(['mkdir', '-p', 'root_dir']),
            call([
                'cp', '/var/adm/fillup-templates/group.aaa_base',
                'tmpdir/etc/group'
            ]),
            call([
                'cp', '/var/adm/fillup-templates/passwd.aaa_base',
                'tmpdir/etc/passwd'
            ]),
            call([
                'cp', '/var/adm/fillup-templates/sysconfig.proxy',
                'tmpdir/etc/sysconfig/proxy'
            ])
        ]
        mock_data_sync.assert_called_once_with('tmpdir/', 'root_dir')
        data_sync.sync_data.assert_called_once_with(
            options=['-a', '--ignore-existing'])
        mock_rmtree.assert_called_once_with('tmpdir', ignore_errors=True)

        mock_copy.assert_called_once_with('/.buildenv', 'root_dir')