Merge "Remove poppy server from api tests base"
This commit is contained in:
commit
e66f72d1e7
@ -13,15 +13,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
from cafe.drivers.unittest import fixtures
|
||||
import jsonschema
|
||||
from oslo.config import cfg
|
||||
|
||||
from tests.api.utils import client
|
||||
from tests.api.utils import config
|
||||
from tests.api.utils import server
|
||||
|
||||
|
||||
class TestBase(fixtures.BaseTestFixture):
|
||||
@ -56,16 +53,6 @@ class TestBase(fixtures.BaseTestFixture):
|
||||
deserialize_format='json')
|
||||
|
||||
cls.test_config = config.TestConfig()
|
||||
if cls.test_config.run_server:
|
||||
conf_file = 'poppy_cassandra.conf'
|
||||
conf_path = os.environ["POPPY_TESTS_CONFIGS_DIR"]
|
||||
config_file = os.path.join(conf_path, conf_file)
|
||||
|
||||
conf = cfg.ConfigOpts()
|
||||
conf(project='poppy', prog='poppy', args=[],
|
||||
default_config_files=[config_file])
|
||||
cls.poppy_server = server.CDNServer()
|
||||
cls.poppy_server.start(conf)
|
||||
|
||||
def assertSchema(self, response_json, expected_schema):
|
||||
"""Verify response schema aligns with the expected schema."""
|
||||
@ -77,6 +64,4 @@ class TestBase(fixtures.BaseTestFixture):
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
"""Deletes the added resources."""
|
||||
if cls.test_config.run_server:
|
||||
cls.poppy_server.stop()
|
||||
super(TestBase, cls).tearDownClass()
|
||||
|
@ -37,11 +37,6 @@ class TestConfig(data_interfaces.ConfigSectionInterface):
|
||||
"""Defines the config values specific to test execution."""
|
||||
SECTION_NAME = 'test_configuration'
|
||||
|
||||
@property
|
||||
def run_server(self):
|
||||
"""Boolean value indicating whether to start a Poppy server."""
|
||||
return self.get_boolean('run_server')
|
||||
|
||||
@property
|
||||
def provider_validation(self):
|
||||
"""Boolean value indicating if tests verify provider side details."""
|
||||
|
@ -1,96 +0,0 @@
|
||||
# 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 abc
|
||||
import multiprocessing
|
||||
|
||||
import six
|
||||
|
||||
from poppy import bootstrap
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Server(object):
|
||||
|
||||
name = "poppy-server"
|
||||
|
||||
def __init__(self):
|
||||
self.process = None
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_target(self, conf):
|
||||
"""Prepares the target object
|
||||
|
||||
This method is meant to initialize server's
|
||||
bootstrap and return a callable to run the
|
||||
server.
|
||||
|
||||
:param conf: The config instance for the
|
||||
bootstrap class
|
||||
:returns: A callable object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def is_alive(self):
|
||||
"""Returns True IF the server is running."""
|
||||
|
||||
if self.process is None:
|
||||
return False
|
||||
|
||||
return self.process.is_alive()
|
||||
|
||||
def start(self, conf):
|
||||
"""Starts the server process.
|
||||
|
||||
:param conf: The config instance to use for
|
||||
the new process
|
||||
:returns: A `multiprocessing.Process` instance
|
||||
"""
|
||||
|
||||
target = self.get_target(conf)
|
||||
|
||||
if not callable(target):
|
||||
raise RuntimeError("Target not callable")
|
||||
|
||||
self.process = multiprocessing.Process(target=target,
|
||||
name=self.name)
|
||||
self.process.daemon = True
|
||||
self.process.start()
|
||||
|
||||
# Set the timeout. The calling thread will be blocked until the process
|
||||
# whose join() method is called terminates or until the timeout occurs.
|
||||
# The timeout is set, so that the calling (API tests)
|
||||
# & called processes (CDN Server) can execute in parallel.
|
||||
self.process.join(1)
|
||||
|
||||
return self.process
|
||||
|
||||
def stop(self):
|
||||
"""Terminates a process
|
||||
|
||||
This method kills a process by
|
||||
calling `terminate`. Note that
|
||||
children of this process won't be
|
||||
terminated but become orphaned.
|
||||
"""
|
||||
self.process.terminate()
|
||||
|
||||
|
||||
class CDNServer(Server):
|
||||
name = "poppy-server"
|
||||
|
||||
def get_target(self, conf):
|
||||
server = bootstrap.Bootstrap(conf)
|
||||
return server.run
|
@ -13,7 +13,6 @@ base_url=http://0.0.0.0:8888
|
||||
flavor = {"flavor1": ["provider_1"], "flavor2": ["provider_2", "provider_3"]}
|
||||
|
||||
[test_configuration]
|
||||
run_server=True
|
||||
provider_validation=False
|
||||
|
||||
[provider_1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user