created a mock db to remove relience on cassandra for testing
This commit is contained in:
parent
6673c2b66e
commit
a652866d1d
6
cdn/provider/mock/__init__.py
Normal file
6
cdn/provider/mock/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"""CDN Extension for CDN"""
|
||||||
|
|
||||||
|
from cdn.provider.mock import driver
|
||||||
|
|
||||||
|
# Hoist classes into package namespace
|
||||||
|
CDNProvider = driver.CDNProvider
|
27
cdn/provider/mock/controllers.py
Normal file
27
cdn/provider/mock/controllers.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2013 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""Exports Sample CDN controllers.
|
||||||
|
|
||||||
|
Field Mappings:
|
||||||
|
In order to reduce the disk / memory space used,
|
||||||
|
fields name will be, most of the time, the first
|
||||||
|
letter of their long name. Fields mapping will be
|
||||||
|
updated and documented in each controller class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from cdn.provider.mock import services
|
||||||
|
|
||||||
|
ServiceController = services.ServiceController
|
38
cdn/provider/mock/driver.py
Normal file
38
cdn/provider/mock/driver.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""CDN Provider implementation."""
|
||||||
|
|
||||||
|
from cdn.common import decorators
|
||||||
|
from cdn.openstack.common import log as logging
|
||||||
|
from cdn import provider
|
||||||
|
from cdn.provider.mock import controllers
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CDNProvider(provider.CDNProviderBase):
|
||||||
|
|
||||||
|
def __init__(self, conf):
|
||||||
|
super(CDNProvider, self).__init__(conf)
|
||||||
|
|
||||||
|
def is_alive(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
@decorators.lazy_property(write=False)
|
||||||
|
def service_controller(self):
|
||||||
|
return controllers.ServiceController()
|
35
cdn/provider/mock/services.py
Normal file
35
cdn/provider/mock/services.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# stevedore/example/simple.py
|
||||||
|
from cdn.provider import base
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceController(base.ServiceBase):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(ServiceController, self).__init__()
|
||||||
|
|
||||||
|
self.provider_resp = base.ProviderResponse("mock")
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
return self.provider_resp.updated(service_name)
|
||||||
|
|
||||||
|
def create(self, service_name, service_json):
|
||||||
|
return self.provider_resp.created(service_name)
|
||||||
|
|
||||||
|
def delete(self, service_name):
|
||||||
|
return self.provider_resp.deleted(service_name)
|
||||||
|
|
6
cdn/storage/mockdb/__init__.py
Normal file
6
cdn/storage/mockdb/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"""Storage Driver for CDN"""
|
||||||
|
|
||||||
|
from cdn.storage.mockdb import driver
|
||||||
|
|
||||||
|
# Hoist classes into package namespace
|
||||||
|
StorageDriver = driver.StorageDriver
|
28
cdn/storage/mockdb/controllers.py
Normal file
28
cdn/storage/mockdb/controllers.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
"""Exports storage controllers.
|
||||||
|
|
||||||
|
Field Mappings:
|
||||||
|
In order to reduce the disk / memory space used,
|
||||||
|
fields name will be, most of the time, the first
|
||||||
|
letter of their long name. Fields mapping will be
|
||||||
|
updated and documented in each controller class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from cdn.storage.mockdb import services
|
||||||
|
|
||||||
|
ServicesController = services.ServicesController
|
65
cdn/storage/mockdb/driver.py
Normal file
65
cdn/storage/mockdb/driver.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""Storage driver implementation."""
|
||||||
|
|
||||||
|
from cdn.common import decorators
|
||||||
|
from cdn.openstack.common import log as logging
|
||||||
|
from cdn import storage
|
||||||
|
from cdn.storage.mockdb import controllers
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
MOCKDB_OPTIONS = [
|
||||||
|
cfg.StrOpt('database', default='cdn',
|
||||||
|
help='Database for all queries made in session')
|
||||||
|
]
|
||||||
|
|
||||||
|
MOCKDB_GROUP = 'drivers:storage:mockdb'
|
||||||
|
|
||||||
|
|
||||||
|
def _connection():
|
||||||
|
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class StorageDriver(storage.StorageDriverBase):
|
||||||
|
|
||||||
|
def __init__(self, conf, providers):
|
||||||
|
super(StorageDriver, self).__init__(conf, providers)
|
||||||
|
|
||||||
|
self.conf.register_opts(MOCKDB_OPTIONS,
|
||||||
|
group=MOCKDB_GROUP)
|
||||||
|
self.mockdb_conf = self.conf[MOCKDB_GROUP]
|
||||||
|
|
||||||
|
def is_alive(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@decorators.lazy_property(write=False)
|
||||||
|
def connection(self):
|
||||||
|
"""Connection instance."""
|
||||||
|
return _connection()
|
||||||
|
|
||||||
|
@decorators.lazy_property(write=False)
|
||||||
|
def service_controller(self):
|
||||||
|
return controllers.ServicesController(self)
|
||||||
|
|
||||||
|
@decorators.lazy_property(write=False)
|
||||||
|
def service_database(self):
|
||||||
|
return self.connection
|
108
cdn/storage/mockdb/services.py
Normal file
108
cdn/storage/mockdb/services.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
# Copyright (c) 2014 Rackspace, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from cdn.storage import base
|
||||||
|
|
||||||
|
|
||||||
|
class ServicesController(base.ServicesBase):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ServicesController, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self._session = self.driver.service_database
|
||||||
|
|
||||||
|
|
||||||
|
def list(self):
|
||||||
|
services = {
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"rel": "next",
|
||||||
|
"href": "/v1.0/services?marker=www.myothersite.com&limit=20"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services" : [
|
||||||
|
{
|
||||||
|
"domains": [
|
||||||
|
{
|
||||||
|
"domain": "www.mywebsite.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"origins": [
|
||||||
|
{
|
||||||
|
"origin": "mywebsite.com",
|
||||||
|
"port": 80,
|
||||||
|
"ssl": False
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"caching": [
|
||||||
|
{ "name" : "default", "ttl" : 3600 },
|
||||||
|
{
|
||||||
|
"name" : "home",
|
||||||
|
"ttl" : 17200,
|
||||||
|
"rules" : [
|
||||||
|
{ "name" : "index", "request_url" : "/index.htm" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "images",
|
||||||
|
"ttl" : 12800,
|
||||||
|
"rules" : [
|
||||||
|
{ "name" : "images", "request_url" : "*.png" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"restrictions" : [
|
||||||
|
{
|
||||||
|
"name" : "website only",
|
||||||
|
"rules" : [ { "name" : "mywebsite.com", "http_host" : "www.mywebsite.com" } ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"links" : [
|
||||||
|
{
|
||||||
|
"href": "/v1.0/services/mywebsite",
|
||||||
|
"rel" : "self"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return services
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
# get the requested service from storage
|
||||||
|
print "get service"
|
||||||
|
|
||||||
|
def create(self, service_name, service_json):
|
||||||
|
|
||||||
|
# create at providers
|
||||||
|
providers = super(ServicesController, self).create(service_name, service_json)
|
||||||
|
|
||||||
|
return providers
|
||||||
|
|
||||||
|
def update(self, service_name, service_json):
|
||||||
|
# update configuration in storage
|
||||||
|
|
||||||
|
# update at providers
|
||||||
|
return super(ServicesController, self).update(service_name, service_json)
|
||||||
|
|
||||||
|
def delete(self, service_name):
|
||||||
|
|
||||||
|
# delete from providers
|
||||||
|
return super(ServicesController, self).delete(service_name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user