コード例 #1
0
    def getModulemdYamlconfig(self, urllink=None):
        """
        Return moduleMD file yaml object.
        It can be used also for loading another yaml file via url parameter

        :param (str): url link to load. Default url defined in the `config.yaml` file,
                      can be overridden by the **CONFIG** envvar.
        :return: dict
        """
        link = {"data": {}}
        if urllink:
            modulemd = urllink
        elif self.is_it_module:
            if self.modulemdConf:
                return self.modulemdConf
            else:
                modulemd = get_modulemdurl()
                if not modulemd:
                    modulemd = self.config.get("modulemd-url")
        else:
            return link
        try:
            ymlfile = urllib.urlopen(modulemd)
            link = yaml.load(ymlfile)
        except IOError as e:
            raise ConfigExc("File '%s' cannot be load" % modulemd, e)
        except yaml.parser.ParserError as e:
            raise ConfigExc("Module MD file contains errors: '%s'" % e,
                            modulemd)
        if not urllink:
            self.modulemdConf = link
        return link
コード例 #2
0
def get_config():
    """
    Read the module's configuration file.

    :default: ``./config.yaml`` in the ``tests`` directory of the module's root
     directory
    :envvar: **CONFIG=path/to/file** overrides default value.
    :return: str
    """
    global __persistent_config
    if not __persistent_config:
        cfgfile = os.environ.get('CONFIG')
        if cfgfile:
            if os.path.exists(cfgfile):
                print_debug("Config file defined via envvar: %s" % cfgfile)
            else:
                raise ConfigExc(
                    "File does not exist although defined CONFIG envvar: %s" %
                    cfgfile)
        else:
            cfgfile = "./config.yaml"
            if os.path.exists(cfgfile):
                print_debug("Using module config file: %s" % cfgfile)
            else:
                cfgfile = "/usr/share/moduleframework/docs/example-config-minimal.yaml"
                print_debug("Using default minimal config: %s" % cfgfile)
                if not get_url():
                    raise ModuleFrameworkException(
                        "You have to use URL envvar for testing your images or repos"
                    )

        try:
            with open(cfgfile, 'r') as ymlfile:
                xcfg = yaml.load(ymlfile.read())
            doc_name = ['modularity-testing', 'meta-test-family', 'meta-test']
            if xcfg.get('document') not in doc_name:
                raise ConfigExc("bad yaml file: item (%s)" % doc_name,
                                xcfg.get('document'))
            if not xcfg.get('name'):
                raise ConfigExc("Missing (name:) in config file")
            if not xcfg.get("module"):
                raise ConfigExc("No module in yaml config defined")
            # copy rpm section to nspawn, in case not defined explicitly
            # make it backward compatible
            if xcfg.get("module", {}).get("rpm") and not xcfg.get(
                    "module", {}).get("nspawn"):
                xcfg["module"]["nspawn"] = copy.deepcopy(
                    xcfg.get("module", {}).get("rpm"))
            __persistent_config = xcfg
            return xcfg
        except IOError:
            raise ConfigExc(
                "Error: File '%s' doesn't appear to exist or it's not a YAML file. "
                "Tip: If the CONFIG envvar is not set, mtf-generator looks for './config'."
                % cfgfile)
    else:
        return __persistent_config
コード例 #3
0
 def __init__(self):
     """
     set basic object variables
     """
     super(OpenShiftHelper, self).__init__()
     self.name = None
     self.icontainer = self.get_url()
     self.template = self.get_template()
     self.pod_id = None
     self._ip_address = None
     if not self.icontainer:
         raise ConfigExc(
             "No container image specified in the configuration file or environment variable."
         )
     if "docker=" in self.icontainer:
         self.container_name = self.icontainer[7:]
     else:
         # untrusted source
         self.container_name = self.icontainer
     # application name is taken from docker.io/modularitycontainer/memcached
     self.app_name = self.container_name.split('/')[-1]
     self.app_ip = None
     random_str = ''.join(random.choice(string.lowercase) for _ in range(3))
     self.project_name = "{project}-{random_str}".format(
         project=self.app_name, random_str=random_str)
     common.print_debug(self.icontainer, self.app_name)
コード例 #4
0
 def __init__(self):
     """
     set basic object variables
     """
     super(OpenShiftHelper, self).__init__()
     self.name = None
     self.icontainer = self.get_url()
     self.pod_id = None
     self._pod_status = None
     if not self.icontainer:
         raise ConfigExc(
             "No container image specified in the configuration file or environment variable."
         )
     if "docker=" in self.icontainer:
         self.container_name = self.icontainer[7:]
     else:
         # untrusted source
         self.container_name = self.icontainer
     # application name is taken from docker.io/modularitycontainer/memcached
     self.app_name = self.container_name.split('/')[-1]
     self.app_ip = None
     common.print_debug(self.icontainer, self.app_name)
コード例 #5
0
    def loadconfig(self):
        """
        Load configuration from config.yaml file.

        :return: None
        """
        # we have to copy object. because there is just one global object, to improve performance
        self.config = copy.deepcopy(get_config())
        self.info = self.config.get("module", {}).get(get_module_type_base())
        # if there is inheritance join both dictionary
        self.info.update(self.config.get("module", {}).get(get_module_type()))
        if not self.info:
            raise ConfigExc(
                "There is no section for (module: -> %s:) in the configuration file."
                % get_module_type_base())

        if self.config.get('modulemd-url') and get_if_module():
            self.is_it_module = True
        else:
            pass

        self.component_name = sanitize_text(self.config['name'])
        self.source = self.config.get('source')
        self.set_url()