示例#1
0
 def runTest(self):
     """
     The most basic python test possible, checks that the files we have written
     are importable in python, this is a basic sanity check
     """
     found = []
     for root, dirs, files in os.walk(
             os.path.dirname(__file__) + '/../../src/KAVE'):
         if '.git' in root:
             continue
         for f in files:
             if not (f.endswith('.py')):
                 continue
             if f in self.ignorefiles:
                 continue
             found = found + self.find_repolocations(os.path.join(root, f))
     found = [
         i for i in found
         if i is not None and len(i) and i[-1] not in self.ignorepackages
     ]
     failed = []
     sys.stdout.flush()
     for details in found:
         fn, ln, arch, package = details
         urls = []
         for mirror in kc.mirrors():
             if 'kavetoolbox' in package:
                 urls.append(
                     kc.repo_url(package,
                                 arch=arch,
                                 repo=mirror,
                                 dir='KaveToolbox'))
             else:
                 urls.append(kc.repo_url(package, arch=arch, repo=mirror))
         if not len(urls):
             if 'kavetoolbox' in package:
                 urls.append(
                     kc.repo_url(package, arch=arch, dir='KaveToolbox'))
             else:
                 urls.append(kc.repo_url(package, arch=arch))
         try:
             sys.stdout.flush()
             kc.failover_source(urls)
         except IOError:
             failed.append(details)
     self.assertFalse(
         len(failed), "Some requested downloads do not exist!\n\t" +
         '\n\t'.join([f.__str__() for f in failed]))
示例#2
0
    def runTest(self):
        """
        Tests that verify the kavecommon library and simple functions in that library
        """
        import kavecommon as kc

        sources = []
        for mirror in kc.mirrors():
            sources.append(kc.repo_url("", repo=mirror))
        sources.append(kc.repo_url(""))
        kc.failover_source(sources)
        self.assertRaises(IOError, kc.failover_source, ["non-existing-file-88989381923813.file"])  # ,"bug ABK-112"
        # make some directory structure to check the permissions changing...
        import tempfile
        import os

        tempdir = tempfile.mkdtemp()
        os.system("mkdir -p " + tempdir + "/this/is/a/test1")
        os.system("mkdir -p " + tempdir + "/this/is/a/test2")
        os.system("mkdir -p " + tempdir + "/this/is/a/test3")
        os.system("chmod -R 555 " + tempdir + "/this ")
        kc.chmod_up(tempdir + "/this/is/a/test1", "511", seen=[tempdir, tempdir + "/this"])
        self.assertFalse(os.access(tempdir + "/this/is/a", os.W_OK), tempdir + " permissions settings failed")
        kc.chmod_up(tempdir + "/this/is/a/test1", "744", seen=[tempdir])
        self.assertTrue(os.access(tempdir + "/this/is/a", os.W_OK), tempdir + " permissions settings failed")
        self.assertFalse(os.access(tempdir + "/this/is/a/test2", os.W_OK), tempdir + " permissions settings failed")
        # create a file in this directory to test the copy/caching, at least for things without wget
        os.system("touch " + tempdir + "/this/is/test.test")
        topd = os.path.realpath(os.curdir)
        os.chdir(tempdir)
        kc.copy_or_cache(sources=[tempdir + "/this/is/test.test"], filename="test.test", cache_dir=tempdir + "/this/")
        os.chdir(topd)
        self.assertTrue(os.path.exists(tempdir + "/test.test") and os.path.exists(
            tempdir + "/this/is/test.test") and os.path.exists(tempdir + "/this/test.test"),
            tempdir + " copy/caching failed")
        # Test the trueorfalse method
        cnv = {'true': True, 'y': True, 'ye': True, 'yes': True,
               'false': False, 'n': False, 'no': False, 'none': False,
               ' false': False, 'y ': True}
        for k, v in cnv.iteritems():
            self.assertTrue(kc.trueorfalse(k) == v)
            self.assertTrue(kc.trueorfalse(k.upper()) == v)
        self.assertRaises(TypeError, kc.trueorfalse, {})
        self.assertRaises(TypeError, kc.trueorfalse, 'GAAAH')

        # remove this temporary file when done
        if os.path.exists(tempdir) and len(tempdir) > 4:
            os.system("rm -rf " + tempdir)
示例#3
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')
        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                        + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                        + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                        + params.JENKINS_ADMIN + '&Submit=Sign%20up" "http://'
                        + params.hostname + ':' + str(params.JENKINS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)
示例#4
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')
        self.start(env)
        # using curl to create username password for jenkinsl
        curlCommand = ('curl -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                       + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                       + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                       + params.JENKINS_ADMIN + '&Submit=Sign%20up" "http://'
                       + params.hostname + ':' + str(params.JENKINS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curlCommand)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curlCommand)
示例#5
0
 def runTest(self):
     """
     The most basic python test possible, checks that the files we have written
     are importable in python, this is a basic sanity check
     """
     found = []
     for root, dirs, files in os.walk(os.path.dirname(__file__) + '/../../src/KAVE'):
         if '.git' in root:
             continue
         for f in files:
             if not (f.endswith('.py')):
                 continue
             if f in self.ignorefiles:
                 continue
             found = found + self.find_repolocations(os.path.join(root, f))
     found = [i for i in found if i is not None
              and len(i)
              and i[-1] not in self.ignorepackages]
     failed = []
     sys.stdout.flush()
     for details in found:
         fn, ln, arch, package = details
         urls = []
         for mirror in kc.mirrors():
             if 'kavetoolbox' in package:
                 urls.append(kc.repo_url(package, arch=arch, repo=mirror, dir='KaveToolbox', ver='3.6-Beta'))
             else:
                 urls.append(kc.repo_url(package, arch=arch, repo=mirror))
             if 'Eskapade' in package:
                 urls.append(kc.repo_url(package, arch=arch, repo=mirror, dir='Eskapade', ver='0.6'))
             else:
                 urls.append(kc.repo_url(package, arch=arch, repo=mirror))
         if not len(urls):
             if 'kavetoolbox' in package:
                 urls.append(kc.repo_url(package, arch=arch, dir='KaveToolbox', ver='3.6-Beta'))
             if 'Eskapade' in package:
                 urls.append(kc.repo_url(package, arch=arch, dir='Eskapade', ver='0.6'))
             else:
                 urls.append(kc.repo_url(package, arch=arch))
         try:
             sys.stdout.flush()
             kc.failover_source(urls)
         except IOError:
             failed.append(details)
         except IOError:
             failed.append(details)
     self.assertFalse(len(failed), "Some requested downloads do not exist!\n\t" +
                      '\n\t'.join([f.__str__() for f in failed]))
示例#6
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname,
                              arch='noarch',
                              alternates='http://pkg.jenkins-ci.org/redhat/' +
                              dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = [
                "http://updates.jenkins-ci.org/latest/" + plugin + h
                for h in [".hpi", ".jpi"]
            ]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [
                kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch')
                for h in [".hpi", ".jpi"]
            ]
            source = kc.failover_source(mirrorsources + intsources +
                                        extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        Execute('mkdir -p /var/lib/jenkins/.ssl')
        cpath = "/var/lib/jenkins/.ssl"
        print str(cpath)
        #         #Change to your company details
        country = "NA"
        state = "NA"
        locality = "NA"
        organization = "NA"
        organizationalun = "NA"
        if len(params.hostname) <= 64:
            commonname = params.hostname
        else:
            commonname = params.hostname.split(".", 1)[0]
        email = "*****@*****.**"
        #         Optional
        password = "******"
        print "Generating key request"
        #         #Generate a key
        Execute(
            str.format(
                'openssl req -x509 -newkey rsa:4096' +
                ' -passout pass:{} -keyout /var/lib/jenkins/.ssl/key.pem -out'
                + ' /var/lib/jenkins/.ssl/cert.pem' +
                ' -days 365 -subj "/C={}/ST={}/L={}/O={}/OU={}/CN={}/emailAddress={} '
                + '"', password, country, state, locality, organization,
                organizationalun, commonname, email))
        #         #Import the key to pckc12
        Execute(
            str.format(
                'openssl pkcs12 -inkey /var/lib/jenkins/.ssl/key.pem' +
                ' -in /var/lib/jenkins/.ssl/cert.pem -export -out /var/lib/jenkins/.ssl/cert.p12'
                + ' -passin pass:{} -passout pass:{}', password, password))
        #         #Import keystore
        Execute(
            str.format(
                'keytool -importkeystore -srckeystore /var/lib/jenkins/.ssl/cert.p12'
                +
                ' -destkeystore /var/lib/jenkins/.ssl/jenkins.jks -srcstoretype pkcs12'
                + ' -deststoretype JKS -srcstorepass {} -deststorepass {}',
                password, password))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644)
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')

        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -k -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD +
                        '&email=' + params.JENKINS_ADMIN_EMAIL +
                        '&password2=' + params.JENKINS_ADMIN_PASSWORD +
                        '&fullname=' + params.JENKINS_ADMIN +
                        '&Submit=Sign%20up" "https://' + params.hostname +
                        ':' + str(params.JENKINS_HTTPS_PORT) +
                        '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)
示例#7
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        Execute('mkdir -p /var/lib/jenkins/.ssl')
        cpath = "/var/lib/jenkins/.ssl"
        print str(cpath)
#         #Change to your company details
        country = "NA"
        state = "NA"
        locality = "NA"
        organization = "NA"
        organizationalun = "NA"
        if len(params.hostname) <= 64:
            commonname = params.hostname
        else:
            commonname = params.hostname.split(".", 1)[0]
        email = "*****@*****.**"
#         Optional
        password = "******"
        print "Generating key request"
#         #Generate a key
        Execute(str.format('openssl req -x509 -newkey rsa:4096' +
                           ' -passout pass:{} -keyout /var/lib/jenkins/.ssl/key.pem -out' +
                           ' /var/lib/jenkins/.ssl/cert.pem' +
                           ' -days 365 -subj "/C={}/ST={}/L={}/O={}/OU={}/CN={}/emailAddress={} ' +
                           '"', password, country, state, locality, organization, organizationalun, commonname, email))
#         #Import the key to pckc12
        Execute(str.format('openssl pkcs12 -inkey /var/lib/jenkins/.ssl/key.pem' +
                           ' -in /var/lib/jenkins/.ssl/cert.pem -export -out /var/lib/jenkins/.ssl/cert.p12' +
                           ' -passin pass:{} -passout pass:{}', password, password))
#         #Import keystore
        Execute(str.format('keytool -importkeystore -srckeystore /var/lib/jenkins/.ssl/cert.p12' +
                           ' -destkeystore /var/lib/jenkins/.ssl/jenkins.jks -srcstoretype pkcs12' +
                           ' -deststoretype JKS -srcstorepass {} -deststorepass {}', password, password))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')

        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -k -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                        + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                        + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                        + params.JENKINS_ADMIN + '&Submit=Sign%20up" "https://'
                        + params.hostname + ':' + str(params.JENKINS_HTTPS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)