예제 #1
0
 def configure_primary_replication_node(self, pwd):
     # Configure primary replication node
     with SSHExpect(self.appliance) as interaction:
         interaction.send('ap')
         interaction.answer('Press any key to continue.',
                            '',
                            timeout=AP_WELCOME_SCREEN_TIMEOUT)
         # 6/8 for Configure Database Replication
         interaction.answer(
             'Choose the advanced setting: ',
             VersionPicker({
                 LOWEST: 6,
                 '5.10': 8,
                 '5.11.2.1': 6
             }))
         interaction.answer('Choose the database replication operation: ',
                            '1')
         answer_cluster_related_questions(interaction,
                                          node_uid='1',
                                          db_name='',
                                          db_username='',
                                          db_password=pwd)
         interaction.answer(
             r'Enter the primary database hostname or IP address: \|.*\| ',
             self.appliance.hostname)
         interaction.answer(
             re.escape(
                 'Apply this Replication Server Configuration? (Y/N): '),
             'y')
         interaction.answer('Press any key to continue.', '')
예제 #2
0
 def backup(self, database_path="/tmp/evm_db.backup"):
     """Backup VMDB database using appliance console"""
     if BZ(1741481).blocks:
         self.appliance.ssh_client.run_command("""
             grep 'local replication all peer map=usermap' \
                     /var/lib/pgsql/data/pg_hba.conf ||
             echo 'local replication all peer map=usermap' \
                     >> /var/lib/pgsql/data/pg_hba.conf""")
         self.appliance.db_service.reload()
     self.logger.info('Backing up database using appliance console')
     with SSHExpect(self.appliance) as interaction:
         interaction.send('ap')
         interaction.answer(re.escape('Press any key to continue.'),
                            '',
                            timeout=40)
         interaction.answer(re.escape('Choose the advanced setting: '),
                            VersionPicker({
                                LOWEST: 4,
                                '5.11.2.1': 2
                            }))
         interaction.answer(
             re.escape('Choose the backup output file destination: |1| '),
             '1')
         interaction.answer(
             re.escape('Enter the location to save the backup file to: '
                       '|/tmp/evm_db.backup| '), database_path)
         interaction.answer(re.escape('Press any key to continue.'),
                            '',
                            timeout=240)
예제 #3
0
def test_appliance_console_backup_restore_db_local(
        request, two_appliances_one_with_providers):
    """ Test single appliance backup and restore, configures appliance with providers,
    backs up database, restores it to fresh appliance and checks for matching providers.

    Polarion:
        assignee: jhenner
        casecomponent: Configuration
        caseimportance: critical
        initialEstimate: 1/2h
    """
    appl1, appl2 = two_appliances_one_with_providers
    appl1_provider_names = set(appl1.managed_provider_names)

    backup_file_name = f'/tmp/backup.{fauxfactory.gen_alphanumeric()}.dump'
    appl1.db.backup(backup_file_name)

    # Transfer v2_key and db backup from first appliance to second appliance
    fetch_v2key(appl1, appl2)
    fetch_db_local(appl1, appl2, backup_file_name)

    # Restore DB on the second appliance
    appl2.evmserverd.stop()
    appl2.db.drop()
    appl2.db.create()

    with SSHExpect(appl2) as interaction:
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=40)
        interaction.answer('Choose the advanced setting: ',
                           VersionPicker({
                               LOWEST: '6',
                               '5.11.2.1': 4
                           }))
        interaction.answer(
            re.escape('Choose the restore database file source: |1| '), '')
        interaction.answer(
            re.escape(
                'Enter the location of the local restore file: |/tmp/evm_db.backup| '
            ), backup_file_name)
        interaction.answer(
            re.escape(
                'Should this file be deleted after completing the restore? (Y/N): '
            ), 'n')
        interaction.answer(
            re.escape(
                'Are you sure you would like to restore the database? (Y/N): '
            ), 'y')
        interaction.answer('Press any key to continue.', '', timeout=80)

    appl2.evmserverd.start()
    appl2.wait_for_web_ui()
    appl2.wait_for_api_available()
    # Assert providers on the second appliance
    assert set(appl2.managed_provider_names) == appl1_provider_names, (
        'Restored DB is missing some providers')
    # Verify that existing provider can detect new VMs on the second appliance
    virtual_crud = provider_app_crud(VMwareProvider, appl2)
    vm = provision_vm(request, virtual_crud)
    assert vm.mgmt.is_running, "vm not running"
예제 #4
0
    def reconfigure_primary_replication_node(self, pwd):
        # Configure primary replication node
        with SSHExpect(self.appliance) as interaction:
            interaction.send('ap')
            interaction.answer('Press any key to continue.', '', timeout=20)
            interaction.answer('Choose the advanced setting: ',
                               '6' if self.appliance.version < '5.10' else '8')
            # 6/8 for Configure Database Replication

            interaction.answer('Choose the database replication operation: ',
                               '1')
            answer_cluster_related_questions(interaction,
                                             node_uid='1',
                                             db_name='',
                                             db_username='',
                                             db_password=pwd)
            interaction.answer(
                r'Enter the primary database hostname or IP address: \|.*\| ',
                self.appliance.hostname)
            # Warning: File /etc/repmgr.conf exists. Replication is already configured
            interaction.answer(resc('Continue with configuration? (Y/N): '),
                               'y')
            interaction.answer(
                resc('Apply this Replication Server Configuration? (Y/N): '),
                'y')
            interaction.answer('Press any key to continue.', '')
예제 #5
0
    def configure_standby_replication_node(self, pwd, primary_ip):
        # Configure secondary (standby) replication node
        with SSHExpect(self.appliance) as interaction:
            interaction.send('ap')
            interaction.answer('Press any key to continue.', '', timeout=20)
            interaction.answer('Choose the advanced setting: ',
                               '6' if self.appliance.version < '5.10' else '8')
            # 6/8 for Configure Database Replication

            # Configure Server as Standby
            interaction.answer('Choose the database replication operation: ', '2')
            interaction.answer(resc('Choose the encryption key: |1| '), '2')
            interaction.send(primary_ip)
            interaction.answer(resc('Enter the appliance SSH login: |root| '), '')
            interaction.answer('Enter the appliance SSH password: '******'Enter the path of remote encryption key: '
                                    '|/var/www/miq/vmdb/certs/v2_key| '), '')
            interaction.answer(resc('Choose the standby database disk: '),
                               '1' if self.appliance.version < '5.10' else '2')
            answer_cluster_related_questions(interaction, node_uid='2',
                db_name='', db_username='', db_password=pwd)
            interaction.answer('Enter the primary database hostname or IP address: ', primary_ip)
            interaction.answer(r'Enter the Standby Server hostname or IP address: \|.*\| ',
                               self.appliance.hostname)
            interaction.answer(resc('Configure Replication Manager (repmgrd) for automatic '
                                    r'failover? (Y/N): '), 'y')
            interaction.answer(resc('Apply this Replication Server Configuration? (Y/N): '), 'y')
            interaction.answer('Press any key to continue.', '', timeout=10 * 60)
예제 #6
0
    def reconfigure_standby_replication_node(self,
                                             pwd,
                                             primary_ip,
                                             repmgr_reconfigure=False):
        # Configure secondary (standby) replication node
        with SSHExpect(self.appliance) as interaction:
            interaction.send('ap')
            # When reconfiguring, the ap command may hang for 60s even.
            interaction.answer('Press any key to continue.', '', timeout=120)
            interaction.answer('Choose the advanced setting: ',
                               '6' if self.appliance.version < '5.10' else '8')
            # 6/8 for Configure Database Replication

            # Configure Server as Standby
            interaction.answer('Choose the database replication operation: ',
                               '2')
            # Would you like to remove the existing database before configuring as a standby server?
            # WARNING: This is destructive. This will remove all previous data from this server
            interaction.answer(resc('Continue? (Y/N): '), 'y')
            interaction.answer(
                # Don't partition the disk
                resc('Choose the standby database disk: |1| '),
                '1' if self.appliance.version < '5.10' else '2')
            interaction.answer(
                resc("Are you sure you don't want to partition the Standby "
                     "database disk? (Y/N): "), 'y')
            answer_cluster_related_questions(interaction,
                                             node_uid='2',
                                             db_name='',
                                             db_username='',
                                             db_password=pwd)
            interaction.answer(
                'Enter the primary database hostname or IP address: ',
                primary_ip)
            interaction.answer(
                r'Enter the Standby Server hostname or IP address: \|.*\| ',
                '')
            interaction.answer(
                resc('Configure Replication Manager (repmgrd) for automatic '
                     r'failover? (Y/N): '), 'y')
            # interaction.answer('An active standby node (10.8.198.223) with the node number 2
            # already exists\n')
            # 'Would you like to continue configuration by overwriting '
            # 'the existing node?
            interaction.answer(resc('(Y/N): |N| '), 'y')
            # Warning: File /etc/repmgr.conf exists. Replication is already configured
            interaction.answer(resc('Continue with configuration? (Y/N): '),
                               'y')
            interaction.answer(
                resc('Apply this Replication Server Configuration? (Y/N): '),
                'y')
            interaction.answer('Press any key to continue.', '', timeout=20)
예제 #7
0
    def configure_automatic_failover(self, primary_ip):
        # Configure automatic failover on EVM appliance
        with SSHExpect(self.appliance) as interaction:
            interaction.send('ap')
            interaction.answer('Press any key to continue.', '', timeout=20)
            interaction.expect('Choose the advanced setting: ')

            with waiting_for_ha_monitor_started(self.appliance, primary_ip, timeout=300):
                # Configure Application Database Failover Monitor
                interaction.send('8' if self.appliance.version < '5.10' else '10')
                interaction.answer('Choose the failover monitor configuration: ', '1')
                # Failover Monitor Service configured successfully
                interaction.answer('Press any key to continue.', '')
예제 #8
0
 def scap_harden_appliance(self):
     """Commands:
     1. 'ap' launches appliance_console,
     2. '' clears info screen,
     3. '15' Hardens appliance using SCAP configuration,
     4. '' complete."""
     with SSHExpect(self.appliance) as interaction:
         interaction.send('ap')
         interaction.answer('Press any key to continue.',
                            '',
                            timeout=AP_WELCOME_SCREEN_TIMEOUT)
         interaction.answer('Choose the advanced setting: ',
                            VersionPicker({
                                LOWEST: 15,
                                '5.11.2.1': 13
                            }))
         interaction.answer('Press any key to continue.',
                            '',
                            timeout=AP_WELCOME_SCREEN_TIMEOUT)
예제 #9
0
def restore_db(appl, location=''):
    with SSHExpect(appl) as interaction:
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=40)
        interaction.answer('Choose the advanced setting: ',
                           VersionPicker({
                               LOWEST: '6',
                               '5.11.2.1': 4
                           }))
        interaction.answer(
            re.escape('Choose the restore database file source: |1| '), '1')
        interaction.answer(
            re.escape('Enter the location of the local restore file: '
                      '|/tmp/evm_db.backup| '), location)
        interaction.answer(
            re.escape(
                'Should this file be deleted after completing the restore? '
                '(Y/N): '), 'N')
        interaction.answer(
            re.escape(
                'Are you sure you would like to restore the database? (Y/N): '
            ), 'Y')
        interaction.answer('Press any key to continue.', '', timeout=60)
예제 #10
0
    def configure_automatic_failover(self, primary_ip):
        # Configure automatic failover on EVM appliance
        with SSHExpect(self.appliance) as interaction:
            interaction.send('ap')
            interaction.answer('Press any key to continue.',
                               '',
                               timeout=AP_WELCOME_SCREEN_TIMEOUT)
            interaction.expect('Choose the advanced setting: ')

            with waiting_for_ha_monitor_started(self.appliance,
                                                primary_ip,
                                                timeout=300):
                # Configure Application Database Failover Monitor
                interaction.send(
                    VersionPicker({
                        LOWEST: 8,
                        '5.10': 10,
                        '5.11.2.1': 8
                    }))

                interaction.answer(
                    'Choose the failover monitor configuration: ', '1')
                # Failover Monitor Service configured successfully
                interaction.answer('Press any key to continue.', '')
예제 #11
0
def test_appliance_console_restore_db_samba(request,
                                            two_appliances_one_with_providers,
                                            utility_vm, utility_vm_samba_ip):
    """ Test single appliance backup and restore through smb, configures appliance with providers,
        backs up database, restores it to fresh appliance and checks for matching providers.

    Polarion:
        assignee: jhenner
        casecomponent: Configuration
        caseimportance: critical
        initialEstimate: 1h
    """
    appl1, appl2 = two_appliances_one_with_providers
    _, _, data = utility_vm
    host = utility_vm_samba_ip
    loc = data['network_share']['smb']['path']
    smb_dump_file_name = f'/tmp/backup.{fauxfactory.gen_alphanumeric()}.dump'
    smb_restore_dir_path = f'smb://{host}{loc}'
    smb_restore_file_path = f'{smb_restore_dir_path}/db_backup/{smb_dump_file_name}'

    creds_key = data['network_share']['smb']['credentials']
    pwd = credentials[creds_key]['password']
    usr = credentials[creds_key]['username']
    # Transfer v2_key and db backup from first appliance to second appliance
    fetch_v2key(appl1, appl2)

    appl1_provider_names = set(appl1.managed_provider_names)

    # Do the backup
    with SSHExpect(appl1) as interaction:
        appl1.evmserverd.stop()
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=40)
        interaction.answer('Choose the advanced setting: ',
                           VersionPicker({
                               LOWEST: '4',
                               '5.11.2.1': 2
                           }))
        interaction.answer(
            r'Choose the backup output file destination: \|1\| ', '3')
        interaction.answer(
            r'Enter the location to save the backup file to: \|.*\| ',
            smb_dump_file_name)
        # Enter the location to save the remote backup file to
        interaction.answer(
            re.escape(
                'Example: smb://host.mydomain.com/my_share/daily_backup/db.backup: '
            ), smb_restore_dir_path)
        # Enter the username with access to this file.
        interaction.answer(re.escape("Example: 'mydomain.com/user': "******"Example: 'mydomain.com/user': "******"vm not running"
예제 #12
0
def configure_appliances_ha(appliances, pwd):
    """Configure HA environment

    Appliance one configuring dedicated database, 'ap' launch appliance_console,
    '' clear info screen, '5' setup db, '1' Creates v2_key, '1' selects internal db,
    '1' use partition, 'y' create dedicated db, 'pwd' db password, 'pwd' confirm db password + wait
    and '' finish.

    Appliance two creating region in dedicated database, 'ap' launch appliance_console, '' clear
    info screen, '5' setup db, '2' fetch v2_key, 'app0_ip' appliance ip address, '' default user,
    'pwd' appliance password, '' default v2_key location, '2' create region in external db, '0' db
    region number, 'y' confirm create region in external db 'app0_ip', '' ip and default port for
    dedicated db, '' use default db name, '' default username, 'pwd' db password, 'pwd' confirm db
    password + wait and '' finish.

    Appliance one configuring primary node for replication, 'ap' launch appliance_console, '' clear
    info screen, '6' configure db replication, '1' configure node as primary, '1' cluster node
    number set to 1, '' default dbname, '' default user, 'pwd' password, 'pwd' confirm password,
    'app0_ip' primary appliance ip, confirm settings and wait to configure, '' finish.


    Appliance three configuring standby node for replication, 'ap' launch appliance_console, ''
    clear info screen, '6' configure db replication, '2' configure node as standby, '2' cluster node
    number set to 2, '' default dbname, '' default user, 'pwd' password, 'pwd' confirm password,
    'app0_ip' primary appliance ip, app1_ip standby appliance ip, confirm settings and wait
    to configure finish, '' finish.


    Appliance two configuring automatic failover of database nodes, 'ap' launch appliance_console,
    '' clear info screen '9' configure application database failover monitor, '1' start failover
    monitor. wait 30 seconds for service to start '' finish.

    """
    apps0, apps1, apps2 = appliances
    app0_ip = apps0.hostname

    # Configure first appliance as dedicated database
    with SSHExpect(apps0) as interaction:
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=20)
        interaction.answer(
            'Choose the advanced setting: ',
            '5' if apps0.version < '5.10' else '7')  # Configure Database
        interaction.answer(resc('Choose the encryption key: |1| '), '1')
        interaction.answer('Choose the database operation: ', '1')
        # On 5.10, rhevm provider:
        #
        #    database disk
        #
        #    1) /dev/sr0: 0 MB
        #    2) /dev/vdb: 4768 MB
        #    3) Don't partition the disk
        interaction.answer(resc('Choose the database disk: '),
                           '1' if apps0.version < '5.10' else '2')
        # Should this appliance run as a standalone database server?
        interaction.answer(resc('? (Y/N): |N| '), 'y')
        interaction.answer('Enter the database password on localhost: ', pwd)
        interaction.answer('Enter the database password again: ', pwd)
        # Configuration activated successfully.
        interaction.answer('Press any key to continue.', '', timeout=6 * 60)

        wait_for(lambda: apps0.db.is_dedicated_active, num_sec=4 * 60)

    # Configure EVM webui appliance with create region in dedicated database
    with SSHExpect(apps2) as interaction:
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=20)
        interaction.answer(
            'Choose the advanced setting: ',
            '5' if apps2.version < '5.10' else '7')  # Configure Database
        interaction.answer(resc('Choose the encryption key: |1| '), '2')
        interaction.send(app0_ip)
        interaction.answer(resc('Enter the appliance SSH login: |root| '), '')
        interaction.answer('Enter the appliance SSH password: '******'Enter the path of remote encryption key: |/var/www/miq/vmdb/certs/v2_key| '
            ), '')
        interaction.answer('Choose the database operation: ', '2', timeout=30)
        interaction.answer('Enter the database region number: ', '0')
        # WARNING: Creating a database region will destroy any existing data and
        # cannot be undone.
        interaction.answer(resc('Are you sure you want to continue? (Y/N):'),
                           'y')
        interaction.answer('Enter the database hostname or IP address: ',
                           app0_ip)
        interaction.answer(resc('Enter the port number: |5432| '), '')
        interaction.answer(
            r'Enter the name of the database on .*: \|vmdb_production\| ', '')
        interaction.answer(resc('Enter the username: |root| '), '')
        interaction.answer('Enter the database password on .*: ', pwd)
        # Configuration activated successfully.
        interaction.answer('Press any key to continue.', '', timeout=360)

    apps2.evmserverd.wait_for_running()
    apps2.wait_for_web_ui()

    apps0.appliance_console.configure_primary_replication_node(pwd)
    apps1.appliance_console.configure_standby_replication_node(pwd, app0_ip)

    apps2.appliance_console.configure_automatic_failover(primary_ip=None)
    return appliances
def test_appliance_console_restore_db_nfs(request,
                                          two_appliances_one_with_providers,
                                          utility_vm, utility_vm_nfs_ip):
    """ Test single appliance backup and restore through nfs, configures appliance with providers,
        backs up database, restores it to fresh appliance and checks for matching providers.

    Polarion:
        assignee: jhenner
        casecomponent: Configuration
        caseimportance: critical
        initialEstimate: 1h

    Bugzilla:
        1633573
    """
    appl1, appl2 = two_appliances_one_with_providers
    vm, _, data = utility_vm
    host = utility_vm_nfs_ip
    loc = data['network_share']['nfs']['path']
    nfs_dump_file_name = f'/tmp/backup.{fauxfactory.gen_alphanumeric()}.dump'
    nfs_restore_dir_path = f'nfs://{host}{loc}'
    nfs_restore_file_path = f'{nfs_restore_dir_path}/db_backup/{nfs_dump_file_name}'
    # Transfer v2_key and db backup from first appliance to second appliance
    fetch_v2key(appl1, appl2)

    appl1_provider_names = set(appl1.managed_provider_names)

    # Do the backup
    with SSHExpect(appl1) as interaction:
        appl1.evmserverd.stop()
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=40)
        interaction.answer('Choose the advanced setting: ',
                           VersionPicker({
                               LOWEST: '4',
                               '5.11.2.1': 2
                           }))
        interaction.answer(
            r'Choose the backup output file destination: \|1\| ', '2')
        interaction.answer(
            r'Enter the location to save the backup file to: \|.*\| ',
            nfs_dump_file_name)
        # Enter the location to save the remote backup file to
        interaction.answer(
            re.escape(
                'Example: nfs://host.mydomain.com/exported/my_exported_folder/db.backup: '
            ), nfs_restore_dir_path)
        # Running Database backup to nfs://XX.XX.XX.XX/srv/export...
        interaction.answer('Press any key to continue.', '', timeout=240)

    # Restore DB on the second appliance
    appl2.evmserverd.stop()
    appl2.db.drop()
    appl2.db.create()

    with SSHExpect(appl2) as interaction:
        interaction.send('ap')
        interaction.answer('Press any key to continue.', '', timeout=40)
        interaction.answer('Choose the advanced setting: ',
                           VersionPicker({
                               LOWEST: '6',
                               '5.11.2.1': 4
                           }))
        interaction.answer(r'Choose the restore database file source: \|1\| ',
                           '2')
        # Enter the location of the remote backup file
        interaction.answer(
            re.escape(
                'Example: nfs://host.mydomain.com/exported/my_exported_folder/db.backup: '
            ), nfs_restore_file_path)
        interaction.answer(
            r'Are you sure you would like to restore the database\? \(Y\/N\): ',
            'y')
        interaction.answer('Press any key to continue.', '', timeout=80)

    appl2.evmserverd.start()
    appl2.wait_for_miq_ready()
    # Assert providers on the second appliance
    assert set(appl2.managed_provider_names) == appl1_provider_names, (
        'Restored DB is missing some providers')
    # Verify that existing provider can detect new VMs on the second appliance
    virtual_crud = provider_app_crud(VMwareProvider, appl2)
    vm = provision_vm(request, virtual_crud)
    assert vm.mgmt.is_running, "vm not running"
예제 #14
0
def ha_appliances_with_providers(ha_multiple_preupdate_appliances, app_creds):
    """Configure HA environment

    Appliance one configuring dedicated database, 'ap' launch appliance_console,
    '' clear info screen, '5' setup db, '1' Creates v2_key, '1' selects internal db,
    '1' use partition, 'y' create dedicated db, 'pwd' db password, 'pwd' confirm db password + wait
    and '' finish.

    Appliance two creating region in dedicated database, 'ap' launch appliance_console, '' clear
    info screen, '5' setup db, '2' fetch v2_key, 'app0_ip' appliance ip address, '' default user,
    'pwd' appliance password, '' default v2_key location, '2' create region in external db, '0' db
    region number, 'y' confirm create region in external db 'app0_ip', '' ip and default port for
    dedicated db, '' use default db name, '' default username, 'pwd' db password, 'pwd' confirm db
    password + wait and '' finish.

    Appliance one configuring primary node for replication, 'ap' launch appliance_console, '' clear
    info screen, '6' configure db replication, '1' configure node as primary, '1' cluster node
    number set to 1, '' default dbname, '' default user, 'pwd' password, 'pwd' confirm password,
    'app0_ip' primary appliance ip, confirm settings and wait to configure, '' finish.


    Appliance three configuring standby node for replication, 'ap' launch appliance_console, ''
    clear info screen, '6' configure db replication, '2' configure node as standby, '2' cluster node
    number set to 2, '' default dbname, '' default user, 'pwd' password, 'pwd' confirm password,
    'app0_ip' primary appliance ip, app1_ip standby appliance ip, confirm settings and wait
    to configure finish, '' finish.


    Appliance two configuring automatic failover of database nodes, 'ap' launch appliance_console,
    '' clear info screen '9' configure application database failover monitor, '1' start failover
    monitor. wait 30 seconds for service to start '' finish.

    """
    apps0, apps1, apps2 = ha_multiple_preupdate_appliances
    app0_ip = apps0.hostname
    app1_ip = apps1.hostname
    pwd = app_creds["password"]

    # Configure first appliance as dedicated database
    interaction = SSHExpect(apps0)
    interaction.send('ap')
    interaction.answer('Press any key to continue.', '', timeout=20)
    interaction.answer('Choose the advanced setting: ',
                      '5' if apps0.version < '5.10' else '7')  # Configure Database
    interaction.answer('Choose the encryption key: |1|', '1')
    interaction.answer('Choose the database operation: ', '1')
    # On 5.10, rhevm provider:
    #
    #    database disk
    #
    #    1) /dev/sr0: 0 MB
    #    2) /dev/vdb: 4768 MB
    #    3) Don't partition the disk
    interaction.answer('Choose the database disk: |1| ',
                       '1' if apps0.version < '5.10' else '2')
    # Should this appliance run as a standalone database server?
    interaction.answer(r'\? \(Y\/N\): |N| ', 'y')
    interaction.answer('Enter the database password on localhost: ', pwd)
    interaction.answer('Enter the database password again: ', pwd)
    # Configuration activated successfully.
    interaction.answer('Press any key to continue.', '', timeout=6 * 60)

    wait_for(lambda: apps0.db.is_dedicated_active, num_sec=4 * 60)

    # Configure EVM webui appliance with create region in dedicated database
    interaction = SSHExpect(apps2)
    interaction.send('ap')
    interaction.answer('Press any key to continue.', '', timeout=20)
    interaction.answer('Choose the advanced setting: ',
                       '5' if apps2.version < '5.10' else '7')  # Configure Database
    interaction.answer('Choose the encryption key: |1| ', '2')
    interaction.send(app0_ip)
    interaction.answer('Enter the appliance SSH login: |root| ', '')
    interaction.answer('Enter the appliance SSH password: '******'Enter the path of remote encryption key: |/var/www/miq/vmdb/certs/v2_key|',
                       '')
    interaction.answer('Choose the database operation: ', '2')
    interaction.answer('Enter the database region number: ', '0')
    # WARNING: Creating a database region will destroy any existing data and
    # cannot be undone.
    interaction.answer(r'Are you sure you want to continue\? \(Y\/N\):', 'y')
    interaction.answer('Enter the database hostname or IP address: ', app0_ip)
    interaction.answer('Enter the port number: |5432| ', '')
    interaction.answer('Enter the name of the database on .*: |vmdb_production| ', '')
    interaction.answer('Enter the username: |root|', '')
    interaction.answer('Enter the database password on .*: ', pwd)
    # Configuration activated successfully.
    interaction.answer('Press any key to continue.', '', timeout=360)

    apps2.evmserverd.wait_for_running()
    apps2.wait_for_web_ui()

    # Configure primary replication node
    interaction = SSHExpect(apps0)
    interaction.send('ap')
    interaction.answer('Press any key to continue.', '', timeout=20)
    # 6/8 for Configure Database Replication
    interaction.answer('Choose the advanced setting: ',
                       '6' if apps1.version < '5.10' else '8')
    interaction.answer('Choose the database replication operation: ', '1')
    interaction.answer('Enter the number uniquely identifying '
                       'this node in the replication cluster: ', '1')
    interaction.answer('Enter the cluster database name: |vmdb_production| ', '')
    interaction.answer('Enter the cluster database username: |root| ', '')
    interaction.answer('Enter the cluster database password: '******'Enter the cluster database password: '******'Enter the primary database hostname or IP address: |.*| ', app0_ip)
    interaction.answer(r'Apply this Replication Server Configuration\? \(Y/N\): ', 'y')
    interaction.answer('Press any key to continue.', '')

    if BZ(1732092, forced_streams=get_stream(apps1.version)).blocks:
        assert apps1.ssh_client.run_command('setenforce 0').success

    # Configure secondary (standby) replication node
    interaction = SSHExpect(apps1)
    interaction.send('ap')
    interaction.answer('Press any key to continue.', '', timeout=20)
    interaction.answer('Choose the advanced setting: ',
                       '6' if apps1.version < '5.10' else '8')
    # 6/8 for Configure Database Replication
    # Configure Server as Standby
    interaction.answer('Choose the database replication operation: ', '2')
    interaction.answer('Choose the encryption key: |1| ', '2')
    interaction.send(app0_ip)
    interaction.answer('Enter the appliance SSH login: |root| ', '')
    interaction.answer('Enter the appliance SSH password: '******'Enter the path of remote encryption key: |/var/www/miq/vmdb/certs/v2_key|',
                       '')
    interaction.answer('Choose the standby database disk: |1| ',
                       '1' if apps1.version < '5.10' else '2')
    # "Enter " ... is on line above.
    interaction.answer('.*the number uniquely identifying this '
                       'node in the replication cluster: ',
                       '2')
    interaction.answer('Enter the cluster database name: |vmdb_production| ', '')
    interaction.answer('Enter the cluster database username: |root| ', '')
    interaction.answer('Enter the cluster database password: '******'Enter the cluster database password: '******'Enter the primary database hostname or IP address: ', app0_ip)
    interaction.answer('Enter the Standby Server hostname or IP address: |.*|', app1_ip)
    interaction.answer(r'Configure Replication Manager \(repmgrd\) for automatic '
                       r'failover\? \(Y/N\): ', 'y')
    interaction.answer(r'Apply this Replication Server Configuration\? \(Y/N\): ', 'y')
    interaction.answer('Press any key to continue.', '', timeout=5 * 60)

    # Configure automatic failover on EVM appliance
    interaction = SSHExpect(apps2)
    interaction.send('ap')
    interaction.answer('Press any key to continue.', '', timeout=20)
    interaction.expect('Choose the advanced setting: ')

    with waiting_for_ha_monitor_started(apps2, app1_ip, timeout=300):
        # Configure Application Database Failover Monitor
        interaction.send('8' if apps2.version < '5.10' else '10')
        interaction.answer('Choose the failover monitor configuration: ', '1')
        # Failover Monitor Service configured successfully
        interaction.answer('Press any key to continue.', '')

    # Add infra/cloud providers and create db backup
    provider_app_crud(VMwareProvider, apps2).setup()
    provider_app_crud(EC2Provider, apps2).setup()
    return ha_multiple_preupdate_appliances
def restore_db(appl, location=''):
    interaction = SSHExpect(appl)
    interaction.send('ap')
    interaction.expect('Press any key to continue.', timeout=40)
    interaction.send('')
    interaction.expect('Choose the advanced setting: ')
    interaction.send('6')
    interaction.expect('Choose the restore database file source: |1| ')
    interaction.send('1')
    interaction.expect(
        'Enter the location of the local restore file: |/tmp/evm_db.backup| ')
    interaction.send(location)
    interaction.expect(
        r'Should this file be deleted after completing the restore\? \(Y\/N\): '
    )
    interaction.send('N')
    interaction.expect(
        r'Are you sure you would like to restore the database\? \(Y\/N\): ')
    interaction.send('Y')
    interaction.expect('Press any key to continue.', timeout=60)