Exemplo n.º 1
0
    def _convert_topology(self, topology):
        """
        For backward compatiblity, convert the old topology format
        into the new format. Should be pretty straightforward and simple.

        ;param topology: topology dictionary
        """
        try:
            res_grps = topology.get('resource_groups')
            if res_grps:
                for res_grp in res_grps:
                    if 'res_group_type' in res_grp.keys():
                        res_grp['resource_group_type'] = (
                            res_grp.pop('res_group_type'))

                    if 'res_defs' in res_grp.keys():
                        res_grp['resource_definitions'] = (
                            res_grp.pop('res_defs'))

                    res_defs = res_grp.get('resource_definitions')
                    if not res_defs:
                        # this means it's either a beaker or openshift topology
                        res_grp_type = res_grp.get('resource_group_type')

                        res_group = self._fix_broken_topologies(
                            res_grp, res_grp_type)
                        res_defs = res_group.get('resource_definitions')
                        res_grp['resource_definitions'] = res_defs

                    if res_defs:
                        for res_def in res_defs:
                            if 'res_name' in res_def.keys():
                                res_def['name'] = res_def.pop('res_name')
                            if 'type' in res_def.keys():
                                res_def['role'] = res_def.pop('type')
                            if 'res_type' in res_def.keys():
                                res_def['role'] = res_def.pop('res_type')
                            if 'count' in res_def.keys():
                                res_def['count'] = int(res_def.pop('count'))
                    else:
                        raise TopologyError("'resource_definitions' do not"
                                            " validate in topology"
                                            " ({0})".format(topology))
            else:
                raise TopologyError("'resource_groups' do not validate"
                                    " in topology ({0})".format(topology))

        except Exception:
            raise LinchpinError("Unknown error converting schema. Check"
                                " template data")
Exemplo n.º 2
0
    def _get_data_path(self):
        """
        This function finds the template data path, or returns the data.
        If the file is a full path, it is expanded and used.
        If not found, the workspace is prepended. If still not found, it
        is assumed what is passed in is data and returned to the caller.

        :param data_path:
            Consists of either a absolute path, relative path, or the actual
            template data.
        """

        if not self.pf_data or not self.pf_data.startswith('@'):
            return None
        else:
            pf_data_path = self.pf_data[1:]
            data_w_path = os.path.abspath(os.path.expanduser(pf_data_path))

            if not os.path.exists(data_w_path):
                data_w_path = '{0}/{1}'.format(self.workspace, pf_data_path)
                if not os.path.exists(data_w_path):
                    error_txt = "Template-data (-d) file was not found. Check"
                    error_txt += " the template path and try again."
                    raise TopologyError(error_txt)

            return data_w_path
Exemplo n.º 3
0
    def validate_topology_highlevel(self, topo_data):
        """
        validate the higher-level components of the topology

        These are not specific to the provider and must be validated separately
        from the items within each resource group

        :param topo_data topology data from the pinfile
        """

        role_path = self._find_role_path("common")
        try:
            sp = "{0}/files/topo-schema.json".format(role_path)
            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}'"
                                " {1}".format(sp, e))

        document = {'topology': topo_data}
        v = AnyofValidator(schema, error_handler=ValidationErrorHandler)

        if not v.validate(document):
            try:
                err = self._gen_error_msg("", "", v.errors)
                raise TopologyError(err)
            except NotImplementedError:
                # we shouldn't have this issue using cererus >= 1.2, but
                # this is here just in case an older version has to be used
                self.ctx.log_state("There was an error validating your schema,\
                      but we can't seem to format it for you")
                self.ctx.log_state("Here's the raw error data in case you want\
                      to go through it by hand:")
                self.ctx.log_state(v._errors)