示例#1
0
def test_loop_support():
    output = 'NAME="/dev/loop0" SIZE="10M" TYPE="loop" MOUNTPOINT="" PARTTYPE="" FSTYPE="" MODEL=""'
    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(output)
    assert len(disks) == 1
示例#2
0
def test_do_not_show_squashfs():

    output = 'NAME="/dev/loop1" SIZE="41.1M" TYPE="loop" MOUNTPOINT="/snap/platform/180821" PARTTYPE="" FSTYPE="squashfs" MODEL=""'

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(output)

    assert len(disks) == 0
示例#3
0
def test_empty_disk():

    output = 'NAME="/dev/sda" SIZE="3.7G" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="" MODEL="BLANK DISK"'

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(output)

    assert len(disks[0].partitions) == 0
示例#4
0
def test_list():

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(default_output)
    assert len(disks) == 5
    assert len(disks[0].partitions) == 4
    assert disks[1].partitions[2].mount_point == '/opt/disk/external'
    assert len(disks[1].partitions) == 3
示例#5
0
def test_default_empty_disk_name():
    lsblk_output = 'NAME="/dev/sdb" SIZE="14.4G" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="" MODEL=""\n'
    lsblk_output += 'NAME="/dev/sdb1" SIZE="14.4G" TYPE="part" MOUNTPOINT="" PARTTYPE="0x83" FSTYPE="ext4" MODEL=""\n'
    lsblk_output += 'NAME="/dev/sdb2" SIZE="41.8M" TYPE="part" MOUNTPOINT="" PARTTYPE="0xc" FSTYPE="vfat" MODEL=""'

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(lsblk_output)
    assert disks[0].name == 'Disk'
示例#6
0
def test_do_not_show_disks_with_root_partition():
    lsblk_output = 'NAME="/dev/sdb" SIZE="14.4G" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="" MODEL=""\n'
    lsblk_output += 'NAME="/dev/sdb1" SIZE="14.4G" TYPE="part" MOUNTPOINT="/" PARTTYPE="0x83" FSTYPE="ext4" MODEL=""\n'
    lsblk_output += 'NAME="/dev/sdb2" SIZE="41.8M" TYPE="part" MOUNTPOINT="" PARTTYPE="0xc" FSTYPE="vfat" MODEL=""'

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(lsblk_output)

    assert len(disks) == 0
示例#7
0
    def __init__(self, debug=False, config_dir=None):
        self.platform_config = PlatformConfig(config_dir=config_dir)

        if not logger.factory_instance:
            console = True if debug else False
            level = logging.DEBUG if debug else logging.INFO
            logger.init(level, console, join(self.platform_config.get_platform_log()))

        self.user_platform_config = PlatformUserConfig(self.platform_config.get_user_config())

        self.log_aggregator = Aggregator(self.platform_config)

        self.platform_app_paths = AppPaths(PLATFORM_APP_NAME, self.platform_config)
        self.platform_app_paths.get_data_dir()
        self.versions = Versions(self.platform_config)
        self.redirect_service = RedirectService(self.user_platform_config, self.versions)
        self.port_config = PortConfig(self.platform_app_paths.get_data_dir())

        self.nat_pmp_port_mapper = NatPmpPortMapper()
        self.upnp_port_mapper = UpnpPortMapper(UPnP())
        self.port_mapper_factory = PortMapperFactory(self.nat_pmp_port_mapper, self.upnp_port_mapper)
        self.port_drill_factory = PortDrillFactory(self.user_platform_config, self.port_config,
                                                   self.port_mapper_factory)
        self.device_info = DeviceInfo(self.user_platform_config, self.port_config)
        if self.platform_config.get_installer() == 'sam':
            self.sam = SamStub(self.platform_config, self.device_info)
        else:
            self.sam = Snap(self.platform_config, self.device_info)
        self.platform_cron = PlatformCron(self.platform_config)
        self.systemctl = Systemctl(self.platform_config)
        self.ldap_auth = LdapAuth(self.platform_config, self.systemctl)
        self.event_trigger = EventTrigger(self.sam, self.platform_config)
        self.nginx = Nginx(self.platform_config, self.systemctl, self.device_info)
        self.certbot_genetator = CertbotGenerator(self.platform_config, self.user_platform_config,
                                                  self.device_info, self.sam)
        self.tls = CertificateGenerator(self.platform_config, self.user_platform_config, self.device_info, self.nginx,
                                        self.certbot_genetator)
        
        self.device = Device(self.platform_config, self.user_platform_config, self.redirect_service,
                             self.port_drill_factory, self.sam, self.platform_cron, self.ldap_auth,
                             self.event_trigger, self.tls, self.nginx)

        self.internal = Internal(self.platform_config, self.device, self.redirect_service, self.log_aggregator)
        self.path_checker = PathChecker(self.platform_config)
        self.lsblk = Lsblk(self.platform_config, self.path_checker)
        self.hardware = Hardware(self.platform_config, self.event_trigger,
                                 self.lsblk, self.path_checker, self.systemctl)
        self.network = Network()
        self.public = Public(self.platform_config, self.user_platform_config, self.device, self.device_info, self.sam,
                             self.hardware, self.redirect_service, self.log_aggregator, self.certbot_genetator,
                             self.port_mapper_factory, self.network, self.port_config)
        self.udev = Udev(self.platform_config)
示例#8
0
def test_list():

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(default_output)
    assert len(disks) == 5
    disk = [d for d in disks if d.device == '/dev/sda'][0]
    assert len(disk.partitions) == 4

    disk = [d for d in disks if d.device == '/dev/sdb'][0]
    assert disk.partitions[2].mount_point == '/opt/disk/external'
    assert len(disk.partitions) == 3
示例#9
0
def test_raid():
    raid_output = '''NAME="/dev/sda" SIZE="1.8T" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="linux_raid_member" MODEL="WDC WD20EFRX-68E"
NAME="/dev/sdb" SIZE="1.8T" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="linux_raid_member" MODEL="WDC WD20EFRX-68E"
NAME="/dev/sdc" SIZE="1.8T" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="linux_raid_member" MODEL="WDC WD20EFRX-68E"
NAME="/dev/sdd" SIZE="1.8T" TYPE="disk" MOUNTPOINT="" PARTTYPE="" FSTYPE="linux_raid_member" MODEL="WDC WD20EFRX-68E"
NAME="/dev/md0" SIZE="3.7T" TYPE="raid10" MOUNTPOINT="/mnt/md0" PARTTYPE="" FSTYPE="ext4" MODEL=""
NAME="/dev/md0" SIZE="3.7T" TYPE="raid10" MOUNTPOINT="/mnt/md0" PARTTYPE="" FSTYPE="ext4" MODEL=""
NAME="/dev/md0" SIZE="3.7T" TYPE="raid10" MOUNTPOINT="/mnt/md0" PARTTYPE="" FSTYPE="ext4" MODEL=""
NAME="/dev/md0" SIZE="3.7T" TYPE="raid10" MOUNTPOINT="/mnt/md0" PARTTYPE="" FSTYPE="ext4" MODEL=""'''

    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    disks = lsblk.available_disks(raid_output)
    assert len(disks) == 1
    assert len(disks[0].partitions) == 1
    assert disks[0].partitions[0].mount_point == '/mnt/md0'
示例#10
0
    def __init__(self, debug=False):
        self.platform_config = PlatformConfig()

        if not logger.factory_instance:
            console = True if debug else False
            level = logging.DEBUG if debug else logging.INFO
            logger.init(level, console, join(self.platform_config.get_platform_log()))

        self.user_platform_config = PlatformUserConfig(self.platform_config.get_user_config())

        self.log_aggregator = Aggregator(self.platform_config)

        self.platform_app_paths = AppPaths(PLATFORM_APP_NAME, self.platform_config)
        self.platform_app_paths.get_data_dir()

        self.redirect_service = RedirectService(self.user_platform_config, platform_version)
        self.port_config = PortConfig(self.platform_app_paths.get_data_dir())

        self.nat_pmp_port_mapper = NatPmpPortMapper()
        self.upnp_port_mapper = UpnpPortMapper(UPnP())
        self.port_drill_factory = PortDrillFactory(self.user_platform_config, self.port_config,
                                                   self.nat_pmp_port_mapper, self.upnp_port_mapper)
        self.info = DeviceInfo(self.user_platform_config, self.port_config)
        self.sam = SamStub(self.platform_config, self.info)
        self.platform_cron = PlatformCron(self.platform_config)
        self.ldap_auth = LdapAuth(self.platform_config)
        self.event_trigger = EventTrigger(self.sam)
        self.nginx = Nginx(self.platform_config)
        self.tls = Tls(self.platform_config, self.info, self.nginx)
        
        self.device = Device(self.platform_config, self.user_platform_config, self.redirect_service,
                             self.port_drill_factory, self.sam, self.platform_cron, self.ldap_auth,
                             self.event_trigger, self.tls)

        self.internal = Internal(self.platform_config, self.device, self.redirect_service, self.log_aggregator)
        self.path_checker = PathChecker(self.platform_config)
        self.lsblk = Lsblk(self.platform_config, self.path_checker)
        self.hardware = Hardware(self.platform_config, self.event_trigger, self.lsblk, self.path_checker)

        self.public = Public(self.platform_config, self.user_platform_config, self.device, self.info, self.sam, self.hardware,
                             self.redirect_service, self.log_aggregator)
        self.udev = Udev(self.platform_config)
示例#11
0
def test_is_external_disk_detached():
    platform_config = PlatformConfig(CONFIG_DIR)
    lsblk = Lsblk(platform_config, PathChecker(platform_config))

    assert not lsblk.is_external_disk_attached(default_output,
                                               '/opt/disk/detached')
示例#12
0
def get_lsblk():
    platform_config = PlatformConfig(CONFIG_DIR)
    return Lsblk(platform_config, PathChecker(platform_config))