-
Notifications
You must be signed in to change notification settings - Fork 25
/
rpmDashboardsDistValidation.groovy
149 lines (140 loc) · 5.64 KB
/
rpmDashboardsDistValidation.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/**
* This is a general function for RPM distribution validation.
* @param Map args = [:]
* args.bundleManifest: The location of the distribution manifest.
* args.rpmDistribution: The location of the RPM distribution file.
*/
def call(Map args = [:]) {
def lib = library(identifier: 'jenkins@main', retriever: legacySCM(scm))
def BundleManifestObj = lib.jenkins.BundleManifest.new(readYaml(file: args.bundleManifest))
def distFile = args.rpmDistribution
def name = BundleManifestObj.build.getFilename() //opensearch-dashboards
def version = BundleManifestObj.build.version //2.0.0-rc1
def rpmVersion = version.replace("-", ".") //2.0.0.rc1
def architecture = BundleManifestObj.build.architecture
def plugin_names = BundleManifestObj.getNames();
// This is a reference meta data which the distribution should be consistent with.
def refMap = [:]
refMap['Name'] = name
refMap['Version'] = rpmVersion
refMap['Architecture'] = architecture
refMap['Group'] = "Application/Internet"
refMap['License'] = "Apache-2.0"
refMap['Relocations'] = "(not relocatable)"
refMap['URL'] = "https://opensearch.org/"
// The context of meta data should be for OSD
refMap['Summary'] = "Open source visualization dashboards for OpenSearch"
refMap['Description'] = "OpenSearch Dashboards is the visualization tool for data in OpenSearch\n" +
"For more information, see: https://opensearch.org/"
//Validation for the Meta Data of distribution
rpmMetaValidation(
rpmDistribution: distFile,
refMap: refMap
)
//Validation for the installation
//Install the rpm distribution via yum
rpmCommands(
command: "install",
product: "opensearch-$rpmVersion"
)
println("RPM distribution for OpenSearch $version is also installed with yum.")
rpmCommands(
command: "install",
product: "$name-$rpmVersion"
)
println("RPM distribution for $name $version is installed with yum.")
//Start the installed OpenSearch-Dashboards distribution
systemdCommands(
command: "start",
product: "opensearch"
)
systemdCommands(
command: "start",
product: name
)
//Validate if the running status is succeed
def running_status = systemdCommands(
command: "status",
product: name
)
def active_status_message = "Active: active (running)"
if (running_status.contains(active_status_message)) {
println("After checking the status, the installed $name is actively running!")
} else {
error("Something went run! Installed $name is not actively running.")
}
// Get the OpenSearch-Dashboards api status after start.
def osd_status_json = -1
for (int i = 0; i < 10; i++) {
if (osd_status_json != 0) {
sleep 10
osd_status_json = sh (
script: "curl -s \"http://localhost:5601/api/status\" -u admin:admin",
returnStatus: true
)
} else {
osd_status_json = sh (
script: "curl -s \"http://localhost:5601/api/status\" -u admin:admin",
returnStdout: true
).trim()
break
}
}
println("Dashboards status are: \n" + osd_status_json)
def osd_status = readJSON(text: osd_status_json)
assert osd_status["version"]["number"] == version
println("Dashboards host version has been validated.")
assert osd_status["status"]["overall"]["state"] == "green"
println("OpenSearch Dashboards overall state is running green.")
//Plugin existence validation;
def osd_plugins = sh (
script: "/usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin list --allow-root",
returnStdout: true
).trim()
println("osd_plugins are: \n" + osd_plugins)
def components_list = []
for (component in plugin_names) {
if (component == "OpenSearch-Dashboards" || component == "functionalTestDashboards") {
continue
}
def location = BundleManifestObj.getLocation(component)
def component_name_with_version = location.split('/').last().minus('.zip') //e.g. anomalyDetectionDashboards-2.0.0-rc1
components_list.add(component_name_with_version)
}
for (component in components_list) {
def component_name = component.split("-").first()
def component_version = component.minus(component_name + "-")
if (component_version.contains("-")) { //It has qualifier
component_version = component_version.split("-").first() + ".0-" + component_version.split("-").last()
} else {
component_version = component_version + ".0"
}
def component_with_version = [component_name, component_version].join("@") //e.g. [email protected]
assert osd_plugins.contains(component_with_version)
println("Component $component is present with correct version $version." )
}
systemdCommands(
command: "stop",
product: name
)
rpmCommands(
command: "remove",
product: "opensearch-dashboards"
)
systemdCommands(
command: "stop",
product: "opensearch"
)
rpmCommands(
command: "remove",
product: "opensearch"
)
}