1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Test rollback of deployments |
5
|
|
|
*/ |
6
|
|
|
class RollbackStepTest extends PipelineTest { |
|
|
|
|
7
|
|
|
|
8
|
|
|
protected static $fixture_file = 'PipelineTest.yml'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Makes the dummy deployment step |
12
|
|
|
* |
13
|
|
|
* @return Pipeline |
14
|
|
|
*/ |
15
|
|
|
public function getDummyPipeline($restoreDB = true) { |
16
|
|
|
// Get default backups |
17
|
|
|
$previous = DNDeployment::create(); |
18
|
|
|
$previous->write(); |
19
|
|
|
$current = DNDeployment::create(); |
20
|
|
|
$current->write(); |
21
|
|
|
$snapshot = DNDataTransfer::create(); |
22
|
|
|
$snapshot->write(); |
23
|
|
|
|
24
|
|
|
// Setup default pipeline |
25
|
|
|
$pipeline = $this->objFromFixture('Pipeline', 'testpipesmoketest'); |
26
|
|
|
$pipeline->Config = serialize(array( |
27
|
|
|
'RollbackStep1' => array( |
28
|
|
|
'Class' => 'RollbackStep', |
29
|
|
|
'RestoreDB' => $restoreDB, |
30
|
|
|
'MaxDuration' => '3600' |
31
|
|
|
) |
32
|
|
|
)); |
33
|
|
|
$pipeline->PreviousDeploymentID = $previous->ID; |
34
|
|
|
$pipeline->CurrentDeploymentID = $current->ID; |
35
|
|
|
$pipeline->PreviousSnapshotID = $snapshot->ID; |
36
|
|
|
$pipeline->write(); |
37
|
|
|
return $pipeline; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSuccessful() { |
41
|
|
|
$pipeline = $this->getDummyPipeline(); |
42
|
|
|
|
43
|
|
|
// Start failure |
44
|
|
|
$pipeline->markFailed(); |
45
|
|
|
$step = $pipeline->RollbackStep1(); |
46
|
|
|
|
47
|
|
|
// Assert not error at startup |
48
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
49
|
|
|
$this->assertEquals('Deployment', $step->Doing); |
|
|
|
|
50
|
|
|
$this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet |
51
|
|
|
|
52
|
|
|
// Mark the service as completed and check result |
53
|
|
|
$deployment = $step->RollbackDeployment(); |
|
|
|
|
54
|
|
|
$deployment->markFinished(); |
55
|
|
|
|
56
|
|
|
// Re-enter step as if called from checkPipelineStatus |
57
|
|
|
PipelineTest_MockLog::clear(); |
58
|
|
|
$step->start(); |
59
|
|
|
|
60
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
61
|
|
|
$this->assertEquals('Snapshot', $step->Doing); |
|
|
|
|
62
|
|
|
$this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet |
63
|
|
|
|
64
|
|
|
// Mark the snapshot as completed and check result |
65
|
|
|
$snapshot = $step->RollbackDatabase(); |
|
|
|
|
66
|
|
|
$snapshot->markFinished(); |
67
|
|
|
|
68
|
|
|
// Re-enter step as if called from checkPipelineStatus |
69
|
|
|
PipelineTest_MockLog::clear(); |
70
|
|
|
$step->start(); |
71
|
|
|
|
72
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
73
|
|
|
// confirm the maintenace page has been left up for a failed rollback |
74
|
|
|
$this->assertFalse(PipelineTest_MockLog::has_message('Enabling maintenance page for failed rollback')); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Test rollback without DB restoration |
79
|
|
|
*/ |
80
|
|
|
public function testNoDB() { |
81
|
|
|
$pipeline = $this->getDummyPipeline(false); |
82
|
|
|
|
83
|
|
|
// Start failure |
84
|
|
|
$pipeline->markFailed(); |
85
|
|
|
$step = $pipeline->RollbackStep1(); |
86
|
|
|
|
87
|
|
|
// Assert not error at startup |
88
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
89
|
|
|
$this->assertEquals('Deployment', $step->Doing); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// Mark the service as completed and check result |
92
|
|
|
$deployment = $step->RollbackDeployment(); |
|
|
|
|
93
|
|
|
$deployment->markFinished(); |
94
|
|
|
|
95
|
|
|
// Re-enter step as if called from checkPipelineStatus |
96
|
|
|
PipelineTest_MockLog::clear(); |
97
|
|
|
$step->start(); |
98
|
|
|
|
99
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Test failure at the snapshot step |
104
|
|
|
*/ |
105
|
|
|
public function testSnapshotFailure() { |
106
|
|
|
$pipeline = $this->getDummyPipeline(); |
107
|
|
|
|
108
|
|
|
// Start failure |
109
|
|
|
$pipeline->markFailed(); |
110
|
|
|
$step = $pipeline->RollbackStep1(); |
111
|
|
|
|
112
|
|
|
// Assert not error at startup |
113
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
114
|
|
|
$this->assertEquals('Deployment', $step->Doing); |
|
|
|
|
115
|
|
|
|
116
|
|
|
// Mark the service as completed and check result |
117
|
|
|
$deployment = $step->RollbackDeployment(); |
|
|
|
|
118
|
|
|
$deployment->markFinished(); |
119
|
|
|
|
120
|
|
|
// Re-enter step as if called from checkPipelineStatus |
121
|
|
|
PipelineTest_MockLog::clear(); |
122
|
|
|
$step->start(); |
123
|
|
|
|
124
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
125
|
|
|
$this->assertEquals('Snapshot', $step->Doing); |
|
|
|
|
126
|
|
|
|
127
|
|
|
// Mark the snapshot as completed and check result |
128
|
|
|
$snapshot = $step->RollbackDatabase(); |
|
|
|
|
129
|
|
|
$snapshot->markFailed(); |
130
|
|
|
|
131
|
|
|
// Re-enter step as if called from checkPipelineStatus |
132
|
|
|
PipelineTest_MockLog::clear(); |
133
|
|
|
$step->start(); |
134
|
|
|
|
135
|
|
|
$this->assertEquals('Failed', $step->Status); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Test failure at the deployment step |
140
|
|
|
*/ |
141
|
|
|
public function testDeploymentFailure() { |
142
|
|
|
$pipeline = $this->getDummyPipeline(); |
143
|
|
|
|
144
|
|
|
// Start failure |
145
|
|
|
$pipeline->markFailed(); |
146
|
|
|
$step = $pipeline->RollbackStep1(); |
147
|
|
|
|
148
|
|
|
// Assert not error at startup |
149
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
150
|
|
|
$this->assertEquals('Deployment', $step->Doing); |
|
|
|
|
151
|
|
|
|
152
|
|
|
// Mark the service as completed and check result |
153
|
|
|
$deployment = $step->RollbackDeployment(); |
|
|
|
|
154
|
|
|
$deployment->markFailed(); |
155
|
|
|
|
156
|
|
|
// Confirm that the maintenance page is not disabled |
157
|
|
|
$this->assertNotLogged('Maintenance page disabled'); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
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.