|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
|
5
|
|
|
* All rights reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
8
|
|
|
* modification, are permitted provided that the following conditions |
|
9
|
|
|
* are met: |
|
10
|
|
|
* |
|
11
|
|
|
* * Redistributions of source code must retain the above copyright |
|
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
13
|
|
|
* |
|
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
|
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
|
16
|
|
|
* the documentation and/or other materials provided with the |
|
17
|
|
|
* distribution. |
|
18
|
|
|
* |
|
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
|
20
|
|
|
* contributors may be used to endorse or promote products derived |
|
21
|
|
|
* from this software without specific prior written permission. |
|
22
|
|
|
* |
|
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
|
35
|
|
|
* |
|
36
|
|
|
* @category Libraries |
|
37
|
|
|
* @package Storyplayer/Modules/Host |
|
38
|
|
|
* @author Stuart Herbert <[email protected]> |
|
39
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
41
|
|
|
* @link http://datasift.github.io/storyplayer |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
namespace Storyplayer\SPv2\Modules\Host; |
|
45
|
|
|
|
|
46
|
|
|
use Storyplayer\SPv2\Modules\Exceptions; |
|
47
|
|
|
use Storyplayer\SPv2\Modules\Filesystem; |
|
48
|
|
|
use Storyplayer\SPv2\Modules\Screen; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
* test the state of a (possibly remote) computer |
|
53
|
|
|
* |
|
54
|
|
|
* @category Libraries |
|
55
|
|
|
* @package Storyplayer/Modules/Host |
|
56
|
|
|
* @author Stuart Herbert <[email protected]> |
|
57
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
58
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
59
|
|
|
* @link http://datasift.github.io/storyplayer |
|
60
|
|
|
*/ |
|
61
|
|
|
class ExpectsHost extends HostAwareModule |
|
62
|
|
|
{ |
|
63
|
|
|
public function hostIsRunning() |
|
64
|
|
|
{ |
|
65
|
|
|
// what are we doing? |
|
66
|
|
|
$log = usingLog()->startAction("make sure host '{$this->args[0]}' is running"); |
|
67
|
|
|
|
|
68
|
|
|
// make sure we have valid host details |
|
69
|
|
|
$hostDetails = $this->getHostDetails(); |
|
70
|
|
|
|
|
71
|
|
|
// is it running? |
|
72
|
|
|
$running = fromHost($hostDetails->hostId)->getHostIsRunning(); |
|
73
|
|
|
if (!$running) { |
|
74
|
|
|
$log->endAction(); |
|
75
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, 'host is running', 'host is not running'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// all done |
|
79
|
|
|
$log->endAction(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function hostIsNotRunning() |
|
83
|
|
|
{ |
|
84
|
|
|
// what are we doing? |
|
85
|
|
|
$log = usingLog()->startAction("make sure host '{$this->args[0]}' is not running"); |
|
86
|
|
|
|
|
87
|
|
|
// make sure we have valid host details |
|
88
|
|
|
$hostDetails = $this->getHostDetails(); |
|
89
|
|
|
|
|
90
|
|
|
// is it running? |
|
91
|
|
|
$running = fromHost($hostDetails->hostId)->getHostIsRunning(); |
|
92
|
|
|
if ($running) { |
|
93
|
|
|
$log->endAction(); |
|
94
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, 'host is not running', 'host is running'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// all done |
|
98
|
|
|
$log->endAction(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
View Code Duplication |
public function packageIsInstalled($packageName) |
|
102
|
|
|
{ |
|
103
|
|
|
// what are we doing? |
|
104
|
|
|
$log = usingLog()->startAction("make sure package '{$packageName}' is installed on host '{$this->args[0]}'"); |
|
105
|
|
|
|
|
106
|
|
|
// make sure we have valid host details |
|
107
|
|
|
$hostDetails = $this->getHostDetails(); |
|
108
|
|
|
|
|
109
|
|
|
// is it installed? |
|
110
|
|
|
$details = fromHost($hostDetails->hostId)->getInstalledPackageDetails($packageName); |
|
111
|
|
|
if (!isset($details->version)) { |
|
112
|
|
|
$log->endAction(); |
|
113
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, "package installed", "package is not installed"); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
// all done |
|
117
|
|
|
$log->endAction(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
View Code Duplication |
public function packageIsNotInstalled($packageName) |
|
121
|
|
|
{ |
|
122
|
|
|
// what are we doing? |
|
123
|
|
|
$log = usingLog()->startAction("make sure package '{$packageName}' is not installed on host '{$this->args[0]}'"); |
|
124
|
|
|
|
|
125
|
|
|
// make sure we have valid host details |
|
126
|
|
|
$hostDetails = $this->getHostDetails(); |
|
127
|
|
|
|
|
128
|
|
|
// is it installed? |
|
129
|
|
|
$details = fromHost($hostDetails->hostId)->getInstalledPackageDetails($packageName); |
|
130
|
|
|
|
|
131
|
|
|
if (isset($details->version)) { |
|
132
|
|
|
$log->endAction(); |
|
133
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, "package not installed", "package is installed"); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// all done |
|
137
|
|
|
$log->endAction(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function processIsRunning($processName) |
|
141
|
|
|
{ |
|
142
|
|
|
// what are we doing? |
|
143
|
|
|
$log = usingLog()->startAction("make sure process '{$processName}' is running on host '{$this->args[0]}'"); |
|
144
|
|
|
|
|
145
|
|
|
// make sure we have valid host details |
|
146
|
|
|
$hostDetails = $this->getHostDetails(); |
|
147
|
|
|
|
|
148
|
|
|
// is the process running? |
|
149
|
|
|
$isRunning = fromHost($hostDetails->hostId)->getProcessIsRunning($processName); |
|
150
|
|
|
|
|
151
|
|
|
if (!$isRunning) { |
|
152
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, "process '{$processName}' running", "process '{$processName}' is not running"); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
// all done |
|
156
|
|
|
$log->endAction(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function processIsNotRunning($processName) |
|
160
|
|
|
{ |
|
161
|
|
|
// what are we doing? |
|
162
|
|
|
$log = usingLog()->startAction("make sure process '{$processName}' is not running on host '{$this->args[0]}'"); |
|
163
|
|
|
|
|
164
|
|
|
// make sure we have valid host details |
|
165
|
|
|
$hostDetails = $this->getHostDetails(); |
|
166
|
|
|
|
|
167
|
|
|
// is the process running? |
|
168
|
|
|
$isRunning = fromHost($hostDetails->hostId)->getProcessIsRunning($processName); |
|
169
|
|
|
|
|
170
|
|
|
if ($isRunning) { |
|
171
|
|
|
throw Exceptions::newExpectFailedException(__METHOD__, "process '{$processName}' not running", "process '{$processName}' is running"); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
// all done |
|
175
|
|
|
$log->endAction(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @deprecated since v2.4.0 |
|
180
|
|
|
*/ |
|
181
|
|
|
public function screenIsRunning($sessionName) |
|
182
|
|
|
{ |
|
183
|
|
|
return Screen::expectsHost($this->args[0])->screenIsRunning($sessionName); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @deprecated since v2.4.0 |
|
188
|
|
|
*/ |
|
189
|
|
|
public function screenIsNotRunning($sessionName) |
|
190
|
|
|
{ |
|
191
|
|
|
return Screen::expectsHost($this->args[0])->screenIsNotRunning($sessionName); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* the old SPv1 call, when this was part of expectsShell() |
|
196
|
|
|
* |
|
197
|
|
|
* @deprecated use $this->screenIsRunning() instead |
|
198
|
|
|
* |
|
199
|
|
|
* @param string $sessionName |
|
200
|
|
|
* name of the screen session to check on |
|
201
|
|
|
* @return void |
|
202
|
|
|
*/ |
|
203
|
|
|
public function isRunningInScreen($sessionName) |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->screenIsRunning($sessionName); |
|
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* the old SPv1 call, when this was part of expectsShell() |
|
210
|
|
|
* |
|
211
|
|
|
* @deprecated use $this->screenIsNotRunning() instead |
|
212
|
|
|
* |
|
213
|
|
|
* @param string $sessionName |
|
214
|
|
|
* name of the screen session to check on |
|
215
|
|
|
* @return void |
|
216
|
|
|
*/ |
|
217
|
|
|
public function isNotRunningInScreen($sessionName) |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->screenIsNotRunning($sessionName); |
|
|
|
|
|
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @deprecated since v2.4.0 |
|
224
|
|
|
*/ |
|
225
|
|
|
public function hasFileWithPermissions($filename, $owner, $group, $mode) |
|
226
|
|
|
{ |
|
227
|
|
|
return Filesystem::expectsHost($this->args[0])->hasFileWithPermissions($filename, $owner, $group, $mode); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @deprecated since v2.4.0 |
|
232
|
|
|
*/ |
|
233
|
|
|
public function hasFolderWithPermissions($folder, $owner, $group, $mode) |
|
234
|
|
|
{ |
|
235
|
|
|
return Filesystem::expectsHost($this->args[0])->hasFolderWithPermissions($folder, $owner, $group, $mode); |
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.