Skip to content

Commit

Permalink
Reviewing Reform
Browse files Browse the repository at this point in the history
  • Loading branch information
Msekni Bilel committed Nov 20, 2012
1 parent 8a88288 commit a918029
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 22 deletions.
6 changes: 3 additions & 3 deletions HTTP_HowTo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ It's up to the user to define what format he wants in the request Content-Type h

* Response::

N/A
Location: http://localhost:8090/{location}/{my_custom_resource_id}

2.Get a Resource::

Expand Down Expand Up @@ -248,15 +248,15 @@ It's up to the user to define what format he wants in the request Content-Type h

* Response::

X-OCCI-Location: http://localhost:8090/{location}/{resource-id}
Location: http://localhost:8090/{location}/{resource-id}

4.Partial Update of a Resource::

curl -X POST -d@partial_update_resource -H 'content-type: text/plain' -H 'accept: text/plain' -v http://localhost:8090/{location}/{resource-id}

* Response::

X-OCCI-Location: http://localhost:8090/{location}/{resource-id}
Location: http://localhost:8090/{location}/{resource-id}

5.Trigger an action on a resource::

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ PyOCNI offers two OCCI rendering formats : **HTTP and JSON**. The following comm

* Response::

N/A
{"Location": ["http://localhost:8090/{location}/{my_custom_resource_id}"]}

2.Get a Resource::

Expand Down Expand Up @@ -439,7 +439,7 @@ PyOCNI offers two OCCI rendering formats : **HTTP and JSON**. The following comm
* Response::

{
"X-OCCI-Location": [
Location": [
"http://localhost:8090/{location}/{resource-id}"
]
}
Expand All @@ -451,8 +451,8 @@ PyOCNI offers two OCCI rendering formats : **HTTP and JSON**. The following comm
* Response::

{
"X-OCCI-Location": [
"http://localhost:8090/{location}/resource-id"
"Location": [
"http://localhost:8090/{location}/{resource-id}"
]
}

Expand Down
20 changes: 11 additions & 9 deletions pyocni/TDD/Tests/singleentityInterface_Tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def test_post_entities(self):
"""
storage = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL,'http://127.0.0.1:8090/compute/258af9df-dcba-4ff5-89f6-2c5f17c46e6f')
c.setopt(c.HTTPHEADER, ['Accept: application/occi+json','Content-Type: application/occi+json'])
c.setopt(c.URL,'http://127.0.0.1:8090/compute/this_is_bilel?action=start')
c.setopt(c.HTTPHEADER, ['Accept: application/occi+json','Content-Type: text/plain'])
c.setopt(c.CUSTOMREQUEST, 'POST')
c.setopt(c.VERBOSE, True)
c.setopt(c.POSTFIELDS,entities.j_occi_att)
c.setopt(c.POSTFIELDS,entities.action_att_http)
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
content = storage.getvalue()
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_get_entity(self):
storage = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL,"http://127.0.0.1:8090/compute/9930")
c.setopt(c.HTTPHEADER, ['Accept:text/occi'])
c.setopt(c.HTTPHEADER, ['Accept:application/occi+json'])
c.setopt(c.VERBOSE, True)
c.setopt(c.CUSTOMREQUEST, 'GET')
c.setopt(c.WRITEFUNCTION, storage.write)
Expand Down Expand Up @@ -135,10 +135,9 @@ def test_delete_entity(self):

storage = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL,"http://127.0.0.1:8090/bilel/vms/v01")
c.setopt(c.URL,"http://127.0.0.1:8090/compute/this_is_bilel")
c.setopt(c.HTTPHEADER, ['Content-Type: application/occi+json', 'Accept: application/occi+json'])
c.setopt(c.CUSTOMREQUEST, 'DELETE')
c.setopt(c.USERPWD, 'user_1:password')
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
content = storage.getvalue()
Expand All @@ -156,6 +155,8 @@ def setUp(self):
self.p = Process(target = start_server)
self.p.start()
time.sleep(0.5)
#init_fakeDB()
time.sleep(0.5)

def tearDown(self):
self.p.terminate()
Expand All @@ -165,10 +166,11 @@ def test_create_custom_resource(self):
"""
storage = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL,'http://127.0.0.1:8090/compute/d4e49287-e8bd-4cd8-953a-b90f327084e5')
c.setopt(c.URL,'http://127.0.0.1:8090/compute/this_is_bilel')

c.setopt(c.HTTPHEADER, ['Accept: text/plain','Content-Type: text/occi',entities.part_entity_http])
c.setopt(c.HTTPHEADER, ['Accept: application/occi+json','Content-Type: text/plain'])
c.setopt(c.CUSTOMREQUEST, 'PUT')
c.setopt(c.POSTFIELDS,entities.entity_http)
c.setopt(c.VERBOSE, True)

c.setopt(c.WRITEFUNCTION, storage.write)
Expand All @@ -189,4 +191,4 @@ def test_create_custom_resource(self):
post_suite = loader.loadTestsFromTestCase(test_post)
#Run tests

runner.run(post_suite)
runner.run(delete_suite)
45 changes: 42 additions & 3 deletions pyocni/TDD/fake_Data/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"attributes": {
"occi": {
"compute": {
"speed": 2,
"speed": 12,
"memory": 4,
"cores": 12
}
Expand All @@ -108,7 +108,40 @@
}
"""


action_plus_attributes =\
"""
{
"actions": [
{
"term": "start",
"scheme": "http://schemas.ogf.org/occi/infrastructure/compute/action#",
"title": "Start Compute instance now",
"attributes": {
"method": {
"mutable": true,
"required": false,
"type": "string",
"pattern": "graceful|acpion|poweron",
"default": "poweron"
}
}
}
],
"attributes": {
"occi": {
"infrastructure": {
"networkinterface": {
"interface": "eth0",
"mac": "00:80:41:ae:fd:7e",
"address": "192.168.0.100",
"gateway": "192.168.0.1",
"allocation": "dynamic"
}
}
}
}
}
"""
#=======================================================================================================================
# HTTP format
#=======================================================================================================================
Expand All @@ -124,4 +157,10 @@
#=======================================================================================================================


x_occi_att = "X-OCCI-Attribute: occi.compute.cores=20:2"
x_occi_att = "X-OCCI-Attribute: occi.compute.cores=20:2"

action_att_http = """Category: start;
scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";
class=action;
X-OCCI-Attribute: occi.compute.cores=20:2
"""
6 changes: 4 additions & 2 deletions pyocni/adapters/i_ResponseAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def convert_response_entity_multi_location_content(self, var, res):
return res

def convert_response_entity_location_content(self, var, res):

if str(res.content_type) == "application/occi+json":
res.body = var
res.body = json.dumps({"Location":[var]})

elif str(res.content_type) == "text/occi":
#reformat the response to text/occi
Expand All @@ -97,11 +98,12 @@ def convert_response_entity_location_content(self, var, res):
else:
#reformat the response to text/plain (default OCCI response format)
res.content_type = "text/plain"
res.location = var
res.body = "Location: "+ var

return res

def convert_response_entity_content(self, res, var):

if str(res.content_type) == "application/occi+json":
res.body = json.dumps(var)

Expand Down
2 changes: 1 addition & 1 deletion pyocni/junglers/single_entityJungler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def channel_put_single_resource(self, jBody, path_url):

self.PostMan.save_updated_doc_in_db(entity)

logger.debug("===== Channel_post_single_resource ==== : Finished (2b) with success")
logger.debug("===== Channel_put_single_resource ==== : Finished (2b) with success")
#return the locations of the resources

backend_m.update_entity(olddoc['OCCI_Description'],entity['OCCI_Description'])
Expand Down

0 comments on commit a918029

Please sign in to comment.