Esempio n. 1
0
 def _get_openshift_template(self):
     """
     Function returns template name from OpenShift environment
     :return: dictionary
     """
     template_name = self._oc_get_output('template')
     core.print_debug(template_name)
Esempio 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:
            core.print_info(e, "OpenShift applications were removed")
            pass

        project = self.runHost('oc new-project %s' % self.project_name,
                               ignore_status=True,
                               verbose=core.is_debug())
        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:
            core.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.conf["openshift"]["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()
 def __oc_status(self):
     oc_status = self.runHost("oc status",
                              ignore_status=True,
                              verbose=common.is_not_silent())
     core.print_debug(oc_status.stdout)
     core.print_debug(oc_status.stderr)
     return oc_status.exit_status
Esempio n. 4
0
 def testPaths(self):
     self.start()
     allpackages = filter(bool, self.run("rpm -qa").stdout.split("\n"))
     core.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))
    def stop(self):
        """
        Stop the docker container

        :return: None
        """
        if self.status():
            try:
                self.runHost("docker stop %s" % self.docker_id,
                             verbose=core.is_not_silent())
                self.runHost("docker rm %s" % self.docker_id,
                             verbose=core.is_not_silent())
            except Exception as e:
                core.print_debug(e, "docker already removed")
                pass
Esempio n. 6
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'):
         core.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
Esempio n. 7
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])
        core.print_debug(cmd)
        oc_new_app = self.runHost(' '.join(cmd), ignore_status=True)
        time.sleep(1)
        core.print_debug(oc_new_app.stdout)
        return oc_new_app.exit_status
Esempio n. 8
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 mtfexceptions.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)
     core.print_debug(self.icontainer, self.app_name)