Exemple #1
0
    def test_jenkins_bug_quote(self):
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(
            os.path.join(this, "data", ".local.jenkins.lin.bug.yml"))
        self.assertExists(yml)

        github = "https://github.com/sdpython/"

        modules = [("yml", yml, "H H(10-11) * * 0")]

        engines = dict(Python38="/usr/bin/python3.8",
                       Python37="/usr/bin/python3.7",
                       Python36="/usr/bin/python3.6",
                       Python39="/usr/bin/python3.9",
                       root_path="./rootpath/")
        vers = "%d%d" % sys.version_info[:2]

        srv = JenkinsExt("http://localhost:8080/",
                         "user",
                         "password",
                         mock=True,
                         engines=engines,
                         platform="linux")

        res = srv.setup_jenkins_server(github=github,
                                       modules=modules,
                                       overwrite=True,
                                       add_environ=False,
                                       location="anything",
                                       disable_schedule=False,
                                       credentials="")
        res = list(res)
        self.assertEqual(len(res), 3)
        scripts = [''.join(s) for s in res]
        for sc in scripts:
            self.assertNotIn("Python370_x64", sc)
        nb = 0
        for last in scripts:
            self.assertNotIn(
                "$PYINT -c \"from sphinx.cmd.build import build_main\n'", last)
            if "3.6" in last:
                self.assertIn("export LD_LIBRARY_PATH=/usr/local/Python-3.6.8",
                              last)
            elif "3.7" in last:
                self.assertIn("export LD_LIBRARY_PATH=/usr/local/Python-3.7.2",
                              last)
            elif "3.8" in last:
                self.assertIn("export LD_LIBRARY_PATH=/usr/local/Python-3.8.1",
                              last)
            else:
                raise Exception("Unknown python in job\n----------\n" + last +
                                "\n-------")
            if "NAME=UT" in last:
                self.assertIn(
                    "build_main(['-j2','-v','-T','-b','html','-d','dist/doctrees','_doc','dist/html']",
                    last)
                nb += 1
        self.assertEqual(nb, 1)
    def test_jenkins(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(__file__, "temp_jenkins_yml")
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python34="c:\\Python34_x64",
                       Python35=os.path.dirname(sys.executable),
                       Python36=os.path.dirname(sys.executable),
                       Python37=os.path.dirname(sys.executable),
                       Python38=os.path.dirname(sys.executable),
                       Python27="c:\\Python27_x64",
                       Anaconda3="c:\\Anaconda3", Anaconda2="c:\\Anaconda2",
                       WinPython36="c:\\PythonENSAE",
                       root_path="d:\\jenkins\\yml")
        vers = "%d%d" % sys.version_info[:2]
        context["Python%s" % vers] = os.path.dirname(sys.executable)
        git_repo = "https://github.com/sdpython/pyquickhelper.git"
        srv = JenkinsExt("http://localhost:8080/", "user", "password",
                         mock=True, fLOG=fLOG, engines=context)
        for i, tuconv in enumerate(enumerate_processed_yml(yml, server=srv,
                                                           context=context, git_repo=git_repo, yml_platform="win32")):
            conv, name, var = tuconv
            c = "conda" if "c:\\Anaconda" in conv else 'win'
            with open(os.path.join(temp, "yml-%s-%d.xml" % (c, i)), "w") as f:
                f.write(conv)
    def test_jenkins_bug_quote(self):
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "data", ".local.jenkins.lin.bug.yml"))
        self.assertExists(yml)

        github = "https://github.com/sdpython/"

        modules = [("yml", yml, "H H(10-11) * * 0")]

        engines = dict(Python37="/usr/bin/python3.7",
                       Python36="/usr/bin/python3.6",
                       root_path="./rootpath/")
        vers = "%d%d" % sys.version_info[:2]

        srv = JenkinsExt(
            "http://localhost:8080/", "user", "password", mock=True,
            engines=engines, platform="linux")

        res = srv.setup_jenkins_server(github=github, modules=modules,
                                       overwrite=True, add_environ=False,
                                       location="anything", disable_schedule=False,
                                       credentials="")
        res = list(res)
        self.assertEqual(len(res), 4)
        scripts = [''.join(s) for s in res]
        for sc in scripts:
            self.assertNotIn("Python370_x64", sc)
        nb = 0
        for last in scripts:
            self.assertNotIn(
                "$PYINT -c \"from sphinx.cmd.build import build_main\n'", last)
            if "3.6" in last:
                self.assertIn(
                    "export LD_LIBRARY_PATH=/usr/local/Python-3.6.8", last)
            elif "3.7" in last:
                self.assertIn(
                    "export LD_LIBRARY_PATH=/usr/local/Python-3.7.2", last)
            else:
                raise Exception(
                    "Unknown python in job\n----------\n" + last + "\n-------")
            if "NAME=UT" in last:
                self.assertIn(
                    "build_main(['-j2','-v','-T','-b','html','-d','dist/doctrees','_doc','dist/html']", last)
                nb += 1
        self.assertEqual(nb, 1)
    def _jenkins_ext_setup_server_yaml2(self, use_url):
        srv = JenkinsExt(
            "http://localhost:8080/", "user", "password", mock=True,
            engines=default_engines(platform="win32"), fLOG=fLOG, platform="win32")

        fLOG("---------------------")
        modules = default_jenkins_jobs()
        if not use_url:
            this = os.path.abspath(os.path.dirname(__file__))
            local_file = os.path.join(this, "data", ".local.jenkins.win.yml")
            modules = [('yml', local_file, 'H H(5-6) * * 0')]
        fLOG("[modules]", modules)
        res = setup_jenkins_server_yml(srv, github="sdpython", modules=modules,
                                       overwrite=True, add_environ=False,
                                       location="anything")
        reg = re.compile("<description>(.*)</description>")
        nb = 0
        sch = 0
        for i, r in enumerate(res):
            conf = r[-1]

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            if "PYQUICKHELPER27" in conf:
                raise Exception(conf)

            if "SET VERSION=" not in conf:
                raise Exception(conf)
            if "SET NAME=" not in conf:
                raise Exception(conf)
            if "SET DIST=" not in conf:
                raise Exception(conf)
            if use_url and "anything\\pyquickhelper\\%NAME_JENKINS%" not in conf:
                raise Exception(conf)
            if "pyquickhelper_UT_%d%d_std" % sys.version_info[:2] in conf:
                nb += 1
            if "H H(5-6) * * 0" in conf:
                sch += 1
            if "H H(6-7) * * 0" in conf:
                sch += 1

        self.assertTrue(i > 0)
        if use_url:
            if nb == 0:
                raise AssertionError(
                    "\n##############\n".join(r[-1] for r in res))
        self.assertEqual(sch, 2)
    def _jenkins_ext_setup_server_yaml2(self):
        srv = JenkinsExt("http://localhost:8080/",
                         "user",
                         "password",
                         mock=True,
                         engines=default_engines(platform="win32"),
                         fLOG=fLOG,
                         platform="win32")

        fLOG("---------------------")
        this = os.path.abspath(os.path.dirname(__file__))
        local_file = os.path.join(this, "data", ".local.jenkins.win2.yml")
        modules = [('yml', local_file, None)]

        fLOG("[modules]", modules)
        res = setup_jenkins_server_yml(srv,
                                       github="sdpython",
                                       modules=modules,
                                       overwrite=True,
                                       add_environ=False,
                                       location="anything")
        reg = re.compile("<description>(.*)</description>")
        sch = 0
        for i, r in enumerate(res):
            conf = r[-1]

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            if "PYQUICKHELPER27" in conf:
                raise Exception(conf)

            if "SET VERSION=" not in conf:
                raise Exception(conf)
            if "SET NAME=" not in conf:
                raise Exception(conf)
            if "SET DIST=" not in conf:
                raise Exception(conf)
            if "10 10 * * *" in conf:
                sch += 1

        self.assertEqual(sch, 1)
Exemple #6
0
    def test_jenkins_ext_setup_server_yaml_split2(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        engines = dict(Python35="py35", Python36="C:\\Python36_x64",
                       Python39="C:\\Python39_x64",
                       Python27="py27", Anaconda3="ana3", Anaconda2="ana2",
                       project_name="pyquickhelper", root_path="ROOT")
        srv = JenkinsExt(
            "http://localhost:8080/", "user", "password", mock=True,
            engines=engines, fLOG=fLOG, platform="win32")

        this = os.path.abspath(os.path.dirname(__file__))
        localyml = os.path.abspath(os.path.join(
                                   this, "data", "local2.yml"))

        fLOG("---------------------")
        modules = [('yml', localyml, 'H H(5-6) * * 0')]
        res = setup_jenkins_server_yml(srv, github="sdpython", modules=modules,
                                       overwrite=True, add_environ=False,
                                       location="anything")
        reg = re.compile("<description>(.*)</description>")
        assert len(res) > 0
        for i, r in enumerate(res):
            conf = r[-1]

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            confno = conf.replace("\n", "")
            exp = "</hudson.tasks.BatchFile><hudson.tasks.BatchFile>"
            if exp not in confno:
                raise Exception(confno)
    def _linux_jenkins_ext_setup_server_yaml2(self, local_file, disp):
        srv = JenkinsExt(
            "http://localhost:8080/", "user", "password", mock=True,
            engines=default_engines(platform="linux"), fLOG=fLOG, platform="linux")

        fLOG("---------------------")
        modules = [('yml', local_file, None)]

        fLOG("[modules]", modules)
        res = setup_jenkins_server_yml(srv, github="sdpython", modules=modules,
                                       overwrite=True, add_environ=False,
                                       location="anything")
        reg = re.compile("<description>(.*)</description>")
        sch = 0
        wipe = 0
        pub = 0
        arti = 0
        confs = []
        for i, r in enumerate(res):
            conf = r[-1]
            if "set current=" in conf.lower():
                raise Exception("The job is for linux\n{0}".format(conf))
            if "SET " in conf:
                raise Exception("The job is for linux\n{0}".format(conf))
            if "c:" in conf:
                raise Exception("The job is for linux\n{0}".format(conf))
            if disp:
                fLOG(conf)

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            if "PYQUICKHELPER27" in conf:
                raise Exception(conf)

            if "export VERSION=" not in conf:
                raise Exception(conf)
            if "export NAME=" not in conf:
                raise Exception(conf)
            if "export DIST=" not in conf:
                raise Exception(conf)
            if "<runOnChoice>ON_BOTH</runOnChoice>" in conf:
                sch += 1
            if "PUBLISHER" in conf:
                pub += 1
            if "artifacts" in conf:
                arti += 1
            if 'if [ "PYPI"' in conf:
                raise Exception(conf)
            if "<hudson.plugins.git.extensions.impl.WipeWorkspace />" in conf:
                wipe += 1
            confs.append(conf)

        if sch + pub != 1:
            raise Exception("{0} != {1}\n{2}".format(
                sch + pub, 1, "\n\n\n----------------------------\n\n\n".join(confs)))
        if pub == 0 and wipe != len(confs):
            raise Exception("{0} != {1}\n{2}".format(
                wipe, len(confs), "\n\n\n----------------------------\n\n\n".join(confs)))
        if pub != 0 and wipe != 0:
            raise Exception("{0} != {1}\n{2}".format(
                wipe, len(confs), "\n\n\n----------------------------\n\n\n".join(confs)))
        if arti == 0:
            raise Exception("{0} != {1}\n{2}".format(
                wipe, len(confs), "\n\n\n----------------------------\n\n\n".join(confs)))
    def private_tst_jenkins_ext_setup_server_yaml(self, disable_schedule, credentials):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        yml_url = "https://raw.githubusercontent.com/sdpython/python3_module_template/master/.local.jenkins.win.yml"

        github = "https://github.com/sdpython/"

        modules = [("yml", yml, "H H(10-11) * * 0"),
                   ("yml", yml_url, "H H(10-11) * * 0")]

        engines = dict(Python34="c:\\Python34_x64",
                       Python35=os.path.dirname(sys.executable),
                       Python36=os.path.dirname(sys.executable),
                       Python27="c:\\Python27_x64",
                       Anaconda3="c:\\Anaconda3", Anaconda2="c:\\Anaconda2",
                       WinPython36="c:\\PythonENSAE",
                       root_path="d:\\jenkins\\yml")
        vers = "%d%d" % sys.version_info[:2]
        engines["Python%s" % vers] = os.path.dirname(sys.executable)

        srv = JenkinsExt(
            "http://localhost:8080/", "user", "password", mock=True,
            engines=engines, fLOG=fLOG, platform="win32")

        if not sys.platform.startswith("win"):
            # not yet implemented
            return

        fLOG("---------------------")
        res = srv.setup_jenkins_server(github=github, modules=modules,
                                       overwrite=True, add_environ=False,
                                       location="anything", disable_schedule=disable_schedule,
                                       credentials=credentials)
        reg = re.compile("<description>(.*)</description>")
        exp_ut = "python3_module_template_UT_%s_std" % vers
        nb = 0
        sch = 0
        desc = 0
        to = 0
        nb_jen = 0
        for i, r in enumerate(res):
            conf = r[-1]

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            if "PYQUICKHELPER27" in conf:
                raise Exception(conf)

            if "SET VERSION=" not in conf:
                raise Exception(conf)
            if "SET NAME=" not in conf:
                raise Exception(conf)
            if "SET DIST=" not in conf:
                raise Exception(conf)
            if "anything\\python3_module_template\\%NAME_JENKINS%" not in conf:
                nb_jen += 1
            if "python3_module_template_UT_36_std" in conf or exp_ut in conf:
                nb += 1
            if "H H(20-21) * * 0" in conf:
                sch += 1
            if "H H(16-17) * * 0" in conf:
                sch += 1
            if "0101 - H H(20-21) * * 0" in conf:
                desc += 1
            if "0101 - H H(16-17) * * 0" in conf:
                desc += 1
            if "<timeoutSecondsString>900</timeoutSecondsString>" in conf:
                to += 1

        if sys.version_info[0] != 2:
            self.assertTrue(i > 0)
            self.assertTrue(nb > 0)
            self.assertTrue(nb_jen > 0)
            self.assertTrue(to > 0)
            if disable_schedule:
                self.assertEqual(sch, 0)
                self.assertEqual(desc, 0)
            else:
                self.assertEqual(sch, 2)
                self.assertEqual(desc, 2)
            fLOG(to)
            if credentials:
                if "credentialsId" not in conf:
                    raise Exception(conf)
            else:
                if "<credentialsId>None" not in conf:
                    raise Exception(conf)
        else:
            warnings.warn("disable the test on Python 2.7")
    def private_tst_jenkins_ext_setup_server_yaml(self, disable_schedule,
                                                  credentials):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(
            os.path.join(this, "..", "..", ".local.jenkins.win.yml"))
        yml_url = "https://raw.githubusercontent.com/sdpython/python3_module_template/master/.local.jenkins.win.yml"

        github = "https://github.com/sdpython/"

        modules = [("yml", yml, "H H(10-11) * * 0"),
                   ("yml", yml_url, "H H(10-11) * * 0")]

        engines = dict(Python34="c:\\Python34_x64",
                       Python35=os.path.dirname(sys.executable),
                       Python36=os.path.dirname(sys.executable),
                       Python37=os.path.dirname(sys.executable),
                       Python38=os.path.dirname(sys.executable),
                       Python39=os.path.dirname(sys.executable),
                       Python27="c:\\Python27_x64",
                       Anaconda3="c:\\Anaconda3",
                       Anaconda2="c:\\Anaconda2",
                       WinPython36="c:\\PythonENSAE",
                       root_path="d:\\jenkins\\yml")
        vers = "%d%d" % sys.version_info[:2]
        engines["Python%s" % vers] = os.path.dirname(sys.executable)

        srv = JenkinsExt("http://localhost:8080/",
                         "user",
                         "password",
                         mock=True,
                         engines=engines,
                         fLOG=fLOG,
                         platform="win32")

        if not sys.platform.startswith("win"):
            # not yet implemented
            return

        fLOG("---------------------")
        res = srv.setup_jenkins_server(github=github,
                                       modules=modules,
                                       overwrite=True,
                                       add_environ=False,
                                       location="anything",
                                       disable_schedule=disable_schedule,
                                       credentials=credentials)
        reg = re.compile("<description>(.*)</description>")
        exp_ut = "python3_module_template_UT_%s_std" % vers
        nb = 0
        sch = 0
        desc = 0
        to = 0
        nb_jen = 0
        for i, r in enumerate(res):
            conf = r[-1]

            if not conf.startswith("<?xml version='1.0' encoding='UTF-8'?>"):
                raise Exception(conf)

            search = reg.search(conf)
            if not search:
                raise Exception(conf)

            job = r[0]
            fLOG(search.groups()[0], "--", job, "--", r[1])

            if "PYQUICKHELPER27" in conf:
                raise Exception(conf)

            if "SET VERSION=" not in conf:
                raise Exception(conf)
            if "SET NAME=" not in conf:
                raise Exception(conf)
            if "SET DIST=" not in conf:
                raise Exception(conf)
            if "anything\\python3_module_template\\%NAME_JENKINS%" not in conf:
                nb_jen += 1
            if "UT_39_std" in conf or exp_ut in conf:
                nb += 1
            if "H H(20-21) * * 0" in conf:
                sch += 1
            if "H H(16-17) * * 0" in conf:
                sch += 1
            if "0101 - H H(20-21) * * 0" in conf:
                desc += 1
            if "0101 - H H(16-17) * * 0" in conf:
                desc += 1
            if "<timeoutSecondsString>900</timeoutSecondsString>" in conf:
                to += 1

        if sys.version_info[0] != 2:
            self.assertTrue(i > 0)
            if nb == 0:
                raise AssertionError("\n#######\n".join(r[-1] for r in res))
            self.assertTrue(nb_jen > 0)
            self.assertTrue(to > 0)
            if disable_schedule:
                self.assertEqual(sch, 0)
                self.assertEqual(desc, 0)
            else:
                self.assertEqual(sch, 2)
                self.assertEqual(desc, 2)
            fLOG(to)
            if credentials:
                if "credentialsId" not in conf:
                    raise Exception(conf)
            else:
                if "<credentialsId>None" not in conf:
                    raise Exception(conf)
        else:
            warnings.warn("disable the test on Python 2.7")