Zend_Service_Amazon_Ec2_Ebs = new Zend_Service_Amazon_Ec2_Ebs('access_key', 'secret_access_key'); $adapter = new Zend_Http_Client_Adapter_Test(); $client = new Zend_Http_Client(null, array( 'adapter' => $adapter )); $this->adapter = $adapter; Zend_Service_Amazon_Ec2_Ebs::setHttpClient($client); } /** * Cleans up the environment after running a test. */ protected function tearDown() { unset($this->adapter); $this->Zend_Service_Amazon_Ec2_Ebs = null; parent::tearDown(); } public function testAttachVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " vol-4d826724\r\n" . " i-6058a509\r\n" . " /dev/sdh\r\n" . " attaching\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->attachVolume('vol-4d826724', 'i-6058a509', '/dev/sdh'); $arrAttach = array( 'volumeId' => 'vol-4d826724', 'instanceId' => 'i-6058a509', 'device' => '/dev/sdh', 'status' => 'attaching', 'attachTime' => '2008-05-07T11:51:50.000Z' ); $this->assertSame($arrAttach, $return); } public function testCreateSnapshot() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " snap-78a54011\r\n" . " vol-4d826724\r\n" . " pending\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->createSnapshot('vol-4d826724'); $arrCreateSnapShot = array( 'snapshotId' => 'snap-78a54011', 'volumeId' => 'vol-4d826724', 'status' => 'pending', 'startTime' => '2008-05-07T11:51:50.000Z', 'progress' => '' ); $this->assertSame($arrCreateSnapShot, $return); } public function testCreateNewVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " vol-4d826724\r\n" . " 400\r\n" . " creating\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " us-east-1a\r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->createNewVolume(400, 'us-east-1a'); $arrCreateNewVolume = array( 'volumeId' => 'vol-4d826724', 'size' => '400', 'status' => 'creating', 'createTime' => '2008-05-07T11:51:50.000Z', 'availabilityZone' => 'us-east-1a' ); $this->assertSame($arrCreateNewVolume, $return); } public function testCreateVolumeFromSnapshot() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " vol-4d826724\r\n" . " 400\r\n" . " creating\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " us-east-1a\r\n" . " snap-78a54011\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->createVolumeFromSnapshot('snap-78a54011', 'us-east-1a'); $arrCreateNewVolume = array( 'volumeId' => 'vol-4d826724', 'size' => '400', 'status' => 'creating', 'createTime' => '2008-05-07T11:51:50.000Z', 'availabilityZone' => 'us-east-1a', 'snapshotId' => 'snap-78a54011' ); $this->assertSame($arrCreateNewVolume, $return); } public function testDeleteSnapshot() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " true\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->deleteSnapshot('snap-78a54011'); $this->assertTrue($return); } public function testDeleteVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " true\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->deleteVolume('vol-4d826724'); $this->assertTrue($return); } /** * Tests Zend_Service_Amazon_Ec2_Ebs->describeSnapshot() */ public function testDescribeSingleSnapshot() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " \r\n" . " \r\n" . " snap-78a54011\r\n" . " vol-4d826724\r\n" . " pending\r\n" . " 2008-05-07T12:51:50.000Z\r\n" . " 80%\r\n" . " \r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeSnapshot('snap-78a54011'); $arrSnapshot = array(array( 'snapshotId' => 'snap-78a54011', 'volumeId' => 'vol-4d826724', 'status' => 'pending', 'startTime' => '2008-05-07T12:51:50.000Z', 'progress' => '80%' )); $this->assertSame($arrSnapshot, $return); } public function testDescribeMultipleSnapshots() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " \r\n" . " \r\n" . " snap-78a54011\r\n" . " vol-4d826724\r\n" . " pending\r\n" . " 2008-05-07T12:51:50.000Z\r\n" . " 80%\r\n" . " \r\n" . " \r\n" . " snap-78a54012\r\n" . " vol-4d826725\r\n" . " pending\r\n" . " 2008-08-07T12:51:50.000Z\r\n" . " 65%\r\n" . " \r\n" . " \r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeSnapshot(array('snap-78a54011', 'snap-78a54012')); $arrSnapshots = array( array( 'snapshotId' => 'snap-78a54011', 'volumeId' => 'vol-4d826724', 'status' => 'pending', 'startTime' => '2008-05-07T12:51:50.000Z', 'progress' => '80%', ), array( 'snapshotId' => 'snap-78a54012', 'volumeId' => 'vol-4d826725', 'status' => 'pending', 'startTime' => '2008-08-07T12:51:50.000Z', 'progress' => '65%', ) ); $this->assertSame($arrSnapshots, $return); } /** * Tests Zend_Service_Amazon_Ec2_Ebs->describeVolume() */ public function testDescribeSingleVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . "\r\n" . " \r\n" . " vol-4282672b\r\n" . " 800\r\n" . " in-use\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " \r\n" . " \r\n" . " vol-4282672b\r\n" . " i-6058a509\r\n" . " /dev/sdh\r\n" . " snap-12345678\r\n" . " us-east-1a\r\n" . " attached\r\n" . " 2008-05-07T12:51:50.000Z\r\n" . " \r\n" . " \r\n" . " \r\n" . "\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeVolume('vol-4282672b'); $arrVolumes = array( array( 'volumeId' => 'vol-4282672b', 'size' => '800', 'status' => 'in-use', 'createTime' => '2008-05-07T11:51:50.000Z', 'attachmentSet' => array( 'volumeId' => 'vol-4282672b', 'instanceId' => 'i-6058a509', 'device' => '/dev/sdh', 'status' => 'attached', 'attachTime' => '2008-05-07T12:51:50.000Z', ) ) ); $this->assertSame($arrVolumes, $return); } public function testDescribeMultipleVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . "\r\n" . " \r\n" . " vol-4282672b\r\n" . " 800\r\n" . " in-use\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " \r\n" . " \r\n" . " vol-4282672b\r\n" . " i-6058a509\r\n" . " /dev/sdh\r\n" . " snap-12345678\r\n" . " us-east-1a\r\n" . " attached\r\n" . " 2008-05-07T12:51:50.000Z\r\n" . " \r\n" . " \r\n" . " \r\n" . " \r\n" . " vol-42826775\r\n" . " 40\r\n" . " available\r\n" . " 2008-08-07T11:51:50.000Z\r\n" . " \r\n" . "\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeVolume(array('vol-4282672b', 'vol-42826775')); $arrVolumes = array( array( 'volumeId' => 'vol-4282672b', 'size' => '800', 'status' => 'in-use', 'createTime' => '2008-05-07T11:51:50.000Z', 'attachmentSet' => array( 'volumeId' => 'vol-4282672b', 'instanceId' => 'i-6058a509', 'device' => '/dev/sdh', 'status' => 'attached', 'attachTime' => '2008-05-07T12:51:50.000Z', ) ), array( 'volumeId' => 'vol-42826775', 'size' => '40', 'status' => 'available', 'createTime' => '2008-08-07T11:51:50.000Z' ) ); $this->assertSame($arrVolumes, $return); } public function testDescribeAttachedVolumes() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . "\r\n" . " \r\n" . " vol-4282672b\r\n" . " 800\r\n" . " in-use\r\n" . " 2008-05-07T11:51:50.000Z\r\n" . " \r\n" . " \r\n" . " vol-4282672b\r\n" . " i-6058a509\r\n" . " /dev/sdh\r\n" . " snap-12345678\r\n" . " us-east-1a\r\n" . " attached\r\n" . " 2008-05-07T12:51:50.000Z\r\n" . " \r\n" . " \r\n" . " \r\n" . " \r\n" . " vol-42826775\r\n" . " 40\r\n" . " available\r\n" . " 2008-08-07T11:51:50.000Z\r\n" . " \r\n" . "\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->describeAttachedVolumes('i-6058a509'); $arrVolumes = array( array( 'volumeId' => 'vol-4282672b', 'size' => '800', 'status' => 'in-use', 'createTime' => '2008-05-07T11:51:50.000Z', 'attachmentSet' => array( 'volumeId' => 'vol-4282672b', 'instanceId' => 'i-6058a509', 'device' => '/dev/sdh', 'status' => 'attached', 'attachTime' => '2008-05-07T12:51:50.000Z', ) ) ); $this->assertSame($arrVolumes, $return); } /** * Tests Zend_Service_Amazon_Ec2_Ebs->detachVolume() */ public function testDetachVolume() { $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "\r\n" . " vol-4d826724\r\n" . " i-6058a509\r\n" . " /dev/sdh\r\n" . " detaching\r\n" . " 2008-05-08T11:51:50.000Z\r\n" . ""; $this->adapter->setResponse($rawHttpResponse); $return = $this->Zend_Service_Amazon_Ec2_Ebs->detachVolume('vol-4d826724'); $arrVolume = array( 'volumeId' => 'vol-4d826724', 'instanceId' => 'i-6058a509', 'device' => '/dev/sdh', 'status' => 'detaching', 'attachTime' => '2008-05-08T11:51:50.000Z' ); $this->assertSame($arrVolume, $return); } }