示例#1
0
 def unlock(self):
     # Ensure this has correct data
     self.description
     details_page = navigate_to(self, 'Details')
     details_page.configuration.item_select('Unlock this Domain')
     details_page.flash.assert_no_error()
     details_page.flash.assert_message('The selected Automate Domain were marked as Unlocked')
     clear_property_cache(self, 'locked')
     assert not self.locked
示例#2
0
 def unlock(self):
     # Ensure this has correct data
     self.description
     details_page = navigate_to(self, 'Details')
     details_page.configuration.item_select('Unlock this Domain')
     details_page.flash.assert_no_error()
     details_page.flash.assert_message('The selected Automate Domain were marked as Unlocked')
     clear_property_cache(self, 'locked')
     assert not self.locked
示例#3
0
    def enable_internal(self, region=0, key_address=None, db_password=None, ssh_password=None):
        """Enables internal database

        Args:
            region: Region number of the CFME appliance.
            key_address: Address of CFME appliance where key can be fetched.

        Note:
            If key_address is None, a new encryption key is generated for the appliance.
        """
        self.logger.info('Enabling internal DB (region {}) on {}.'.format(region, self.address))
        self.address = self.appliance.address
        clear_property_cache(self, 'client')

        client = self.ssh_client

        # Defaults
        db_password = db_password or conf.credentials['database']['password']
        ssh_password = ssh_password or conf.credentials['ssh']['password']

        if self.appliance.has_cli:
            # use the cli
            if key_address:
                status, out = client.run_command(
                    'appliance_console_cli --region {0} --internal --fetch-key {1} -p {2} -a {3}'
                    .format(region, key_address, db_password, ssh_password)
                )
            else:
                status, out = client.run_command(
                    'appliance_console_cli --region {} --internal --force-key -p {}'
                    .format(region, db_password)
                )
        else:
            # no cli, use the enable internal db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'region': region,
                'postgres_version': self.postgres_version
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            status, out = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        return status, out
示例#4
0
    def unlock(self):
        # Ensure this has correct data
        self.description
        details_page = navigate_to(self, 'Details')
        details_page.configuration.item_select('Unlock this Domain')
        details_page.flash.assert_no_error()
        details_page.flash.assert_message('The selected Automate Domain were marked as Unlocked')

        # TODO(BZ-1704439): Remove the work-around once this BZ got fixed
        if BZ(1704439).blocks:
            self.browser.refresh()

        clear_property_cache(self, 'locked')
        assert not self.locked
示例#5
0
    def lock(self):
        # Ensure this has correct data
        self.description
        details_page = navigate_to(self, 'Details')
        details_page.configuration.item_select('Lock this Domain')
        details_page.flash.assert_no_error()
        details_page.flash.assert_message('The selected Automate Domain were marked as Locked')

        # TODO(BZ-1704439): Remove the work-around once this BZ got fixed
        if BZ(1704439).blocks:
            self.browser.refresh()

        clear_property_cache(self, 'locked')
        assert self.locked
def test_server_name(appliance):
    """Tests that changing the server name updates the about page"""

    view = navigate_to(appliance.server.settings, 'Details')
    old_server_name = view.basic_information.appliance_name.read()
    new_server_name = "{}-CFME".format(old_server_name)
    appliance.server.settings.update_basic_information(
        {'appliance_name': new_server_name})

    # CFME updates about box only after any navigation BZ(1408681) - closed wontfix
    navigate_to(appliance.server, 'Dashboard')

    # opens and closes about modal
    current_server_name = about.get_detail(about.SERVER)

    assert new_server_name == current_server_name, (
        "Server name in About section does not match the new name")

    clear_property_cache(appliance, 'configuration_details')
    appliance.server.settings.update_basic_information(
        {'appliance_name': old_server_name})
    clear_property_cache(appliance, 'configuration_details')
示例#7
0
    def enable_internal(self,
                        region=0,
                        key_address=None,
                        db_password=None,
                        ssh_password=None,
                        db_disk=None):
        """Enables internal database

        Args:
            region: Region number of the CFME appliance.
            key_address: Address of CFME appliance where key can be fetched.
            db_disk: Path of the db disk for --dbdisk appliance_console_cli. If not specified it
                     tries to load it from the appliance.

        Note:
            If key_address is None, a new encryption key is generated for the appliance.
        """
        self.logger.info(
            f'Enabling internal DB (region {region}) on {self.address}.')
        self.address = self.appliance.hostname
        clear_property_cache(self, 'client')

        client = self.ssh_client

        # Defaults
        db_password = db_password or conf.credentials['database']['password']
        ssh_password = ssh_password or conf.credentials['ssh']['password']

        if not db_disk:
            # See if there's any unpartitioned disks on the appliance
            try:
                db_disk = self.appliance.unpartitioned_disks[0]
                self.logger.info("Using unpartitioned disk for DB at %s",
                                 db_disk)
            except IndexError:
                db_disk = None

        db_mounted = False
        if not db_disk:
            # If we still don't have a db disk to use, see if a db disk/partition has already
            # been created & mounted (such as by us in self.create_db_lvm)
            result = client.run_command(
                "mount | grep $APPLIANCE_PG_MOUNT_POINT | cut -f1 -d' '")
            if "".join(str(result).split(
            )):  # strip all whitespace to see if we got a real result
                self.logger.info("Using pre-mounted DB disk at %s", result)
                db_mounted = True

        if not db_mounted and not db_disk:
            self.logger.warning(
                'Failed to find a mounted DB disk, or a free unpartitioned disk.'
            )

        if self.appliance.has_cli:
            base_command = f'appliance_console_cli --region {region}'
            # use the cli
            if key_address:
                command_options = (
                    '--internal --fetch-key {key} -p {db_pass} -a {ssh_pass}'.
                    format(key=key_address,
                           db_pass=db_password,
                           ssh_pass=ssh_password))

            else:
                command_options = f'--internal --force-key -p {db_password}'

            if db_disk:
                # make sure the dbdisk is unmounted, RHOS ephemeral disks come up mounted
                result = client.run_command(f'umount {db_disk}')
                if not result.success:
                    self.logger.warning(
                        f'umount non-zero return, output was: ')
                command_options = ' '.join(
                    [command_options, f'--dbdisk {db_disk}'])

            result = client.run_command(' '.join(
                [base_command, command_options]))
            if result.failed or 'failed' in result.output.lower():
                raise Exception(
                    f'Could not set up the database:\n{result.output}')
        else:
            # no cli, use the enable internal db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'region': region,
                'postgres_svcname': self.service_name,
                'postgres_prefix': self.pg_prefix,
                'db_mounted': str(db_mounted),
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt',
                                                  scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # sent rb file over to /tmp
            remote_file = f'/tmp/{fauxfactory.gen_alphanumeric()}'
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            result = client.run_command(f'ruby {remote_file}')
            client.run_command(f'rm {remote_file}')

        self.logger.info('Output from appliance db configuration: %s',
                         result.output)

        return result.rc, result.output
示例#8
0
    def enable_external(self,
                        db_address,
                        region=0,
                        db_name=None,
                        db_username=None,
                        db_password=None):
        """Enables external database

        Args:
            db_address: Address of the external database
            region: Number of region to join
            db_name: Name of the external DB
            db_username: Username to access the external DB
            db_password: Password to access the external DB

        Returns a tuple of (exitstatus, script_output) for reporting, if desired
        """
        self.logger.info(
            'Enabling external DB (db_address {}, region {}) on {}.'.format(
                db_address, region, self.address))
        # reset the db address and clear the cached db object if we have one
        self.address = db_address
        clear_property_cache(self, 'client')

        # default
        db_name = db_name or 'vmdb_production'
        db_username = db_username or conf.credentials['database']['username']
        db_password = db_password or conf.credentials['database']['password']

        client = self.ssh_client

        if self.appliance.has_cli:
            # copy v2 key
            master_client = client(hostname=self.address)
            rand_filename = "/tmp/v2_key_{}".format(
                fauxfactory.gen_alphanumeric())
            master_client.get_file("/var/www/miq/vmdb/certs/v2_key",
                                   rand_filename)
            client.put_file(rand_filename, "/var/www/miq/vmdb/certs/v2_key")

            # enable external DB with cli
            status, out = client.run_command(
                'appliance_console_cli '
                '--hostname {0} --region {1} --dbname {2} --username {3} --password {4}'
                .format(self.address, region, db_name, db_username,
                        db_password))
        else:
            # no cli, use the enable external db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'host': self.address,
                'region': region,
                'database': db_name,
                'username': db_username,
                'password': db_password
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt',
                                                  scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # Init SSH client and sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            status, out = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        if status != 0:
            self.logger.error('error enabling external db')
            self.logger.error(out)
            msg = ('Appliance {} failed to enable external DB running on {}'.
                   format(self.appliance.hostname, db_address))
            self.logger.error(msg)
            from . import ApplianceException
            raise ApplianceException(msg)

        return status, out
示例#9
0
    def enable_internal(self,
                        region=0,
                        key_address=None,
                        db_password=None,
                        ssh_password=None,
                        db_disk=None):
        """Enables internal database

        Args:
            region: Region number of the CFME appliance.
            key_address: Address of CFME appliance where key can be fetched.
            db_disk: Path of the db disk for --dbdisk appliance_console_cli. If not specified it
                     tries to load it from the appliance.

        Note:
            If key_address is None, a new encryption key is generated for the appliance.
        """
        # self.logger.info('Enabling internal DB (region {}) on {}.'.format(region, self.address))
        self.address = self.appliance.hostname
        clear_property_cache(self, 'client')

        client = self.ssh_client

        # Defaults
        db_password = db_password or conf.credentials['database']['password']
        ssh_password = ssh_password or conf.credentials['ssh']['password']
        if not db_disk:
            try:
                db_disk = self.appliance.unpartitioned_disks[0]
            except IndexError:
                db_disk = None
                self.logger.warning(
                    'Failed to set --dbdisk from the appliance. On 5.9.0.3+ it will fail.'
                )

        # make sure the dbdisk is unmounted, RHOS ephemeral disks come up mounted
        result = client.run_command('umount {}'.format(db_disk))
        if not result.success:
            self.logger.warning(
                'umount non-zero return, output was: '.format(result))

        if self.appliance.has_cli:
            base_command = 'appliance_console_cli --region {}'.format(region)
            # use the cli
            if key_address:
                command_options = (
                    '--internal --fetch-key {key} -p {db_pass} -a {ssh_pass}'.
                    format(key=key_address,
                           db_pass=db_password,
                           ssh_pass=ssh_password))

            else:
                command_options = '--internal --force-key -p {db_pass}'.format(
                    db_pass=db_password)

            if db_disk:
                command_options = ' '.join(
                    [command_options, '--dbdisk {}'.format(db_disk)])

            status, out = client.run_command(' '.join(
                [base_command, command_options]))
            if status != 0 or 'failed' in out.lower():
                raise Exception(
                    'Could not set up the database:\n{}'.format(out))
        else:
            # no cli, use the enable internal db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'region': region,
                'postgres_version': self.postgres_version
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt',
                                                  scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            status, out = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        self.logger.info('Output from appliance db configuration: %s', out)

        return status, out
示例#10
0
 def close(self, browser):
     if browser:
         browser.quit()
         clear_property_cache(self, '_firefox_profile')
示例#11
0
文件: db.py 项目: apagac/cfme_tests
    def enable_external(self, db_address, region=0, db_name=None, db_username=None,
                        db_password=None):
        """Enables external database

        Args:
            db_address: Address of the external database
            region: Number of region to join
            db_name: Name of the external DB
            db_username: Username to access the external DB
            db_password: Password to access the external DB

        Returns a tuple of (exitstatus, script_output) for reporting, if desired
        """
        self.logger.info('Enabling external DB (db_address {}, region {}) on {}.'
            .format(db_address, region, self.address))
        # reset the db address and clear the cached db object if we have one
        self.address = db_address
        clear_property_cache(self, 'client')

        # default
        db_name = db_name or 'vmdb_production'
        db_username = db_username or conf.credentials['database']['username']
        db_password = db_password or conf.credentials['database']['password']

        client = self.ssh_client

        if self.appliance.has_cli:

            if not client.is_pod:
                # copy v2 key
                master_client = client(hostname=self.address)
                rand_filename = "/tmp/v2_key_{}".format(fauxfactory.gen_alphanumeric())
                master_client.get_file("/var/www/miq/vmdb/certs/v2_key", rand_filename)
                client.put_file(rand_filename, "/var/www/miq/vmdb/certs/v2_key")

            # enable external DB with cli
            result = client.run_command(
                'appliance_console_cli '
                '--hostname {0} --region {1} --dbname {2} --username {3} --password {4}'.format(
                    self.address, region, db_name, db_username, db_password
                )
            )
        else:
            # no cli, use the enable external db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'host': self.address,
                'region': region,
                'database': db_name,
                'username': db_username,
                'password': db_password
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # Init SSH client and sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            result = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        if result.failed:
            self.logger.error('error enabling external db')
            self.logger.error(result.output)
            msg = ('Appliance {} failed to enable external DB running on {}'
                  .format(self.appliance.hostname, db_address))
            self.logger.error(msg)
            from . import ApplianceException
            raise ApplianceException(msg)

        return result.rc, result.output
示例#12
0
文件: db.py 项目: apagac/cfme_tests
    def enable_internal(self, region=0, key_address=None, db_password=None, ssh_password=None,
                        db_disk=None):
        """Enables internal database

        Args:
            region: Region number of the CFME appliance.
            key_address: Address of CFME appliance where key can be fetched.
            db_disk: Path of the db disk for --dbdisk appliance_console_cli. If not specified it
                     tries to load it from the appliance.

        Note:
            If key_address is None, a new encryption key is generated for the appliance.
        """
        # self.logger.info('Enabling internal DB (region {}) on {}.'.format(region, self.address))
        self.address = self.appliance.hostname
        clear_property_cache(self, 'client')

        client = self.ssh_client

        # Defaults
        db_password = db_password or conf.credentials['database']['password']
        ssh_password = ssh_password or conf.credentials['ssh']['password']

        if not db_disk:
            # See if there's any unpartitioned disks on the appliance
            try:
                db_disk = self.appliance.unpartitioned_disks[0]
                self.logger.info("Using unpartitioned disk for DB at %s", db_disk)
            except IndexError:
                db_disk = None

        db_mounted = False
        if not db_disk:
            # If we still don't have a db disk to use, see if a db disk/partition has already
            # been created & mounted (such as by us in self.create_db_lvm)
            result = client.run_command("mount | grep $APPLIANCE_PG_MOUNT_POINT | cut -f1 -d' '")
            if "".join(str(result).split()):  # strip all whitespace to see if we got a real result
                self.logger.info("Using pre-mounted DB disk at %s", result)
                db_mounted = True

        if not db_mounted and not db_disk:
            self.logger.warning('Failed to find a mounted DB disk, or a free unpartitioned disk.')

        if self.appliance.has_cli:
            base_command = 'appliance_console_cli --region {}'.format(region)
            # use the cli
            if key_address:
                command_options = ('--internal --fetch-key {key} -p {db_pass} -a {ssh_pass}'
                                   .format(key=key_address, db_pass=db_password,
                                           ssh_pass=ssh_password))

            else:
                command_options = '--internal --force-key -p {db_pass}'.format(db_pass=db_password)

            if db_disk:
                # make sure the dbdisk is unmounted, RHOS ephemeral disks come up mounted
                result = client.run_command('umount {}'.format(db_disk))
                if not result.success:
                    self.logger.warning('umount non-zero return, output was: '.format(result))
                command_options = ' '.join([command_options, '--dbdisk {}'.format(db_disk)])

            result = client.run_command(' '.join([base_command, command_options]))
            if result.failed or 'failed' in result.output.lower():
                raise Exception('Could not set up the database:\n{}'.format(result.output))
        else:
            # no cli, use the enable internal db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'region': region,
                'postgres_version': self.postgres_version,
                'db_mounted': str(db_mounted),
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            result = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        self.logger.info('Output from appliance db configuration: %s', result.output)

        return result.rc, result.output
示例#13
0
 def __setattr__(self, attr, value):
     super(self.__class__, self).__setattr__(attr, value)
     if self._top is not None:
         self.logger.info(
             "Invalidating lazy_cache ssh_client current_appliance object")
         clear_property_cache(self._top, 'ssh_client')
示例#14
0
 def close(self, browser):
     if browser:
         browser.quit()
         clear_property_cache(self, '_firefox_profile')
示例#15
0
    def enable_internal(self, region=0, key_address=None, db_password=None, ssh_password=None,
                        db_disk=None):
        """Enables internal database

        Args:
            region: Region number of the CFME appliance.
            key_address: Address of CFME appliance where key can be fetched.
            db_disk: Path of the db disk for --dbdisk appliance_console_cli. If not specified it
                     tries to load it from the appliance.

        Note:
            If key_address is None, a new encryption key is generated for the appliance.
        """
        # self.logger.info('Enabling internal DB (region {}) on {}.'.format(region, self.address))
        self.address = self.appliance.hostname
        clear_property_cache(self, 'client')

        client = self.ssh_client

        # Defaults
        db_password = db_password or conf.credentials['database']['password']
        ssh_password = ssh_password or conf.credentials['ssh']['password']
        if not db_disk:
            try:
                db_disk = self.appliance.unpartitioned_disks[0]
            except IndexError:
                db_disk = None
                self.logger.warning(
                    'Failed to set --dbdisk from the appliance. On 5.9.0.3+ it will fail.')

        # make sure the dbdisk is unmounted, RHOS ephemeral disks come up mounted
        result = client.run_command('umount {}'.format(db_disk))
        if not result.success:
            self.logger.warning('umount non-zero return, output was: '.format(result))

        if self.appliance.has_cli:
            base_command = 'appliance_console_cli --region {}'.format(region)
            # use the cli
            if key_address:
                command_options = ('--internal --fetch-key {key} -p {db_pass} -a {ssh_pass}'
                                   .format(key=key_address, db_pass=db_password,
                                           ssh_pass=ssh_password))

            else:
                command_options = '--internal --force-key -p {db_pass}'.format(db_pass=db_password)

            if db_disk:
                command_options = ' '.join([command_options, '--dbdisk {}'.format(db_disk)])

            result = client.run_command(' '.join([base_command, command_options]))
            if result.failed or 'failed' in result.output.lower():
                raise Exception('Could not set up the database:\n{}'.format(result.output))
        else:
            # no cli, use the enable internal db script
            rbt_repl = {
                'miq_lib': '/var/www/miq/lib',
                'region': region,
                'postgres_version': self.postgres_version
            }

            # Find and load our rb template with replacements
            rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath)
            rb = datafile.load_data_file(rbt, rbt_repl)

            # sent rb file over to /tmp
            remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric())
            client.put_file(rb.name, remote_file)

            # Run the rb script, clean it up when done
            result = client.run_command('ruby {}'.format(remote_file))
            client.run_command('rm {}'.format(remote_file))

        self.logger.info('Output from appliance db configuration: %s', result.output)

        return result.rc, result.output
示例#16
0
 def __setattr__(self, attr, value):
     super(self.__class__, self).__setattr__(attr, value)
     if self._top is not None:
         self.logger.info("Invalidating lazy_cache ssh_client current_appliance object")
         clear_property_cache(self._top, 'ssh_client')