示例#1
0
    def trigger_deferred_restart_via_charm(self, restart_config_file):
        """Set charm config option which requires a service start.

        Set the charm debug option and wait for that change to be renderred in
        applications config file.

        NOTE: The implementation assumes the restart_config_file in an oslo
              config file. If that is not true the derived class should
              override this method.

        :param restart_config_file: Config file that updated value is expected
                                    in.
        :type restart_config_file: str
        """
        new_debug_value = self.set_new_config()
        expected_contents = {
            'DEFAULT': {
                'debug': [new_debug_value]}}
        logging.info("Waiting for debug to be {} in {}".format(
            new_debug_value,
            restart_config_file))
        model.block_until_oslo_config_entries_match(
            self.application_name,
            restart_config_file,
            expected_contents)
        logging.info("Waiting for units to be idle")
        model.block_until_all_units_idle()
示例#2
0
    def restart_on_changed(self, config_file, default_config, alternate_config,
                           default_entry, alternate_entry, services):
        """Run restart on change tests.

        Test that changing config results in config file being updates and
        services restarted. Return config to default_config afterwards

        :param config_file: Config file to check for settings
        :type config_file: str
        :param default_config: Dict of charm settings to set on completion
        :type default_config: dict
        :param alternate_config: Dict of charm settings to change to
        :type alternate_config: dict
        :param default_entry: Config file entries that correspond to
                              default_config
        :type default_entry: dict
        :param alternate_entry: Config file entries that correspond to
                                alternate_config
        :type alternate_entry: dict
        :param services: Services expected to be restarted when config_file is
                         changed.
        :type services: list
        """
        # lead_unit is only useed to grab a timestamp, the assumption being
        # that all the units times are in sync.

        mtime = model.get_unit_time(self.lead_unit, model_name=self.model_name)
        logging.debug('Remote unit timestamp {}'.format(mtime))

        with self.config_change(default_config, alternate_config):
            logging.debug(
                'Waiting for updates to propagate to {}'.format(config_file))
            model.block_until_oslo_config_entries_match(
                self.application_name,
                config_file,
                alternate_entry,
                model_name=self.model_name)

            # Config update has occured and hooks are idle. Any services should
            # have been restarted by now:
            logging.debug(
                'Waiting for services ({}) to be restarted'.format(services))
            model.block_until_services_restarted(self.application_name,
                                                 mtime,
                                                 services,
                                                 model_name=self.model_name)

            logging.debug(
                'Waiting for updates to propagate to '.format(config_file))
            model.block_until_oslo_config_entries_match(
                self.application_name,
                config_file,
                default_entry,
                model_name=self.model_name)
示例#3
0
    def block_until_oslo_config_entries_match_base(self, file_contents,
                                                   expected_contents):
        async def _scp_from(remote_file, tmpdir):
            with open('{}/myfile.txt'.format(tmpdir), 'w') as f:
                f.write(file_contents)

        self.patch_object(model, 'Model')
        self.patch_object(model, 'get_juju_model', return_value='mname')
        self.Model.return_value = self.Model_mock
        self.unit1.scp_from.side_effect = _scp_from
        self.unit2.scp_from.side_effect = _scp_from
        model.block_until_oslo_config_entries_match('app',
                                                    '/tmp/src/myfile.txt',
                                                    expected_contents,
                                                    timeout=0.1)