|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DryRunPipelineTest extends PipelineTest { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
protected static $fixture_file = 'PipelineTest.yml'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Makes the dummy pipeline |
|
9
|
|
|
* |
|
10
|
|
|
* @return Pipeline |
|
11
|
|
|
*/ |
|
12
|
|
|
public function getDummyPipeline() { |
|
13
|
|
|
// Load data into step and pipeline |
|
14
|
|
|
$data = $this->getPipelineConfig(); |
|
15
|
|
|
$pipeline = $this->objFromFixture('Pipeline', 'testpipe'); |
|
16
|
|
|
$pipeline->Config = serialize($data); |
|
17
|
|
|
$pipeline->DryRun = true; |
|
18
|
|
|
$pipeline->write(); |
|
19
|
|
|
|
|
20
|
|
|
return $pipeline; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Makes the dummy deployment step |
|
25
|
|
|
* |
|
26
|
|
|
* @return DeploymentPipelineStep |
|
27
|
|
|
*/ |
|
28
|
|
View Code Duplication |
public function getDummyDeployment() { |
|
|
|
|
|
|
29
|
|
|
$deployStep = $this->objFromFixture('DeploymentPipelineStep', 'testdeploy'); |
|
30
|
|
|
$deployStep->Config = serialize(array('MaxDuration' => '3600')); |
|
31
|
|
|
$deployStep->write(); |
|
32
|
|
|
$pipeline = $deployStep->Pipeline(); |
|
33
|
|
|
$pipeline->Config = serialize(array()); |
|
34
|
|
|
$pipeline->DryRun = true; |
|
35
|
|
|
$pipeline->write(); |
|
36
|
|
|
return $deployStep; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return RollbackStep |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getDummyRollback() { |
|
43
|
|
|
$rollbackStep = RollbackStep::create(); |
|
44
|
|
|
$rollbackStep->Status = 'Queued'; |
|
45
|
|
|
$rollbackStep->Doing = 'Queued'; |
|
46
|
|
|
$rollbackStep->Config = serialize(array( |
|
47
|
|
|
'Class' => 'RollbackStep', |
|
48
|
|
|
'MaxDuration' => '3600', |
|
49
|
|
|
'RestoreDB' => true |
|
50
|
|
|
)); |
|
51
|
|
|
$rollbackStep->write(); |
|
52
|
|
|
$pipeline = $this->getDummyPipeline(); |
|
53
|
|
|
$pipeline->RollbackStep1 = $rollbackStep->ID; |
|
|
|
|
|
|
54
|
|
|
$rollbackStep->PipelineID = $pipeline->ID; |
|
55
|
|
|
$rollbackStep->write(); |
|
56
|
|
|
$pipeline->write(); |
|
57
|
|
|
return $rollbackStep; |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Test messages aren't sent |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testMessages() { |
|
65
|
|
|
$pipeline = $this->getDummyPipeline(); |
|
66
|
|
|
$sender = new EmailMessagingService(); |
|
67
|
|
|
$sender->sendMessage($pipeline, 'Test message', '[email protected]'); |
|
68
|
|
|
$this->assertHasLog('[Skipped] Sent message to [email protected] (subject: Deploynaut notification)'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Test deployments dont do anything |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function testDeployment() { |
|
|
|
|
|
|
75
|
|
|
$step = $this->getDummyDeployment(); |
|
76
|
|
|
|
|
77
|
|
|
// First run; creates snapshot |
|
78
|
|
|
$step->start(); |
|
79
|
|
|
$this->assertHasLog('TestDeployStep:Snapshot creating snapshot of database'); |
|
80
|
|
|
$this->assertHasLog('[Skipped] Create DNDataTransfer backup'); |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
// Second run, finalises snapshot and creates deployment |
|
84
|
|
|
PipelineTest_MockLog::clear(); |
|
85
|
|
|
$step->start(); |
|
86
|
|
|
$this->assertHasLog('Checking status of TestDeployStep:Snapshot...'); |
|
87
|
|
|
$this->assertHasLog('[Skipped] Checking progress of snapshot backup'); |
|
88
|
|
|
$this->assertHasLog('TestDeployStep:Deployment starting deployment'); |
|
89
|
|
|
$this->assertHasLog('[Skipped] Create DNDeployment for SHA 9ae502821345ab39b04d46ce6bb822ccdd7f7414'); |
|
90
|
|
|
|
|
91
|
|
|
// Third run, complete deployment |
|
92
|
|
|
PipelineTest_MockLog::clear(); |
|
93
|
|
|
$step->start(); |
|
94
|
|
|
$this->assertHasLog('Checking status of TestDeployStep:Deployment...'); |
|
95
|
|
|
$this->assertHasLog('[Skipped] Checking progress of deployment'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Test the rollback step |
|
100
|
|
|
*/ |
|
101
|
|
View Code Duplication |
public function testRollback() { |
|
|
|
|
|
|
102
|
|
|
$step = $this->getDummyRollback(); |
|
103
|
|
|
|
|
104
|
|
|
// First run, start revert code |
|
105
|
|
|
$step->start(); |
|
106
|
|
|
$this->assertHasLog('RollbackStep:Deployment starting revert deployment'); |
|
107
|
|
|
$this->assertHasLog('[Skipped] Create DNDeployment'); |
|
108
|
|
|
|
|
109
|
|
|
// Second run, finish deployment and start database restoration |
|
110
|
|
|
PipelineTest_MockLog::clear(); |
|
111
|
|
|
$step->start(); |
|
112
|
|
|
$this->assertHasLog('Checking status of RollbackStep:Deployment...'); |
|
113
|
|
|
$this->assertHasLog('[Skipped] Checking progress of deployment'); |
|
114
|
|
|
$this->assertHasLog('RollbackStep:Snapshot reverting database from snapshot'); |
|
115
|
|
|
$this->assertHasLog('[Skipped] Create DNDataTransfer restore'); |
|
116
|
|
|
|
|
117
|
|
|
// Third run, complete snapshot restore |
|
118
|
|
|
PipelineTest_MockLog::clear(); |
|
119
|
|
|
$step->start(); |
|
120
|
|
|
$this->assertHasLog('Checking status of RollbackStep:Snapshot...'); |
|
121
|
|
|
$this->assertHasLog('[Skipped] Checking progress of snapshot restore'); |
|
122
|
|
|
$this->assertHasLog('Step finished successfully!'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Make the dummy deployment step |
|
127
|
|
|
* |
|
128
|
|
|
* @return SmokeTestPipelineStep |
|
129
|
|
|
*/ |
|
130
|
|
View Code Duplication |
public function getDummySmokeTestStep($name) { |
|
|
|
|
|
|
131
|
|
|
// Load data inte step and pipeline |
|
132
|
|
|
$data = $this->getPipelineConfig(); |
|
133
|
|
|
$smokeStep = $this->objFromFixture('SmokeTestPipelineStep', 'testsmoketest'); |
|
134
|
|
|
$pipeline = $smokeStep->Pipeline(); |
|
135
|
|
|
$pipeline->Config = serialize($data); |
|
136
|
|
|
$pipeline->DryRun = true; |
|
137
|
|
|
$pipeline->write(); |
|
138
|
|
|
$smokeStep->Config = serialize($pipeline->getConfigSetting('Steps', $name)); |
|
139
|
|
|
$smokeStep->write(); |
|
140
|
|
|
return $smokeStep; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Test failed smoke test |
|
145
|
|
|
*/ |
|
146
|
|
|
public function testSmokeTestFail() { |
|
147
|
|
|
// the testsmokefaile yml config contains a invalid smoketest url |
|
148
|
|
|
// which is how it fails |
|
149
|
|
|
$step = $this->getDummySmokeTestStep('FailTest'); |
|
150
|
|
|
$step->start(); |
|
151
|
|
|
$this->assertHasLog('Starting smoke test "BrokenPage" to URL http://bob.bob.bob.bob/'); |
|
152
|
|
|
$this->assertHasLog('Curl error: '); |
|
153
|
|
|
$this->assertHasLog('[Skipped] Smoke testing failed: Putting up emergency maintenance page'); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.