Beispiel #1
0
    def test_make_nested_views(self):
        job = self._create_job()
        top_view_name = random_string()
        sub1_view_name = random_string()
        sub2_view_name = random_string()

        self.assertNotIn(top_view_name, self.jenkins.views)
        tv = self.jenkins.views.create(top_view_name, Views.NESTED_VIEW)
        self.assertIn(top_view_name, self.jenkins.views)
        self.assertIsInstance(tv, View)

        # Empty sub view
        sv1 = tv.views.create(sub1_view_name)
        self.assertIn(sub1_view_name, tv.views)
        self.assertIsInstance(sv1, View)

        # Sub view with job in it
        tv.views[sub2_view_name] = job.name
        self.assertIn(sub2_view_name, tv.views)
        sv2 = tv.views[sub2_view_name]
        self.assertIsInstance(sv2, View)
        self.assertTrue(job.name in sv2)

        # Can we use the API convenience methods
        v = get_view_from_url(sv2.baseurl)
        self.assertEquals(v, sv2)
Beispiel #2
0
    def test_add_job_to_view(self):
        job_name = random_string()
        self._create_job(job_name)

        view_name = random_string()
        self.assertNotIn(view_name, self.jenkins.views)
        v = self.jenkins.views.create(view_name)
        self.assertIn(view_name, self.jenkins.views)
        self.assertIsInstance(v, View)

        self.assertNotIn(job_name, v)
        self.assertTrue(v.add_job(job_name))
        self.assertIn(job_name, v)
        self.assertIsInstance(v[job_name], Job)

        self.assertTrue(len(v) == 1)
        for j_name, j in v.iteritems():
            self.assertEquals(j_name, job_name)
            self.assertIsInstance(j, Job)

        for j in v.values():
            self.assertIsInstance(j, Job)

        jobs = v.items()
        self.assertIsInstance(jobs, list)
        self.assertIsInstance(jobs[0], tuple)

        self.assertFalse(v.add_job(job_name))
        self.assertFalse(v.add_job('unknown'))

        del self.jenkins.views[view_name]
Beispiel #3
0
def test_add_job_to_view(jenkins):
    job_name = random_string()
    create_job(jenkins, job_name)

    view_name = random_string()
    assert view_name not in jenkins.views
    new_view = jenkins.views.create(view_name)
    assert view_name in jenkins.views
    assert isinstance(new_view, View) is True

    assert job_name not in new_view
    assert new_view.add_job(job_name) is True
    assert job_name in new_view
    assert isinstance(new_view[job_name], Job) is True

    assert len(new_view) == 1
    for j_name, j in new_view.iteritems():
        assert j_name == job_name
        assert isinstance(j, Job) is True

    for j in new_view.values():
        assert isinstance(j, Job) is True

    jobs = new_view.items()
    assert isinstance(jobs, list) is True
    assert isinstance(jobs[0], tuple) is True

    assert new_view.add_job(job_name) is False
    assert new_view.add_job('unknown') is False

    del jenkins.views[view_name]
    def test_parameterized_job_build_queuing(self):
        """Accept multiple builds of parameterized jobs with unique
           parameters."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            param_B = random_string()
            params = {'B': param_B}
            job.invoke(build_params=params)
            time.sleep(0.25)

        self.assertTrue(job.has_queued_build(params))

        while job.has_queued_build(params):
            time.sleep(0.25)

        build = job.get_last_build()
        while build.is_running():
            time.sleep(0.25)

        artifacts = build.get_artifact_dict()
        self.assertIsInstance(artifacts, dict)
        artB = artifacts['b.txt']
        self.assertTrue(artB.get_data().strip(), param_B)

        self.assertIn(param_B, build.get_console())
    def test_parameterized_job_build_queuing(self):
        """Accept multiple builds of parameterized jobs with unique
           parameters."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            param_B = random_string()
            params = {'B': param_B}
            job.invoke(build_params=params)
            time.sleep(0.25)

        self.assertTrue(job.has_queued_build(params))

        while job.has_queued_build(params):
            time.sleep(0.25)

        build = job.get_last_build()
        while build.is_running():
            time.sleep(0.25)

        artifacts = build.get_artifact_dict()
        self.assertIsInstance(artifacts, dict)
        artB = artifacts['b.txt']
        self.assertTrue(artB.get_data().strip(), param_B)

        self.assertIn(param_B, build.get_console())
Beispiel #6
0
def test_running_executor(jenkins):
    node_name = random_string()
    node_dict = {
        'num_executors': 1,
        'node_description': 'Test JNLP Node',
        'remote_fs': '/tmp',
        'labels': 'systest_jnlp',
        'exclusive': True
    }
    jenkins.nodes.create_node(node_name, node_dict)
    job_name = 'create_%s' % random_string()
    job = jenkins.create_job(job_name, LONG_RUNNING_JOB)
    qq = job.invoke()
    qq.block_until_building()

    if job.is_running() is False:
        time.sleep(1)
    executors = jenkins.get_executors(node_name)
    all_idle = True
    for execs in executors:
        if execs.is_idle() is False:
            all_idle = False
            assert execs.get_progress() != -1
            assert execs.get_current_executable() == qq.get_build_number()
            assert execs.likely_stuck() is False
    assert all_idle is True, "Executor should have been triggered."
def test_running_executor(jenkins):
    node_name = random_string()
    node_dict = {
        'num_executors': 1,
        'node_description': 'Test JNLP Node',
        'remote_fs': '/tmp',
        'labels': 'systest_jnlp',
        'exclusive': True
    }
    jenkins.nodes.create_node(node_name, node_dict)
    job_name = 'create_%s' % random_string()
    job = jenkins.create_job(job_name, LONG_RUNNING_JOB)
    qq = job.invoke()
    qq.block_until_building()

    if job.is_running() is False:
        time.sleep(1)
    executors = jenkins.get_executors(node_name)
    all_idle = True
    for execs in executors:
        if execs.is_idle() is False:
            all_idle = False
            assert execs.get_progress() != -1
            assert execs.get_current_executable() == qq.get_build_number()
            assert execs.likely_stuck() is False
    assert all_idle is True, "Executor should have been triggered."
def test_parameterized_job_build_queuing(jenkins):
    """
    Accept multiple builds of parameterized jobs with unique parameters.
    """
    job_name = 'create_%s' % random_string()
    job = jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

    # Latest Jenkins schedules builds to run right away, so remove all
    # executors from master node to investigate queue
    master = jenkins.nodes['master']
    num_executors = master.get_num_executors()
    master.set_num_executors(0)

    for i in range(3):
        param_B = random_string()
        params = {'B': param_B}
        job.invoke(build_params=params)

    assert job.has_queued_build(params) is True

    master.set_num_executors(num_executors)

    while job.has_queued_build(params):
        time.sleep(0.25)

    build = job.get_last_build()
    while build.is_running():
        time.sleep(0.25)

    artifacts = build.get_artifact_dict()
    assert isinstance(artifacts, dict) is True
    artB = artifacts['b.txt']
    assert artB.get_data().decode('utf-8').strip() == param_B

    assert param_B in build.get_console()
def test_parameterized_job_build_queuing(jenkins):
    """Accept multiple builds of parameterized jobs with unique
        parameters."""
    job_name = 'create_%s' % random_string()
    job = jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

    for i in range(3):
        param_B = random_string()
        params = {'B': param_B}
        job.invoke(build_params=params)
        time.sleep(0.25)

    assert job.has_queued_build(params) is True

    while job.has_queued_build(params):
        time.sleep(0.25)

    build = job.get_last_build()
    while build.is_running():
        time.sleep(0.25)

    artifacts = build.get_artifact_dict()
    assert isinstance(artifacts, dict) is True
    artB = artifacts['b.txt']
    assert artB.get_data().decode('utf-8').strip() == param_B

    assert param_B in build.get_console()
Beispiel #10
0
def test_make_nested_views(jenkins):
    job = create_job(jenkins)
    top_view_name = random_string()
    sub1_view_name = random_string()
    sub2_view_name = random_string()

    assert top_view_name not in jenkins.views
    tv = jenkins.views.create(top_view_name, Views.NESTED_VIEW)
    assert top_view_name in jenkins.views
    assert isinstance(tv, View) is True

    # Empty sub view
    sv1 = tv.views.create(sub1_view_name)
    assert sub1_view_name in tv.views
    assert isinstance(sv1, View) is True

    # Sub view with job in it
    tv.views[sub2_view_name] = job.name
    assert sub2_view_name in tv.views
    sv2 = tv.views[sub2_view_name]
    assert isinstance(sv2, View) is True
    assert job.name in sv2

    # Can we use the API convenience methods
    new_view = get_view_from_url(sv2.baseurl)
    assert new_view == sv2
def test_parameterized_job_build_queuing(jenkins):
    """
    Accept multiple builds of parameterized jobs with unique parameters.
    """
    job_name = 'create_%s' % random_string()
    job = jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

    for i in range(3):
        param_B = random_string()
        params = {'B': param_B}
        job.invoke(build_params=params)
        time.sleep(0.25)

    assert job.has_queued_build(params) is True

    while job.has_queued_build(params):
        time.sleep(0.25)

    build = job.get_last_build()
    while build.is_running():
        time.sleep(0.25)

    artifacts = build.get_artifact_dict()
    assert isinstance(artifacts, dict) is True
    artB = artifacts['b.txt']
    assert artB.get_data().decode('utf-8').strip() == param_B

    assert param_B in build.get_console()
Beispiel #12
0
    def test_get_jobs_list(self):
        job1_name = 'first_%s' % random_string()
        job2_name = 'second_%s' % random_string()

        self._create_job(job1_name)
        self._create_job(job2_name)
        job_list = self.jenkins.get_jobs_list()
        self.assertEqual([job1_name, job2_name], job_list)
Beispiel #13
0
def test_rename_job(jenkins):
    job1_name = 'A__%s' % random_string()
    job2_name = 'B__%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.rename_job(job1_name, job2_name)
    job_absent(jenkins, job1_name)
    job_present(jenkins, job2_name)
Beispiel #14
0
    def test_get_jobs_list(self):
        job1_name = 'first_%s' % random_string()
        job2_name = 'second_%s' % random_string()

        self._create_job(job1_name)
        self._create_job(job2_name)
        job_list = self.jenkins.get_jobs_list()
        self.assertEqual([job1_name, job2_name], job_list)
Beispiel #15
0
    def test_rename_job(self):
        job1_name = 'A__%s' % random_string()
        job2_name = 'B__%s' % random_string()

        self._create_job(job1_name)
        self.jenkins.rename_job(job1_name, job2_name)
        self.assertJobIsAbsent(job1_name)
        self.assertJobIsPresent(job2_name)
Beispiel #16
0
def test_rename_job(jenkins):
    job1_name = 'A__%s' % random_string()
    job2_name = 'B__%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.rename_job(job1_name, job2_name)
    job_absent(jenkins, job1_name)
    job_present(jenkins, job2_name)
Beispiel #17
0
    def test_rename_job(self):
        job1_name = 'A__%s' % random_string()
        job2_name = 'B__%s' % random_string()

        self._create_job(job1_name)
        self.jenkins.rename_job(job1_name, job2_name)
        self.assertJobIsAbsent(job1_name)
        self.assertJobIsPresent(job2_name)
Beispiel #18
0
def test_create_ssh_node(jenkins):
    node_name = random_string()
    creds = jenkins.get_credentials()

    cred_descr = random_string()
    cred_dict = {
        'description': cred_descr,
        'userName': '******',
        'passphrase': '',
        'private_key': '-----BEGIN RSA PRIVATE KEY-----'
    }
    creds[cred_descr] = SSHKeyCredential(cred_dict)
    node_dict = {
        'num_executors':
        1,
        'node_description':
        'Description %s' % node_name,
        'remote_fs':
        '/tmp',
        'labels':
        node_name,
        'exclusive':
        False,
        'host':
        '127.0.0.1',
        'port':
        22,
        'credential_description':
        cred_descr,
        'jvm_options':
        '',
        'java_path':
        '',
        'prefix_start_slave_cmd':
        '',
        'suffix_start_slave_cmd':
        '',
        'retention':
        'ondemand',
        'ondemand_delay':
        0,
        'ondemand_idle_delay':
        5,
        'tool_location': [
            {
                "key":
                "hudson.tasks.Maven$MavenInstallation$DescriptorImpl@Maven 3.0.5",
                "home": "/home/apache-maven-3.0.5/"
            },
        ]
    }
    node = jenkins.nodes.create_node(node_name, node_dict)
    assert isinstance(node, Node) is True
    del jenkins.nodes[node_name]

    jenkins.nodes[node_name] = node_dict
    assert isinstance(jenkins.nodes[node_name], Node) is True
    del jenkins.nodes[node_name]
    def test_invoke_job_with_file(self):
        file_data = random_string()
        param_file = StringIO(file_data)

        job_name = 'create1_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_FILE)

        with self.assertRaises(ValueError) as ve:
            item = job.invoke(block=True, files={'file.txt': param_file})
Beispiel #20
0
def test_get_jobs_list(jenkins):
    job1_name = 'first_%s' % random_string()
    job2_name = 'second_%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.create_job(job2_name, EMPTY_JOB)
    assert len(jenkins.jobs) >= 2
    job_list = jenkins.get_jobs_list()
    assert [job1_name, job2_name] == job_list
Beispiel #21
0
    def test_copy_job(self):

        template_job_name = "TPL%s" % random_string()
        copied_job_name = "CPY%s" % random_string()

        self._create_job(template_job_name)
        self.jenkins.copy_job(template_job_name, copied_job_name)
        self.assertJobIsPresent(template_job_name)
        self.assertJobIsPresent(copied_job_name)
Beispiel #22
0
def test_get_jobs_list(jenkins):
    job1_name = 'first_%s' % random_string()
    job2_name = 'second_%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.create_job(job2_name, EMPTY_JOB)
    assert len(jenkins.jobs) >= 2
    job_list = jenkins.get_jobs_list()
    assert [job1_name, job2_name] == job_list
Beispiel #23
0
 def test_add_to_view_after_copy(self):
     # This test is for issue #291
     job = self._create_job()
     new_job_name = random_string()
     view_name = random_string()
     new_view = self.jenkins.views.create(view_name)
     new_view = self.jenkins.views[view_name]
     new_job = self.jenkins.copy_job(job.name, new_job_name)
     self.assertTrue(new_view.add_job(new_job.name))
     self.assertIn(new_job.name, new_view)
Beispiel #24
0
def test_copy_job(jenkins):
    template_job_name = 'TPL%s' % random_string()
    copied_job_name = 'CPY%s' % random_string()

    jenkins.create_job(template_job_name, EMPTY_JOB)
    j = jenkins.copy_job(template_job_name, copied_job_name)
    job_present(jenkins, template_job_name)
    job_present(jenkins, copied_job_name)
    assert isinstance(j, Job) is True
    assert j.name == copied_job_name
Beispiel #25
0
 def test_add_to_view_after_copy(self):
     # This test is for issue #291
     job = self._create_job()
     new_job_name = random_string()
     view_name = random_string()
     new_view = self.jenkins.views.create(view_name)
     new_view = self.jenkins.views[view_name]
     new_job = self.jenkins.copy_job(job.name, new_job_name)
     self.assertTrue(new_view.add_job(new_job.name))
     self.assertIn(new_job.name, new_view)
Beispiel #26
0
def test_add_to_view_after_copy(jenkins):
    # This test is for issue #291
    job = create_job(jenkins)
    new_job_name = random_string()
    view_name = random_string()
    new_view = jenkins.views.create(view_name)
    new_view = jenkins.views[view_name]
    new_job = jenkins.copy_job(job.name, new_job_name)
    assert new_view.add_job(new_job.name) is True
    assert new_job.name in new_view
Beispiel #27
0
def test_copy_job(jenkins):
    template_job_name = 'TPL%s' % random_string()
    copied_job_name = 'CPY%s' % random_string()

    jenkins.create_job(template_job_name, EMPTY_JOB)
    j = jenkins.copy_job(template_job_name, copied_job_name)
    job_present(jenkins, template_job_name)
    job_present(jenkins, copied_job_name)
    assert isinstance(j, Job) is True
    assert j.name == copied_job_name
Beispiel #28
0
    def test_invoke_job_with_file_and_params(self):
        file_data = random_string()
        param_data = random_string()
        param_file = StringIO(file_data)

        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_FILE_AND_PARAMS)
        with self.assertRaises(ValueError) as ve:
            job.invoke(block=True,
                       files={'file.txt': param_file},
                       build_params={'B': param_data})
Beispiel #29
0
    def test_copy_job(self):

        template_job_name = 'TPL%s' % random_string()
        copied_job_name = 'CPY%s' % random_string()

        self._create_job(template_job_name)
        j = self.jenkins.copy_job(template_job_name, copied_job_name)
        self.assertJobIsPresent(template_job_name)
        self.assertJobIsPresent(copied_job_name)
        self.assertIsInstance(j, Job)
        self.assertEquals(j.name, copied_job_name)
Beispiel #30
0
    def test_copy_job(self):

        template_job_name = 'TPL%s' % random_string()
        copied_job_name = 'CPY%s' % random_string()

        self._create_job(template_job_name)
        j = self.jenkins.copy_job(template_job_name, copied_job_name)
        self.assertJobIsPresent(template_job_name)
        self.assertJobIsPresent(copied_job_name)
        self.assertIsInstance(j, Job)
        self.assertEquals(j.name, copied_job_name)
    def test_parameterized_multiple_builds_get_the_same_queue_item(self):
        """Multiple attempts to run the same parameterized
        build will get the same queue item."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            params = {'B': random_string()}
            qq0 = job.invoke(build_params=params)

        qq1 = job.invoke(build_params=params)
        self.assertEqual(qq0, qq1)
    def test_parameterized_multiple_builds_get_the_same_queue_item(self):
        """Multiple attempts to run the same parameterized
        build will get the same queue item."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            params = {'B': random_string()}
            qq0 = job.invoke(build_params=params)

        qq1 = job.invoke(build_params=params)
        self.assertEqual(qq0, qq1)
Beispiel #33
0
    def test_get_jobs(self):
        job1_name = 'first_%s' % random_string()
        job2_name = 'second_%s' % random_string()

        self._create_job(job1_name)
        self._create_job(job2_name)
        jobs = self.jenkins.jobs
        self.assertIsInstance(jobs, Jobs)
        self.assertGreaterEqual(len(jobs), 2)
        for job_name, job in jobs.iteritems():
            self.assertIsInstance(job_name, str)
            self.assertIsInstance(job, Job)
Beispiel #34
0
def test_get_jobs(jenkins):
    job1_name = 'first_%s' % random_string()
    job2_name = 'second_%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.create_job(job2_name, EMPTY_JOB)
    jobs = jenkins.jobs
    assert isinstance(jobs, Jobs) is True
    assert len(jobs) >= 2
    for job_name, job in jobs.iteritems():
        assert isinstance(job_name, str) is True
        assert isinstance(job, Job) is True
Beispiel #35
0
def test_get_jobs(jenkins):
    job1_name = 'first_%s' % random_string()
    job2_name = 'second_%s' % random_string()

    jenkins.create_job(job1_name, EMPTY_JOB)
    jenkins.create_job(job2_name, EMPTY_JOB)
    jobs = jenkins.jobs
    assert isinstance(jobs, Jobs) is True
    assert len(jobs) >= 2
    for job_name, job in jobs.iteritems():
        assert isinstance(job_name, str) is True
        assert isinstance(job, Job) is True
    def test_invoke_job_with_file_and_params(self):
        file_data = random_string()
        param_data = random_string()
        param_file = StringIO(file_data)

        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_FILE_AND_PARAMS)
        with self.assertRaises(ValueError) as ve:
            job.invoke(
                block=True,
                files={'file.txt': param_file},
                build_params={'B': param_data}
            )
def test_invoke_job_parameterized(jenkins):
    param_B = random_string()

    job_name = 'create2_%s' % random_string()
    job = jenkins.create_job(job_name, JOB_WITH_PARAMETERS)
    job.invoke(block=True, build_params={'B': param_B})
    build = job.get_last_build()

    artifacts = build.get_artifact_dict()
    artB = artifacts['b.txt']
    assert artB.get_data().decode('UTF-8', 'replace').strip() == param_B

    assert param_B in build.get_console()
def test_invoke_job_parameterized(jenkins):
    param_B = random_string()

    job_name = 'create2_%s' % random_string()
    job = jenkins.create_job(job_name, JOB_WITH_PARAMETERS)
    job.invoke(block=True, build_params={'B': param_B})
    build = job.get_last_build()

    artifacts = build.get_artifact_dict()
    artB = artifacts['b.txt']
    assert artB.get_data().decode('UTF-8', 'replace').strip() == param_B

    assert param_B in build.get_console()
    def test_parameterized_job_build_rejection(self):
        """Reject build of paramterized job when existing build with same
           parameters is queued, raising WillNotBuild."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            params = {'B': random_string()}
            job.invoke(build_params=params)

        with self.assertRaises(WillNotBuild) as na:
            job.invoke(build_params=params)
        expected_msg = 'A build with these parameters is already queued.'
        self.assertEqual(str(na.exception), expected_msg)
Beispiel #40
0
    def test_parameterized_job_build_rejection(self):
        """Reject build of paramterized job when existing build with same
           parameters is queued, raising WillNotBuild."""
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)

        for i in range(3):
            params = {'B': random_string()}
            job.invoke(build_params=params)

        with self.assertRaises(WillNotBuild) as na:
            job.invoke(build_params=params)
        expected_msg = 'A build with these parameters is already queued.'
        self.assertEqual(na.exception.message, expected_msg)
    def test_invoke_job_parameterized(self):
        param_B = random_string()

        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_CONFIG)
        job.invoke(block=True, build_params={ 'B':param_B})

        b = job.get_last_build()
        while b.is_running():
            time.sleep(0.25)

        artifacts = b.get_artifact_dict()
        self.assertIsInstance(artifacts, dict)
        artB = artifacts['b.txt']
        self.assertTrue(artB.get_data().strip(), param_B)
Beispiel #42
0
def test_mi_and_delete_build(jenkins):
    job_name = 'Ecreate_%s' % random_string()

    job = jenkins.create_job(job_name, EMPTY_JOB)

    for invocation in range(3):
        qq = job.invoke()
        qq.block_until_complete(delay=1)
        build_number = qq.get_build_number()
        assert build_number == invocation + 1

    # Delete build using Job.delete_build
    job.get_build(1)
    job.delete_build(1)
    with pytest.raises(NotFound):
        job.get_build(1)

    # Delete build using Job as dictionary of builds
    assert isinstance(job[2], Build)
    del job[2]

    with pytest.raises(NotFound):
        job.get_build(2)

    with pytest.raises(NotFound):
        job.delete_build(99)
Beispiel #43
0
 def test_get_job_and_update_config(self):
     job_name = 'config_%s' % random_string()
     self.jenkins.create_job(job_name, EMPTY_JOB)
     self.assertJobIsPresent(job_name)
     config = self.jenkins[job_name].get_config()
     self.assertEquals(config.strip(), EMPTY_JOB.strip())
     self.jenkins[job_name].update_config(EMPTY_JOB)
Beispiel #44
0
def test_invoke_many_jobs(jenkins, no_executors):
    job_names = [random_string() for _ in range(5)]
    jobs = []

    while len(jenkins.get_queue()) != 0:
        log.info('Sleeping to get queue empty...')
        time.sleep(1)

    for job_name in job_names:
        j = jenkins.create_job(job_name, LONG_RUNNING_JOB)
        jobs.append(j)
        j.invoke()

        assert j.is_queued_or_running() is True

    queue = jenkins.get_queue()

    reprString = repr(queue)
    assert queue.baseurl in reprString
    assert len(queue) == 5, queue.keys()
    assert isinstance(queue[queue.keys()[0]].get_job(), Job) is True
    items = queue.get_queue_items_for_job(job_names[2])
    assert isinstance(items, list) is True
    assert len(items) == 1
    assert isinstance(items[0], QueueItem) is True
    assert items[0].get_parameters() == []

    for _, item in queue.iteritems():
        queue.delete_item(item)

    queue.poll()

    assert len(queue) == 0
Beispiel #45
0
def test_invoke_many_jobs(jenkins):
    job_names = [random_string() for _ in range(5)]
    jobs = []

    while len(jenkins.get_queue()) != 0:
        log.info('Sleeping to get queue empty...')
        time.sleep(1)

    for job_name in job_names:
        j = jenkins.create_job(job_name, LONG_RUNNING_JOB)
        jobs.append(j)
        j.invoke()

        assert j.is_queued_or_running() is True

    queue = jenkins.get_queue()

    reprString = repr(queue)
    assert queue.baseurl in reprString
    assert len(queue) == 5, queue.keys()
    assert isinstance(queue[queue.keys()[0]].get_job(), Job) is True
    items = queue.get_queue_items_for_job(job_names[2])
    assert isinstance(items, list) is True
    assert len(items) == 1
    assert isinstance(items[0], QueueItem) is True
    assert items[0].get_parameters() == []

    for _, item in queue.iteritems():
        queue.delete_item(item)

    queue.poll()

    assert len(queue) == 0
Beispiel #46
0
    def test_multiple_invocations_and_delete_build(self):
        job_name = 'Ecreate_%s' % random_string()

        job = self.jenkins.create_job(job_name, EMPTY_JOB)

        for invocation in range(3):
            qq = job.invoke()
            qq.block_until_complete(delay=1)
            build_number = qq.get_build_number()
            self.assertEquals(build_number, invocation + 1)

        # Delete build using Job.delete_build
        job.get_build(1)
        job.delete_build(1)
        with self.assertRaises(NotFound):
            job.get_build(1)

        # Delete build using Job as dictionary of builds
        job[2]
        del job[2]
        with self.assertRaises(NotFound):
            job.get_build(2)

        with self.assertRaises(NotFound):
            job.delete_build(99)
    def test_invoke_job(self):
        job_name = 'create_%s' % random_string()
        job = self.jenkins.create_job(job_name, JOB_WITH_ARTIFACTS)
        job.invoke(block=True)

        b = job.get_last_build()

        while b.is_running():
            time.sleep(1)

        artifacts = b.get_artifact_dict()
        self.assertIsInstance(artifacts, dict)

        text_artifact = artifacts['out.txt']
        binary_artifact = artifacts['out.gz']

        tempDir = tempfile.mkdtemp()

        try:
            # Verify that we can handle text artifacts
            text_artifact.save_to_dir(tempDir)
            readBackText = open(os.path.join(
                tempDir, text_artifact.filename), 'rb').read().strip()
            self.assertTrue(re.match(r'^PING \S+ \(127.0.0.1\)', readBackText))
            self.assertTrue(readBackText.endswith('ms'))

            # Verify that we can hande binary artifacts
            binary_artifact.save_to_dir(tempDir)
            readBackText = gzip.open(os.path.join(tempDir, binary_artifact.filename,), 'rb').read().strip()
            self.assertTrue(re.match(r'^PING \S+ \(127.0.0.1\)', readBackText))
            self.assertTrue(readBackText.endswith('ms'))
        finally:
            shutil.rmtree(tempDir)
Beispiel #48
0
 def test_delete_view_which_does_not_exist(self):
     self._create_job()
     view1_name = random_string()
     new_view = self.jenkins.views.create(view1_name)
     self.assertIn(view1_name, self.jenkins.views)
     del self.jenkins.views[view1_name]
     self.assertNotIn(view1_name, self.jenkins.views)
 def test_invocation_object(self):
     job_name = 'create_%s' % random_string()
     job = self.jenkins.create_job(job_name, LONG_RUNNING_JOB)
     ii = job.invoke(invoke_pre_check_delay=7)
     self.assertIsInstance(ii, Invocation)
     self.assertTrue(ii.is_queued_or_running())
     self.assertEquals(ii.get_build_number(), 1)
Beispiel #50
0
 def test_delete_view_which_does_not_exist(self):
     self._create_job()
     view1_name = random_string()
     new_view = self.jenkins.views.create(view1_name)
     self.assertIn(view1_name, self.jenkins.views)
     del self.jenkins.views[view1_name]
     self.assertNotIn(view1_name, self.jenkins.views)
Beispiel #51
0
def test_create_jnlp_node(jenkins):
    node_name = random_string()
    node_dict = {
        'num_executors':
        1,
        'node_description':
        'Test JNLP Node',
        'remote_fs':
        '/tmp',
        'labels':
        'systest_jnlp',
        'exclusive':
        True,
        'tool_location': [
            {
                "key":
                "hudson.tasks.Maven$MavenInstallation$DescriptorImpl@Maven 3.0.5",
                "home": "/home/apache-maven-3.0.5/"
            },
        ]
    }
    node = jenkins.nodes.create_node(node_name, node_dict)
    assert isinstance(node, Node) is True

    del jenkins.nodes[node_name]
Beispiel #52
0
 def test_get_job_and_update_config(self):
     job_name = 'config_%s' % random_string()
     self.jenkins.create_job(job_name, EMPTY_JOB)
     self.assertJobIsPresent(job_name)
     config = self.jenkins[job_name].get_config()
     self.assertEquals(config.strip(), EMPTY_JOB.strip())
     self.jenkins[job_name].update_config(EMPTY_JOB)