示例#1
0
    def load_connection_from_file(
            self, file_name: str) -> Optional[JenkinsConnection]:
        try:
            with open(file_name, 'r') as data_file:
                connection_name = data_file.readline().rstrip()
                jenkins_connection = self.get_connection(connection_name)

                while True:
                    try:
                        jenkins_job = JenkinsJob.deserialize(data_file)
                        jenkins_connection.jenkins_jobs.update(
                            {jenkins_job.name: jenkins_job})
                    except EOFError:
                        break

        except ConfigError as ce:
            print(
                'Failed to load cached data for connection from config file: {}'
                .format(file_name))
            print('Error: {}'.format(ce))
            return None

        print('Loaded connection [{}] with {} jobs cached.'.format(
            jenkins_connection.name, len(jenkins_connection.jenkins_jobs)))
        return jenkins_connection
示例#2
0
    def test_pickled_jenkins_job_equals_new_jenkins_job(self):
        """
        Tests that a pickled jenkins_job loaded from disk is identical to a new jenkins_job
        created from a job_instance pulled from the jenkins server.
        """

        file_path = os.path.join(self.JENKINS_JOBS_DIR, self.build_data_file('job_with_no_builds'))
        with open(file_path, 'rb') as data_file:
            pickled_jenkins_job = JenkinsJob.deserialize(data_file)

        url = 'http://jenkins-cassandra.datastax.lan/'
        job_name = 'mshuler-9608-java9-trunk-cqlsh-tests'

        jenkins_obj = Jenkins(url)
        jenkins_builds = download_builds(jenkins_obj, job_name)
        jenkins_job = JenkinsJob(job_name, jenkins_builds)

        self.assertEqual(pickled_jenkins_job, jenkins_job,
                         'The pickled jenkins job does not match the new jenkins job.')
示例#3
0
    def load_job_data(self, file_name):
        try:
            with open(file_name, 'rb') as data_file:
                connection_name = get_connection_name(data_file.name)
                jenkins_connection = self.get_connection(connection_name)

                while True:
                    try:
                        jenkins_job = JenkinsJob.deserialize(data_file)
                        jenkins_connection.jenkins_jobs.update(
                            {jenkins_job.name: jenkins_job})
                    except EOFError:
                        break

        except ConfigError:
            print(
                'Failed to load cached data for connection from config file: {}'
                .format(file_name))
            traceback.print_exc()
            return None

        print('Loaded connection [{}] with {} jobs cached.'.format(
            jenkins_connection.name, len(jenkins_connection.jenkins_jobs)))
        return jenkins_connection