예제 #1
0
파일: commands.py 프로젝트: dankilman/claw
def _generate_configuration(cmd_inputs_override,
                            cmd_blueprint_override,
                            conf_obj,
                            conf_key,
                            conf_name,
                            conf_additional,
                            conf_blueprint_key,
                            blueprint_dir_name,
                            blueprint_override_key,
                            blueprint_override_template_key,
                            blueprint_path,
                            reset,
                            properties,
                            user_yaml):
    if conf_name not in user_yaml[conf_key]:
        raise NO_SUCH_CONFIGURATION
    conf = user_yaml[conf_key][conf_name]
    cmd_inputs_override = [user_yaml['inputs_override_templates'][key]
                           for key in (cmd_inputs_override or [])]
    cmd_blueprint_override = [user_yaml[blueprint_override_template_key][key]
                              for key in (cmd_blueprint_override or [])]
    original_inputs_path = os.path.expanduser(conf.get('inputs', ''))
    original_blueprint_path = os.path.expanduser(conf[conf_blueprint_key])
    if conf_obj.dir.exists():
        if reset:
            if conf_obj.dir == os.getcwd():
                os.chdir(conf_obj.dir.dirname())
            shutil.rmtree(conf_obj.dir)
        else:
            raise ALREADY_INITIALIZED
    conf_obj.dir.makedirs()
    if not original_inputs_path:
        fd, original_inputs_path = tempfile.mkstemp()
        os.close(fd)
        with open(original_inputs_path, 'w') as f:
            f.write('{}')
    _, tmp_blueprint_path = util.generate_unique_configurations(
        workdir=conf_obj.dir,
        original_inputs_path=original_inputs_path,
        original_manager_blueprint_path=original_blueprint_path,
        manager_blueprint_dir_name=blueprint_dir_name)
    shutil.move(tmp_blueprint_path, blueprint_path)
    conf['inputs'] = str(conf_obj.inputs_path)
    conf[conf_blueprint_key] = str(blueprint_path)
    conf.update(conf_additional or {})
    user_yaml['variables'] = user_yaml.get('variables', {})
    user_yaml['variables']['properties'] = properties or {}
    overrides = [
        (conf_obj.inputs_path, 'inputs_override', cmd_inputs_override),
        (blueprint_path, blueprint_override_key, cmd_blueprint_override)
    ]
    for yaml_path, prop, additional_overrides in overrides:
        unprocessed = conf.pop(prop, {})
        for additional in additional_overrides:
            unprocessed.update(additional)
        override = util.process_variables(user_yaml, unprocessed)
        with patcher.YamlPatcher(yaml_path, default_flow_style=False) as patch:
            for k, v in override.items():
                patch.set_value(k, v)
    return conf
예제 #2
0
def _generate_configuration(cmd_inputs_override,
                            cmd_blueprint_override,
                            conf_obj,
                            conf_key,
                            conf_name,
                            conf_additional,
                            conf_blueprint_key,
                            blueprint_dir_name,
                            blueprint_override_key,
                            blueprint_override_template_key,
                            blueprint_path,
                            reset,
                            properties,
                            user_yaml):
    if conf_name not in user_yaml[conf_key]:
        raise NO_SUCH_CONFIGURATION
    conf = user_yaml[conf_key][conf_name]
    cmd_inputs_override = [user_yaml['inputs_override_templates'][key]
                           for key in (cmd_inputs_override or [])]
    cmd_blueprint_override = [user_yaml[blueprint_override_template_key][key]
                              for key in (cmd_blueprint_override or [])]
    original_inputs_path = os.path.expanduser(conf.get('inputs', ''))
    original_blueprint_path = os.path.expanduser(conf[conf_blueprint_key])
    if conf_obj.exists():
        if reset:
            if conf_obj.dir == os.getcwd():
                os.chdir(conf_obj.dir.dirname())
            shutil.rmtree(conf_obj.dir)
        else:
            raise ALREADY_INITIALIZED
    conf_obj.dir.makedirs()
    if not original_inputs_path:
        fd, original_inputs_path = tempfile.mkstemp()
        os.close(fd)
        with open(original_inputs_path, 'w') as f:
            f.write('{}')
    _, tmp_blueprint_path = util.generate_unique_configurations(
        workdir=conf_obj.dir,
        original_inputs_path=original_inputs_path,
        original_manager_blueprint_path=original_blueprint_path,
        manager_blueprint_dir_name=blueprint_dir_name)
    shutil.move(tmp_blueprint_path, blueprint_path)
    conf['inputs'] = str(conf_obj.inputs_path)
    conf[conf_blueprint_key] = str(blueprint_path)
    conf.update(conf_additional or {})
    user_yaml['variables'] = user_yaml.get('variables', {})
    user_yaml['variables']['properties'] = properties or {}
    overrides = [
        (conf_obj.inputs_path, 'inputs_override', cmd_inputs_override),
        (blueprint_path, blueprint_override_key, cmd_blueprint_override)
    ]
    for yaml_path, prop, additional_overrides in overrides:
        unprocessed = conf.pop(prop, {})
        for additional in additional_overrides:
            unprocessed.update(additional)
        override = util.process_variables(user_yaml, unprocessed)
        with patcher.YamlPatcher(yaml_path, default_flow_style=False) as patch:
            for k, v in override.items():
                patch.set_value(k, v)
    return conf
예제 #3
0
 def __init__(self, env):
     self.env = env
     properties_name = env.handler_configuration.get('properties')
     if properties_name:
         properties = env.suites_yaml['handler_properties'][properties_name]
         processed_properties = process_variables(env.suites_yaml,
                                                  properties)
         for attr_name, attr_value in processed_properties.items():
             setattr(self, attr_name, attr_value)
예제 #4
0
 def properties(self):
     handler_configuration = self.handler_configuration
     properties_name = handler_configuration.get('properties')
     if not properties_name:
         return {}
     suites_yaml = self.load(settings.main_suites_yaml)
     handler_properties = suites_yaml.get('handler_properties', {})
     properties = handler_properties.get(properties_name, {})
     return util.process_variables(suites_yaml, properties)
예제 #5
0
 def __init__(self, env):
     self.env = env
     properties_name = env.handler_configuration.get('properties')
     if properties_name:
         properties = env.suites_yaml['handler_properties'][properties_name]
         processed_properties = process_variables(env.suites_yaml,
                                                  properties)
         for attr_name, attr_value in processed_properties.items():
             setattr(self, attr_name, attr_value)
    def __init__(self):
        self._initial_cwd = os.getcwd()
        self._global_cleanup_context = None
        self._management_running = False
        self.rest_client = None
        self.management_ip = None
        self.handler = None
        self._manager_blueprint_path = None
        self._workdir = tempfile.mkdtemp(prefix='cloudify-testenv-')

        if HANDLER_CONFIGURATION not in os.environ:
            raise RuntimeError('handler configuration name must be configured '
                               'in "HANDLER_CONFIGURATION" env variable')
        handler_configuration = os.environ[HANDLER_CONFIGURATION]
        suites_yaml_path = os.environ.get(
            SUITES_YAML_PATH,
            path(__file__).dirname().dirname().dirname() / 'suites' /
            'suites' / 'suites.yaml')
        with open(suites_yaml_path) as f:
            self.suites_yaml = yaml.load(f.read())
        if os.path.exists(os.path.expanduser(handler_configuration)):
            configuration_path = os.path.expanduser(handler_configuration)
            with open(configuration_path) as f:
                self.handler_configuration = yaml.load(f.read())
        else:
            self.handler_configuration = self.suites_yaml[
                'handler_configurations'][handler_configuration]

        self.cloudify_config_path = path(os.path.expanduser(
            self.handler_configuration['inputs']))

        if not self.cloudify_config_path.isfile():
            raise RuntimeError('config file configured in handler '
                               'configuration does not seem to exist: {0}'
                               .format(self.cloudify_config_path))

        if 'manager_blueprint' not in self.handler_configuration:
            raise RuntimeError(
                'manager blueprint must be configured in handler '
                'configuration')

        manager_blueprint = self.handler_configuration['manager_blueprint']
        self._manager_blueprint_path = os.path.expanduser(
            manager_blueprint)

        # make a temp config files than can be modified freely
        self._generate_unique_configurations()

        with YamlPatcher(self._manager_blueprint_path) as patch:
            manager_blueprint_override = process_variables(
                self.suites_yaml,
                self.handler_configuration.get(
                    'manager_blueprint_override', {}))
            for key, value in manager_blueprint_override.items():
                patch.set_value(key, value)

        handler = self.handler_configuration['handler']
        try:
            handler_module = importlib.import_module(
                'system_tests.{0}'.format(handler))
        except ImportError:
            handler_module = importlib.import_module(
                'suites.helpers.handlers.{0}.handler'.format(handler))
        handler_class = handler_module.handler
        self.handler = handler_class(self)

        self.cloudify_config = yaml.load(self.cloudify_config_path.text())
        self._config_reader = self.handler.CloudifyConfigReader(
            self.cloudify_config,
            manager_blueprint_path=self._manager_blueprint_path)
        with self.handler.update_cloudify_config() as patch:
            processed_inputs = process_variables(
                self.suites_yaml,
                self.handler_configuration.get('inputs_override', {}))
            for key, value in processed_inputs.items():
                patch.set_value(key, value)

        if 'manager_ip' in self.handler_configuration:
            self._running_env_setup(self.handler_configuration['manager_ip'])

        self.install_plugins = self.handler_configuration.get(
            'install_manager_blueprint_dependencies', True)

        if self.handler_configuration.get('clean_env_on_init', False) is True:
            logger.info('Cleaning environment on init..')
            self.handler.CleanupContext.clean_all(self)

        global test_environment
        test_environment = self
예제 #7
0
def _process_variables(suites_yaml, unprocessed_dict):
    from cosmo_tester.framework.util import process_variables
    return process_variables(suites_yaml, unprocessed_dict)
def _process_variables(suites_yaml, unprocessed_dict):
    from cosmo_tester.framework.util import process_variables
    return process_variables(suites_yaml, unprocessed_dict)
예제 #9
0
    def __init__(self):
        self._initial_cwd = os.getcwd()
        self._global_cleanup_context = None
        self._management_running = False
        self.rest_client = None
        self.management_ip = None
        self.handler = None
        self._manager_blueprint_path = None
        self._workdir = tempfile.mkdtemp(prefix='cloudify-testenv-')

        if HANDLER_CONFIGURATION not in os.environ:
            raise RuntimeError('handler configuration name must be configured '
                               'in "HANDLER_CONFIGURATION" env variable')
        handler_configuration = os.environ[HANDLER_CONFIGURATION]
        suites_yaml_path = os.environ.get(
            SUITES_YAML_PATH,
            path(__file__).dirname().dirname().dirname() / 'suites' /
            'suites' / 'suites.yaml')
        with open(suites_yaml_path) as f:
            self.suites_yaml = yaml.load(f.read())
        if os.path.exists(os.path.expanduser(handler_configuration)):
            configuration_path = os.path.expanduser(handler_configuration)
            with open(configuration_path) as f:
                self.handler_configuration = yaml.load(f.read())
        else:
            self.handler_configuration = self.suites_yaml[
                'handler_configurations'][handler_configuration]

        self.cloudify_config_path = path(os.path.expanduser(
            self.handler_configuration['inputs']))

        if not self.cloudify_config_path.isfile():
            raise RuntimeError('config file configured in handler '
                               'configuration does not seem to exist: {0}'
                               .format(self.cloudify_config_path))

        if 'manager_blueprint' not in self.handler_configuration:
            raise RuntimeError(
                'manager blueprint must be configured in handler '
                'configuration')

        manager_blueprint = self.handler_configuration['manager_blueprint']
        self._manager_blueprint_path = os.path.expanduser(
            manager_blueprint)

        # make a temp config files than can be modified freely
        self._generate_unique_configurations()

        with YamlPatcher(self._manager_blueprint_path) as patch:
            manager_blueprint_override = process_variables(
                self.suites_yaml,
                self.handler_configuration.get(
                    'manager_blueprint_override', {}))
            for key, value in manager_blueprint_override.items():
                patch.set_value(key, value)

        handler = self.handler_configuration['handler']
        try:
            handler_module = importlib.import_module(
                'system_tests.{0}'.format(handler))
        except ImportError:
            handler_module = importlib.import_module(
                'suites.helpers.handlers.{0}.handler'.format(handler))
        handler_class = handler_module.handler
        self.handler = handler_class(self)

        self.cloudify_config = yaml.load(self.cloudify_config_path.text())
        self._config_reader = self.handler.CloudifyConfigReader(
            self.cloudify_config,
            manager_blueprint_path=self._manager_blueprint_path)
        with self.handler.update_cloudify_config() as patch:
            processed_inputs = process_variables(
                self.suites_yaml,
                self.handler_configuration.get('inputs_override', {}))
            for key, value in processed_inputs.items():
                patch.set_value(key, value)

        if 'manager_ip' in self.handler_configuration:
            self._running_env_setup(self.handler_configuration['manager_ip'])

        self.install_plugins = self.handler_configuration.get(
            'install_manager_blueprint_dependencies', True)

        if self.handler_configuration.get('clean_env_on_init', False) is True:
            logger.info('Cleaning environment on init..')
            self.handler.CleanupContext.clean_all(self)

        global test_environment
        test_environment = self