EbsTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Amazon
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Http/Client.php';
  23. require_once 'Zend/Http/Client/Adapter/Test.php';
  24. require_once 'Zend/Service/Amazon/Ec2/Ebs.php';
  25. /**
  26. * Zend_Service_Amazon_Ec2_Ebs test case.
  27. *
  28. * @category Zend
  29. * @package Zend_Service_Amazon
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Service
  34. * @group Zend_Service_Amazon
  35. * @group Zend_Service_Amazon_Ec2
  36. */
  37. class Zend_Service_Amazon_Ec2_EbsTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_Service_Amazon_Ec2_Ebs
  41. */
  42. private $Zend_Service_Amazon_Ec2_Ebs;
  43. /**
  44. * Prepares the environment before running a test.
  45. */
  46. protected function setUp()
  47. {
  48. parent::setUp();
  49. $this->Zend_Service_Amazon_Ec2_Ebs = new Zend_Service_Amazon_Ec2_Ebs('access_key', 'secret_access_key');
  50. $adapter = new Zend_Http_Client_Adapter_Test();
  51. $client = new Zend_Http_Client(null, array(
  52. 'adapter' => $adapter
  53. ));
  54. $this->adapter = $adapter;
  55. Zend_Service_Amazon_Ec2_Ebs::setHttpClient($client);
  56. }
  57. /**
  58. * Cleans up the environment after running a test.
  59. */
  60. protected function tearDown()
  61. {
  62. unset($this->adapter);
  63. $this->Zend_Service_Amazon_Ec2_Ebs = null;
  64. parent::tearDown();
  65. }
  66. public function testAttachVolume()
  67. {
  68. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  69. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  70. . "Server: hi\r\n"
  71. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  72. . "Status: 200 OK\r\n"
  73. . "Content-type: application/xml; charset=utf-8\r\n"
  74. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  75. . "Connection: close\r\n"
  76. . "\r\n"
  77. . "<AttachVolumeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  78. . " <volumeId>vol-4d826724</volumeId>\r\n"
  79. . " <instanceId>i-6058a509</instanceId>\r\n"
  80. . " <device>/dev/sdh</device>\r\n"
  81. . " <status>attaching</status>\r\n"
  82. . " <attachTime>2008-05-07T11:51:50.000Z</attachTime>\r\n"
  83. . "</AttachVolumeResponse >";
  84. $this->adapter->setResponse($rawHttpResponse);
  85. $return = $this->Zend_Service_Amazon_Ec2_Ebs->attachVolume('vol-4d826724', 'i-6058a509', '/dev/sdh');
  86. $arrAttach = array(
  87. 'volumeId' => 'vol-4d826724',
  88. 'instanceId' => 'i-6058a509',
  89. 'device' => '/dev/sdh',
  90. 'status' => 'attaching',
  91. 'attachTime' => '2008-05-07T11:51:50.000Z'
  92. );
  93. $this->assertSame($arrAttach, $return);
  94. }
  95. public function testCreateSnapshot()
  96. {
  97. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  98. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  99. . "Server: hi\r\n"
  100. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  101. . "Status: 200 OK\r\n"
  102. . "Content-type: application/xml; charset=utf-8\r\n"
  103. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  104. . "Connection: close\r\n"
  105. . "\r\n"
  106. . "<CreateSnapshotResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  107. . " <snapshotId>snap-78a54011</snapshotId>\r\n"
  108. . " <volumeId>vol-4d826724</volumeId>\r\n"
  109. . " <status>pending</status>\r\n"
  110. . " <startTime>2008-05-07T11:51:50.000Z</startTime>\r\n"
  111. . " <progress></progress>\r\n"
  112. . "</CreateSnapshotResponse>";
  113. $this->adapter->setResponse($rawHttpResponse);
  114. $return = $this->Zend_Service_Amazon_Ec2_Ebs->createSnapshot('vol-4d826724');
  115. $arrCreateSnapShot = array(
  116. 'snapshotId' => 'snap-78a54011',
  117. 'volumeId' => 'vol-4d826724',
  118. 'status' => 'pending',
  119. 'startTime' => '2008-05-07T11:51:50.000Z',
  120. 'progress' => ''
  121. );
  122. $this->assertSame($arrCreateSnapShot, $return);
  123. }
  124. public function testCreateNewVolume()
  125. {
  126. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  127. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  128. . "Server: hi\r\n"
  129. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  130. . "Status: 200 OK\r\n"
  131. . "Content-type: application/xml; charset=utf-8\r\n"
  132. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  133. . "Connection: close\r\n"
  134. . "\r\n"
  135. . "<CreateVolumeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  136. . " <volumeId>vol-4d826724</volumeId>\r\n"
  137. . " <size>400</size>\r\n"
  138. . " <status>creating</status>\r\n"
  139. . " <createTime>2008-05-07T11:51:50.000Z</createTime>\r\n"
  140. . " <availabilityZone>us-east-1a</availabilityZone>\r\n"
  141. . " <snapshotId></snapshotId>\r\n"
  142. . "</CreateVolumeResponse>";
  143. $this->adapter->setResponse($rawHttpResponse);
  144. $return = $this->Zend_Service_Amazon_Ec2_Ebs->createNewVolume(400, 'us-east-1a');
  145. $arrCreateNewVolume = array(
  146. 'volumeId' => 'vol-4d826724',
  147. 'size' => '400',
  148. 'status' => 'creating',
  149. 'createTime' => '2008-05-07T11:51:50.000Z',
  150. 'availabilityZone' => 'us-east-1a'
  151. );
  152. $this->assertSame($arrCreateNewVolume, $return);
  153. }
  154. public function testCreateVolumeFromSnapshot()
  155. {
  156. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  157. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  158. . "Server: hi\r\n"
  159. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  160. . "Status: 200 OK\r\n"
  161. . "Content-type: application/xml; charset=utf-8\r\n"
  162. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  163. . "Connection: close\r\n"
  164. . "\r\n"
  165. . "<CreateVolumeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  166. . " <volumeId>vol-4d826724</volumeId>\r\n"
  167. . " <size>400</size>\r\n"
  168. . " <status>creating</status>\r\n"
  169. . " <createTime>2008-05-07T11:51:50.000Z</createTime>\r\n"
  170. . " <availabilityZone>us-east-1a</availabilityZone>\r\n"
  171. . " <snapshotId>snap-78a54011</snapshotId>\r\n"
  172. . "</CreateVolumeResponse>";
  173. $this->adapter->setResponse($rawHttpResponse);
  174. $return = $this->Zend_Service_Amazon_Ec2_Ebs->createVolumeFromSnapshot('snap-78a54011', 'us-east-1a');
  175. $arrCreateNewVolume = array(
  176. 'volumeId' => 'vol-4d826724',
  177. 'size' => '400',
  178. 'status' => 'creating',
  179. 'createTime' => '2008-05-07T11:51:50.000Z',
  180. 'availabilityZone' => 'us-east-1a',
  181. 'snapshotId' => 'snap-78a54011'
  182. );
  183. $this->assertSame($arrCreateNewVolume, $return);
  184. }
  185. public function testDeleteSnapshot()
  186. {
  187. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  188. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  189. . "Server: hi\r\n"
  190. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  191. . "Status: 200 OK\r\n"
  192. . "Content-type: application/xml; charset=utf-8\r\n"
  193. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  194. . "Connection: close\r\n"
  195. . "\r\n"
  196. . "<DeleteSnapshotResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  197. . " <return>true</return>\r\n"
  198. . "</DeleteSnapshotResponse>";
  199. $this->adapter->setResponse($rawHttpResponse);
  200. $return = $this->Zend_Service_Amazon_Ec2_Ebs->deleteSnapshot('snap-78a54011');
  201. $this->assertTrue($return);
  202. }
  203. public function testDeleteVolume()
  204. {
  205. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  206. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  207. . "Server: hi\r\n"
  208. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  209. . "Status: 200 OK\r\n"
  210. . "Content-type: application/xml; charset=utf-8\r\n"
  211. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  212. . "Connection: close\r\n"
  213. . "\r\n"
  214. . "<DeleteVolumeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  215. . " <return>true</return>\r\n"
  216. . "</DeleteVolumeResponse>";
  217. $this->adapter->setResponse($rawHttpResponse);
  218. $return = $this->Zend_Service_Amazon_Ec2_Ebs->deleteVolume('vol-4d826724');
  219. $this->assertTrue($return);
  220. }
  221. /**
  222. * Tests Zend_Service_Amazon_Ec2_Ebs->describeSnapshot()
  223. */
  224. public function testDescribeSingleSnapshot()
  225. {
  226. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  227. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  228. . "Server: hi\r\n"
  229. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  230. . "Status: 200 OK\r\n"
  231. . "Content-type: application/xml; charset=utf-8\r\n"
  232. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  233. . "Connection: close\r\n"
  234. . "\r\n"
  235. . "<DescribeSnapshotsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  236. . " <snapshotSet>\r\n"
  237. . " <item>\r\n"
  238. . " <snapshotId>snap-78a54011</snapshotId>\r\n"
  239. . " <volumeId>vol-4d826724</volumeId>\r\n"
  240. . " <status>pending</status>\r\n"
  241. . " <startTime>2008-05-07T12:51:50.000Z</startTime>\r\n"
  242. . " <progress>80%</progress>\r\n"
  243. . " </item>\r\n"
  244. . " </snapshotSet>\r\n"
  245. . "</DescribeSnapshotsResponse>";
  246. $this->adapter->setResponse($rawHttpResponse);
  247. $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeSnapshot('snap-78a54011');
  248. $arrSnapshot = array(array(
  249. 'snapshotId' => 'snap-78a54011',
  250. 'volumeId' => 'vol-4d826724',
  251. 'status' => 'pending',
  252. 'startTime' => '2008-05-07T12:51:50.000Z',
  253. 'progress' => '80%'
  254. ));
  255. $this->assertSame($arrSnapshot, $return);
  256. }
  257. public function testDescribeMultipleSnapshots()
  258. {
  259. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  260. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  261. . "Server: hi\r\n"
  262. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  263. . "Status: 200 OK\r\n"
  264. . "Content-type: application/xml; charset=utf-8\r\n"
  265. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  266. . "Connection: close\r\n"
  267. . "\r\n"
  268. . "<DescribeSnapshotsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  269. . " <snapshotSet>\r\n"
  270. . " <item>\r\n"
  271. . " <snapshotId>snap-78a54011</snapshotId>\r\n"
  272. . " <volumeId>vol-4d826724</volumeId>\r\n"
  273. . " <status>pending</status>\r\n"
  274. . " <startTime>2008-05-07T12:51:50.000Z</startTime>\r\n"
  275. . " <progress>80%</progress>\r\n"
  276. . " </item>\r\n"
  277. . " <item>\r\n"
  278. . " <snapshotId>snap-78a54012</snapshotId>\r\n"
  279. . " <volumeId>vol-4d826725</volumeId>\r\n"
  280. . " <status>pending</status>\r\n"
  281. . " <startTime>2008-08-07T12:51:50.000Z</startTime>\r\n"
  282. . " <progress>65%</progress>\r\n"
  283. . " </item>\r\n"
  284. . " </snapshotSet>\r\n"
  285. . "</DescribeSnapshotsResponse>";
  286. $this->adapter->setResponse($rawHttpResponse);
  287. $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeSnapshot(array('snap-78a54011', 'snap-78a54012'));
  288. $arrSnapshots = array(
  289. array(
  290. 'snapshotId' => 'snap-78a54011',
  291. 'volumeId' => 'vol-4d826724',
  292. 'status' => 'pending',
  293. 'startTime' => '2008-05-07T12:51:50.000Z',
  294. 'progress' => '80%',
  295. ),
  296. array(
  297. 'snapshotId' => 'snap-78a54012',
  298. 'volumeId' => 'vol-4d826725',
  299. 'status' => 'pending',
  300. 'startTime' => '2008-08-07T12:51:50.000Z',
  301. 'progress' => '65%',
  302. )
  303. );
  304. $this->assertSame($arrSnapshots, $return);
  305. }
  306. /**
  307. * Tests Zend_Service_Amazon_Ec2_Ebs->describeVolume()
  308. */
  309. public function testDescribeSingleVolume()
  310. {
  311. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  312. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  313. . "Server: hi\r\n"
  314. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  315. . "Status: 200 OK\r\n"
  316. . "Content-type: application/xml; charset=utf-8\r\n"
  317. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  318. . "Connection: close\r\n"
  319. . "\r\n"
  320. . "<DescribeVolumesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  321. . "<volumeSet>\r\n"
  322. . " <item>\r\n"
  323. . " <volumeId>vol-4282672b</volumeId>\r\n"
  324. . " <size>800</size>\r\n"
  325. . " <status>in-use</status>\r\n"
  326. . " <createTime>2008-05-07T11:51:50.000Z</createTime>\r\n"
  327. . " <attachmentSet>\r\n"
  328. . " <item>\r\n"
  329. . " <volumeId>vol-4282672b</volumeId>\r\n"
  330. . " <instanceId>i-6058a509</instanceId>\r\n"
  331. . " <device>/dev/sdh</device>\r\n"
  332. . " <snapshotId>snap-12345678</snapshotId>\r\n"
  333. . " <availabilityZone>us-east-1a</availabilityZone>\r\n"
  334. . " <status>attached</status>\r\n"
  335. . " <attachTime>2008-05-07T12:51:50.000Z</attachTime>\r\n"
  336. . " </item>\r\n"
  337. . " </attachmentSet>\r\n"
  338. . " </item>\r\n"
  339. . "</volumeSet>\r\n"
  340. . "</DescribeVolumesResponse>";
  341. $this->adapter->setResponse($rawHttpResponse);
  342. $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeVolume('vol-4282672b');
  343. $arrVolumes = array(
  344. array(
  345. 'volumeId' => 'vol-4282672b',
  346. 'size' => '800',
  347. 'status' => 'in-use',
  348. 'createTime' => '2008-05-07T11:51:50.000Z',
  349. 'attachmentSet' => array(
  350. 'volumeId' => 'vol-4282672b',
  351. 'instanceId' => 'i-6058a509',
  352. 'device' => '/dev/sdh',
  353. 'status' => 'attached',
  354. 'attachTime' => '2008-05-07T12:51:50.000Z',
  355. )
  356. )
  357. );
  358. $this->assertSame($arrVolumes, $return);
  359. }
  360. public function testDescribeMultipleVolume()
  361. {
  362. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  363. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  364. . "Server: hi\r\n"
  365. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  366. . "Status: 200 OK\r\n"
  367. . "Content-type: application/xml; charset=utf-8\r\n"
  368. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  369. . "Connection: close\r\n"
  370. . "\r\n"
  371. . "<DescribeVolumesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  372. . "<volumeSet>\r\n"
  373. . " <item>\r\n"
  374. . " <volumeId>vol-4282672b</volumeId>\r\n"
  375. . " <size>800</size>\r\n"
  376. . " <status>in-use</status>\r\n"
  377. . " <createTime>2008-05-07T11:51:50.000Z</createTime>\r\n"
  378. . " <attachmentSet>\r\n"
  379. . " <item>\r\n"
  380. . " <volumeId>vol-4282672b</volumeId>\r\n"
  381. . " <instanceId>i-6058a509</instanceId>\r\n"
  382. . " <device>/dev/sdh</device>\r\n"
  383. . " <snapshotId>snap-12345678</snapshotId>\r\n"
  384. . " <availabilityZone>us-east-1a</availabilityZone>\r\n"
  385. . " <status>attached</status>\r\n"
  386. . " <attachTime>2008-05-07T12:51:50.000Z</attachTime>\r\n"
  387. . " </item>\r\n"
  388. . " </attachmentSet>\r\n"
  389. . " </item>\r\n"
  390. . " <item>\r\n"
  391. . " <volumeId>vol-42826775</volumeId>\r\n"
  392. . " <size>40</size>\r\n"
  393. . " <status>available</status>\r\n"
  394. . " <createTime>2008-08-07T11:51:50.000Z</createTime>\r\n"
  395. . " </item>\r\n"
  396. . "</volumeSet>\r\n"
  397. . "</DescribeVolumesResponse>";
  398. $this->adapter->setResponse($rawHttpResponse);
  399. $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeVolume(array('vol-4282672b', 'vol-42826775'));
  400. $arrVolumes = array(
  401. array(
  402. 'volumeId' => 'vol-4282672b',
  403. 'size' => '800',
  404. 'status' => 'in-use',
  405. 'createTime' => '2008-05-07T11:51:50.000Z',
  406. 'attachmentSet' => array(
  407. 'volumeId' => 'vol-4282672b',
  408. 'instanceId' => 'i-6058a509',
  409. 'device' => '/dev/sdh',
  410. 'status' => 'attached',
  411. 'attachTime' => '2008-05-07T12:51:50.000Z',
  412. )
  413. ),
  414. array(
  415. 'volumeId' => 'vol-42826775',
  416. 'size' => '40',
  417. 'status' => 'available',
  418. 'createTime' => '2008-08-07T11:51:50.000Z'
  419. )
  420. );
  421. $this->assertSame($arrVolumes, $return);
  422. }
  423. public function testDescribeAttachedVolumes()
  424. {
  425. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  426. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  427. . "Server: hi\r\n"
  428. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  429. . "Status: 200 OK\r\n"
  430. . "Content-type: application/xml; charset=utf-8\r\n"
  431. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  432. . "Connection: close\r\n"
  433. . "\r\n"
  434. . "<DescribeVolumesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  435. . "<volumeSet>\r\n"
  436. . " <item>\r\n"
  437. . " <volumeId>vol-4282672b</volumeId>\r\n"
  438. . " <size>800</size>\r\n"
  439. . " <status>in-use</status>\r\n"
  440. . " <createTime>2008-05-07T11:51:50.000Z</createTime>\r\n"
  441. . " <attachmentSet>\r\n"
  442. . " <item>\r\n"
  443. . " <volumeId>vol-4282672b</volumeId>\r\n"
  444. . " <instanceId>i-6058a509</instanceId>\r\n"
  445. . " <device>/dev/sdh</device>\r\n"
  446. . " <snapshotId>snap-12345678</snapshotId>\r\n"
  447. . " <availabilityZone>us-east-1a</availabilityZone>\r\n"
  448. . " <status>attached</status>\r\n"
  449. . " <attachTime>2008-05-07T12:51:50.000Z</attachTime>\r\n"
  450. . " </item>\r\n"
  451. . " </attachmentSet>\r\n"
  452. . " </item>\r\n"
  453. . " <item>\r\n"
  454. . " <volumeId>vol-42826775</volumeId>\r\n"
  455. . " <size>40</size>\r\n"
  456. . " <status>available</status>\r\n"
  457. . " <createTime>2008-08-07T11:51:50.000Z</createTime>\r\n"
  458. . " </item>\r\n"
  459. . "</volumeSet>\r\n"
  460. . "</DescribeVolumesResponse>";
  461. $this->adapter->setResponse($rawHttpResponse);
  462. $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeAttachedVolumes('i-6058a509');
  463. $arrVolumes = array(
  464. array(
  465. 'volumeId' => 'vol-4282672b',
  466. 'size' => '800',
  467. 'status' => 'in-use',
  468. 'createTime' => '2008-05-07T11:51:50.000Z',
  469. 'attachmentSet' => array(
  470. 'volumeId' => 'vol-4282672b',
  471. 'instanceId' => 'i-6058a509',
  472. 'device' => '/dev/sdh',
  473. 'status' => 'attached',
  474. 'attachTime' => '2008-05-07T12:51:50.000Z',
  475. )
  476. )
  477. );
  478. $this->assertSame($arrVolumes, $return);
  479. }
  480. /**
  481. * Tests Zend_Service_Amazon_Ec2_Ebs->detachVolume()
  482. */
  483. public function testDetachVolume()
  484. {
  485. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  486. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  487. . "Server: hi\r\n"
  488. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  489. . "Status: 200 OK\r\n"
  490. . "Content-type: application/xml; charset=utf-8\r\n"
  491. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  492. . "Connection: close\r\n"
  493. . "\r\n"
  494. . "<DetachVolumeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  495. . " <volumeId>vol-4d826724</volumeId>\r\n"
  496. . " <instanceId>i-6058a509</instanceId>\r\n"
  497. . " <device>/dev/sdh</device>\r\n"
  498. . " <status>detaching</status>\r\n"
  499. . " <attachTime>2008-05-08T11:51:50.000Z</attachTime>\r\n"
  500. . "</DetachVolumeResponse>";
  501. $this->adapter->setResponse($rawHttpResponse);
  502. $return = $this->Zend_Service_Amazon_Ec2_Ebs->detachVolume('vol-4d826724');
  503. $arrVolume = array(
  504. 'volumeId' => 'vol-4d826724',
  505. 'instanceId' => 'i-6058a509',
  506. 'device' => '/dev/sdh',
  507. 'status' => 'detaching',
  508. 'attachTime' => '2008-05-08T11:51:50.000Z'
  509. );
  510. $this->assertSame($arrVolume, $return);
  511. }
  512. }