def __init__(self):
     """
     set basic object variables
     """
     super(ContainerHelper, self).__init__()
     static_name = "testcontainer"
     self.tarbased = None
     self.name = None
     self.docker_id = None
     self._icontainer = self.get_url()
     if not self._icontainer:
         raise mtfexceptions.ConfigExc(
             "No container image specified in the configuration file or environment variable."
         )
     if ".tar" in self._icontainer:
         self.name = static_name
         self.tarbased = True
     if "docker=" in self._icontainer:
         self.name = self._icontainer[7:]
         self.tarbased = False
     else:
         # untrusted source
         self.tarbased = False
         self.name = self._icontainer
     self.docker_static_name = ""
     if common.get_if_reuse():
         self.docker_static_name = "--name %s" % static_name
예제 #2
0
 def __init__(self):
     """
     Set basic variables for NSPAWN environment, the most important is that it set
     relative change root path
     """
     super(NspawnHelper, self).__init__()
     self.baseprefix = os.path.join(BASEPATHDIR, "chroot_")
     time.time()
     actualtime = time.time()
     self.chrootpath_baseimage = ""
     if not get_if_reuse():
         self.name = "%s_%r" % (self.component_name, actualtime)
     else:
         self.name = self.component_name
     self.chrootpath = os.path.abspath(self.baseprefix + self.name)
예제 #3
0
    def tearDown(self):
        """
        cleanup environment after test is finished and call cleanup section in config file

        :return: None
        """
        if get_if_do_cleanup() and not get_if_reuse():
            try:
                self.__container.stop()
            except:
                pass
            try:
                self.__container.rm()
            except:
                pass
        else:
            print_info("tearDown skipped", "running nspawn: %s" % self.name)
            print_info("To connect to a machine use:",
                       "machinectl shell root@%s /bin/bash" % self.name)
    def status(self, command=None):
        """
        get status if container is running

        :return: bool
        """
        if not self.docker_id and common.get_if_reuse():
            result = self.runHost("docker ps -q --filter %s" %
                                  self.docker_static_name[2:],
                                  ignore_status=True,
                                  verbose=core.is_debug())
            # lenght of docker id  number is 12
            if result.exit_status == 0 and len(result.stdout) > 10:
                self.docker_id = result.stdout.strip()
                return True
        if self.docker_id and self.docker_id[:12] in self.runHost(
                "docker ps", shell=True, verbose=core.is_not_silent()).stdout:
            return True
        else:
            return False