Пример #1
0
    def test_main_kexec_reboot(self, mock_Fstab, mock_Command_run,
                               mock_logger_setup,
                               mock_get_migration_config_file,
                               mock_os_path_exists):
        def skip_device(device):
            if '/dev/mynode' in device:
                return False
            return True

        mock_os_path_exists.side_effect = skip_device
        fstab = Fstab()
        fstab_mock = Mock()
        fstab_mock.read.return_value = fstab.read('../data/system-root.fstab')
        fstab_mock.get_devices.return_value = fstab.get_devices()
        mock_Fstab.return_value = fstab_mock
        mock_get_migration_config_file.return_value = \
            '../data/migration-config.yml'
        main()
        assert mock_Command_run.call_args_list == [
            call(['systemctl', 'status', '-l', '--all'], raise_on_error=False),
            call(['systemctl', 'stop', 'suse-migration-console-log'],
                 raise_on_error=False),
            call(['umount', '--lazy', '/system-root/home'],
                 raise_on_error=False),
            call(['umount', '--lazy', '/system-root/boot/efi'],
                 raise_on_error=False),
            call(['umount', '--lazy', '/system-root/'], raise_on_error=False),
            call(['systemctl', 'kexec'])
        ]
Пример #2
0
 def test_main_force_reboot(self, mock_Fstab, mock_Command_run, mock_info,
                            mock_warning, mock_get_migration_config_file):
     fstab = Fstab()
     fstab_mock = Mock()
     fstab_mock.read.return_value = fstab.read('../data/system-root.fstab')
     fstab_mock.get_devices.return_value = fstab.get_devices()
     mock_Fstab.return_value = fstab_mock
     mock_Command_run.side_effect = [
         MagicMock(),
         MagicMock(),
         MagicMock(),
         MagicMock(), Exception, None
     ]
     mock_get_migration_config_file.return_value = \
         '../data/migration-config.yml'
     main()
     assert mock_info.called
     assert mock_Command_run.call_args_list == [
         call(['systemctl', 'status', '-l', '--all'], raise_on_error=False),
         call(['umount', '--lazy', '/system-root/home'],
              raise_on_error=False),
         call(['umount', '--lazy', '/system-root/boot/efi'],
              raise_on_error=False),
         call(['umount', '--lazy', '/system-root/'], raise_on_error=False),
         call(['systemctl', 'reboot']),
         call(['systemctl', '--force', 'reboot'])
     ]
     mock_warning.assert_called_once_with('Reboot system: [Force Reboot]')
Пример #3
0
 def test_main_skip_reboot_due_to_debug_file_set(self, mock_MigrationConfig,
                                                 mock_Command_run,
                                                 mock_logger_setup):
     config = Mock()
     config.is_debug_requested.return_value = True
     mock_MigrationConfig.return_value = config
     with self._caplog.at_level(logging.INFO):
         main()
         assert 'Reboot skipped due to debug flag set' in self._caplog.text
Пример #4
0
 def test_main_skip_reboot_due_to_debug_file_set(self, mock_MigrationConfig,
                                                 mock_Command_run,
                                                 mock_info, mock_warning):
     config = Mock()
     config.is_debug_requested.return_value = True
     mock_MigrationConfig.return_value = config
     main()
     assert mock_info.call_args_list[1] == call(
         'Reboot skipped due to debug flag set')
Пример #5
0
    def test_main_force_reboot(
        self, mock_Fstab, mock_get_migration_config_file,
        mock_logger_setup, mock_Command_run, mock_os_path_exists
    ):
        def skip_device(device):
            if '/dev/mynode' in device:
                return False
            return True

        mock_os_path_exists.side_effect = skip_device
        fstab = Fstab()
        fstab_mock = Mock()
        fstab_mock.read.return_value = fstab.read('../data/system-root.fstab')
        fstab_mock.get_devices.return_value = fstab.get_devices()
        mock_Fstab.return_value = fstab_mock
        mock_Command_run.side_effect = [
            MagicMock(),
            MagicMock(),
            MagicMock(),
            MagicMock(),
            MagicMock(),
            Exception,
            None
        ]
        mock_get_migration_config_file.return_value = \
            '../data/migration-config-hard-reboot.yml'
        with self._caplog.at_level(logging.WARNING):
            main()
            assert mock_Command_run.call_args_list == [
                call(
                    ['systemctl', 'status', '-l', '--all'],
                    raise_on_error=False
                ),
                call(
                    ['systemctl', 'stop', 'suse-migration-console-log'],
                    raise_on_error=False
                ),
                call(
                    ['umount', '--lazy', '/system-root/boot/efi'],
                    raise_on_error=False
                ),
                call(
                    ['umount', '--lazy', '/system-root/home'],
                    raise_on_error=False
                ),
                call(
                    ['umount', '--lazy', '/system-root/'],
                    raise_on_error=False
                ),
                call(['systemctl', 'reboot']),
                call(['systemctl', '--force', 'reboot'])
            ]
            assert 'Reboot system: [Force Reboot]' in self._caplog.text
Пример #6
0
 def test_main_kexec_reboot(self, mock_Fstab, mock_Command_run, mock_info,
                            mock_get_migration_config_file):
     fstab = Fstab()
     fstab_mock = Mock()
     fstab_mock.read.return_value = fstab.read('../data/system-root.fstab')
     fstab_mock.get_devices.return_value = fstab.get_devices()
     mock_Fstab.return_value = fstab_mock
     mock_get_migration_config_file.return_value = \
         '../data/migration-config.yml'
     main()
     assert mock_info.called
     assert mock_Command_run.call_args_list == [
         call(['systemctl', 'status', '-l', '--all'], raise_on_error=False),
         call(['umount', '--lazy', '/system-root/home'],
              raise_on_error=False),
         call(['umount', '--lazy', '/system-root/boot/efi'],
              raise_on_error=False),
         call(['umount', '--lazy', '/system-root/'], raise_on_error=False),
         call(['systemctl', 'reboot'])
     ]