@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import httpretty
from novaclient . openstack . common import jsonutils
from novaclient . tests import fakes
from novaclient . tests . fixture_data import base
@ -28,29 +26,28 @@ class FloatingFixture(base.Fixture):
{ ' id ' : 2 , ' fixed_ip ' : ' 10.0.0.2 ' , ' ip ' : ' 11.0.0.2 ' } ]
get_os_floating_ips = { ' floating_ips ' : floating_ips }
httpretty . register_uri ( httpretty . GET , self . url ( ) ,
body = jsonutils . dumps ( get_os_floating_ips ) ,
content_type = ' application/json ' )
self . requests . register_uri ( ' GET ' , self . url ( ) ,
json = get_os_floating_ips ,
headers = self . json_headers )
for ip in floating_ips :
get_os_floating_ip = { ' floating_ip ' : ip }
httpretty . register_uri ( httpretty . GET , self . url ( ip [ ' id ' ] ) ,
body = jsonutils . dumps ( get_os_floating_ip ) ,
content_type = ' application/json ' )
self . requests . register_uri ( ' GET ' , self . url ( ip [ ' id ' ] ) ,
json = get_os_floating_ip ,
headers = self . json_headers )
httpretty . register_uri ( httpretty . DELETE , self . url ( ip [ ' id ' ] ) ,
content_type = ' application/json ' ,
status = 204 )
self . requests . register_uri ( ' DELETE ' , self . url ( ip [ ' id ' ] ) ,
headers = self . json_headers ,
status _code = 204 )
def post_os_floating_ips ( request , url, headers ) :
body = jsonutils . loads ( request . body . decode ( ' utf-8 ' ) )
def post_os_floating_ips ( request , context ) :
body = jsonutils . loads ( request . body )
ip = floating_ips [ 0 ] . copy ( )
ip [ ' pool ' ] = body . get ( ' pool ' )
ip = jsonutils . dumps ( { ' floating_ip ' : ip } )
return 200 , headers , ip
httpretty . register_uri ( httpretty . POST , self . url ( ) ,
body = post_os_floating_ips ,
content_type = ' application/json ' )
return { ' floating_ip ' : ip }
self . requests . register_uri ( ' POST ' , self . url ( ) ,
json = post_os_floating_ips ,
headers = self . json_headers )
class DNSFixture ( base . Fixture ) :
@ -66,10 +63,10 @@ class DNSFixture(base.Fixture):
{ ' domain ' : ' example.com ' }
]
}
httpretty . register_uri ( httpretty . GET , self . url ( ) ,
body = jsonutils . dumps ( get_os_floating_ip_dns ) ,
content_type = ' application/json ' ,
status = 205 )
self . requests . register_uri ( ' GET ' , self . url ( ) ,
json = get_os_floating_ip_dns ,
headers = self . json_headers ,
status _code = 205 )
get_dns_testdomain_entries_testname = {
' dns_entry ' : {
@ -80,31 +77,30 @@ class DNSFixture(base.Fixture):
}
}
url = self . url ( ' testdomain ' , ' entries ' , ' testname ' )
body = jsonutils . dumps ( get_dns_testdomain_entries_testname )
httpretty . register_uri ( httpretty . GET , url ,
body = body ,
content_type = ' application/json ' ,
status = 205 )
self . requests . register_uri ( ' GET ' , url ,
json = get_dns_testdomain_entries_testname ,
headers = self . json_headers ,
status_code = 205 )
httpretty . register_uri ( httpretty . DELETE , self . url ( ' testdomain ' ) ,
status = 200 )
self . requests . register_uri ( ' DELETE ' , self . url ( ' testdomain ' ) )
url = self . url ( ' testdomain ' , ' entries ' , ' testname ' )
httpretty . register_uri ( httpretty . DELETE , url , status = 200 )
self . requests . register_uri ( ' DELETE ' , url )
def put_dns_testdomain_entries_testname ( request , url, headers ) :
body = jsonutils . loads ( request . body . decode ( ' utf-8 ' ) )
def put_dns_testdomain_entries_testname ( request , context ) :
body = jsonutils . loads ( request . body )
fakes . assert_has_keys ( body [ ' dns_entry ' ] ,
required = [ ' ip ' , ' dns_type ' ] )
return 205 , headers , request . body
httpretty . register_uri ( httpretty . PUT , url ,
body = put_dns_testdomain_entries_testname ,
content_type = ' application/json ' )
context . status_code = 205
return request . body
self . requests . register_uri ( ' PUT ' , url ,
body = put_dns_testdomain_entries_testname ,
headers = self . json_headers )
url = self . url ( ' testdomain ' , ' entries ' )
httpretty . register_uri ( httpretty . GET , url , status = 404 )
self . requests . register_uri ( ' GET ' , url , status_code = 404 )
get_os_floating_ip_dns_testdomain _entries = {
get_os_floating_ip_dns_testdomain = {
' dns_entries ' : [
{
' dns_entry ' : {
@ -124,14 +120,13 @@ class DNSFixture(base.Fixture):
} ,
]
}
body = jsonutils . dumps ( get_os_floating_ip_dns_testdomain_entries )
httpretty . register_uri ( httpretty . GET , url + ' ?ip=1.2.3.4 ' ,
body = body ,
status = 205 ,
content_type = ' application/json ' )
def put_os_floating_ip_dns_testdomain ( request , url , headers ) :
body = jsonutils . loads ( request . body . decode ( ' utf-8 ' ) )
self . requests . register_uri ( ' GET ' , url + ' ?ip=1.2.3.4 ' ,
json = get_os_floating_ip_dns_testdomain ,
status_code = 205 ,
headers = self . json_headers )
def put_os_floating_ip_dns_testdomain ( request , context ) :
body = jsonutils . loads ( request . body )
if body [ ' domain_entry ' ] [ ' scope ' ] == ' private ' :
fakes . assert_has_keys ( body [ ' domain_entry ' ] ,
required = [ ' availability_zone ' , ' scope ' ] )
@ -142,11 +137,12 @@ class DNSFixture(base.Fixture):
fakes . assert_has_keys ( body [ ' domain_entry ' ] ,
required = [ ' project ' , ' scope ' ] )
headers [ ' Content-Type ' ] = ' application/json '
return ( 205 , headers , request . body )
return request . body
httpretty . register_uri ( httpretty . PUT , self . url ( ' testdomain ' ) ,
body = put_os_floating_ip_dns_testdomain )
self . requests . register_uri ( ' PUT ' , self . url ( ' testdomain ' ) ,
body = put_os_floating_ip_dns_testdomain ,
status_code = 205 ,
headers = self . json_headers )
class BulkFixture ( base . Fixture ) :
@ -162,40 +158,38 @@ class BulkFixture(base.Fixture):
{ ' id ' : 2 , ' fixed_ip ' : ' 10.0.0.2 ' , ' ip ' : ' 11.0.0.2 ' } ,
]
}
httpretty . register_uri ( httpretty . GET , self . url ( ) ,
body = jsonutils . dumps ( get_os_floating_ips_bulk ) ,
content_type = ' application/json ' )
httpretty . register_uri ( httpretty . GET , self . url ( ' testHost ' ) ,
body = jsonutils . dumps ( get_os_floating_ips_bulk ) ,
content_type = ' application/json ' )
def put_os_floating_ips_bulk_delete ( request , url, headers ) :
body = jsonutils . loads ( request . body . decode ( ' utf-8 ' ) )
self . requests . register_uri ( ' GET ' , self . url ( ) ,
json = get_os_floating_ips_bulk ,
headers = self . json_headers )
self . requests . register_uri ( ' GET ' , self . url ( ' testHost ' ) ,
json = get_os_floating_ips_bulk ,
headers = self . json_headers )
def put_os_floating_ips_bulk_delete ( request , context ) :
body = jsonutils . loads ( request . body )
ip_range = body . get ( ' ip_range ' )
data = { ' floating_ips_bulk_delete ' : ip_range }
return 200 , headers , jsonutils . dumps ( data )
return { ' floating_ips_bulk_delete ' : ip_range }
httpretty . register_uri ( httpretty . PUT , self . url ( ' delete ' ) ,
body = put_os_floating_ips_bulk_delete ,
content_type = ' application/json ' )
self . requests . register_uri ( ' PUT ' , self . url ( ' delete ' ) ,
json = put_os_floating_ips_bulk_delete ,
headers = self . json_headers )
def post_os_floating_ips_bulk ( request , url, headers ) :
body = jsonutils . loads ( request . body . decode ( ' utf-8 ' ) )
def post_os_floating_ips_bulk ( request , context ) :
body = jsonutils . loads ( request . body )
params = body . get ( ' floating_ips_bulk_create ' )
pool = params . get ( ' pool ' , ' defaultPool ' )
interface = params . get ( ' interface ' , ' defaultInterface ' )
data = {
return {
' floating_ips_bulk_create ' : {
' ip_range ' : ' 192.168.1.0/30 ' ,
' pool ' : pool ,
' interface ' : interface
}
}
return 200 , headers , jsonutils . dumps ( data )
httpretty . register_uri ( httpretty . POST , self . url ( ) ,
body = post_os_floating_ips_bulk ,
content_type = ' application/json ' )
self . requests . register_uri ( ' POST ' , self . url ( ) ,
json = post_os_floating_ips_bulk ,
headers = self . json_headers )
class PoolsFixture ( base . Fixture ) :
@ -211,6 +205,6 @@ class PoolsFixture(base.Fixture):
{ ' name ' : ' bar ' }
]
}
httpretty . register_uri ( httpretty . GET , self . url ( ) ,
body = jsonutils . dumps ( get_os_floating_ip_pools ) ,
content_type = ' application/json ' )
self . requests . register_uri ( ' GET ' , self . url ( ) ,
json = get_os_floating_ip_pools ,
headers = self . json_headers )