Skip to content

Commit

Permalink
Fixes to make it work in a onpremise environment with special needs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-romero committed Aug 4, 2020
1 parent 2804e06 commit fdb7bb9
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 79 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OPENSHIFT_PROJECT=edpp
OPENSHIFT_PUBLIC_HOST=.ocp.odsbox.lan
OPENSHIFT_CLUSTER=https://ocp.odsbox.lan:8443/
SIMULATE=false
OPENSHIFT_TOKEN=THE_TOKEN
# values provided by ods-configuration/ods-core.env if present
JIRA_URL=http://jira.odsbox.lan:8080/
NEXUS_URL=https://nexus-ods.ocp.odsbox.lan
Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ You can have a look at the `build.gradle` and `src/test/resources/GebConfig.groo
## Usage
You need to set several environment variables in order to make this work, as it is intended to use in a container / pod lately.

| Variable | Value | Description |
|-----------------------|----------------------------------|----------------------------------------------------------------------------- |
| PROV_APP_USER | openshift | Provisioning app user name |
| PROV_APP_PASSWORD | openshift | Provisioning app password |
| ATLASSIAN_USER | openshift | Atlassian user name |
| ATLASSIAN_PASSWORD | openshift | Atlassian password |
| JENKINS_USER | developer | Jenkins user name |
| JENKINS_PASSWORD | any | Jenkins password |
| OPENSHIFT_USER | developer | Openshift user name |
| OPENSHIFT_PASSWORD | any | Openshift password |
| PROV_APP_NAME | openshift | Name of the deployment of the provisioning app |
| JIRA_URL | http://jira.odsbox.lan:8080/ | Url of Jira instance related with the prov app |
| OPENSHIFT_PROJECT | edpp | project identifier for prov app in the preliminary tests(jira tests) |
| OPENSHIFT_PUBLIC_HOST | .ocp.odsbox.lan | host where we can locate the prov app |
| OPENSHIFT_CLUSTER | https://ocp.odsbox.lan:8443/ | URL of the Openshift Cluster |
| BITBUCKET_URL | http://bitbucket.odsbox.lan:7990 | Url of Bitbucket instance |
| SIMULATE | false | Specify (true or false) if we skip the creation of project, components, etc |
| NO_NEXUS | true | In case you want to use the public repositories, if it set to true it is not needed to set the next 3 properties |
| NEXUS_URL | https://nexus-ods.ocp.odsbox.lan | The nexus url if we want to use an specific nexus instance |
| NEXUS_USERNAME | admin | The nexus user |
| NEXUS_PASSWORD | openshift | The nexus password |
|BITBUCKET_BASE_BRANCH | master | The branck used as base branch for the QS(useful when you are testing the box)|
|QUICKSTARTERS_CONFIGMAP| quickstarters.properties | The configmap name where the qs of the provisioning app gets its configuration|
| Variable | Value | Description |
|------------------------|----------------------------------|----------------------------------------------------------------------------- |
| PROV_APP_USER | openshift | Provisioning app user name |
| PROV_APP_PASSWORD | openshift | Provisioning app password |
| ATLASSIAN_USER | openshift | Atlassian user name |
| ATLASSIAN_PASSWORD | openshift | Atlassian password |
| JENKINS_USER | developer | Jenkins user name |
| JENKINS_PASSWORD | any | Jenkins password |
| OPENSHIFT_USER | developer | Openshift user name |
| OPENSHIFT_PASSWORD | any | Openshift password |
| PROV_APP_NAME | openshift | Name of the deployment of the provisioning app |
| JIRA_URL | http://jira.odsbox.lan:8080/ | Url of Jira instance related with the prov app |
| OPENSHIFT_PROJECT | edpp | project identifier for prov app in the preliminary tests(jira tests) |
| OPENSHIFT_PUBLIC_HOST | .ocp.odsbox.lan | host where we can locate the prov app |
| OPENSHIFT_CLUSTER | https://ocp.odsbox.lan:8443/ | URL of the Openshift Cluster |
| BITBUCKET_URL | http://bitbucket.odsbox.lan:7990 | Url of Bitbucket instance |
| SIMULATE | false | Specify (true or false) if we skip the creation of project, components, etc |
| NO_NEXUS | true | In case you want to use the public repositories, if it set to true it is not needed to set the next 3 properties |
| NEXUS_URL | https://nexus-ods.ocp.odsbox.lan | The nexus url if we want to use an specific nexus instance |
| NEXUS_USERNAME | admin | The nexus user |
| NEXUS_PASSWORD | openshift | The nexus password |
| BITBUCKET_BASE_BRANCH | master | The branck used as base branch for the QS(useful when you are testing the box)|
| QUICKSTARTERS_CONFIGMAP| quickstarters.properties | The configmap name where the qs of the provisioning app gets its configuration|
| OPENSHIFT_TOKEN | the_token | Token to login in Openshift to be use instead of the openshift user for specific tasks |

### Environment variables setup
To get the information needed to run the tests there are 3 steps that override the previous one:
Expand Down
110 changes: 58 additions & 52 deletions src/test/groovy/org/ods/e2e/ODSSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.ods.e2e


import org.ods.e2e.bitbucket.pages.DashboardPage
import org.ods.e2e.bitbucket.pages.LoginPage
import org.ods.e2e.bitbucket.pages.ProjectPage
import org.ods.e2e.bitbucket.pages.RepositoryPage
import org.ods.e2e.jenkins.pages.JenkinsConsoleParametrizedBuildPage
import org.ods.e2e.jenkins.pages.JenkinsJobFolderPage
import org.ods.e2e.jenkins.pages.JenkinsLoginPage
import org.ods.e2e.openshift.client.OpenShiftClient
import org.ods.e2e.openshift.client.OpenShiftHelper
import org.ods.e2e.openshift.pages.ConsoleDeploymentsPage
import org.ods.e2e.openshift.pages.ConsoleProjectsPage
import org.ods.e2e.openshift.pages.ConsoleResourcesConfigMaps
import org.ods.e2e.openshift.pages.PodsPage
import org.ods.e2e.provapp.pages.HomePage
Expand All @@ -19,6 +19,7 @@ import org.ods.e2e.util.BaseSpec
import org.ods.e2e.util.GitUtil
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import spock.lang.Ignore

class ODSSpec extends BaseSpec {

Expand All @@ -27,6 +28,7 @@ class ODSSpec extends BaseSpec {
def static E2E_TEST_FILE = 'e2e-tests.txt'
def static E2E_TEST_QUICKSTARTER = 'e2e-test-quickstarter'
def static E2E_TEST_COMPONENT = 'test-component'
def static openshifHelper = new OpenShiftHelper()

def static projects = [
default: [
Expand Down Expand Up @@ -87,6 +89,7 @@ class ODSSpec extends BaseSpec {
println 'Tests setup'
}


/**
* Test Objective:
* The purpose of this test case is to present a level of evidences that the use of Provisioning Application,
Expand All @@ -112,6 +115,7 @@ class ODSSpec extends BaseSpec {
// Result: Login works, within a provisioning and history links
// -------------------------------------------------------------------------------------------------------------
given: 'We are logged in the provisioning app'
def openshifHelper = new OpenShiftHelper()
def project = projects.default
baseUrl = baseUrlProvisioningApp

Expand Down Expand Up @@ -143,7 +147,9 @@ class ODSSpec extends BaseSpec {
and: 'Get the next key'
def nextId = getNextId(project.key)
project.name = String.format("$project.name - %02d", nextId)
project.key = String.format("${project.key}%02d", nextId)
if (!simulate) {
project.key = String.format("${project.key}%02d", nextId)
}

and: 'We open the project creation form'
provisionOptionChooser.doSelectCreateNewProject()
Expand All @@ -166,7 +172,7 @@ class ODSSpec extends BaseSpec {
projectCreateForm.doStartProvision()

// wait until project is created
waitFor {
waitFor('verySlow') {
$(".modal-dialog").css("display") != "hidden"
$("#resProject.alert-success")
$("#resButton").text() == "Close"
Expand All @@ -185,7 +191,9 @@ class ODSSpec extends BaseSpec {
simulate ? true : $("#resProject.alert-success").size() == 1

report("step 4 - project has been created")
$("#resButton").click()
if (!simulate) {
$("#resButton").click()
}


// -------------------------------------------------------------------------------------------------------------
Expand All @@ -207,48 +215,29 @@ class ODSSpec extends BaseSpec {

then: 'We are in the project page'
currentUrl.endsWith("projects/${project.key}/")
if (!simulate) {
$("h2.page-panel-content-header")?.text()?.contains('Repositories')
}
report("step 5 - project in bitbucket")

// -------------------------------------------------------------------------------------------------------------
// STEP 6: Go to openshift – and find the new project with its key (-cd). Locate a running Jenkins instance
// Result: Find a running Jenkins deployment – click on it and verify that the image used comes from the
// CD namespace
// -------------------------------------------------------------------------------------------------------------
when: 'Visit Openshift'
baseUrl = baseUrlOpenshift

and: 'and login in Openshift'
doOpenshiftLoginProcess()
when: 'Check if we have a Jenkins instance running'
baseUrl = getJenkinsBaseUrl(project.key)

then: "Visit all project page and check for the projects"
waitFor('mediumSlow') {
to ConsoleProjectsPage
findProjects(project.key).size() > 0
findProjects(project.key).contains(project.key.toLowerCase() + '-cd')
and:
waitFor('extremelySlow') {
openshifHelper.existsNamespace(project.key.toLowerCase() + '-cd')
}


when:
'Visit pods page'
to PodsPage, project.key.toLowerCase() + '-cd'
sleep(5000)

then:
waitFor('verySlow') {
getPods().find { pod ->
pod.name.startsWith('jenkins') &&
pod.status == 'Running' &&
!pod.isDeployPod &&
pod.containersReady == '1/1'
}

getPods().find { pod ->
pod.name.startsWith('webhook') &&
pod.status == 'Running' &&
!pod.isDeployPod &&
pod.containersReady == '1/1'
}
waitFor('extremelySlow') {
doJenkinsLoginProcess()
}

report("step 6 - existing jenkins instance for the project")

// -------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -332,7 +321,7 @@ class ODSSpec extends BaseSpec {
baseUrl = getJenkinsBaseUrl(project.key)

and:
doJenkinsLoginProcess()
to JenkinsLoginPage

then: 'The project folder exists'
assert $("#job_${project.key.toLowerCase()}-cd")
Expand All @@ -341,6 +330,11 @@ class ODSSpec extends BaseSpec {
'Visit the jobs'
to JenkinsJobFolderPage, project.key

and:
if (activateAutorefreshLink) {
activateAutorefreshLink.click()
}

and:
project.components.each { component ->
component.jobs = getComponentJobs(project.key, component.componentId)
Expand All @@ -349,11 +343,11 @@ class ODSSpec extends BaseSpec {
then:
'The component startup jobs finished succesfully'
waitFor('verySlow') {
project.components.each {
project.components.every {
component ->
getComponentJobs(project.key, component.componentId).jobs.find {
getComponentJobs(project.key, component.componentId).find {
job -> job.value.odsStartupComponentJob && job.value.success
}
} != null
}
}

Expand All @@ -375,11 +369,11 @@ class ODSSpec extends BaseSpec {
and:
'Checks that exists jobs that are not qs startup jobs for the components'
waitFor('verySlow') {
project.components.each {
project.components.every {
component ->
getComponentJobs(project.key, component.componentId).jobs.find {
getComponentJobs(project.key, component.componentId).find {
job -> !job.value.odsStartupComponentJob && job.value.success
}
} != null
}
}

Expand All @@ -394,6 +388,7 @@ class ODSSpec extends BaseSpec {
* to the console/terminal logs of Jenkins, Nexus and SonarQube and have administrator access to the Bitbucket
* repositories including the OpenDevStack one.
*/
@Ignore
def "FT_01_002"() {
// STEP 1: Go to Bitbucket ODS project – into repository ods-quickstarters
// Result: Project and repository available
Expand Down Expand Up @@ -761,11 +756,15 @@ class ODSSpec extends BaseSpec {
}
}

and: 'Wait if the job is still running'

// After adding the new component some changes are introduced to the configuration of the jenkins pod
// so the pod is restarted.
and: 'Wait if the job is still running or jenkins is still running'
waitFor('verySlow') {
getComponentJobs(project.key, releaseManagerComponent.componentId).find {
job -> job.value.odsStartupComponentJob && job.value.success
}
$("body > div >h1").text()?.toLowerCase()?.contains('application is not available') != null ||
getComponentJobs(project.key, releaseManagerComponent.componentId).find {
job -> job.value.odsStartupComponentJob && job.value.success
} != null
}

// -------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -843,25 +842,32 @@ class ODSSpec extends BaseSpec {
metadataRepositories = metadataYml.getAt('repositories')
}
def component = project.components.first()
metadataRepositories.putAt(metadataRepositories.size, [
id : component.componentId.toLowerCase(),
name: "$project.key-$component.componentId".toLowerCase(), type: 'ods'])
if (metadataRepositories.size() == 0 || metadataRepositories.findAll { it -> it.id == component.componentId.toLowerCase() }.size() == 0) {
metadataRepositories.putAt(metadataRepositories.size, [
id : component.componentId.toLowerCase(),
name: "$project.key-$component.componentId".toLowerCase(), type: 'ods'])
}


and: 'Save metada.yml'
parser.dump(metadataYml, new FileWriter("$repositoryFolder/metadata.yml"))

and: 'Commit the file'
GitUtil.commitAddAll(gitRepository,'New component added')
GitUtil.commitAddAll(gitRepository, 'New component added')

and: 'Push it to the repository'
GitUtil.push(gitRepository,'origin')
GitUtil.push(gitRepository, 'origin')

// -------------------------------------------------------------------------------------------------------------
// 3.2 Trigger Jenkins build of the release manager.
// -------------------------------------------------------------------------------------------------------------
and:
and: 'Go to jenkins'
baseUrl = getJenkinsBaseUrl(project.key)

and: 'Login again in jenkins as it has been rebooted'
waitFor('extremelySlow') {
doJenkinsLoginProcess()
}
def parameters = [environment: 'dev', version: 'WIP',]
to JenkinsConsoleParametrizedBuildPage, project.key, releaseManagerPipelineJob
fillData(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import geb.Page

class JenkinsConsoleParametrizedBuildPage extends Page {

static url = '/job/'
static url = '/job'
/**
* Adapt the url to get to the jenkins job/jobfolder page
* https://jenkins-url/job/$project$-cd/job/$job$/build?delay=0sec
Expand Down
Loading

0 comments on commit fdb7bb9

Please sign in to comment.