Skip to content

Commit

Permalink
Merge pull request #20 from RachelTucker/4-0-ids-request-payload
Browse files Browse the repository at this point in the history
SA-196: Added request payloads to clear blob and mark blob commands
  • Loading branch information
rpmoore authored Mar 12, 2018
2 parents 984f7b6 + c9a437a commit 09f68db
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 10 deletions.
106 changes: 96 additions & 10 deletions ds3/ds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ def to_xml(self):
return xml_part_list


class IdsList(object):
def __init__(self, id_list):
for cur_id in id_list:
if not isinstance(cur_id, str):
raise TypeError("Ids should only contain strings")
self.id_list = id_list

def to_xml(self):
xml_id_list = xmldom.Element('Ids')
for cur_id in self.id_list:
xml_cur_id = xmldom.Element('Id')
xml_cur_id.text = cur_id
xml_id_list.append(xml_cur_id)
return xml_id_list


# Type Descriptors


Expand Down Expand Up @@ -3461,8 +3477,15 @@ def __init__(self, s3_data_replication_rule, initial_data_placement=None, max_bl

class ClearSuspectBlobAzureTargetsSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(ClearSuspectBlobAzureTargetsSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'ClearSuspectBlobAzureTargetsSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_azure_target'
Expand All @@ -3471,8 +3494,15 @@ def __init__(self, force=None):

class ClearSuspectBlobDs3TargetsSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(ClearSuspectBlobDs3TargetsSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'ClearSuspectBlobDs3TargetsSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_ds3_target'
Expand All @@ -3481,8 +3511,15 @@ def __init__(self, force=None):

class ClearSuspectBlobPoolsSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(ClearSuspectBlobPoolsSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'ClearSuspectBlobPoolsSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_pool'
Expand All @@ -3491,8 +3528,15 @@ def __init__(self, force=None):

class ClearSuspectBlobS3TargetsSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(ClearSuspectBlobS3TargetsSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'ClearSuspectBlobS3TargetsSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_s3_target'
Expand All @@ -3501,8 +3545,15 @@ def __init__(self, force=None):

class ClearSuspectBlobTapesSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(ClearSuspectBlobTapesSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'ClearSuspectBlobTapesSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_tape'
Expand Down Expand Up @@ -3808,8 +3859,15 @@ def __init__(self, bucket_id=None, storage_domain_id=None):

class MarkSuspectBlobAzureTargetsAsDegradedSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(MarkSuspectBlobAzureTargetsAsDegradedSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'MarkSuspectBlobAzureTargetsAsDegradedSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_azure_target'
Expand All @@ -3818,8 +3876,15 @@ def __init__(self, force=None):

class MarkSuspectBlobDs3TargetsAsDegradedSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(MarkSuspectBlobDs3TargetsAsDegradedSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'MarkSuspectBlobDs3TargetsAsDegradedSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_ds3_target'
Expand All @@ -3828,8 +3893,15 @@ def __init__(self, force=None):

class MarkSuspectBlobPoolsAsDegradedSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(MarkSuspectBlobPoolsAsDegradedSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'MarkSuspectBlobPoolsAsDegradedSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_pool'
Expand All @@ -3838,8 +3910,15 @@ def __init__(self, force=None):

class MarkSuspectBlobS3TargetsAsDegradedSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(MarkSuspectBlobS3TargetsAsDegradedSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'MarkSuspectBlobS3TargetsAsDegradedSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_s3_target'
Expand All @@ -3848,8 +3927,15 @@ def __init__(self, force=None):

class MarkSuspectBlobTapesAsDegradedSpectraS3Request(AbstractRequest):

def __init__(self, force=None):
def __init__(self, id_list, force=None):
super(MarkSuspectBlobTapesAsDegradedSpectraS3Request, self).__init__()
if id_list is not None:
if not (isinstance(cur_id, str) for cur_id in id_list):
raise TypeError(
'MarkSuspectBlobTapesAsDegradedSpectraS3Request should have request payload of type: list of strings')
xml_id_list = IdsList(id_list)
self.body = xmldom.tostring(xml_id_list.to_xml())

if force is not None:
self.query_params['force'] = force
self.path = '/_rest_/suspect_blob_tape'
Expand Down
48 changes: 48 additions & 0 deletions tests/clientTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,14 @@ def read(self):


class ResponseParsingTestCase(unittest.TestCase):
@staticmethod
def __get_test_ids():
return ['obj1', 'obj2', 'obj3']

@staticmethod
def __get_marshaled_ids():
return b'<Ids><Id>obj1</Id><Id>obj2</Id><Id>obj3</Id></Ids>'

def testGetJobToReplicate(self):
content = "some content to test response parsing"

Expand Down Expand Up @@ -1411,3 +1419,43 @@ def testVerifyPhysicalPlacementRequestPayload(self):

request = VerifyPhysicalPlacementForObjectsSpectraS3Request(bucket_name="bucketName", object_list=l)
self.assertEqual(request.body.decode(), '<Objects><Object Name="obj1" /><Object Name="obj2" /></Objects>')

def testClearSuspectBlobAzureTargetsRequestPayload(self):
request = ClearSuspectBlobAzureTargetsSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testClearSuspectBlobDs3TargetsRequestPayload(self):
request = ClearSuspectBlobDs3TargetsSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testClearSuspectBlobPoolsRequestPayload(self):
request = ClearSuspectBlobPoolsSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testClearSuspectBlobS3TargetsRequestPayload(self):
request = ClearSuspectBlobS3TargetsSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testClearSuspectBlobTapesRequestPayload(self):
request = ClearSuspectBlobTapesSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testMarkSuspectBlobAzureTargetsAsDegradedRequestPayload(self):
request = MarkSuspectBlobAzureTargetsAsDegradedSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testMarkSuspectBlobPoolsAsDegradedRequestPayload(self):
request = MarkSuspectBlobPoolsAsDegradedSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testMarkSuspectBlobDs3TargetsAsDegradedRequestPayload(self):
request = MarkSuspectBlobDs3TargetsAsDegradedSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testMarkSuspectBlobS3TargetsAsDegradedRequestPayload(self):
request = MarkSuspectBlobS3TargetsAsDegradedSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

def testMarkSuspectBlobTapesAsDegradedRequestPayload(self):
request = MarkSuspectBlobTapesAsDegradedSpectraS3Request(id_list=self.__get_test_ids())
self.assertEqual(request.body, self.__get_marshaled_ids())

0 comments on commit 09f68db

Please sign in to comment.