Example #1
0
 def _create_app_by_template(self):
     """
     It creates an application in OpenShift environment by OpenShift template
     Steps:
     * oc cluster up
     * oc create -f <template> -n openshift
     * oc new-app memcached -p APPLICATION_NAME=memcached
     :return:
     """
     self._register_docker_to_openshift_registry()
     self.runHost('oc get is')
     oc_template_app = self.runHost('oc process -f "%s"' % self.template,
                                    verbose=common.is_not_silent())
     self._change_openshift_account()
     oc_template_create = None
     try:
         oc_template_create = self.runHost(
             'oc create -f %s -n %s' % (self.template, self.project_name),
             verbose=common.is_not_silent())
     except CmdError as cme:
         common.print_info('oc create -f failed with traceback %s' %
                           cme.message)
         self.runHost('oc status')
         self._oc_get_output('all')
         return False
     self._change_openshift_account(account=common.get_openshift_user(),
                                    password=common.get_openshift_passwd())
     template_name = self._get_openshift_template()
     time.sleep(1)
     self._create_app(template=template_name)
     self.runHost('oc status')
     return True
Example #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()
Example #3
0
    def _register_docker_to_openshift_registry(self):
        """
        Function pushes an OpenShift docker-registry into docker
        Commands which are use are in this order
        * oc whoami -t
        * switch to OpenShift system:admin account
        * gets an IP of OpenShift registry
        * switch to user defined OpenShift user and password.
        * runs docker login with token and IP:5000
        * tag container name
        * push container name into docker
        """
        whoami = self.runHost("oc whoami -t", ignore_status=True, verbose=core.is_debug())

        self._change_openshift_account()
        if self.get_docker_pull():
            self.runHost('docker pull %s' % self.container_name)
        openshift_ip_register = self._get_openshift_ip_registry()
        self._change_openshift_account(account=common.get_openshift_user(),
                                password=common.get_openshift_passwd())

        docker_login = self.runHost('docker login -u {user} -p {token} {ip}:5000'.format(
            user=common.get_openshift_user(),
            token=whoami.stdout.strip(),
            ip=openshift_ip_register), ignore_status=True, verbose=core.is_debug())
        oc_path = "{ip}:5000/{project}/{name}".format(ip=openshift_ip_register,
                                                      name=self.app_name,
                                                      project=self.project_name)


        self.runHost('docker tag %s %s' % (self.container_name,
                                           oc_path), ignore_status=True)
        self.runHost('docker push %s' % oc_path, ignore_status=True)
Example #4
0
    def stop(self):
        """
        This method checks if the application is deployed within OpenShift environment
        and removes service, deployment config and imagestream from OpenShift.

        :return: None
        """
        self._change_openshift_account(account=common.get_openshift_user(),
                                       password=common.get_openshift_passwd())
        self._oc_get_output('all')
        if self._app_exists():
            try:
                self._app_remove()
            except Exception as e:
                common.print_info(e, "OpenShift application already removed")
                pass
 def _openshift_login(self,
                      oc_ip="127.0.0.1",
                      oc_user='******',
                      oc_passwd='developer',
                      env=False):
     """
     It logins to an OpenShift environment on specific IP and under user and his password.
     :param oc_ip: an IP where is an OpenShift environment running
     :param oc_user: an username under which we can login to OpenShift environment
     :param oc_passwd: a password for specific username
     :param env: is used for specification OpenShift IP, user and password, otherwise defaults are used
     :return:
     """
     if env:
         oc_ip = common.get_openshift_ip()
         oc_user = common.get_openshift_user()
         oc_passwd = common.get_openshift_passwd()
     oc_output = self.runHost(
         "oc login %s:8443 --username=%s --password=%s" %
         (oc_ip, oc_user, oc_passwd),
         verbose=common.is_not_silent())
     return oc_output.exit_status