예제 #1
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 = []
예제 #2
0
파일: prepare.py 프로젝트: Conan-Kudo/kiwi
    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 = []
예제 #3
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()
예제 #4
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()
예제 #5
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()
예제 #6
0
    def test_create(self, mock_Path_create, mock_temp, mock_data_sync,
                    mock_rmtree, 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_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')
        ]
        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')
        mock_create.assert_called_once_with('root_dir')
예제 #7
0
파일: prepare.py 프로젝트: petrpavlu/kiwi
    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 = []
예제 #8
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
     )
예제 #9
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'
        )
예제 #10
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
예제 #11
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()