* Two fixes to support Citrix AWS hypervisor plugin: ebs responses for putting a block and completing a snapshot should be 201 and 202 respectively rather than 200; If the body cannot be utf-8 decoded, try base64.Z * Update responses.py * Update responses.py * Update responses.py * Add EBS snapshot unit test * EBS: put_snapshot_block() should support raw bytes --------- Co-authored-by: Demetrios Tsillas <Demetrios.Tsillas@citrix.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
		
			
				
	
	
		
			57 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using FluentAssertions;
 | |
| 
 | |
| // To interact with Amazon EBS
 | |
| using Amazon.EBS;
 | |
| using Amazon.EBS.Model;
 | |
| 
 | |
| using System.Security.Cryptography;
 | |
| 
 | |
| 
 | |
| public class EbsSnashotTest
 | |
| {
 | |
|     [Fact]
 | |
|     public async Task TestSnapshotCreation()
 | |
|     {
 | |
| 
 | |
|         AmazonEBSConfig config = new AmazonEBSConfig()
 | |
|         {
 | |
|             ServiceURL = "http://localhost:5000",
 | |
|         };
 | |
| 
 | |
|         AmazonEBSClient ebsClient = new AmazonEBSClient(config);
 | |
| 
 | |
|         // https://docs.aws.amazon.com/ebs/latest/APIReference/API_StartSnapshot.html
 | |
|         var startSnapshotRequest = new StartSnapshotRequest { VolumeSize = 1 };
 | |
|         var startSnapshotResponse = await ebsClient.StartSnapshotAsync(startSnapshotRequest);
 | |
|         startSnapshotResponse.Status.Should().Be("pending");    
 | |
| 
 | |
|         // https://docs.aws.amazon.com/ebs/latest/APIReference/API_PutSnapshotBlock.html
 | |
|         var blockData = new byte[] { 0x01, 0x02, 0x03, 0x04 };
 | |
|         Stream blockDataStream = new MemoryStream(blockData);
 | |
|         SHA256Managed sha256hasher = new SHA256Managed();
 | |
|         byte[] sha256Hash = sha256hasher.ComputeHash(blockDataStream);
 | |
|         var sha256checksum = Convert.ToBase64String(sha256Hash);
 | |
|         var putSnapshotBlockRequest = new PutSnapshotBlockRequest
 | |
|         {
 | |
|             BlockIndex = 0,
 | |
|             Checksum = sha256checksum,
 | |
|             ChecksumAlgorithm = "SHA256",
 | |
|             DataLength = blockData.Length,
 | |
|             SnapshotId = startSnapshotResponse.SnapshotId,
 | |
|             BlockData = blockDataStream
 | |
|         };
 | |
|         var putSnapshotBlockResponse = await ebsClient.PutSnapshotBlockAsync(putSnapshotBlockRequest);
 | |
|         putSnapshotBlockResponse.Checksum.Should().Be(sha256checksum);
 | |
|         putSnapshotBlockResponse.ChecksumAlgorithm.Should().Be("SHA256");
 | |
| 
 | |
|         https://docs.aws.amazon.com/ebs/latest/APIReference/API_CompleteSnapshot.html
 | |
|         var completeSnapshotRequest = new CompleteSnapshotRequest
 | |
|         {
 | |
|             ChangedBlocksCount = 1,
 | |
|             SnapshotId = startSnapshotResponse.SnapshotId
 | |
|         };
 | |
|         var completeSnapshotResponse = await ebsClient.CompleteSnapshotAsync(completeSnapshotRequest);
 | |
|         completeSnapshotResponse.Status.Should().Be("completed");
 | |
|     }
 | |
| }
 |