Skip to content
Permalink
Browse files
Test volumes / zones
  • Loading branch information
brogand93 committed Feb 26, 2014
1 parent 12ab54d commit 7143809f4d1676ec204f18a400f8aa517f8e4eea
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 7 deletions.
@@ -13,9 +13,6 @@ def get_disk_offerings_id_by_name(name):


def _describe_disk_offerings_request(args=None):
if args is None:
args = {}

args['command'] = 'listDiskOfferings'

response = requester.make_request(args)
@@ -10,7 +10,7 @@

volume_error_to_aws = {
'unable to find a snapshot': errors.invalid_snapshot_id,
'Invalid parameter id': errors.invalid_volume_id
'Unable to aquire volume with ID': errors.invalid_volume_id
}


@@ -19,9 +19,6 @@ def get_zones_id_by_name(name):


def _describe_zones_request(args=None):
if args is None:
args = {}

args['command'] = 'listZones'

response = requester.make_request(args)
@@ -0,0 +1,8 @@
{
"createvolumeresponse": {
"errorcode": 431,
"uuidlist": [],
"cserrorcode": 4350,
"errortext": "unable to find a snapshot with id 45"
}
}
@@ -0,0 +1,8 @@
{
"deletevolumeresponse": {
"errorcode": 431,
"uuidlist": [],
"cserrorcode": 4350,
"errortext": "Unable to aquire volume with ID: 45"
}
}
@@ -0,0 +1,17 @@
{
"listdiskofferingsresponse": {
"count": 1,
"diskoffering": [
{
"iscustomized": true,
"name": "Custom",
"created": "2014-02-15T02:01:42+0000",
"storagetype": "shared",
"displaytext": "Custom Disk",
"disksize": 0,
"id": "46f0a62e-ba3c-4a49-b619-877a8b2a07ed",
"displayoffering": true
}
]
}
}
@@ -0,0 +1,19 @@
{
"listzonesresponse": {
"count": 1,
"zone": [
{
"localstorageenabled": false,
"name": "Sandbox-simulator",
"zonetoken": "038bf1a4-c55c-3d1e-9176-b42e22ee00c1",
"dns1": "8.8.8.8",
"securitygroupsenabled": true,
"allocationstate": "Enabled",
"internaldns1": "8.8.8.8",
"dhcpprovider": "VirtualRouter",
"networktype": "Basic",
"id": "1e47a2fc-61c7-401c-b90e-416b472ada64"
}
]
}
}
@@ -8,6 +8,7 @@


class VolumeTestCase(Ec2StackAppTestCase):

def test_describe_volumes(self):
data = self.get_example_data()
data['Action'] = 'DescribeVolumes'
@@ -27,3 +28,182 @@ def test_describe_volumes(self):

self.assertOk(response)
assert 'DescribeVolumesResponse' in response.data

@mock.patch('ec2stack.providers.cloudstack.disk_offerings.get_disk_offerings_id_by_name')
@mock.patch('ec2stack.providers.cloudstack.zones.get_zones_id_by_name')
def test_create_volume_by_size(self, mock_get_zone, mock_get_disk):
data = self.get_example_data()
data['Action'] = 'CreateVolume'
data['Size'] = 'size'
data['AvailabilityZone'] = 'zone'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

mock_get_zone.return_value = 'zone'
mock_get_disk.return_value = 'diskid'

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/create_volume_response.json'
)
get_request.return_value.status_code = 200

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'CreateVolumeResponse' in response.data

@mock.patch('ec2stack.providers.cloudstack.disk_offerings.get_disk_offerings_id_by_name')
@mock.patch('ec2stack.providers.cloudstack.zones.get_zones_id_by_name')
def test_create_volume_by_snapshot(self, mock_get_zone, mock_get_disk):
data = self.get_example_data()
data['Action'] = 'CreateVolume'
data['SnapshotId'] = 'snapshotid'
data['AvailabilityZone'] = 'zone'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

mock_get_zone.return_value = 'zone'
mock_get_disk.return_value = 'diskid'

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/create_volume_response.json'
)
get_request.return_value.status_code = 200

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'CreateVolumeResponse' in response.data

@mock.patch('ec2stack.providers.cloudstack.disk_offerings.get_disk_offerings_id_by_name')
def test_create_volume_invalid_zone(self, mock_get_disk):
data = self.get_example_data()
data['Action'] = 'CreateVolume'
data['Size'] = 'size'
data['AvailabilityZone'] = 'zone'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

mock_get_disk.return_value = 'diskid'

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/invalid_zone_name.json'
)
get_request.return_value.status_code = 200

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertBadRequest(response)
assert 'InvalidZone.NotFound' in response.data

@mock.patch('ec2stack.providers.cloudstack.disk_offerings.get_disk_offerings_id_by_name')
@mock.patch('requests.get')
def test_create_volume_valid_zone(self, get, mock_get_disk):
data = self.get_example_data()
data['Action'] = 'CreateVolume'
data['Size'] = 'size'
data['AvailabilityZone'] = 'zone'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

mock_get_disk.return_value = 'diskid'

get.return_value.text = read_file(
'tests/data/create_volume_response.json'
)
get.return_value.status_code = 200

get_zone = mock.Mock()
get_zone.return_value.text = read_file(
'tests/data/list_zone_by_name_response.json'
)
get_zone.return_value.status_code = 200

with mock.patch('ec2stack.providers.cloudstack.zones.get_zones_id_by_name', get_zone):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'CreateVolumeResponse' in response.data

@mock.patch('ec2stack.providers.cloudstack.disk_offerings.get_disk_offerings_id_by_name')
@mock.patch('ec2stack.providers.cloudstack.zones.get_zones_id_by_name')
def test_create_volume_inavild_snapshot(self, mock_get_zone, mock_get_disk):
data = self.get_example_data()
data['Action'] = 'CreateVolume'
data['Size'] = 'size'
data['AvailabilityZone'] = 'zone'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

mock_get_zone.return_value = 'zone'
mock_get_disk.return_value = 'diskid'

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/create_volume_invalid_snapshot_response.json'
)
get_request.return_value.status_code = 431

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertBadRequest(response)
assert 'InvalidSnapshot.NotFound' in response.data

def test_delete_volume(self):
data = self.get_example_data()
data['Action'] = 'DeleteVolume'
data['VolumeId'] = 'volumeid'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/delete_volume_response.json'
)
get_request.return_value.status_code = 200

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DeleteVolumeResponse' in response.data

def test_delete_volume_invalid_volume_id(self):
data = self.get_example_data()
data['Action'] = 'DeleteVolume'
data['VolumeId'] = 'volumeid'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get_request = mock.Mock()
get_request.return_value.text = read_file(
'tests/data/invalid_volume_id.json'
)
get_request.return_value.status_code = 200

with mock.patch('requests.get', get_request):
response = self.post(
'/',
data=data
)

self.assertBadRequest(response)
assert 'InvalidVolume.NotFound' in response.data

0 comments on commit 7143809

Please sign in to comment.