Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Add a Service Book class with a shared testProject method, for scripted pipelines #23

Merged
merged 23 commits into from
Sep 5, 2017

Conversation

stephendonner
Copy link
Contributor

@davehunt @tarekziade @rpappalax - thoughts and feedback much-desired and appreciated!

I anticipate a fair amount of cleanup needed/desired here, but this is, IMHO, very much a working prototype.

It can be seen working (i.e. getting to the same "tox" error) on https://qa-preprod-master.fxtest.jenkins.stage.mozaws.net/job/kinto.stage.stephend/15/console as in https://qa-preprod-master.fxtest.jenkins.stage.mozaws.net/job/kinto.stage/3/console

Full output (patch): https://gist.github.com/stephendonner/9a3904b1294c12b9ecc67ea42c5ced71 vs. (existing): https://gist.github.com/stephendonner/146f85214800dd25527974ac52929f5a

Since it's a shared library, we'll also need corresponding changes to call testProject() from a project's Jenkinsfile, which I've done (also rough) in mozilla-services/kinto-integration-tests#35

Copy link
Member

@davehunt davehunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great! Please add docs and tests where possible.

import groovy.json.JsonSlurperClassic;


HttpResponse doGetHttpRequest(String requestUrl){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of seeing if we can use the HTTP Request plugin, though that could be a future enhancement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Futured, for now, but will file an Issue for us to get that evaluated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davehunt filed #25, as you've seen; thanks for the reminder/gentle prod :-)

}


return this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? It looks superfluous.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't return "this", you can't use the module as a top namespace object in other modules, but maybe there are better ways to do it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. it was working fine when I had a dummy method in https://github.com/davehunt/fxtest-jenkins-pipeline/blob/servicebook/src/org/mozilla/fxtest/ServiceBook.groovy without return this;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe that's what "package" is for :)

}
}
stage('Ship it!') {
if (failures == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking the size of the failures array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I hope!

}

def testProject(String name) {
node {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not want to put the node here. We're using node within the stages, and this is only needed for the exit codes on lins 158-160, so we could simple wrap those in a node. I think that would be a more efficient use of our executors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; fixed!

)
}
echo "checked out"
node {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will run on any executor. If we have a specific agent or label that we wanted to run on, we should do that. I suspect we want a specific docker image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't yet know much about these actual tests, and/or where/how they best should run, besides that they should run in Docker, on the slave/execution node (at least in the qa-preprod* new setup).

Can we defer that for now, or should we hold off on merging this in until we have it clarified and codified, here?

@stephendonner
Copy link
Contributor Author

Latest run is https://qa-preprod-master.fxtest.jenkins.stage.mozaws.net/job/kinto.stage.stephend/19/console.

I'll work as I have time, now, on version history and code examples, in the README. Dave and I will likely pair on the tests next week.



def validURL(url) {
allowedOrgs = ['Kinto', 'mozilla', 'mozilla-services', 'tarekziade', 'rpappalax']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restriction is good to be aware of. I was thinking folks could make sure tests were somewhat viable before pushing them to a mozilla* org (i.e. that tests could be triggered from any org), but this is much safer route. I suppose we can still follow that workflow in PreProdJenkins and do soak testing there (without hooking into pipeline).
If you don't need the org for tarekziade or me, I'd go ahead and remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Richard. Actually, yes: now that we're getting really close to using this in a production/production-like environment and workflow, it's probably a good time to reel the validation back a bit; I'll make that change now.

// script.doGetHttpRequest = { String url -> [resp] }
// def tests = script.getProjectTests('foo')
// assert tests != null
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tarekziade, we're trying to mock out the getProjectTests but hit various issues with our attempts. Do you have any suggestions for how to test this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a shot

README.md Outdated
tests, and ```exit 1``` in the event of failed builds.

## Examples
```@Library('fxtest@1.7') _
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ```groovy and I don't think we need to include the tag in the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

README.md Outdated
@@ -133,6 +133,19 @@ submitToTreeherder(
)
```

## testProject
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other entries are pipeline steps, whereas this is a ServiceBook class. It feels like there should be some separation in the documentation. Perhaps a heading for pipeline steps, and a heading for ServiceBook with the testProject method documentated? We're probably close to wanting to break the documentation out to a readthedocs or similar too, as it's getting quite lenghty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a stab at this, but currently the "Shared Libraries..." heading and "Pipeline Steps" and "ServiceBook Class" are all the same heading weight of "#" - let me know if that's a deal-breaker, and I'll rework the subheadings' weights to match!

README.md Outdated

def sb = new org.mozilla.fxtest.ServiceBook()
sb.testProject('kinto')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to close the code sample with ```, otherwise the next heading is considered code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed; thanks (and, oops!)

README.md Outdated
@@ -158,6 +171,8 @@ writeCapabilities(

## Version History

### 1.7 (2017-09-04)
* Introduced `testProject` method, which queries Service Book for project repos.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reword as something like: Introduces ServiceBook class, with testProject method to execute tests for all pipelines associated with the specified project name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - fixed.

README.md Outdated

## Examples
```groovy
def sb = new org.mozilla.fxtest.ServiceBook()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't mean to remove the library import, just the version tag as that will become dated.

Copy link
Member

@davehunt davehunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ with comments addressed. For the headings, I think I'd prefer Pipeline Steps and ServiceBook to be under the top heading, but that would require pushing everything else down a level, which might not look great. This is why I think it's worth moving to readthedocs, as these can then be separate pages then. Would you mind filing a separate issue for that?

README.md Outdated
@@ -155,9 +156,23 @@ writeCapabilities(
path: 'fx51win10.json'
)
```
# ServiceBook Class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd drop 'Class'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@stephendonner
Copy link
Contributor Author

Filed #29 to track moving the README to Read the Docs.

@stephendonner stephendonner merged commit 58c7efc into mozilla:master Sep 5, 2017
@stephendonner stephendonner changed the title [WIP] Add a Service Book class with a shared testProject method, for scripted pipelines Add a Service Book class with a shared testProject method, for scripted pipelines Sep 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants