Esempio n. 1
0
    def pip_cmd(self, pkgnames, cmd="install", pip_args=None):
        if pip_args is None:
            pip_args = []

        try:
            from setuptools import find_packages
            import pip
        except ImportError as ie:
            glob_logger.error(ie.msg)

        pip_args.append(cmd)
        if isinstance(pkgnames, str):
            pip_args.append(pkgnames)
        else:
            ## concatenate the lists
            pip_args += [pkg for pkg in pkgnames]

        msg = "Running pip " + " ".join(pip_args)
        glob_logger.info(msg)
        try:
            import pip
            pip.main(initial_args=pip_args)
        except ImportError as ie:
            self.logger.error("Unable to import pip")
            raise ie
Esempio n. 2
0
    def download_url(urlpath, output_dir=".", binary=False):
        try:
            thing = urlopen(urlpath)
        except Exception as e:
            print(str(e))
            return

        parsed = urlparse(urlpath)
        filename = os.path.basename(parsed.path)
        writemod = "wb" if binary else "w"

        fobj = thing.read()
        if output_dir != ".":
            if not os.path.exists(output_dir):
                glob_logger.error("{0} does not exist".format(output_dir))
                glob_logger.error("Writing file to {0}".format(os.getcwd()))
            else:
                filename = "/".join([output_dir, filename])
        with open(filename, writemod) as downloaded:
            try:
                downloaded.write(fobj)
            except TypeError:
                with open(filename, "wb") as downloaded:
                    downloaded.write(fobj)
        return os.path.exists(filename)
Esempio n. 3
0
def test_and_set_nested(host, timeout=600):
    """
    Verifies that the host has nested virtualization set for kvm module

    :param host:
    :param timeout:
    :return: ProcessResult
    """
    cmd = "cat /sys/module/kvm_intel/parameters/nested"
    res = Command(cmd, host=host)(showout=False)
    if res.output.strip() != "Y":
        # Reboot the masters machine
        glob_logger.info("rebooting {} to set nested param".format(host))
        rebooter(host, timeout=timeout)
        time.sleep(45)    # Fudge factor here...
        pinger(host, timeout=timeout)

        # After reboot, make sure nested support is there
        path = "/sys/module/kvm_intel/parameters/nested"
        cmd = "cat {}".format(path)
        try:
            res = Command(cmd, host=host)(showout=False)
            if res.output.strip() != "Y":
                glob_logger.error("{}={}".format(path, res.output.strip()))
                raise sce.ConfigException("Nested support still not enabled")
        except CommandException:
            raise sce.ConfigException("Nested support still not enabled")
    return res
Esempio n. 4
0
    def boot_instance(self, server_name, server_image, flavor, netid, count=1, **kwargs):
        """
        Boots up a compute instance

        So, in kilo you now have to specify a neutron_tests network ID

        :param netid:
        :param count:
        :param kwargs:
        :param server_name: string of name to give to compute instance
        :param server_image: the nova image object to boot up
        :param flavor: the flavor
        :return: instance if successful, None otherwise
        """
        if count == 1:
            default = dict([("name", server_name), ("image", server_image),
                            ("flavor", flavor), ("netid", netid)])
            if not kwargs:
                kwargs = default
            else:
                kwargs.update(default)

            instance = self.nova_session.servers.create(**kwargs)
            servers = self.nova_session.servers.list()
            for s in servers:
                if s.name == server_name:
                    return instance
            else:
                glob_logger.error("Base image did not boot up")
                return None
        else:
            for node in count:
                node_name = server_name + str(node)

                self.boot_instance(node_name, server_image, flavor, netid)
Esempio n. 5
0
def test_and_set_nested(host, timeout=600):
    """
    Verifies that the host has nested virtualization set for kvm module

    :param host:
    :param timeout:
    :return: ProcessResult
    """
    cmd = "cat /sys/module/kvm_intel/parameters/nested"
    res = Command(cmd, host=host)(showout=False)
    if res.output.strip() != "Y":
        # Reboot the masters machine
        glob_logger.info("rebooting {} to set nested param".format(host))
        rebooter(host, timeout=timeout)
        time.sleep(45)  # Fudge factor here...
        pinger(host, timeout=timeout)

        # After reboot, make sure nested support is there
        path = "/sys/module/kvm_intel/parameters/nested"
        cmd = "cat {}".format(path)
        try:
            res = Command(cmd, host=host)(showout=False)
            if res.output.strip() != "Y":
                glob_logger.error("{}={}".format(path, res.output.strip()))
                raise sce.ConfigException("Nested support still not enabled")
        except CommandException:
            raise sce.ConfigException("Nested support still not enabled")
    return res
Esempio n. 6
0
    def _poll_for_status(self, instance, status, poll_interval=2, timeout=300, log=False):
        """
        Polls for the status of a nova instance

        :param instance: The nova instance object to poll
        :param status: What status to check for.  If "deleted", polls until the
                       instance has been deleted
        :param poll_interval:
        :param timeout:
        :return:
        """
        start_time = time.time()

        def timer():
            endtime = start_time + timeout
            if timeout is None:
                return True
            else:
                timenow = time.time()
                check = endtime > timenow
                return check

        achieved = False
        while timer():
            try:
                instance.get()
            except NotFound as nf:
                if status == "deleted":
                    achieved = True
                    break
                else:
                    raise nf
            except AttributeError as ae:
                if status == "deleted":
                    achieved = True
                    break
                else:
                    raise ae
            else:
                if instance.status == "ERROR":
                    if status == "ERROR":
                        achieved = True
                    else:
                        glob_logger.error("Failed to boot instance")
                    break
                if instance.status != status:
                    if log:
                        msg = "Checking for {} on {}: status is {}"
                        msg = msg.format(status, instance.name, instance.status)
                        glob_logger.info(msg)
                    time.sleep(poll_interval)
                else:
                    achieved = True
                    break
        return achieved