Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.core
Commits
dc996cc6
Commit
dc996cc6
authored
Oct 20, 2014
by
Marco Mariani
Committed by
Rafael Monnerat
Nov 10, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update tests conforming to requests API
parent
f86f0d39
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1430 additions
and
1483 deletions
+1430
-1483
setup.py
setup.py
+2
-1
slapos/proxy/views.py
slapos/proxy/views.py
+1
-1
slapos/slap/slap.py
slapos/slap/slap.py
+15
-13
slapos/tests/client.py
slapos/tests/client.py
+0
-2
slapos/tests/slap.py
slapos/tests/slap.py
+386
-341
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+1017
-1001
slapos/tests/slapmock/httplib.py
slapos/tests/slapmock/httplib.py
+0
-123
slapos/tests/slapmock/requests.py
slapos/tests/slapmock/requests.py
+8
-0
slapos/tests/slapproxy/__init__.py
slapos/tests/slapproxy/__init__.py
+1
-1
No files found.
setup.py
View file @
dc996cc6
...
...
@@ -66,7 +66,8 @@ setup(name=name,
'bpython_console'
:
(
'bpython'
,)},
tests_require
=
[
'pyflakes'
,
'mock'
'mock'
,
'httmock'
,
],
zip_safe
=
False
,
# proxy depends on Flask, which has issues with
# accessing templates
...
...
slapos/proxy/views.py
View file @
dc996cc6
...
...
@@ -495,7 +495,7 @@ def forwardRequestToExternalMaster(master_url, request_form):
filter_kw
[
'source_instance_id'
]
=
partition_reference
new_request_form
[
'filter_xml'
]
=
dumps
(
filter_kw
)
partition
=
loads
(
slap
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
new_request_form
))
partition
=
loads
(
slap
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
data
=
new_request_form
))
# XXX move to other end
partition
.
_master_url
=
master_url
...
...
slapos/slap/slap.py
View file @
dc996cc6
...
...
@@ -338,7 +338,7 @@ class Computer(SlapDocument):
'message'
:
message
})
def
getStatus
(
self
):
xml
=
self
.
_connection_helper
.
GET
(
'getComputerStatus'
,
{
'computer_id'
:
self
.
_computer_id
})
xml
=
self
.
_connection_helper
.
GET
(
'getComputerStatus'
,
params
=
{
'computer_id'
:
self
.
_computer_id
})
return
xml_marshaller
.
loads
(
xml
)
def
revokeCertificate
(
self
):
...
...
@@ -548,7 +548,7 @@ class ComputerPartition(SlapRequester):
def
getCertificate
(
self
):
xml
=
self
.
_connection_helper
.
GET
(
'getComputerPartitionCertificate'
,
{
params
=
{
'computer_id'
:
self
.
_computer_id
,
'computer_partition_id'
:
self
.
_partition_id
,
}
...
...
@@ -557,7 +557,7 @@ class ComputerPartition(SlapRequester):
def
getStatus
(
self
):
xml
=
self
.
_connection_helper
.
GET
(
'getComputerPartitionStatus'
,
{
params
=
{
'computer_id'
:
self
.
_computer_id
,
'computer_partition_id'
:
self
.
_partition_id
,
}
...
...
@@ -579,7 +579,7 @@ class ConnectionHelper:
self
.
timeout
=
timeout
def
getComputerInformation
(
self
,
computer_id
):
xml
=
self
.
GET
(
'getComputerInformation'
,
{
'computer_id'
:
computer_id
})
xml
=
self
.
GET
(
'getComputerInformation'
,
params
=
{
'computer_id'
:
computer_id
})
return
xml_marshaller
.
loads
(
xml
)
def
getFullComputerInformation
(
self
,
computer_id
):
...
...
@@ -591,20 +591,21 @@ class ConnectionHelper:
params
=
{
'computer_id'
:
computer_id
}
if
not
computer_id
:
# XXX-Cedric: should raise something smarter than "NotFound".
raise
NotFoundError
(
'%r %r'
(
path
,
params
))
raise
NotFoundError
(
'%r %r'
%
(
path
,
params
))
try
:
xml
=
self
.
GET
(
path
,
params
)
xml
=
self
.
GET
(
path
,
params
=
params
)
except
NotFoundError
:
# XXX: This is a ugly way to keep backward compatibility,
# We should stablise slap library soon.
xml
=
self
.
GET
(
'getComputerInformation'
,
{
'computer_id'
:
computer_id
}
)
xml
=
self
.
GET
(
'getComputerInformation'
,
params
=
params
)
return
xml_marshaller
.
loads
(
xml
)
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
):
url
=
urlparse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
if
path
.
startswith
(
'/'
):
raise
ValueError
(
'method path should be relative: %s'
%
path
)
path
=
path
[
1
:]
# raise ValueError('method path should be relative: %s' % path)
try
:
if
url
.
startswith
(
'https'
):
...
...
@@ -707,7 +708,7 @@ class slap:
raise
NotFoundError
xml
=
self
.
_connection_helper
.
GET
(
'registerComputerPartition'
,
{
params
=
{
'computer_reference'
:
computer_guid
,
'computer_partition_reference'
:
partition_id
,
}
...
...
@@ -726,18 +727,19 @@ class slap:
def
getSoftwareReleaseListFromSoftwareProduct
(
self
,
software_product_reference
=
None
,
software_release_url
=
None
):
url
=
'/getSoftwareReleaseListFromSoftwareProduct?'
url
=
'getSoftwareReleaseListFromSoftwareProduct'
params
=
{}
if
software_product_reference
:
if
software_release_url
is
not
None
:
raise
AttributeError
(
'Both software_product_reference and '
'software_release_url parameters are specified.'
)
url
+=
'software_product_reference=%s'
%
software_product_reference
params
[
'software_product_reference'
]
=
software_product_reference
else
:
if
software_release_url
is
None
:
raise
AttributeError
(
'None of software_product_reference and '
'software_release_url parameters are specified.'
)
url
+=
'software_release_url=%s'
%
software_release_url
params
[
'software_release_url'
]
=
software_release_url
result
=
xml_marshaller
.
loads
(
self
.
_connection_helper
.
GET
(
url
))
result
=
xml_marshaller
.
loads
(
self
.
_connection_helper
.
GET
(
url
,
params
=
params
))
assert
(
type
(
result
)
==
list
)
return
result
slapos/tests/client.py
View file @
dc996cc6
...
...
@@ -27,8 +27,6 @@
import
logging
import
unittest
# XXX: BasicMixin should be in a separated module, not in slapgrid test module.
from
slapos.tests.slapgrid
import
BasicMixin
import
slapos.slap
import
slapos.client
...
...
slapos/tests/slap.py
View file @
dc996cc6
This diff is collapsed.
Click to expand it.
slapos/tests/slapgrid.py
View file @
dc996cc6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
slapos/tests/slapmock/httplib.py
deleted
100644 → 0
View file @
f86f0d39
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Mocked httplib
"""
__all__
=
[]
def
log
(
message
):
"""Need to be overridden to get a proper logger
"""
pass
class
HTTPConnection
(
object
):
scheme
=
'http'
def
_callback
(
self
,
path
,
method
,
body
,
headers
):
"""To get it works properly, you need to override
HTTPConnection._callback. This method received the instance, the path,
method and request body as parameter, and it has to return a tuple with
headers dictionary and body response string.
@param self object instance reference
@param URL the parsed URL
@param method the http method
@param body the request body
@param headers the request headers
@return tuple containing status integer, headers dictionary and body
response"""
return
(
0
,
{},
''
,
)
def
__init__
(
self
,
host
,
port
=
None
,
strict
=
None
,
timeout
=
None
,
source_address
=
None
):
self
.
host
=
host
self
.
port
=
port
self
.
strict
=
strict
self
.
timeout
=
timeout
self
.
source_address
=
source_address
self
.
__response
=
None
def
request
(
self
,
method
,
url
,
body
=
None
,
headers
=
None
):
status
,
headers
,
body
=
self
.
_callback
(
url
,
method
,
body
,
headers
)
self
.
__response
=
HTTPResponse
(
'HTTP/1.1'
,
status
,
'OK'
,
body
,
headers
)
def
getresponse
(
self
):
response
=
self
.
__response
self
.
__response
=
None
return
response
def
set_debuglevel
(
self
,
level
):
pass
def
set_tunnel
(
self
,
host
,
port
=
None
,
headers
=
None
):
pass
def
connect
(
self
):
pass
def
close
(
self
):
pass
def
putrequest
(
self
,
request
,
selector
,
skip_host
=
None
,
skip_accept_encoding
=
None
):
pass
def
putheader
(
self
,
*
args
):
pass
def
endheaders
(
self
):
pass
def
send
(
self
,
data
):
pass
class
HTTPSConnection
(
HTTPConnection
):
def
__init__
(
self
,
host
,
port
=
None
,
key_file
=
None
,
cert_file
=
None
,
strict
=
None
,
timeout
=
None
,
source_address
=
None
):
super
(
HTTPSConnection
,
self
).
__init__
(
host
,
port
,
strict
,
timeout
,
source_address
)
self
.
certificate
=
open
(
cert_file
,
'r'
).
read
()
self
.
key
=
open
(
key_file
,
'r'
).
read
()
def
request
(
self
,
method
,
url
,
body
=
None
,
headers
=
None
):
headers
[
'certificate'
]
=
self
.
certificate
headers
[
'key'
]
=
self
.
key
status
,
headers
,
body
=
self
.
_callback
(
url
,
method
,
body
,
headers
)
self
.
__response
=
HTTPResponse
(
'HTTP/1.1'
,
status
,
'OK'
,
body
,
headers
)
def
getresponse
(
self
):
response
=
self
.
__response
self
.
__response
=
None
return
response
class
HTTPResponse
(
object
):
def
__init__
(
self
,
version
,
status
,
reason
,
content
,
headers
=
()):
self
.
version
=
version
self
.
status
=
status
self
.
reason
=
reason
self
.
__headers
=
headers
self
.
__content
=
content
def
read
(
self
,
amt
=
None
):
result
=
None
if
amt
is
None
:
result
=
self
.
__content
self
.
__content
=
''
else
:
end
=
max
(
amt
,
len
(
self
.
__content
))
result
=
self
.
__content
[:
end
]
del
self
.
__content
[:
end
]
return
result
def
getheader
(
self
,
name
,
default
=
None
):
pass
def
getheaders
(
self
):
pass
slapos/tests/slapmock/requests.py
0 → 100644
View file @
dc996cc6
# -*- coding: utf-8 -*-
def
response_ok
(
url
,
request
):
return
{
'status_code'
:
200
,
'content'
:
''
}
slapos/tests/slapproxy/__init__.py
View file @
dc996cc6
...
...
@@ -968,7 +968,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
'xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
computer_dict
),
}
self
.
external_proxy_slap
.
_connection_helper
.
POST
(
'/loadComputerConfigurationFromXML'
,
parameter_dict
=
request_dict
)
data
=
request_dict
)
def
_checkInstanceIsFowarded
(
self
,
name
,
partition_parameter_kw
,
software_release
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment