Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/corelib/Core/Domain/CloudBlockStorage.cs

This file was deleted.

23 changes: 23 additions & 0 deletions src/corelib/Core/Domain/CloudBlockStorageVolume.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Runtime.Serialization;

namespace net.openstack.Core.Domain
{
[DataContract]
public class CreateCloudBlockStorageVolumeDetails
{
[DataMember(Name = "size")]
public int Size { get; set; }

[DataMember(Name = "display_description")]
public string DisplayDescription { get; set; }

[DataMember(Name = "display_name")]
public string DisplayName { get; set; }

[DataMember(Name = "snapshot_id")]
public string SnapshotId { get; set; }

[DataMember(Name = "volume_type")]
public string VolumeType { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/corelib/Core/Domain/CloudBlockStorageVolumeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace net.openstack.Core.Domain
{
public class CloudBlockStorageVolumeType
{
public static string SSD { get { return "SSD"; } }
public static string SATA { get { return "SATA"; } }
}
}
10 changes: 2 additions & 8 deletions src/corelib/Core/ICloudBlockStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using net.openstack.Core.Domain;

namespace net.openstack.Core
{
public interface ICloudBlockStorageProvider
{




bool CreateVolume(int size, string display_description = null, string display_name = null, string snapshot_id = null, string volume_type = null, string region = null, CloudIdentity identity = null);
}
}
2 changes: 1 addition & 1 deletion src/corelib/Core/ICloudBlockStorageValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface ICloudBlockStorageValidator
{

void ValidateVolumeSize(int size);
}
}
19 changes: 16 additions & 3 deletions src/corelib/Providers/Rackspace/CloudBlockStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using JSIStudios.SimpleRESTServices.Client;
using System;
using System.Linq;
using JSIStudios.SimpleRESTServices.Client;
using JSIStudios.SimpleRESTServices.Client.Json;
using net.openstack.Core;
using net.openstack.Core.Domain;
using net.openstack.Providers.Rackspace.Objects.Request;
using net.openstack.Providers.Rackspace.Validators;

namespace net.openstack.Providers.Rackspace
{
public class CloudBlockStorageProvider : ProviderBase, ICloudBlockStorageProvider
{

private readonly int[] _validResponseCode = new[] { 200 };
private readonly ICloudBlockStorageValidator _cloudBlockStorageValidator;

public CloudBlockStorageProvider()
Expand All @@ -17,17 +21,26 @@ public CloudBlockStorageProvider()
public CloudBlockStorageProvider(CloudIdentity defaultIdentity)
: this(defaultIdentity, new IdentityProvider(), new JsonRestServices(), new CloudBlockStorageValidator()) { }

public CloudBlockStorageProvider(IIdentityProvider identityProvider, IRestService restService, ICloudBlockStorageValidator cloudBlockStorageValidator)
internal CloudBlockStorageProvider(IIdentityProvider identityProvider, IRestService restService, ICloudBlockStorageValidator cloudBlockStorageValidator)
: this(null, identityProvider, restService, cloudBlockStorageValidator) { }

public CloudBlockStorageProvider(CloudIdentity defaultIdentity, IIdentityProvider identityProvider, IRestService restService, ICloudBlockStorageValidator cloudBlockStorageValidator)
internal CloudBlockStorageProvider(CloudIdentity defaultIdentity, IIdentityProvider identityProvider, IRestService restService, ICloudBlockStorageValidator cloudBlockStorageValidator)
: base(defaultIdentity, identityProvider, restService)
{
_cloudBlockStorageValidator = cloudBlockStorageValidator;
}


public bool CreateVolume(int size, string display_description = null, string display_name = null, string snapshot_id = null, string volume_type = null, string region = null, CloudIdentity identity = null)
{
_cloudBlockStorageValidator.ValidateVolumeSize(size);

var urlPath = new Uri(string.Format("{0}/volumes", GetServiceEndpoint(identity, region)));
var requestBody = new CreateCloudBlockStorageVolumeRequest { CreateCloudBlockStorageVolumeDetails = new CreateCloudBlockStorageVolumeDetails { Size = size, DisplayDescription = display_description, DisplayName = display_name, SnapshotId = snapshot_id, VolumeType = volume_type } };
var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.POST, requestBody);

return response != null && _validResponseCode.Contains(response.StatusCode);
}

#region Private methods

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.Serialization;
using net.openstack.Core.Domain;

namespace net.openstack.Providers.Rackspace.Objects.Request
{
[DataContract]
internal class CreateCloudBlockStorageVolumeRequest
{
[DataMember(Name = "volume")]
public CreateCloudBlockStorageVolumeDetails CreateCloudBlockStorageVolumeDetails { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ namespace net.openstack.Providers.Rackspace.Validators
{
public class CloudBlockStorageValidator : ICloudBlockStorageValidator
{
public void ValidateVolumeSize(int size)
{
if (size < 100 || size > 1000)
throw new ArgumentException("ERROR: The volume size value must be between 100 and 1000");
}
}
}
4 changes: 3 additions & 1 deletion src/corelib/corelib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Core\Domain\Address.cs" />
<Compile Include="Core\Domain\CloudBlockStorage.cs" />
<Compile Include="Core\Domain\CloudBlockStorageVolume.cs" />
<Compile Include="Core\Domain\CloudBlockStorageVolumeType.cs" />
<Compile Include="Core\Domain\CloudIdentity.cs" />
<Compile Include="Core\Domain\Container.cs" />
<Compile Include="Core\Domain\Flavor.cs" />
Expand Down Expand Up @@ -86,6 +87,7 @@
<Compile Include="Providers\Rackspace\Objects\Request\AddRoleRequest.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\AddUserRequest.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\ConfirmServerResizeRequest.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\CreateCloudBlockStorageVolumeRequest.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\CreateServerImageDetails.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\CreateServerImageRequest.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\ChangeServerAdminPasswordRequest.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class CloudBlockStorageTests
private static RackspaceCloudIdentity _testIdentity;
private static RackspaceCloudIdentity _testAdminIdentity;
private TestContext testContextInstance;
private const string volumeDisplayName = "Test Volume";
private const string volumeDisplayDescription = "Test Volume Description";

/// <summary>
///Gets or sets the test context which provides
Expand All @@ -33,6 +35,25 @@ public static void Init(TestContext context)
{
_testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);

}


#region Create Volume Tests
[TestMethod]
public void Should_Create_Volume_Only_Required_Parameters()
{
var provider = new CloudBlockStorageProvider();
var volumeCreatedResponse = provider.CreateVolume(100, identity: _testIdentity);
Assert.IsTrue(volumeCreatedResponse);
}

[TestMethod]
public void Should_Create_Volume_Full_Parameters()
{
var provider = new CloudBlockStorageProvider();
var volumeCreatedResponse = provider.CreateVolume(100, volumeDisplayDescription, volumeDisplayName, null, CloudBlockStorageVolumeType.SATA, null, _testIdentity);
Assert.IsTrue(volumeCreatedResponse);
}
#endregion
}
}
57 changes: 55 additions & 2 deletions src/testing/unit/Providers/Rackspace/CloudBlockStorageTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using net.openstack.Providers.Rackspace.Validators;

namespace OpenStackNet.Testing.Unit.Providers.Rackspace
{
[TestClass]
public class CloudBlockStorageTests
{

[TestMethod]
public void Should_Not_Throw_Exception_When_Size_Is_In_Range()
{
const int size = 900;

try
{
var cloudBlockStorageValidator = new CloudBlockStorageValidator();
cloudBlockStorageValidator.ValidateVolumeSize(size);
}
catch (Exception ex)
{

Assert.Fail("Exception should not be thrown.");
}
}

[TestMethod]
public void Should_Throw_Exception_When_Size_Is_Less_Than_100()
{
const int size = 50;

try
{
var cloudBlockStorageValidator = new CloudBlockStorageValidator();
cloudBlockStorageValidator.ValidateVolumeSize(size);
Assert.Fail("Expected was not thrown.");
}
catch (Exception ex)
{

Assert.AreEqual("ERROR: The volume size value must be between 100 and 1000", ex.Message);
}
}

[TestMethod]
public void Should_Throw_Exception_When_Size_Is_Greater_Than_1000()
{
const int size = 1050;

try
{
var cloudBlockStorageValidator = new CloudBlockStorageValidator();
cloudBlockStorageValidator.ValidateVolumeSize(size);
Assert.Fail("Expected was not thrown.");
}
catch (Exception ex)
{

Assert.AreEqual("ERROR: The volume size value must be between 100 and 1000", ex.Message);
}
}
}
}