<commit_before>from collections import namedtuple
from backup.tasks import mysql_binlog_save
from workflow.steps.mysql.util import get_replication_information_from_file, \
    change_master_to, start_slave
from disk import RestoreSnapshot, AddDiskPermissionsRestoredDisk, \
    UnmountOldestExportRestore, MountNewerExportRestore, ConfigureFstabRestore
from zabbix import ZabbixStep
from base import BaseInstanceStep


class MySQLStep(BaseInstanceStep):

    def undo(self):
        pass


class SetMasterRestore(MySQLStep):

    def __unicode__(self):
        return "Set master position..."

    def do(self):
        pair = self.restore.instances_pairs()[0]
        log_file, log_pos = get_replication_information_from_file(
            pair.master.hostname
        )

        secondary = pair.master
        if self.instance == secondary:
            secondary = pair.slave

        change_master_to(
            self.instance, secondary.hostname.address, log_file, log_pos
        )


class StartSlave(MySQLStep):

    def __unicode__(self):
        return "Start slave..."

    def do(self):
        start_slave(self.instance)


class ConfigureFoxHARestore(MySQLStep):

    def __unicode__(self):
        return "Configuring FoxHA..."

    def do(self):
        driver = self.infra.get_driver()
        if self.restore.is_master(self.instance):
            driver.set_master(self.instance)
        else:
            driver.set_read_ip(self.instance)


class SaveMySQLBinlog(MySQLStep):

    def __unicode__(self):
        return "Saving binlog position..."

    @property
    def is_valid(self):
        return self.restore.is_master(self.instance)

    def do(self):
        if not self.is_valid:
            return

        driver = self.infra.get_driver()
        client = driver.get_client(self.instance)
        mysql_binlog_save(client, self.instance, self.host)


class RestoreSnapshotMySQL(RestoreSnapshot):

    @property
    def snapshot(self):
        return self.restore.group.backups.first()

    @property
    def disk_host(self):
        return self.host


class DiskRestoreMySQL(MySQLStep):

    @property
    def is_valid(self):
        return True


class AddDiskPermissionsRestoredDiskMySQL(
    DiskRestoreMySQL, AddDiskPermissionsRestoredDisk
):
    pass


class UnmountOldestExportRestoreMySQL(
    DiskRestoreMySQL, UnmountOldestExportRestore
):
    pass


class MountNewerExportRestoreMySQL(DiskRestoreMySQL, MountNewerExportRestore):
    pass


class ConfigureFstabRestoreMySQL(ConfigureFstabRestore):
    pass


class ZabbixVip(ZabbixStep):

    @property
    def is_valid(self):
        return self.instance == self.infra.instances.first()
<commit_msg>Configure FSTAB in MySQL FoxHA Restore<commit_after>from backup.tasks import mysql_binlog_save
from workflow.steps.mysql.util import get_replication_information_from_file, \
    change_master_to, start_slave
from disk import RestoreSnapshot, AddDiskPermissionsRestoredDisk, \
    UnmountOldestExportRestore, MountNewerExportRestore, ConfigureFstabRestore
from zabbix import ZabbixStep
from base import BaseInstanceStep


class MySQLStep(BaseInstanceStep):

    def undo(self):
        pass


class SetMasterRestore(MySQLStep):

    def __unicode__(self):
        return "Set master position..."

    def do(self):
        pair = self.restore.instances_pairs()[0]
        log_file, log_pos = get_replication_information_from_file(
            pair.master.hostname
        )

        secondary = pair.master
        if self.instance == secondary:
            secondary = pair.slave

        change_master_to(
            self.instance, secondary.hostname.address, log_file, log_pos
        )


class StartSlave(MySQLStep):

    def __unicode__(self):
        return "Start slave..."

    def do(self):
        start_slave(self.instance)


class ConfigureFoxHARestore(MySQLStep):

    def __unicode__(self):
        return "Configuring FoxHA..."

    def do(self):
        driver = self.infra.get_driver()
        if self.restore.is_master(self.instance):
            driver.set_master(self.instance)
        else:
            driver.set_read_ip(self.instance)


class SaveMySQLBinlog(MySQLStep):

    def __unicode__(self):
        return "Saving binlog position..."

    @property
    def is_valid(self):
        return self.restore.is_master(self.instance)

    def do(self):
        if not self.is_valid:
            return

        driver = self.infra.get_driver()
        client = driver.get_client(self.instance)
        mysql_binlog_save(client, self.instance, self.host)


class RestoreSnapshotMySQL(RestoreSnapshot):

    @property
    def snapshot(self):
        return self.restore.group.backups.first()

    @property
    def disk_host(self):
        return self.host


class DiskRestoreMySQL(MySQLStep):

    @property
    def is_valid(self):
        return True


class AddDiskPermissionsRestoredDiskMySQL(
    DiskRestoreMySQL, AddDiskPermissionsRestoredDisk
):
    pass


class UnmountOldestExportRestoreMySQL(
    DiskRestoreMySQL, UnmountOldestExportRestore
):
    pass


class MountNewerExportRestoreMySQL(DiskRestoreMySQL, MountNewerExportRestore):
    pass


class ConfigureFstabRestoreMySQL(DiskRestoreMySQL, ConfigureFstabRestore):
    pass


class ZabbixVip(ZabbixStep):

    @property
    def is_valid(self):
        return self.instance == self.infra.instances.first()

{'fraction_non_alphanumeric': 0.07865377463741167, 'fraction_numerical': 0.0003718854592785422, 'mean_word_length': 3.1155317521040553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3378659', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1574, 'n_words': 320}