Skip to content

Commit 449dd9e

Browse files
committed
Tests were previously not pushed.
1 parent 97463ee commit 449dd9e

7 files changed

Lines changed: 1782 additions & 75 deletions

File tree

test/groovy/org/ods/component/HelmDeploymentStrategySpec.groovy

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.ods.component
22

3+
import groovy.json.JsonSlurperClassic
34
import org.ods.services.JenkinsService
45
import org.ods.services.OpenShiftService
56
import org.ods.services.ServiceRegistry
7+
import org.ods.util.HelmStatusSimpleData
68
import org.ods.util.Logger
79
import org.ods.util.PodData
810
import spock.lang.Shared
11+
import util.FixtureHelper
912
import vars.test_helper.PipelineSpockTestBase
1013

1114
class HelmDeploymentStrategySpec extends PipelineSpockTestBase {
@@ -21,45 +24,75 @@ class HelmDeploymentStrategySpec extends PipelineSpockTestBase {
2124
buildUrl: 'https://jenkins.example.com/job/foo-cd/job/foo-cd-bar-master/11/console',
2225
buildTime: '2020-03-23 12:27:08 +0100',
2326
odsSharedLibVersion: '2.x',
24-
projectId: 'foo',
25-
componentId: 'bar',
26-
cdProject: 'foo-cd',
27+
projectId: 'guardians',
28+
componentId: 'core',
29+
cdProject: 'guardians-cd',
2730
artifactUriStore: [builds: [bar: [:]]]
2831
]
2932

3033
def "rollout: check deploymentMean"() {
3134
given:
3235

36+
def expectedDeploymentMean = [
37+
type : "helm",
38+
selector : "app=guardians-core",
39+
chartDir : "chart",
40+
helmReleaseName : "core",
41+
helmEnvBasedValuesFiles: [],
42+
helmValuesFiles : ["values.yaml"],
43+
helmValues : [:],
44+
helmDefaultFlags : ["--install", "--atomic"],
45+
helmAdditionalFlags : [],
46+
helmStatus : [
47+
releaseName : "standalone-app",
48+
releaseRevision : "43",
49+
namespace : "guardians-test",
50+
deployStatus : "deployed",
51+
deployDescription: "Upgrade complete",
52+
lastDeployed : "2024-03-04T15:21:09.34520527Z",
53+
resources : [
54+
[kind: "ConfigMap", name: "core-appconfig-configmap"],
55+
[kind: "Deployment", name: "core"],
56+
[kind: "Deployment", name: "standalone-gateway"],
57+
[kind: "Service", name: "core"],
58+
[kind: "Service", name: "standalone-gateway"],
59+
[kind: "Cluster", name: "edb-cluster"],
60+
[kind: "Secret", name: "core-rsa-key-secret"],
61+
[kind: "Secret", name: "core-security-exandradev-secret"],
62+
[kind: "Secret", name: "core-security-unify-secret"]
63+
]
64+
]
65+
]
3366
def expectedDeploymentMeans = [
34-
"builds": [:],
35-
"deployments": [
36-
"bar-deploymentMean": [
37-
"type": "helm",
38-
"selector": "app=foo-bar",
39-
"chartDir": "chart",
40-
"helmReleaseName": "bar",
41-
"helmEnvBasedValuesFiles": [],
42-
"helmValuesFiles": ["values.yaml"],
43-
"helmValues": [:],
44-
"helmDefaultFlags": ["--install", "--atomic"],
45-
"helmAdditionalFlags": []
67+
builds : [:],
68+
deployments: [
69+
"core-deploymentMean" : expectedDeploymentMean,
70+
"core" : [
71+
podName : null,
72+
podNamespace : null,
73+
podMetaDataCreationTimestamp: null,
74+
deploymentId : "core-124",
75+
podStatus : null,
76+
containers : null
77+
],
78+
"standalone-gateway-deploymentMean": expectedDeploymentMean,
79+
"standalone-gateway" : [
80+
podName : null,
81+
podNamespace : null,
82+
podMetaDataCreationTimestamp: null,
83+
deploymentId : "core-124",
84+
podStatus : null,
85+
containers : null,
4686
],
47-
"bar":[
48-
"podName": null,
49-
"podNamespace": null,
50-
"podMetaDataCreationTimestamp": null,
51-
"deploymentId": "bar-124",
52-
"podNode": null,
53-
"podIp": null,
54-
"podStatus": null,
55-
"podStartupTimeStamp": null,
56-
"containers": null,
57-
]
5887
]
5988
]
89+
6090
def config = [:]
6191

62-
def ctxData = contextData + [environment: 'dev', targetProject: 'foo-dev', openshiftRolloutTimeoutRetries: 5, chartDir: 'chart']
92+
def helmStatusFile = new FixtureHelper().getResource("helmstatus.json")
93+
def helmStatus = HelmStatusSimpleData.fromJsonObject(new JsonSlurperClassic().parseText(helmStatusFile.text))
94+
95+
def ctxData = contextData + [environment: 'test', targetProject: 'guardians-test', openshiftRolloutTimeoutRetries: 5, chartDir: 'chart']
6396
IContext context = new Context(null, ctxData, logger)
6497
OpenShiftService openShiftService = Mock(OpenShiftService.class)
6598
openShiftService.checkForPodData(*_) >> [new PodData([deploymentId: "${contextData.componentId}-124"])]
@@ -72,8 +105,7 @@ class HelmDeploymentStrategySpec extends PipelineSpockTestBase {
72105
HelmDeploymentStrategy strategy = Spy(HelmDeploymentStrategy, constructorArgs: [null, context, config, openShiftService, jenkinsService, logger])
73106

74107
when:
75-
def deploymentResources = [Deployment: ['bar']]
76-
def rolloutData = strategy.getRolloutData(deploymentResources)
108+
strategy.getRolloutData(helmStatus)
77109
def actualDeploymentMeans = context.getBuildArtifactURIs()
78110

79111

test/groovy/org/ods/orchestration/usecase/LeVADocumentUseCaseSpec.groovy

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.ods.orchestration.usecase
22

33
import groovy.json.JsonSlurper
4+
import groovy.json.JsonSlurperClassic
45
import groovy.util.logging.Log
56
import groovy.util.logging.Slf4j
67
import org.apache.commons.io.FileUtils
78
import org.junit.Rule
89
import org.junit.rules.TemporaryFolder
910
import org.ods.util.ILogger
1011
import org.ods.services.ServiceRegistry
12+
import org.ods.util.PodData
1113
import spock.lang.Unroll
1214

1315
import org.ods.services.JenkinsService
@@ -890,6 +892,7 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
890892
1 * usecase.updateJiraDocumentationTrackingIssue(documentType, uri, "${docHistory.getVersion()}")
891893
}
892894

895+
893896
def "create IVR"() {
894897
given:
895898
jiraUseCase = Spy(new JiraUseCase(project, steps, util, Mock(JiraService), logger))
@@ -960,10 +963,10 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
960963
def version = (odsRepoType == MROPipelineUtil.PipelineConfig.REPO_TYPE_ODS_CODE) ? 'WIP' : '1.0'
961964

962965
def expectedSpecifications = systemDesignSpec
963-
? ["key":"NET-128",
964-
"req_key":"NET-125",
965-
"description":systemDesignSpec]
966-
: null
966+
? ["key":"NET-128",
967+
"req_key":"NET-125",
968+
"description":systemDesignSpec]
969+
: null
967970
def expectedComponents = ["key":"Technology-demo-app-catalogue",
968971
"nameOfSoftware":"demo-app-catalogue",
969972
"componentType":componentTypeLong,
@@ -1073,7 +1076,7 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
10731076
"risks": ["NET-126"],
10741077
"tests": ["NET-127"]
10751078
}''',
1076-
'''
1079+
'''
10771080
{
10781081
"key": "NET-128",
10791082
"id": "128",
@@ -1087,7 +1090,7 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
10871090
"risks": ["NET-126"],
10881091
"tests": ["NET-127"]
10891092
}''',
1090-
'''
1093+
'''
10911094
{
10921095
"key": "NET-128",
10931096
"id": "128",
@@ -1278,6 +1281,43 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
12781281
1 * usecase.createDocument(documentType, repo, _, [:], _, documentTemplate, watermarkText)
12791282
}
12801283

1284+
def "assemble deploymentInfo for TIR"() {
1285+
given:
1286+
def file = new FixtureHelper().getResource("deployments-data.json")
1287+
os.isDeploymentKind(*_) >> true
1288+
1289+
when:
1290+
def deploymentsData = new JsonSlurperClassic().parseText(file.text)
1291+
def assembledData = usecase.assembleDeployments(deploymentsData.deployments)
1292+
1293+
then:
1294+
1295+
assembledData["backend-helm-monorepo-deploymentMean"] == [
1296+
chartDir : "chart",
1297+
repoId : "backend-helm-monorepo",
1298+
helmAdditionalFlags: [],
1299+
helmEnvBasedValuesFiles :[],
1300+
helmValues :[
1301+
registry :"image-registry.openshift-image-registry.svc:5000",
1302+
componentId :"backend-helm-monorepo"
1303+
],
1304+
helmDefaultFlags :["--install", "--atomic"],
1305+
helmReleaseName :"backend-helm-monorepo",
1306+
selector :"app.kubernetes.io/instance=backend-helm-monorepo",
1307+
helmValuesFiles :["values.yaml"],
1308+
type :"helm", ]
1309+
1310+
assembledData["backend-helm-monorepo-deploymentStatus"] == [
1311+
releaseRevision :"2",
1312+
releaseName :"backend-helm-monorepo",
1313+
namespace: "kraemerh-dev",
1314+
deployDescription :"Upgrade complete",
1315+
resources : "Deployment: backend-helm-monorepo-chart-component-a, backend-helm-monorepo-chart-component-b, Service: backend-helm-monorepo-chart",
1316+
deployStatus :"deployed",
1317+
lastDeployed :"2024-06-26T12:59:51.270713404Z"
1318+
]
1319+
}
1320+
12811321
def "create overall DTR"() {
12821322
given:
12831323
// Argument Constraints
@@ -1657,25 +1697,25 @@ class LeVADocumentUseCaseSpec extends SpecHelper {
16571697
def "order steps"() {
16581698
given:
16591699
def testIssue = [ key: "JIRA-1" ,
1660-
steps: [
1661-
[
1662-
orderId: 2,
1663-
data: "N/A"
1664-
],
1665-
[
1666-
orderId: 1,
1667-
data: "N/A"
1668-
]
1669-
]]
1700+
steps: [
1701+
[
1702+
orderId: 2,
1703+
data: "N/A"
1704+
],
1705+
[
1706+
orderId: 1,
1707+
data: "N/A"
1708+
]
1709+
]]
16701710

1671-
when:
1672-
LeVADocumentUseCase leVADocumentUseCase = new LeVADocumentUseCase(null, null, null,
1673-
null, null, null, null, null, null, null,
1674-
null, null, null, null)
1675-
def ordered = leVADocumentUseCase.sortTestSteps(testIssue.steps)
1711+
when:
1712+
LeVADocumentUseCase leVADocumentUseCase = new LeVADocumentUseCase(null, null, null,
1713+
null, null, null, null, null, null, null,
1714+
null, null, null, null)
1715+
def ordered = leVADocumentUseCase.sortTestSteps(testIssue.steps)
16761716

1677-
then:
1678-
ordered.get(0).orderId == 1
1717+
then:
1718+
ordered.get(0).orderId == 1
16791719
}
16801720

16811721
def "referenced documents version"() {

test/groovy/org/ods/services/OpenShiftServiceSpec.groovy

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package org.ods.services
33

44
import groovy.json.JsonSlurperClassic
5+
import org.ods.util.HelmStatusSimpleData
56
import org.ods.util.ILogger
67
import org.ods.util.IPipelineSteps
78
import org.ods.util.Logger
@@ -189,6 +190,10 @@ class OpenShiftServiceSpec extends SpecHelper {
189190
then:
190191
results.size() == expected.size()
191192
for (int i = 0; i < results.size(); i++) {
193+
// Note: podIp, podNode and podStartupTimeStamp are no longer in type PodData.
194+
// Each result is only a subset of the corresponding expected data.
195+
// While it can surpise that the == assertion below would not catch this,
196+
// it actually comes in handy so we can leave the original data in place.
192197
results[i].toMap() == expected[i]
193198
}
194199
}
@@ -200,25 +205,17 @@ class OpenShiftServiceSpec extends SpecHelper {
200205
def file = new FixtureHelper().getResource("pods.json")
201206
List<PodData> expected = [
202207
[
203-
podName : 'example-be-token-6fcb4d85d6-7jr2r',
204208
podNamespace : 'proj-dev',
205209
podMetaDataCreationTimestamp: '2023-07-24T11:58:29Z',
206210
deploymentId : 'example-be-token-6fcb4d85d6',
207-
podNode : 'ip-10-32-10-30.eu-west-1.compute.internal',
208-
podIp : '192.0.2.172',
209211
podStatus : 'Running',
210-
podStartupTimeStamp : '2023-07-24T11:58:29Z',
211212
containers : ['be-token': 'image-registry.openshift-image-registry.svc:5000/proj-dev/example-be-token@sha256:cc5e57f98ee789429384e8df2832a89fbf1092b724aa8f3faff2708e227cb39e']
212213
],
213214
[
214-
podName : 'example-be-token-6fcb4d85d6-ndp8x',
215215
podNamespace : 'proj-dev',
216216
podMetaDataCreationTimestamp: '2023-07-24T11:58:29Z',
217217
deploymentId : 'example-be-token-6fcb4d85d6',
218-
podNode : 'ip-10-32-9-69.eu-west-1.compute.internal',
219-
podIp : '192.0.2.171',
220218
podStatus : 'Running',
221-
podStartupTimeStamp : '2023-07-24T11:58:29Z',
222219
containers : ['be-token': 'image-registry.openshift-image-registry.svc:5000/proj-dev/example-be-token@sha256:cc5e57f98ee789429384e8df2832a89fbf1092b724aa8f3faff2708e227cb39e']
223220
]
224221
]
@@ -250,16 +247,61 @@ class OpenShiftServiceSpec extends SpecHelper {
250247
podNamespace: 'foo-dev',
251248
podMetaDataCreationTimestamp: '2020-05-18T10:43:56Z',
252249
deploymentId: 'bar-164',
253-
podNode: 'ip-172-31-61-82.eu-central-1.compute.internal',
254-
podIp: '10.128.17.92',
255250
podStatus: 'Running',
256-
podStartupTimeStamp: '2020-05-18T10:43:56Z',
257251
containers: [
258252
bar: '172.30.21.196:5000/foo-dev/bar@sha256:07ba1778e7003335e6f6e0f809ce7025e5a8914dc5767f2faedd495918bee58a'
259253
]
260254
]
261255
}
262256

257+
def "helm status data extraction"() {
258+
given:
259+
def steps = Spy(util.PipelineSteps)
260+
def service = new OpenShiftService(steps, new Logger(steps, false))
261+
def helmJsonText = new FixtureHelper().getResource("helmstatus.json").text
262+
263+
when:
264+
def helmStatusData = service.retrieveHelmStatus('guardians-test', 'standalone-app')
265+
// OpenShiftService.DEPLOYMENT_KIND, OpenShiftService.DEPLOYMENTCONFIG_KIND,])
266+
then:
267+
1 * steps.sh(
268+
script: 'helm -n guardians-test status standalone-app --show-resources -o json',
269+
label: 'Gather Helm status for release standalone-app in guardians-test',
270+
returnStdout: true,
271+
) >> helmJsonText
272+
helmStatusData.name == 'standalone-app'
273+
helmStatusData.namespace == 'guardians-test'
274+
}
275+
276+
def "helm status data extraction bad content"() {
277+
given:
278+
def steps = Spy(util.PipelineSteps)
279+
def service = new OpenShiftService(steps, new Logger(steps, false))
280+
def helmJsonText = """
281+
{
282+
"name": "standalone-app",
283+
"info": {
284+
"first_deployed": "2022-12-19T09:44:32.164490076Z",
285+
"last_deployed": "2024-03-04T15:21:09.34520527Z",
286+
"deleted": "",
287+
"description": "Upgrade complete",
288+
"status": "deployed",
289+
"resources" : {}
290+
}
291+
}
292+
"""
293+
when:
294+
def helmStatusData = service.helmStatus('guardians-test', 'standalone-app')
295+
// OpenShiftService.DEPLOYMENT_KIND, OpenShiftService.DEPLOYMENTCONFIG_KIND,])
296+
then:
297+
1 * steps.sh(
298+
script: 'helm -n guardians-test status standalone-app --show-resources -o json',
299+
label: 'Gather Helm status for release standalone-app in guardians-test',
300+
returnStdout: true,
301+
)
302+
thrown RuntimeException
303+
}
304+
263305
def "helm upgrade"() {
264306
given:
265307
def steps = Spy(util.PipelineSteps)
@@ -752,7 +794,7 @@ class OpenShiftServiceSpec extends SpecHelper {
752794
when:
753795
def result = service.getConsoleUrl(steps)
754796

755-
then:
797+
then:
756798
result == routeUrl
757799
}
758800

0 commit comments

Comments
 (0)