def test_get_rpi_model(cpu):
    from kano.utils.hardware import get_rpi_model

    if is_revision_valid(cpu.revision):
        assert (
            get_rpi_model(use_cached=False) ==
            cpu.platform_key
        )
    else:
        assert (
            get_rpi_model(use_cached=False) ==
            'unknown revision: {}'.format(cpu.revision).strip()
        )
def test_get_rpi_model_w_revision(cpu):
    from kano.utils.hardware import get_rpi_model

    if not cpu.revision:
        return  # Same case as above

    if is_revision_valid(cpu.revision):
        assert (
            get_rpi_model(revision=cpu.revision, use_cached=False) ==
            cpu.platform_key
        )
    else:
        assert (
            get_rpi_model(revision=cpu.revision, use_cached=False) ==
            'unknown revision: {}'.format(cpu.revision).strip()
        )
def get_board_props(board_name=None):
    if not board_name:
        board_name = get_rpi_model()

    cpu_profile = get_board_property(board_name, 'cpu_profile')

    if not cpu_profile:
        cpu_profile = RPI_1_CPU_PROFILE

    board_module = re.sub(r'[-/ ]', '_', cpu_profile).lower()

    try:
        board = importlib.import_module(
            '{}.{}'.format(__name__, board_module)
        )
    except ImportError:
        logger.error('Board not found')
        return None

    required_props = ['CLOCKING', 'DEFAULT_CONFIG']

    for prop in required_props:
        if not hasattr(board, prop):
            logger.error('No {} data in board config'
                         .format(prop.replace('_', ' ').lower()))
            return None

    # TODO: Validate board info

    return board
Beispiel #4
0
def get_board_props(board_name=None):
    if not board_name:
        board_name = get_rpi_model()

    cpu_profile = get_board_property(board_name, 'cpu_profile')

    if not cpu_profile:
        cpu_profile = RPI_1_CPU_PROFILE

    board_module = re.sub(r'[-/ ]', '_', cpu_profile).lower()

    try:
        board = importlib.import_module('{}.{}'.format(__name__, board_module))
    except ImportError:
        logger.error('Board not found')
        return None

    required_props = ['CLOCKING', 'DEFAULT_CONFIG']

    for prop in required_props:
        if not hasattr(board, prop):
            logger.error('No {} data in board config'.format(
                prop.replace('_', ' ').lower()))
            return None

    # TODO: Validate board info

    return board
def check_clock_config_matches_chip():
    """  Check if the clock setting in the current config is supported on
         the chip we have booted on.
         If not, try to restore from a backup file. If that is not possible,
         set to a default appropraite to this chip.
    """

    current_model = get_rpi_model()

    current_model_profile = get_board_property(current_model, 'cpu_profile')

    if current_model_profile is None:
        logger.error("Unknown pi model {}, not messing with config.txt",
                     current_model)
        return False

    old_model_profile = overclock.get_matching_board_profile()
    logger.debug("Checked the two boards, the old one is {} type " \
                 "and the new one is {} type"
                 .format(old_model_profile, current_model_profile))

    if current_model_profile == old_model_profile:
        # Config looks good
        return False

    new_config = BootConfig.new_from_model(current_model)
    if old_model_profile:
        logger.info("Config settings match for {} but running {}. "
                    "Backing up old settings and restoring new settings"
                    .format(old_model_profile, current_model_profile))

        old_config = BootConfig.new_from_model(old_model_profile)
        overclock.backup_overclock_values(old_config)

    restore_config(new_config, current_model)

    return True  # we need to reboot if we get here
import kano.utils.hardware as hw

from tests.fixtures.alsa_config import *
from tests.fixtures.edid_data import *


REASON_NOT_IMPLEMENTED = '' \
    'Test case is not yet implemented, but a note of the requirement was made.'

REASON_REQUIRES_KANO_OS = '' \
    'Function makes system wide changes in Kano OS and was designed to' \
    ' be executed in that environment, e.g. systemd, config files, etc.'


require_rpi = unittest.skipIf(
    hw.get_rpi_model().lower().startswith('error') or
    hw.get_rpi_model().lower().startswith('unknown'),
    'Test must be run on a RPi'
)


@contextmanager
def mock_file(file_path, mock_data=None):
    original_file = file_path + '.orig'

    if os.path.exists(file_path):
        shutil.move(file_path, original_file)

    if mock_data:
        with open(file_path, 'w') as mock_file_handle:
            mock_file_handle.write(mock_data)
Beispiel #7
0
from contextlib import contextmanager, wraps

import kano.utils.hardware as hw

def test_print(s):
    print '\n        ........{}'.format(s)


@contextmanager
def mock_file(file_path, mock_data=None):
    original_file = file_path + '.orig'

    if os.path.exists(file_path):
        shutil.move(file_path, original_file)

    if mock_data:
        with open(file_path, 'w') as mock_file_handle:
            mock_file_handle.write(mock_data)

    yield

    if os.path.exists(file_path):
        os.remove(file_path)

    if os.path.exists(original_file):
        shutil.move(original_file, file_path)


require_rpi = unittest.skipIf(hw.get_rpi_model() == 'Error getting model name',
                              'Test must be run on a RPi')
Beispiel #8
0
import kano.utils.hardware as hw

from tests.fixtures.alsa_config import *
from tests.fixtures.edid_data import *


REASON_NOT_IMPLEMENTED = '' \
    'Test case is not yet implemented, but a note of the requirement was made.'

REASON_REQUIRES_KANO_OS = '' \
    'Function makes system wide changes in Kano OS and was designed to' \
    ' be executed in that environment, e.g. systemd, config files, etc.'

require_rpi = unittest.skipIf(
    hw.get_rpi_model().lower().startswith('error')
    or hw.get_rpi_model().lower().startswith('unknown'),
    'Test must be run on a RPi')


@contextmanager
def mock_file(file_path, mock_data=None):
    original_file = file_path + '.orig'

    if os.path.exists(file_path):
        shutil.move(file_path, original_file)

    if mock_data:
        with open(file_path, 'w') as mock_file_handle:
            mock_file_handle.write(mock_data)
Beispiel #9
0
def get_model_name():
    model = get_rpi_model()
    model_name = get_board_property(model, 'name')

    return model_name
Beispiel #10
0
def get_model_name():
    model = get_rpi_model()
    model_name = get_board_property(model, 'name')

    return model_name
Beispiel #11
0
import kano.utils.hardware as hw


def test_print(s):
    print '\n        ........{}'.format(s)


@contextmanager
def mock_file(file_path, mock_data=None):
    original_file = file_path + '.orig'

    if os.path.exists(file_path):
        shutil.move(file_path, original_file)

    if mock_data:
        with open(file_path, 'w') as mock_file_handle:
            mock_file_handle.write(mock_data)

    yield

    if os.path.exists(file_path):
        os.remove(file_path)

    if os.path.exists(original_file):
        shutil.move(original_file, file_path)


require_rpi = unittest.skipIf(hw.get_rpi_model() == 'Error getting model name',
                              'Test must be run on a RPi')