Skip to content

Commit aba2052

Browse files
committed
add jenkins plugin create/delete obj test; allow for jenkins mem mon disable
1 parent 3b2bbe5 commit aba2052

File tree

5 files changed

+283
-33
lines changed

5 files changed

+283
-33
lines changed

test/extended/image_ecosystem/plugin.go

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type JenkinsRef struct {
3535

3636
const (
3737
useLocalPluginSnapshotEnvVarName = "USE_SNAPSHOT_JENKINS_IMAGE"
38+
disableJenkinsMemoryStats = "DISABLE_JENKINS_MEMORY_MONITORING"
3839
localPluginSnapshotImage = "openshift/jenkins-plugin-snapshot-test:latest"
3940
)
4041

@@ -63,7 +64,7 @@ func (j *JenkinsRef) buildURI(resourcePathFormat string, a ...interface{}) strin
6364
// Returns a response body and status code or an error.
6465
func (j *JenkinsRef) getResource(resourcePathFormat string, a ...interface{}) (string, int, error) {
6566
uri := j.buildURI(resourcePathFormat, a...)
66-
ginkgolog("Retrieving Jekins resource: %q", uri)
67+
ginkgolog("Retrieving Jenkins resource: %q", uri)
6768
req, err := http.NewRequest("GET", uri, nil)
6869
if err != nil {
6970
return "", 0, fmt.Errorf("Unable to build request for uri %q: %v", uri, err)
@@ -433,6 +434,22 @@ func initExecPod(oc *exutil.CLI) *kapi.Pod {
433434
return targetPod
434435
}
435436

437+
type apiObjJob struct {
438+
jobName string
439+
create bool
440+
}
441+
442+
// Validate create/delete of objects
443+
func validateCreateDelete(create bool, key, out string, err error) {
444+
ginkgolog("\nOBJ: %s\n", out)
445+
if create {
446+
o.Expect(err).NotTo(o.HaveOccurred())
447+
o.Expect(strings.Contains(out, key)).To(o.BeTrue())
448+
} else {
449+
o.Expect(err).To(o.HaveOccurred())
450+
}
451+
}
452+
436453
// Designed to match if RSS memory is greater than 500000000 (i.e. > 476MB)
437454
var memoryOverragePattern = regexp.MustCompile(`\s+rss\s+5\d\d\d\d\d\d\d\d`)
438455

@@ -446,7 +463,9 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
446463

447464
g.AfterEach(func() {
448465

449-
ticker.Stop()
466+
if os.Getenv(disableJenkinsMemoryStats) == "" {
467+
ticker.Stop()
468+
}
450469

451470
oc.SetNamespace(j.namespace)
452471
ginkgolog("Jenkins DC description follows. If there were issues, check to see if there were any restarts in the jenkins pod.")
@@ -565,42 +584,44 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
565584

566585
jenkinsPod := findJenkinsPod(oc)
567586

568-
ticker = time.NewTicker(10 * time.Second)
569-
go func() {
570-
for t := range ticker.C {
571-
memstats, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "cat", "/sys/fs/cgroup/memory/memory.stat").Output()
572-
if err != nil {
573-
ginkgolog("\nUnable to acquire Jenkins cgroup memory.stat")
574-
}
575-
ps, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "ps", "faux").Output()
576-
if err != nil {
577-
ginkgolog("\nUnable to acquire Jenkins ps information")
578-
}
579-
ginkgolog("\nJenkins memory statistics at %v\n%s\n%s\n\n", t, ps, memstats)
580-
581-
// This is likely a temporary measure in place to extract diagnostic information during unexpectedly
582-
// high memory utilization within the Jenkins image. If Jenkins is using
583-
// a large amount of RSS, extract JVM information from the pod.
584-
if memoryOverragePattern.MatchString(memstats) {
585-
histogram, err := oc.Run("rsh").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "jmap", "-histo", "1").Output()
586-
if err == nil {
587-
ginkgolog("\n\nJenkins histogram:\n%s\n\n", histogram)
588-
} else {
589-
ginkgolog("Unable to acquire Jenkins histogram: %v", err)
587+
if os.Getenv(disableJenkinsMemoryStats) == "" {
588+
ticker = time.NewTicker(10 * time.Second)
589+
go func() {
590+
for t := range ticker.C {
591+
memstats, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "cat", "/sys/fs/cgroup/memory/memory.stat").Output()
592+
if err != nil {
593+
ginkgolog("\nUnable to acquire Jenkins cgroup memory.stat")
590594
}
591-
stack, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "jstack", "1").Output()
592-
if err == nil {
593-
ginkgolog("\n\nJenkins thread dump:\n%s\n\n", stack)
594-
} else {
595-
ginkgolog("Unable to acquire Jenkins thread dump: %v", err)
595+
ps, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "ps", "faux").Output()
596+
if err != nil {
597+
ginkgolog("\nUnable to acquire Jenkins ps information")
598+
}
599+
ginkgolog("\nJenkins memory statistics at %v\n%s\n%s\n\n", t, ps, memstats)
600+
601+
// This is likely a temporary measure in place to extract diagnostic information during unexpectedly
602+
// high memory utilization within the Jenkins image. If Jenkins is using
603+
// a large amount of RSS, extract JVM information from the pod.
604+
if memoryOverragePattern.MatchString(memstats) {
605+
histogram, err := oc.Run("rsh").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "jmap", "-histo", "1").Output()
606+
if err == nil {
607+
ginkgolog("\n\nJenkins histogram:\n%s\n\n", histogram)
608+
} else {
609+
ginkgolog("Unable to acquire Jenkins histogram: %v", err)
610+
}
611+
stack, err := oc.Run("exec").Args("--namespace", jenkinsNamespace, jenkinsPod.Name, "--", "jstack", "1").Output()
612+
if err == nil {
613+
ginkgolog("\n\nJenkins thread dump:\n%s\n\n", stack)
614+
} else {
615+
ginkgolog("Unable to acquire Jenkins thread dump: %v", err)
616+
}
596617
}
597-
}
598618

599-
}
600-
}()
619+
}
620+
}()
621+
}
601622

602623
// Start capturing logs from this deployment config.
603-
// This command will terminate if the Jekins instance crashes. This
624+
// This command will terminate if the Jenkins instance crashes. This
604625
// ensures that even if the Jenkins DC restarts, we should capture
605626
// logs from the crash.
606627
dcLogFollow, dcLogStdOut, dcLogStdErr, err = oc.Run("logs").Args("-f", "dc/jenkins").Background()
@@ -675,6 +696,31 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
675696

676697
})
677698

699+
g.It("jenkins-plugin test create obj delete obj", func() {
700+
701+
jobsToCreate := map[string]string{"test-create-obj": "create-job.xml", "test-delete-obj": "delete-job.xml", "test-delete-obj-labels": "delete-job-labels.xml", "test-delete-obj-keys": "delete-job-keys.xml"}
702+
for jobName, jobConfig := range jobsToCreate {
703+
data := j.readJenkinsJob(jobConfig, oc.Namespace())
704+
j.createItem(jobName, data)
705+
}
706+
707+
jobsToRun := []apiObjJob{{"test-create-obj", true}, {"test-delete-obj", false}, {"test-create-obj", true}, {"test-delete-obj-labels", false}, {"test-create-obj", true}, {"test-delete-obj-keys", false}}
708+
for _, job := range jobsToRun {
709+
jmon := j.startJob(job.jobName)
710+
jmon.await(10 * time.Minute)
711+
712+
g.By("get build console logs and see if succeeded")
713+
logs, err := j.waitForContent("Finished: SUCCESS", 200, 10*time.Minute, "job/%s/lastBuild/consoleText", job.jobName)
714+
ginkgolog("\n\nJenkins logs>\n%s\n\n", logs)
715+
o.Expect(err).NotTo(o.HaveOccurred())
716+
out, err := oc.Run("get").Args("bc", "forcepull-bldr").Output()
717+
validateCreateDelete(job.create, "forcepull-bldr", out, err)
718+
out, err = oc.Run("get").Args("is", "forcepull-extended-test-builder").Output()
719+
validateCreateDelete(job.create, "forcepull-extended-test-builder", out, err)
720+
}
721+
722+
})
723+
678724
g.It("jenkins-plugin test trigger build with envs", func() {
679725

680726
jobName := "test-build-with-env-job"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<scm class="hudson.scm.NullSCM"/>
7+
<canRoam>true</canRoam>
8+
<disabled>false</disabled>
9+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
10+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
11+
<triggers/>
12+
<concurrentBuild>false</concurrentBuild>
13+
<builders>
14+
15+
<com.openshift.jenkins.plugins.pipeline.OpenShiftCreator>
16+
<namespace>${PROJECT_NAME}</namespace>
17+
<jsonyaml>{
18+
"kind": "List",
19+
"apiVersion": "v1",
20+
"metadata": {},
21+
"items": [
22+
{
23+
24+
"kind": "ImageStream",
25+
"apiVersion": "v1",
26+
"metadata": {
27+
"name": "forcepull-extended-test-builder",
28+
"labels": {
29+
"foo": "bar"
30+
},
31+
"creationTimestamp": null
32+
},
33+
"spec": {},
34+
"status": {
35+
"dockerImageRepository": ""
36+
}
37+
38+
},
39+
{
40+
"kind": "BuildConfig",
41+
"apiVersion": "v1",
42+
"metadata": {
43+
"name": "forcepull-bldr",
44+
"creationTimestamp": null,
45+
"labels": {
46+
"foo": "bar"
47+
}
48+
},
49+
"spec": {
50+
"triggers": [],
51+
"source": {
52+
"type": "Git",
53+
"git": {
54+
"uri": "https://github.com/gabemontero/forcepull-extended-test-builder.git"
55+
}
56+
},
57+
"strategy": {
58+
"type": "Docker",
59+
"dockerStrategy": {
60+
"nocache": true
61+
}
62+
},
63+
"output":{
64+
"to":{
65+
"kind":"ImageStreamTag",
66+
"name":"forcepull-extended-test-builder:latest"
67+
}
68+
}
69+
}
70+
}
71+
]
72+
}
73+
</jsonyaml>
74+
</com.openshift.jenkins.plugins.pipeline.OpenShiftCreator>
75+
76+
</builders>
77+
<publishers/>
78+
<buildWrappers/>
79+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<scm class="hudson.scm.NullSCM"/>
7+
<canRoam>true</canRoam>
8+
<disabled>false</disabled>
9+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
10+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
11+
<triggers/>
12+
<concurrentBuild>false</concurrentBuild>
13+
<builders>
14+
15+
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterList>
16+
<namespace>${PROJECT_NAME}</namespace>
17+
<types>is,bc</types>
18+
<keys>forcepull-extended-test-builder,forcepull-bldr</keys>
19+
</com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterList>
20+
21+
</builders>
22+
<publishers/>
23+
<buildWrappers/>
24+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<scm class="hudson.scm.NullSCM"/>
7+
<canRoam>true</canRoam>
8+
<disabled>false</disabled>
9+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
10+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
11+
<triggers/>
12+
<concurrentBuild>false</concurrentBuild>
13+
<builders>
14+
15+
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterLabels>
16+
<namespace>${PROJECT_NAME}</namespace>
17+
<types>bc,is</types>
18+
<keys>foo</keys>
19+
<values>bar</values>
20+
</com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterLabels>
21+
22+
</builders>
23+
<publishers/>
24+
<buildWrappers/>
25+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<scm class="hudson.scm.NullSCM"/>
7+
<canRoam>true</canRoam>
8+
<disabled>false</disabled>
9+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
10+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
11+
<triggers/>
12+
<concurrentBuild>false</concurrentBuild>
13+
<builders>
14+
15+
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterJsonYaml>
16+
<namespace>${PROJECT_NAME}</namespace>
17+
<jsonyaml>{
18+
"kind": "List",
19+
"apiVersion": "v1",
20+
"metadata": {},
21+
"items": [
22+
{
23+
24+
"kind": "ImageStream",
25+
"apiVersion": "v1",
26+
"metadata": {
27+
"name": "forcepull-extended-test-builder",
28+
"creationTimestamp": null
29+
},
30+
"spec": {},
31+
"status": {
32+
"dockerImageRepository": ""
33+
}
34+
35+
},
36+
{
37+
"kind": "BuildConfig",
38+
"apiVersion": "v1",
39+
"metadata": {
40+
"name": "forcepull-bldr",
41+
"creationTimestamp": null,
42+
"labels": {
43+
"name": "forcepull-bldr"
44+
}
45+
},
46+
"spec": {
47+
"triggers": [],
48+
"source": {
49+
"type": "Git",
50+
"git": {
51+
"uri": "https://github.com/gabemontero/forcepull-extended-test-builder.git"
52+
}
53+
},
54+
"strategy": {
55+
"type": "Docker",
56+
"dockerStrategy": {
57+
"nocache": true
58+
}
59+
},
60+
"output":{
61+
"to":{
62+
"kind":"ImageStreamTag",
63+
"name":"forcepull-extended-test-builder:latest"
64+
}
65+
}
66+
}
67+
}
68+
]
69+
}
70+
</jsonyaml>
71+
</com.openshift.jenkins.plugins.pipeline.OpenShiftDeleterJsonYaml>
72+
73+
</builders>
74+
<publishers/>
75+
<buildWrappers/>
76+
</project>

0 commit comments

Comments
 (0)