Andrey Adamovich, Aestas/IT
Our take on:
Automate the provisioning and maintenance of servers:
No Manual Changes!
remoteSession {url = 'user2:654321@localhost:2222'exec 'rm -rf /tmp/*'exec 'touch /var/lock/my.pid'remoteFile('/var/my.conf').text = "enabled=true"}
remoteSession {scp {from { localDir "$buildDir/application" }into { remoteDir '/var/bea/domain/application' }}}
def result = exec(command: '/usr/bin/mycmd',failOnError: false, showOutput: false)if (result.exitStatus == 1) {result.output.eachLine { line ->if (line.contains('WARNING')) {throw new RuntimeException("Warning!!!")}}}
task uploadModules << {remoteSession {exec 'rm -rf /tmp/repo.zip'scp {from { localFile "${buildDir}/repo.zip" }into { remoteDir "/root" }}...
...exec 'rm -rf /etc/puppet/modules'exec 'unzip /tmp/repo.zip -d /etc/puppet/modules'}}
task puppetApply(dependsOn: uploadModules) << {remoteSession {scp {from { localFile "${buildDir}/setup.pp" }into { remoteDir "/tmp" }}exec 'puppet apply /tmp/setup.pp'}}
class DerbyInstallTestextends BasePuppetIntegrationTest {@Beforevoid installDerby() {apply("include derby")}...}
@Testdef void ensureDerbyRunning() {command('service derby status > derbystatus.log')assertTrue fileText("/root/derbystatus.log").contains('Derby')assertTrue fileText("/root/derbystatus.log").contains('is running.')}
@Testdef void ensureCanConnect() {Thread.sleep(10000)uploadScript()command('/opt/derby/db-derby-10.9.1.0-bin/bin/ij ' +'testDataScript.sql > derbytest.log')...
...// Check if the log of the insert// operation contains the word ERROR.assertFalse("The script should return at least one error",fileText("/root/derbytest.log").contains('ERROR'))...
...// Check on data that was inserted into a table.assertTrue("The log should contain a SELECT result",fileText("/root/derbytest.log").contains('Grand Ave.'))}
session {tunnel ('127.0.0.1', 8080) { int localPort ->// Login to Jenkins.def driver = new HtmlUnitDriver(false)driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS).implicitlyWait(30, TimeUnit.SECONDS)driver.get("http://127.0.0.1:${localPort}/login")...
...def input = driver.findElement(By.name('j_username'))input.sendKeys('john')input = driver.findElement(By.name('j_password'))input.sendKeys('123456')input.submit()...
...// Verify login.def wait = new WebDriverWait(driver, 30)wait.until ExpectedConditions.presenceOfElementLocated (By.linkText('John Doe'))...}}
session {tunnel ('127.0.0.1', 80) { int localPort ->// Initilize repository connection data.DAVRepositoryFactory.setup()def url = SVNURL.create('http', null, '127.0.0.1', localPort, 'repos/cafebabe', true)def repository = SVNRepositoryFactory.create(url)println "Verifying SVN repository at ${url}"...
...// Setup credentials.def authManager = SVNWCUtil.createDefaultAuthenticationManager('joe', '123456')repository.setAuthenticationManager(authManager)// Verify repository is at revision 0.assertEquals 0, repository.getLatestRevision()...
...// Commit first revision.ISVNEditor editor = repository.getCommitEditor("Initial commit.", null)editor.with {openRoot(-1)addFile('dummy.txt', null, -1)applyTextDelta('dummy.txt', null)def deltaGenerator = new SVNDeltaGenerator()...
...def checksum = deltaGenerator.sendDelta('dummy.txt', new ByteArrayInputStream("data".getBytes()), editor, true)closeFile('dummy.txt', checksum)def commitInfo = closeEdit()println commitInfo}...
...// Verify repository is at revision 1 now.assertEquals 1, repository.getLatestRevision()}}
task startInstance(type: StartInstance) {keyName 'cloud-do'securityGroup 'cloud-do'instanceName 'gramazon/cloud-do'stateFileName 'cloud-do.json'ami 'ami-6f07e418'instanceType 't1.micro'waitForStart true}
task terminateInstance(type: TerminateInstance) {stateFileName 'cloud-do.json'}