Exemplo n.º 1
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)
Exemplo n.º 2
0
    def start(self, command="/bin/bash"):
        """
        starts the OpenShift application

        :param command: Do not use it directly (It is defined in config.yaml)
        :return: None
        """
        # Clean environment before running tests
        try:
            self._app_remove()
        except Exception as e:
            common.print_info(e, "OpenShift applications were removed")
            pass

        project = self.runHost('oc new-project %s' % self.project_name,
                               ignore_status=True,
                               verbose=common.is_not_silent())
        if self.template is None:
            if not self._app_exists():
                # This part is used for running an application without template or s2i
                self._create_app()
        else:
            common.print_debug(self.template)
            self._change_openshift_account(
                account=common.get_openshift_user(),
                password=common.get_openshift_passwd())
            self._remove_apps_from_openshift_resources(common.TEMPLATE)
            if not self._create_app_by_template():
                return False
        # Verify application is really deploy and prepared for testing.
        if not self._verify_pod():
            return False

        self._get_ip_instance()
Exemplo n.º 3
0
 def _get_openshift_template(self):
     """
     Function returns template name from OpenShift environment
     :return: dictionary
     """
     template_name = self._oc_get_output('template')
     common.print_debug(template_name)
 def __oc_status(self):
     oc_status = self.runHost("oc status",
                              ignore_status=True,
                              verbose=common.is_not_silent())
     common.print_debug(oc_status.stdout)
     common.print_debug(oc_status.stderr)
     return oc_status.exit_status
Exemplo n.º 5
0
 def testPaths(self):
     self.start()
     allpackages = filter(bool, self.run("rpm -qa").stdout.split("\n"))
     common.print_debug(allpackages)
     for package in allpackages:
         if 'filesystem' in package:
             continue
         for package_file in filter(bool, self.run("rpm -ql %s" % package).stdout.split("\n")):
             if not self._compare_fhs(package_file):
                 self.fail("(%s): File [%s] violates the FHS." % (package, package_file))
Exemplo n.º 6
0
 def _tcinfo(self, testcases, header, logs=True, description=True):
     """
     Parse testcases dics and print output for them in nicer format
     Main purpose is to display docstrings of testcases for failures
     example:
         def test_some(something)
             '''
             This is line1.
             This is line2.
             :return: None
             '''
             self.assertTrue(False, msg="This is fail reason")
     procudes line:    desc -> This is line1. This is line2.
                       reason -> This is fail reason
     :param testcases: dict of testcases
     :param header: str what to print as header
     :param logs: boolean if print logs for these testcases (default True)
     :param description: boolean if print description = docs strings for test class + function
     :return: None
     """
     if testcases:
         emptydelimiter = ""
         harddelimiter = "------------------------"
         common.print_info(emptydelimiter, "{0} {1} {0}".format(harddelimiter, header))
         for testcase in testcases:
             tcname = testcase
             if re.search('^[0-9]+-', testcase.get('id',"")):
                 tcname = testcase.get('id').split("-", 1)[1]
             tcnameoutput = tcname
             splitted = re.search("(.*):(.+)\.(.+)$", tcname)
             if splitted:
                 docstrcls = []
                 docstrtst = []
                 testfile, classname, fnname = splitted.groups()
                 try:
                     testmodule = imp.load_source("test", testfile)
                     if getattr(testmodule, classname).__doc__:
                         docstrcls = getattr(testmodule, classname).__doc__.strip().split("\n")
                     if getattr(getattr(testmodule, classname), fnname).__doc__:
                         docstrtst = getattr(getattr(testmodule, classname), fnname).__doc__.strip().split("\n")
                     tcnameoutput = " ".join([x for x in docstrcls + docstrtst if not re.search(":.*:", x)])
                     # TODO: replace more whitespaces just by one - we should find better solution how to that
                     tcnameoutput = ' '.join(tcnameoutput.split())
                 except Exception as e:
                     common.print_debug("(INFO) Error happen when parsing testcase name ({})".format(tcname), e)
                     pass
             common.print_info("TEST {0}:  {1}".format(testcase.get('status'), tcname))
             if description and tcnameoutput!=tcname and tcnameoutput and tcnameoutput.strip():
                 common.print_info("     desc -> {0}".format(tcnameoutput))
             if testcase.get('fail_reason') and testcase.get('fail_reason') != "None":
                 common.print_info("     reason -> {0}".format(testcase.get('fail_reason')))
             if logs:
                 common.print_info("     {0}".format(testcase.get('logfile')))
             common.print_info(emptydelimiter)
Exemplo n.º 7
0
def cli():
    # unknown options are forwarded to avocado run
    args, unknown = mtfparser().parse_known_args()

    if args.version:
        print "0.7.7"
        exit(0)

    # uses additional arguments, set up variable asap, its used afterwards:
    if args.debug:
        os.environ['DEBUG'] = 'yes'
        os.environ['AVOCADO_LOG_DEBUG'] = 'yes'
    if args.config:
        os.environ['CONFIG'] = args.config
    if args.url:
        os.environ['URL'] = args.url
    if args.modulemdurl:
        os.environ['MODULEMDURL'] = args.modulemdurl

    common.print_debug(
        "Options: linter={0}, setup={1}, action={2}, module={3}".format(
            args.linter, args.setup, args.action, args.module))
    common.print_debug(
        "remaining options for avocado or test files: {0}".format(unknown))

    # environment usage:
    #   read: os.environ.get('MODULE')
    #   write: os.environ['MODULE']

    # MODULE could be from:
    #   1. common.get_module_type() ... it reads config.yaml and treceback if it doesn't exist
    #   2. environment ... MODULE=docker etc
    #   3. argument ... --module=docker
    try:
        args.module = common.get_module_type()
        # TODO it wrongly writes: 'Using default minimal config ...', change in common.py
    except moduleframework.mtfexceptions.ModuleFrameworkException:
        pass

    if os.environ.get('MODULE') is not None:
        # environment is the highest priority because mtf uses environment (too much)
        args.module = os.environ['MODULE']

    if args.module:
        # setup also environment
        os.environ['MODULE'] = args.module

    if args.module in common.get_backend_list():
        # for debug purposes, to be sure about module variables or options
        common.print_debug("MODULE={0}, options={1}".format(
            os.environ.get('MODULE'), args.module))
    else:
        # TODO: what to do here? whats the defaults value for MODULE, do I know it?
        common.print_info(
            "MODULE={0} ; we support {1} \n === expecting your magic, enjoy! === "
            .format(os.environ.get('MODULE'), common.get_backend_list()))

    common.print_debug("MODULE={0}".format(os.environ.get('MODULE')))
    return args, unknown
Exemplo n.º 8
0
 def avocado_general(self):
     # additional parameters
     # self.additionalAvocadoArg: its from cmd line, whats unknown to this tool
     avocado_args = ""  # when needed => specify HERE your additional stuff
     avocadoAction = "avocado {ACTION} {AVOCADO_ARGS}".format(
         ACTION=self.args.action, AVOCADO_ARGS=avocado_args)
     bash = process.run("{AVOCADO} {a} {b}".format(
         AVOCADO=avocadoAction,
         a=self.additionalAvocadoArg,
         b=" ".join(self.tests)),
                        shell=True,
                        ignore_status=True)
     common.print_info(bash.stdout, bash.stderr)
     common.print_debug("Command used: ", bash.command)
     return bash.exit_status
Exemplo n.º 9
0
 def _get_pod_status(self):
     """
     This method checks if the POD is running within OpenShift environment.
     :return: True if POD is running with status "Running"
              False all other statuses
     """
     pod_initiated = False
     for pod in self._oc_get_output('pod'):
         common.print_debug(self.pod_id)
         if self._check_resource_in_json(pod):
             self._pod_status = pod.get('status').get('phase')
             if self._pod_status == "Running":
                 pod_initiated = True
                 break
     return pod_initiated
Exemplo n.º 10
0
def main():
    common.print_debug('verbose/debug mode')
    args, unknown = cli()

    if args.setup:
        # mtfenvset need bash environment!
        from moduleframework.mtf_environment import mtfenvset
        mtfenvset()

    a = AvocadoStart(args, unknown)
    if args.action == 'run':
        returncode = a.avocado_run()
        a.show_error()
    else:
        # when there is any need, change general method or create specific one:
        returncode = a.avocado_general()
    exit(returncode)
Exemplo n.º 11
0
    def avocado_run(self):
        self.json_tmppath = tempfile.mktemp()
        avocado_args = "--json {JSON_LOG}".format(JSON_LOG=self.json_tmppath)
        if self.args.xunit:
            avocado_args += " --xunit {XUNIT} ".format(XUNIT=self.args.xunit)
        avocadoAction = "avocado {ACTION} {AVOCADO_ARGS}".format(
            ACTION=self.args.action, AVOCADO_ARGS=avocado_args)

        # run avocado with right cmd arguments
        bash = process.run("{AVOCADO} {a} {b}".format(
            AVOCADO=avocadoAction,
            a=self.additionalAvocadoArg,
            b=" ".join(self.tests)),
                           shell=True,
                           ignore_status=True)
        common.print_info(bash.stdout, bash.stderr)
        common.print_debug("Command used: ", bash.command)
        return bash.exit_status
Exemplo n.º 12
0
    def _create_app(self, template=None):
        """
        It creates an application in OpenShift environment

        :param template: If parameter present, then create an application from template
        :return: Exit status of oc new-app.
        """
        cmd = ["oc", "new-app"]
        if template is None:
            cmd.append(self.container_name)
        else:
            cmd.extend([template, "-p", "APPLICATION_NAME=%s" % self.app_name])
        cmd.extend(["-l", "mtf_testing=true"])
        cmd.extend(["--name", self.app_name])
        common.print_debug(cmd)
        oc_new_app = self.runHost(' '.join(cmd), ignore_status=True)
        time.sleep(1)
        common.print_debug(oc_new_app.stdout)
        return oc_new_app.exit_status
Exemplo n.º 13
0
    def __init__(self, args, unknown):
        # choose between TESTS and ADDITIONAL ENVIRONMENT from options
        if args.linter:
            self.tests.append("{MTF_TOOLS}/*.py".format(
                MTF_TOOLS=metadata_common.MetadataLoaderMTF.MTF_LINTER_PATH))
        self.args = args

        for param in unknown:
            # take care of this, see tags for safe/unsafe:
            # http://avocado-framework.readthedocs.io/en/52.0/WritingTests.html#categorizing-tests
            if os.path.exists(param):
                # this is list of tests in local file
                self.tests.append(param)
            else:
                # this is additional avocado param
                self.additionalAvocadoArg += " {0} ".format(param)
        if self.args.metadata:
            common.print_info("Using Metadata loader for tests and filtering")
            metadata_tests = filtertests(backend="mtf",
                                         location=os.getcwd(),
                                         linters=False,
                                         tests=[],
                                         tags=[],
                                         relevancy="")
            tests_dict = [x[metadata_common.SOURCE] for x in metadata_tests]
            self.tests += tests_dict
            common.print_debug("Loaded tests via metadata file: %s" %
                               tests_dict)
        common.print_debug("tests = {0}".format(self.tests))
        common.print_debug("additionalAvocadoArg = {0}".format(
            self.additionalAvocadoArg))
Exemplo n.º 14
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)