Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SAN-6464-make-all-iccs-unique' i…
Browse files Browse the repository at this point in the history
…nto SAN-6464-make-all-iccs-unique
  • Loading branch information
Nathan219 committed Jun 29, 2017
2 parents 6b01e1f + 1cd944b commit fe26f46
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 13 deletions.
5 changes: 3 additions & 2 deletions lib/models/services/cluster-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module.exports = class ClusterConfigService {
clusterCreateId,
repoFullName,
triggeredAction: data.triggeredAction,
shouldNotAutoFork: data.shouldNotAutoFork,
mainInstanceServiceName
}
return ClusterConfigService.createFromRunnableConfig(
Expand Down Expand Up @@ -793,7 +794,7 @@ module.exports = class ClusterConfigService {
inputInstanceOpts.name
)
}
const shouldNotAutofork = keypather.get(parsedInstanceData, 'metadata.name') !== buildOpts.mainInstanceServiceName
const shouldNotAutofork = !(keypather.get(parsedInstanceData, 'metadata.name') === buildOpts.mainInstanceServiceName && !buildOpts.shouldNotAutoFork)
const defaultInstanceOpts = {
// short name is service name
shortName: serviceName,
Expand All @@ -803,7 +804,7 @@ module.exports = class ClusterConfigService {
ipWhitelist: {
enabled: false
},
shouldNotAutofork: shouldNotAutofork,
shouldNotAutofork,
isolated: buildOpts.isolated,
isTesting: testingOpts.isTesting,
isTestReporter: testingOpts.isTestReporter
Expand Down
5 changes: 4 additions & 1 deletion lib/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const postSchema = joi.object({
isTesting: joi.boolean().optional(),
testReporters: joi.array().optional(),
githubId: joi.number().optional(),
parentInputClusterConfigId: joi.string().allow('').optional()
parentInputClusterConfigId: joi.string().allow('').optional(),
shouldNotAutoFork: joi.boolean().optional()
}).unknown().required()

const multiPostSchema = joi.object({
Expand Down Expand Up @@ -61,6 +62,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) {
const parentInputClusterConfigId = keypather.get(body, 'parentInputClusterConfigId')
const isTesting = keypather.get(body, 'isTesting')
const testReporters = keypather.get(body, 'testReporters')
const shouldNotAutoFork = keypather.get(body, 'shouldNotAutoFork')
return {
mainInstanceServiceName,
clusterCreateId: uuid(),
Expand All @@ -73,6 +75,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) {
isTesting: isTesting || false,
testReporters: testReporters || [],
clusterName,
shouldNotAutoFork,
parentInputClusterConfigId: parentInputClusterConfigId || ''
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/workers/cluster.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports.jobSchema = joi.object({
clusterName: joi.string().required(),
clusterCreateId: joi.string(),
parentInputClusterConfigId: joi.string().allow(''),
testReporters: joi.array()
testReporters: joi.array(),
shouldNotAutoFork: joi.boolean().required()
}).unknown().required()

/**
Expand All @@ -50,6 +51,7 @@ module.exports.task = (job) => {
'clusterCreateId',
'testReporters',
'parentInputClusterConfigId',
'shouldNotAutoFork',
'mainInstanceServiceName'
]
const opts = pick(job, props)
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "api",
"description": "Runnable API Server",
"version": "12.10.2",
"version": "12.10.3",
"repository": {
"type": "git",
"url": "http://github.com/CodeNow/api.git"
Expand Down
116 changes: 111 additions & 5 deletions unit/models/services/cluster-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ describe('Cluster Config Service Unit Tests', function () {
const repoFullName = orgName + '/' + repoName
const branchName = 'feature-1'
const clusterName = 'api-unit'
const shouldNotAutoFork = true
const parsedInput = {
repositoryName: clusterName,
ownerUsername: orgName,
Expand All @@ -208,7 +209,7 @@ describe('Cluster Config Service Unit Tests', function () {
}

const testData = {
triggeredAction, repoFullName, branchName, filePath, isTesting, testReporters, clusterName, clusterCreateId, parentInputClusterConfigId
triggeredAction, repoFullName, branchName, filePath, isTesting, testReporters, clusterName, clusterCreateId, parentInputClusterConfigId, shouldNotAutoFork
}

beforeEach(function (done) {
Expand Down Expand Up @@ -268,7 +269,7 @@ describe('Cluster Config Service Unit Tests', function () {
const args = ClusterConfigService.createFromRunnableConfig.getCall(0).args
expect(args[0]).to.equal(testSessionUser)
expect(args[1]).to.equal(testParsedContent.results)
expect(args[2]).to.equal( { triggeredAction, clusterCreateId, repoFullName, mainInstanceServiceName: 'api' })
expect(args[2]).to.equal( { triggeredAction, clusterCreateId, repoFullName, shouldNotAutoFork, mainInstanceServiceName: 'api' })
expect(args[3]).to.equal({
branch: branchName,
commit: commitSha,
Expand All @@ -284,7 +285,7 @@ describe('Cluster Config Service Unit Tests', function () {
ClusterConfigService.createFromRunnableConfig,
testSessionUser,
testParsedContent.results,
{ triggeredAction, clusterCreateId, repoFullName, mainInstanceServiceName: 'api' },
{ triggeredAction, clusterCreateId, repoFullName, shouldNotAutoFork, mainInstanceServiceName: 'api' },
sinon.match({
branch: branchName,
commit: commitSha,
Expand Down Expand Up @@ -973,6 +974,7 @@ describe('Cluster Config Service Unit Tests', function () {
buildOpts = {
isolated: objectId('407f191e810c19729de860e1'),
masterShorthash: 'asdasdsad',
shouldNotAutoFork: true,
clusterCreateId,
mainInstanceServiceName: 'a1'
}
Expand Down Expand Up @@ -1000,15 +1002,119 @@ describe('Cluster Config Service Unit Tests', function () {
}
const composeData = {
metadata: {
name: 'a1',
isMain: true
name: 'a1'
},
instance: testParentComposeData,
build: {
dockerFilePath: 'Nathan219/hello'
}
}
const testInstance = 'build'
InstanceService.createInstance.resolves(testInstance)

return ClusterConfigService._createInstance(testSessionUser, composeData, testParentBuildId, testingOpts, buildOpts)
.then(instance => {
sinon.assert.calledOnce(InstanceService.createInstance)
sinon.assert.calledWithExactly(InstanceService.createInstance, {
shortName: composeData.metadata.name,
build: testParentBuildId,
aliases: testParentComposeData.aliases,
env: testParentComposeData.env,
clusterCreateId,
containerStartCommand: testParentComposeData.containerStartCommand,
name: buildOpts.masterShorthash + '--' + testParentComposeData.name,
isTesting,
isTestReporter,
isolated: buildOpts.isolated,
isIsolationGroupMaster: false,
shouldNotAutofork: true,
masterPod: false,
ipWhitelist: {
enabled: false
}
}, testSessionUser)

expect(instance).to.equal(testInstance)
})
})

it('should set shouldNotAutoFork to true if it is not supplied', () => {
const testParentBuildId = objectId('407f191e810c19729de860ef')
const testParentComposeData = {
env: 'env',
aliases: {
'dGhyZWUtY2hhbmdpbmctdGhlLWhvc3RuYW1l': {
'instanceName': 'compose-test-5-1-rethinkdb4',
'alias': 'three-changing-the-hostname'
}
},
containerStartCommand: 'containerStartCommand',
name: 'name'
}
const composeData = {
metadata: {
name: 'a2'
},
instance: testParentComposeData,
build: {
dockerFilePath: 'Nathan219/hello'
}
}
const testInstance = 'build'
buildOpts.shouldNotAutoFork = undefined
InstanceService.createInstance.resolves(testInstance)

return ClusterConfigService._createInstance(testSessionUser, composeData, testParentBuildId, testingOpts, buildOpts)
.then(instance => {
sinon.assert.calledOnce(InstanceService.createInstance)
sinon.assert.calledWithExactly(InstanceService.createInstance, {
shortName: composeData.metadata.name,
build: testParentBuildId,
aliases: testParentComposeData.aliases,
clusterCreateId,
env: testParentComposeData.env,
containerStartCommand: testParentComposeData.containerStartCommand,
name: buildOpts.masterShorthash + '--' + testParentComposeData.name,
isTesting,
isTestReporter,
clusterCreateId,
isolated: buildOpts.isolated,
isIsolationGroupMaster: false,
shouldNotAutofork: true,
masterPod: false,
ipWhitelist: {
enabled: false
}
}, testSessionUser)

expect(instance).to.equal(testInstance)
})
})

it('should set shouldNotAutoFork to false by default for non-main instances', () => {
const testParentBuildId = objectId('407f191e810c19729de860ef')
const testParentComposeData = {
env: 'env',
aliases: {
'dGhyZWUtY2hhbmdpbmctdGhlLWhvc3RuYW1l': {
'instanceName': 'compose-test-5-1-rethinkdb4',
'alias': 'three-changing-the-hostname'
}
},
containerStartCommand: 'containerStartCommand',
name: 'name'
}
const composeData = {
metadata: {
name: 'a1'
},
instance: testParentComposeData,
build: {
dockerFilePath: 'Nathan219/hello'
}
}
const testInstance = 'build'
buildOpts.shouldNotAutoFork = undefined
InstanceService.createInstance.resolves(testInstance)

return ClusterConfigService._createInstance(testSessionUser, composeData, testParentBuildId, testingOpts, buildOpts)
Expand Down
8 changes: 6 additions & 2 deletions unit/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('/docker-compose-cluster', function () {
const sessionUserBigPoppaId = 8084808
const parentInputClusterConfigId = 'funk flex'
const githubId = sessionUserGithubId
const shouldNotAutoFork = true
const mockSessionUser ={
accounts: {
github: { id: sessionUserGithubId }
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('/docker-compose-cluster', function () {
createClusterStub = sinon.stub(rabbitMQ, 'createCluster')
validateOrBoomStub = sinon.spy(joi, 'validateOrBoomAsync')
reqMock = {
body: { repo, branch, filePath, name, parentInputClusterConfigId, githubId },
body: { repo, branch, filePath, name, parentInputClusterConfigId, githubId, shouldNotAutoFork },
sessionUser: {
accounts: {
github: { id: sessionUserGithubId }
Expand Down Expand Up @@ -122,6 +123,7 @@ describe('/docker-compose-cluster', function () {
isTesting,
parentInputClusterConfigId,
testReporters,
shouldNotAutoFork,
clusterCreateId,
clusterName: name
})
Expand Down Expand Up @@ -150,6 +152,7 @@ describe('/docker-compose-cluster', function () {
const branch = 'master'
const filePath = '/docker-compose.yml'
const name = 'super-cool-name'
const shouldNotAutoFork = true
const mains = {
builds: {
hello: {},
Expand All @@ -164,7 +167,7 @@ describe('/docker-compose-cluster', function () {
builds: ['hello'],
externals: ['cheese', 'rain']
}
const body = { repo, branch, filePath, name, parentInputClusterConfigId, githubId }
const body = { repo, branch, filePath, name, parentInputClusterConfigId, githubId, shouldNotAutoFork }
beforeEach(function (done) {
createClusterStub = sinon.stub(rabbitMQ, 'createCluster')
validateOrBoomStub = sinon.spy(joi, 'validateOrBoomAsync')
Expand Down Expand Up @@ -216,6 +219,7 @@ describe('/docker-compose-cluster', function () {
isTesting,
clusterCreateId,
parentInputClusterConfigId,
shouldNotAutoFork,
testReporters,
clusterName: sinon.match.string
})
Expand Down

0 comments on commit fe26f46

Please sign in to comment.