本文整理汇总了Python中manager_rest.file_server.FileServer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python FileServer.stop方法的具体用法?Python FileServer.stop怎么用?Python FileServer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类manager_rest.file_server.FileServer
的用法示例。
在下文中一共展示了FileServer.stop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_put_blueprint_archive_from_url
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
def test_put_blueprint_archive_from_url(self):
port = 53230
blueprint_id = 'new_blueprint_id'
archive_path = self.archive_mock_blueprint(
archive_func=archiving.make_tarbz2file)
archive_filename = os.path.basename(archive_path)
archive_dir = os.path.dirname(archive_path)
archive_url = 'http://localhost:{0}/{1}'.format(
port, archive_filename)
fs = FileServer(archive_dir, False, port)
fs.start()
try:
self.wait_for_url(archive_url)
blueprint_id = self.client.blueprints.publish_archive(
archive_url,
blueprint_id).id
# verifying blueprint exists
result = self.client.blueprints.get(blueprint_id)
self.assertEqual(blueprint_id, result.id)
finally:
fs.stop()
示例2: test_publish_archive_blueprint_main_file_name
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
def test_publish_archive_blueprint_main_file_name(self):
port = 53230
blueprint_id = 'publish_archive_blueprint_main_file_name'
main_file_name = 'blueprint_with_workflows.yaml'
archive_path = self.archive_mock_blueprint()
archive_filename = os.path.basename(archive_path)
archive_dir = os.path.dirname(archive_path)
fs = FileServer(archive_dir, False, port)
fs.start()
try:
archive_url = 'http://localhost:{0}/{1}'.format(
port, archive_filename)
self.wait_for_url(archive_url)
response = self.client.blueprints.publish_archive(archive_url,
blueprint_id,
main_file_name)
finally:
fs.stop()
self.assertEqual(blueprint_id, response.id)
self.assertEqual(main_file_name, response.main_file_name)
示例3: test_put_blueprint_from_url
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
def test_put_blueprint_from_url(self):
port = 53230
blueprint_id = 'new_blueprint_id'
resource_path = '/blueprints/{0}'.format(blueprint_id)
archive_path = self.archive_mock_blueprint()
archive_filename = os.path.basename(archive_path)
archive_dir = os.path.dirname(archive_path)
fs = FileServer(archive_dir, False, port)
fs.start()
try:
archive_url = 'http://localhost:{0}/{1}'.format(
port, archive_filename)
self.wait_for_url(archive_url)
response = self.put(
resource_path,
None,
{'blueprint_archive_url': archive_url})
self.assertEqual(blueprint_id, response.json['id'])
finally:
fs.stop()
示例4: test_publish_bz2_archive_from_url
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
def test_publish_bz2_archive_from_url(self):
port = 53231
archive_location = self._make_archive_file("dsl/basic.yaml", 'w:bz2')
archive_filename = os.path.basename(archive_location)
archive_dir = os.path.dirname(archive_location)
archive_url = 'http://localhost:{0}/{1}'.format(
port, archive_filename)
fs = FileServer(archive_dir, False, port)
fs.start()
try:
wait_for_url(archive_url, timeout=30)
blueprint_id = self.client.blueprints.publish_archive(
archive_url,
str(uuid.uuid4()),
'basic.yaml').id
# verifying blueprint exists
result = self.client.blueprints.get(blueprint_id)
self.assertEqual(blueprint_id, result.id)
finally:
fs.stop()
示例5: TestEnvironment
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
#.........这里部分代码省略.........
def start_fileserver(self):
# workaround to update path
manager_rest_path = \
path.dirname(path.dirname(path.dirname(__file__)))
manager_rest_path = path.join(manager_rest_path, 'rest-service')
sys.path.append(manager_rest_path)
os.mkdir(self.fileserver_dir)
from manager_rest.file_server import FileServer
from manager_rest.utils import copy_resources
self.file_server_process = FileServer(self.fileserver_dir)
self.file_server_process.start()
# copy resources (base yaml etc)
resources_path = path.abspath(__file__)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.join(resources_path, 'resources')
copy_resources(self.fileserver_dir, resources_path)
self.patch_source_urls(self.fileserver_dir)
def destroy(self):
logger.info('Destroying test environment...')
if self.riemann_process:
self.riemann_process.close()
if self.elasticsearch_process:
self.elasticsearch_process.close()
if self.manager_rest_process:
self.manager_rest_process.close()
if self.file_server_process:
self.file_server_process.stop()
self.delete_working_directory()
def delete_working_directory(self):
if os.path.exists(self.test_working_dir):
logger.info('Deleting test environment from: %s',
self.test_working_dir)
# shutil.rmtree(self.test_working_dir, ignore_errors=True)
def handle_logs(self, output, event):
pass
def handle_logs_with_es(self, index):
"""
set this test environment to store logs
in a custom elasticsearch index
:param index: index name to use
"""
def es_log_handler(_, event):
timestamp = datetime.now()
event['@timestamp'] = timestamp
es_client = Elasticsearch()
doc_type = event['type']
# simulate log index
res = es_client.index(index=index,
doc_type=doc_type,
body=event)
if not res['created']:
raise Exception('failed to write to elasticsearch')
self.handle_logs = es_log_handler
示例6: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
class BaseServerTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(BaseServerTestCase, self).__init__(*args, **kwargs)
def create_client(self, headers=None):
client = CloudifyClient(host='localhost',
headers=headers)
mock_http_client = MockHTTPClient(self.app,
headers=headers)
client._client = mock_http_client
client.blueprints.api = mock_http_client
client.deployments.api = mock_http_client
client.deployments.outputs.api = mock_http_client
client.deployment_modifications.api = mock_http_client
client.executions.api = mock_http_client
client.nodes.api = mock_http_client
client.node_instances.api = mock_http_client
client.manager.api = mock_http_client
client.evaluate.api = mock_http_client
client.tokens.api = mock_http_client
client.events.api = mock_http_client
# only exists in v2 and above
if CLIENT_API_VERSION != 'v1':
client.plugins.api = mock_http_client
client.snapshots.api = mock_http_client
return client
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.rest_service_log = tempfile.mkstemp()[1]
self.securest_log_file = tempfile.mkstemp()[1]
self.file_server = FileServer(self.tmpdir)
self.addCleanup(self.cleanup)
self.file_server.start()
storage_manager.storage_manager_module_name = \
STORAGE_MANAGER_MODULE_NAME
# workaround for setting the rest service log path, since it's
# needed when 'server' module is imported.
# right after the import the log path is set normally like the rest
# of the variables (used in the reset_state)
tmp_conf_file = tempfile.mkstemp()[1]
json.dump({'rest_service_log_path': self.rest_service_log,
'rest_service_log_file_size_MB': 1,
'rest_service_log_files_backup_count': 1,
'rest_service_log_level': 'DEBUG'},
open(tmp_conf_file, 'w'))
os.environ['MANAGER_REST_CONFIG_PATH'] = tmp_conf_file
try:
from manager_rest import server
finally:
del(os.environ['MANAGER_REST_CONFIG_PATH'])
server.reset_state(self.create_configuration())
utils.copy_resources(config.instance().file_server_root)
server.setup_app()
server.app.config['Testing'] = True
self.app = server.app.test_client()
self.client = self.create_client()
self.initialize_provider_context()
def cleanup(self):
self.quiet_delete(self.rest_service_log)
self.quiet_delete(self.securest_log_file)
if self.file_server:
self.file_server.stop()
def initialize_provider_context(self, client=None):
if not client:
client = self.client
# creating an empty bootstrap context
client.manager.create_context(self.id(), {'cloudify': {}})
def create_configuration(self):
from manager_rest.config import Config
test_config = Config()
test_config.test_mode = True
test_config.file_server_root = self.tmpdir
test_config.file_server_base_uri = 'http://localhost:{0}'.format(
FILE_SERVER_PORT)
test_config.file_server_blueprints_folder = \
FILE_SERVER_BLUEPRINTS_FOLDER
test_config.file_server_uploaded_blueprints_folder = \
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER
test_config.file_server_resources_uri = FILE_SERVER_RESOURCES_URI
test_config.rest_service_log_level = 'DEBUG'
test_config.rest_service_log_path = self.rest_service_log
test_config.rest_service_log_file_size_MB = 100,
test_config.rest_service_log_files_backup_count = 20
test_config.security_audit_log_level = 'DEBUG'
test_config.security_audit_log_file = self.securest_log_file
test_config.security_audit_log_file_size_MB = 100
test_config.security_audit_log_files_backup_count = 20
return test_config
def _version_url(self, url):
# method for versionifying URLs for requests which don't go through
# the REST client; the version is taken from the REST client regardless
#.........这里部分代码省略.........
示例7: TestEnvironment
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
#.........这里部分代码省略.........
def start_fileserver(self):
# workaround to update path
manager_rest_path = \
path.dirname(path.dirname(path.dirname(__file__)))
manager_rest_path = path.join(manager_rest_path, 'rest-service')
sys.path.append(manager_rest_path)
os.mkdir(self.fileserver_dir)
from manager_rest.file_server import FileServer
from manager_rest.util import copy_resources
self.file_server_process = FileServer(self.fileserver_dir)
self.file_server_process.start()
# copy resources (base yaml etc)
resources_path = path.abspath(__file__)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.join(resources_path, 'resources')
copy_resources(self.fileserver_dir, resources_path)
self.patch_source_urls(self.fileserver_dir)
def destroy(self):
logger.info('Destroying test environment...')
if self.riemann_process:
self.riemann_process.close()
if self.elasticsearch_process:
self.elasticsearch_process.close()
if self.manager_rest_process:
self.manager_rest_process.close()
if self.file_server_process:
self.file_server_process.stop()
self.delete_working_directory()
def delete_working_directory(self):
if os.path.exists(self.test_working_dir):
logger.info('Deleting test environment from: %s',
self.test_working_dir)
shutil.rmtree(self.test_working_dir, ignore_errors=True)
@classmethod
def _get_riemann_config(cls):
manager_dir = cls._get_manager_root()
plugins_dir = os.path.join(manager_dir, 'plugins')
riemann_dir = os.path.join(plugins_dir, 'riemann-controller')
package_dir = os.path.join(riemann_dir, 'riemann_controller')
resources_dir = os.path.join(package_dir, 'resources')
manager_config = os.path.join(resources_dir, 'manager.config')
return manager_config
@classmethod
def _get_libs_path(cls):
return path.join(cls._get_manager_root(), '.libs')
@staticmethod
def reset_elasticsearch_data():
global testenv_instance
testenv_instance.elasticsearch_process.reset_data()
@staticmethod
def stop_celery_management_worker():
global testenv_instance
testenv_instance.celery_management_worker_process.stop()
示例8: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
class BaseServerTestCase(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.file_server = FileServer(self.tmpdir)
self.file_server.start()
storage_manager.storage_manager_module_name = \
STORAGE_MANAGER_MODULE_NAME
server.reset_state(self.create_configuration())
util.copy_resources(config.instance().file_server_root)
server.setup_app()
server.app.config['Testing'] = True
self.app = server.app.test_client()
self.client = CloudifyClient('localhost')
mock_http_client = MockHTTPClient(self.app)
self.client.blueprints.api = mock_http_client
self.client.deployments.api = mock_http_client
self.client.deployments.outputs.api = mock_http_client
self.client.executions.api = mock_http_client
self.client.nodes.api = mock_http_client
self.client.node_instances.api = mock_http_client
self.client.manager.api = mock_http_client
def tearDown(self):
self.file_server.stop()
def create_configuration(self):
from manager_rest.config import Config
test_config = Config()
test_config.test_mode = True
test_config.file_server_root = self.tmpdir
test_config.file_server_base_uri = 'http://localhost:{0}'.format(
FILE_SERVER_PORT)
test_config.file_server_blueprints_folder = \
FILE_SERVER_BLUEPRINTS_FOLDER
test_config.file_server_uploaded_blueprints_folder = \
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER
test_config.file_server_resources_uri = FILE_SERVER_RESOURCES_URI
return test_config
def post(self, resource_path, data, query_params=None):
url = self._build_url(resource_path, query_params)
result = self.app.post(url,
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def post_file(self, resource_path, file_path, query_params=None):
with open(file_path) as f:
result = self.app.post(
self._build_url(resource_path, query_params), data=f.read())
result.json = json.loads(result.data)
return result
def put_file(self, resource_path, file_path, query_params=None):
with open(file_path) as f:
result = self.app.put(
self._build_url(resource_path, query_params), data=f.read())
result.json = json.loads(result.data)
return result
def put(self, resource_path, data):
result = self.app.put(urllib.quote(resource_path),
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def patch(self, resource_path, data):
result = self.app.patch(urllib.quote(resource_path),
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def get(self, resource_path, query_params=None):
result = self.app.get(self._build_url(resource_path, query_params))
result.json = json.loads(result.data)
return result
def head(self, resource_path):
result = self.app.head(urllib.quote(resource_path))
return result
def delete(self, resource_path, query_params=None):
result = self.app.delete(self._build_url(resource_path, query_params))
result.json = json.loads(result.data)
return result
def check_if_resource_on_fileserver(self, blueprint_id, resource_path):
url = 'http://localhost:{0}/{1}/{2}/{3}'.format(
FILE_SERVER_PORT, FILE_SERVER_BLUEPRINTS_FOLDER,
blueprint_id, resource_path)
try:
urllib2.urlopen(url)
return True
except urllib2.HTTPError:
return False
#.........这里部分代码省略.........
示例9: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
class BaseServerTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(BaseServerTestCase, self).__init__(*args, **kwargs)
def create_client(self, api_version=DEFAULT_API_VERSION, headers=None):
client = CloudifyClient(host='localhost',
api_version=api_version,
headers=headers)
mock_http_client = MockHTTPClient(self.app,
api_version=api_version,
headers=headers)
client._client = mock_http_client
client.blueprints.api = mock_http_client
client.deployments.api = mock_http_client
client.deployments.outputs.api = mock_http_client
client.deployment_modifications.api = mock_http_client
client.executions.api = mock_http_client
client.nodes.api = mock_http_client
client.node_instances.api = mock_http_client
client.manager.api = mock_http_client
client.evaluate.api = mock_http_client
client.tokens.api = mock_http_client
return client
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.rest_service_log = tempfile.mkstemp()[1]
self.securest_log_file = tempfile.mkstemp()[1]
self.file_server = FileServer(self.tmpdir)
self.addCleanup(self.cleanup)
self.file_server.start()
storage_manager.storage_manager_module_name = \
STORAGE_MANAGER_MODULE_NAME
# workaround for setting the rest service log path, since it's
# needed when 'server' module is imported.
# right after the import the log path is set normally like the rest
# of the variables (used in the reset_state)
tmp_conf_file = tempfile.mkstemp()[1]
json.dump({'rest_service_log_path': self.rest_service_log,
'rest_service_log_file_size_MB': 1,
'rest_service_log_files_backup_count': 1,
'rest_service_log_level': 'DEBUG'},
open(tmp_conf_file, 'w'))
os.environ['MANAGER_REST_CONFIG_PATH'] = tmp_conf_file
try:
from manager_rest import server
finally:
del(os.environ['MANAGER_REST_CONFIG_PATH'])
server.reset_state(self.create_configuration())
utils.copy_resources(config.instance().file_server_root)
server.setup_app()
server.app.config['Testing'] = True
self.app = server.app.test_client()
self.client = self.create_client()
self.initialize_provider_context()
def cleanup(self):
self.quiet_delete(self.rest_service_log)
self.quiet_delete(self.securest_log_file)
if self.file_server:
self.file_server.stop()
def initialize_provider_context(self):
# creating an empty bootstrap context
self.client.manager.create_context(self.id(), {'cloudify': {}})
def create_configuration(self):
from manager_rest.config import Config
test_config = Config()
test_config.test_mode = True
test_config.file_server_root = self.tmpdir
test_config.file_server_base_uri = 'http://localhost:{0}'.format(
FILE_SERVER_PORT)
test_config.file_server_blueprints_folder = \
FILE_SERVER_BLUEPRINTS_FOLDER
test_config.file_server_uploaded_blueprints_folder = \
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER
test_config.file_server_resources_uri = FILE_SERVER_RESOURCES_URI
test_config.rest_service_log_level = 'DEBUG'
test_config.rest_service_log_path = self.rest_service_log
test_config.rest_service_log_file_size_MB = 100,
test_config.rest_service_log_files_backup_count = 20
test_config.securest_log_level = 'DEBUG'
test_config.securest_log_file = self.securest_log_file
test_config.securest_log_file_size_MB = 100
test_config.securest_log_files_backup_count = 20
return test_config
def post(self, resource_path, data, query_params=None):
url = self.client._client.version_url(resource_path)
result = self.app.post(urllib.quote(url),
content_type='application/json',
data=json.dumps(data),
query_string=build_query_string(query_params))
result.json = json.loads(result.data)
return result
#.........这里部分代码省略.........
示例10: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
class BaseServerTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(BaseServerTestCase, self).__init__(*args, **kwargs)
def create_client(self, headers=None):
client = CloudifyClient(host="localhost", headers=headers)
mock_http_client = MockHTTPClient(self.app, headers=headers)
client._client = mock_http_client
client.blueprints.api = mock_http_client
client.deployments.api = mock_http_client
client.deployments.outputs.api = mock_http_client
client.deployment_modifications.api = mock_http_client
client.executions.api = mock_http_client
client.nodes.api = mock_http_client
client.node_instances.api = mock_http_client
client.manager.api = mock_http_client
client.evaluate.api = mock_http_client
client.tokens.api = mock_http_client
return client
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.rest_service_log = tempfile.mkstemp()[1]
self.securest_log_file = tempfile.mkstemp()[1]
self.file_server = FileServer(self.tmpdir)
self.addCleanup(self.cleanup)
self.file_server.start()
storage_manager.storage_manager_module_name = STORAGE_MANAGER_MODULE_NAME
# workaround for setting the rest service log path, since it's
# needed when 'server' module is imported.
# right after the import the log path is set normally like the rest
# of the variables (used in the reset_state)
tmp_conf_file = tempfile.mkstemp()[1]
json.dump(
{
"rest_service_log_path": self.rest_service_log,
"rest_service_log_file_size_MB": 1,
"rest_service_log_files_backup_count": 1,
"rest_service_log_level": "DEBUG",
},
open(tmp_conf_file, "w"),
)
os.environ["MANAGER_REST_CONFIG_PATH"] = tmp_conf_file
try:
from manager_rest import server
finally:
del (os.environ["MANAGER_REST_CONFIG_PATH"])
server.reset_state(self.create_configuration())
utils.copy_resources(config.instance().file_server_root)
server.setup_app()
server.app.config["Testing"] = True
self.app = server.app.test_client()
self.client = self.create_client()
self.initialize_provider_context()
def cleanup(self):
self.quiet_delete(self.rest_service_log)
self.quiet_delete(self.securest_log_file)
if self.file_server:
self.file_server.stop()
def initialize_provider_context(self, client=None):
if not client:
client = self.client
# creating an empty bootstrap context
client.manager.create_context(self.id(), {"cloudify": {}})
def create_configuration(self):
from manager_rest.config import Config
test_config = Config()
test_config.test_mode = True
test_config.file_server_root = self.tmpdir
test_config.file_server_base_uri = "http://localhost:{0}".format(FILE_SERVER_PORT)
test_config.file_server_blueprints_folder = FILE_SERVER_BLUEPRINTS_FOLDER
test_config.file_server_uploaded_blueprints_folder = FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER
test_config.file_server_resources_uri = FILE_SERVER_RESOURCES_URI
test_config.rest_service_log_level = "DEBUG"
test_config.rest_service_log_path = self.rest_service_log
test_config.rest_service_log_file_size_MB = (100,)
test_config.rest_service_log_files_backup_count = 20
test_config.security_audit_log_level = "DEBUG"
test_config.security_audit_log_file = self.securest_log_file
test_config.security_audit_log_file_size_MB = 100
test_config.security_audit_log_files_backup_count = 20
return test_config
def _version_url(self, url):
# method for versionifying URLs for requests which don't go through
# the REST client; the version is taken from the REST client regardless
if CLIENT_API_VERSION not in url:
url = "/api/{0}{1}".format(CLIENT_API_VERSION, url)
return url
def post(self, resource_path, data, query_params=None):
url = self._version_url(resource_path)
#.........这里部分代码省略.........
示例11: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
class BaseServerTestCase(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.file_server = FileServer(self.tmpdir)
self.file_server.start()
storage_manager.storage_manager_module_name = \
STORAGE_MANAGER_MODULE_NAME
server.reset_state(self.create_configuration())
util.copy_resources(config.instance().file_server_root)
server.setup_app()
server.app.config['Testing'] = True
self.app = server.app.test_client()
def tearDown(self):
self.file_server.stop()
def create_configuration(self):
from manager_rest.config import Config
test_config = Config()
test_config.test_mode = True
test_config.file_server_root = self.tmpdir
test_config.file_server_base_uri = 'http://localhost:{0}'.format(
FILE_SERVER_PORT)
test_config.file_server_blueprints_folder = \
FILE_SERVER_BLUEPRINTS_FOLDER
return test_config
def post(self, resource_path, data, query_params=None):
url = self._build_url(resource_path, query_params)
result = self.app.post(url,
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def post_file(self, resource_path, file_path, query_params=None):
with open(file_path) as f:
result = self.app.post(
self._build_url(resource_path, query_params), data=f.read())
result.json = json.loads(result.data)
return result
def put_file(self, resource_path, file_path, query_params=None):
with open(file_path) as f:
result = self.app.put(
self._build_url(resource_path, query_params), data=f.read())
result.json = json.loads(result.data)
return result
def put(self, resource_path, data):
result = self.app.put(urllib.quote(resource_path),
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def patch(self, resource_path, data):
result = self.app.patch(urllib.quote(resource_path),
content_type='application/json',
data=json.dumps(data))
result.json = json.loads(result.data)
return result
def get(self, resource_path, query_params=None):
result = self.app.get(self._build_url(resource_path, query_params))
result.json = json.loads(result.data)
return result
def head(self, resource_path):
result = self.app.head(urllib.quote(resource_path))
return result
def delete(self, resource_path):
result = self.app.delete(urllib.quote(resource_path))
result.json = json.loads(result.data)
return result
def check_if_resource_on_fileserver(self, blueprint_id, resource_path):
url = 'http://localhost:{0}/{1}/{2}/{3}'.format(
FILE_SERVER_PORT, FILE_SERVER_BLUEPRINTS_FOLDER,
blueprint_id, resource_path)
try:
urllib2.urlopen(url)
return True
except urllib2.HTTPError:
return False
def _build_url(self, resource_path, query_params):
query_string = ''
if query_params and len(query_params) > 0:
query_string += '&' + urllib.urlencode(query_params)
return '{0}?{1}'.format(urllib.quote(resource_path), query_string)
示例12: TestEnvironment
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
#.........这里部分代码省略.........
copy_resources(fileserver_dir, resources_path)
# manager rest
file_server_base_uri = 'http://localhost:{0}'.format(FS_PORT)
self._manager_rest_process = ManagerRestProcess(
MANAGER_REST_PORT,
fileserver_dir,
file_server_base_uri,
FILE_SERVER_BLUEPRINTS_FOLDER,
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER,
FILE_SERVER_RESOURCES_URI,
self._tempdir)
self._manager_rest_process.start()
except BaseException as error:
logger.error("Error in test environment setup: %s", error)
self._destroy()
raise
def _destroy(self):
logger.info("Destroying test environment... [scope={0}]".format(
self._scope))
if self._riemann_process:
self._riemann_process.close()
if self._elasticsearch_process:
self._elasticsearch_process.close()
if self._celery_operations_worker_process:
self._celery_operations_worker_process.close()
if self._celery_workflows_worker_process:
self._celery_workflows_worker_process.close()
if self._manager_rest_process:
self._manager_rest_process.close()
if self._file_server_process:
self._file_server_process.stop()
if self._tempdir:
logger.info("Deleting test environment from: %s", self._tempdir)
# shutil.rmtree(self._tempdir, ignore_errors=True)
def _create_celery_worker(self, queue):
return CeleryTestWorkerProcess(
self._tempdir,
self._plugins_tempdir,
MANAGER_REST_PORT,
queue)
@staticmethod
def create(scope=TestEnvironmentScope.PACKAGE,
use_mock_workers_installation=True):
"""
Creates the test environment if not already created.
:param scope: The scope the test environment is created at.
"""
if not TestEnvironment._instance:
TestEnvironment._instance = TestEnvironment(
scope,
use_mock_workers_installation)
return TestEnvironment._instance
@staticmethod
def destroy(scope=TestEnvironmentScope.PACKAGE):
"""
Destroys the test environment if the provided scope matches the scope
the environment was created with.
:param scope: The scope this method is invoked from.
"""
if TestEnvironment._instance and \
示例13: TestEnvironment
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import stop [as 别名]
#.........这里部分代码省略.........
def start_fileserver(self):
# workaround to update path
manager_rest_path = path.dirname(path.dirname(path.dirname(__file__)))
manager_rest_path = path.join(manager_rest_path, "rest-service")
sys.path.append(manager_rest_path)
os.mkdir(self.fileserver_dir)
from manager_rest.file_server import FileServer
from manager_rest.utils import copy_resources
self.file_server_process = FileServer(self.fileserver_dir)
self.file_server_process.start()
# copy resources (base yaml etc)
resources_path = path.abspath(__file__)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.dirname(resources_path)
resources_path = path.join(resources_path, "resources")
copy_resources(self.fileserver_dir, resources_path)
self.patch_source_urls(self.fileserver_dir)
def destroy(self):
logger.info("Destroying test environment...")
if self.riemann_process:
self.riemann_process.close()
if self.elasticsearch_process:
self.elasticsearch_process.close()
if self.manager_rest_process:
self.manager_rest_process.close()
if self.file_server_process:
self.file_server_process.stop()
self.delete_working_directory()
def delete_working_directory(self):
if os.path.exists(self.test_working_dir):
logger.info("Deleting test environment from: %s", self.test_working_dir)
# shutil.rmtree(self.test_working_dir, ignore_errors=True)
def handle_logs(self, output, event):
pass
def _logs_handler_retriever(self):
return self.handle_logs
@classmethod
def _get_riemann_config(cls):
manager_dir = cls._get_manager_root()
plugins_dir = os.path.join(manager_dir, "plugins")
riemann_dir = os.path.join(plugins_dir, "riemann-controller")
package_dir = os.path.join(riemann_dir, "riemann_controller")
resources_dir = os.path.join(package_dir, "resources")
manager_config = os.path.join(resources_dir, "manager.config")
return manager_config
@classmethod
def _get_libs_path(cls):
return path.join(cls._get_manager_root(), ".libs")
@staticmethod
def reset_elasticsearch_data():
global testenv_instance
testenv_instance.elasticsearch_process.reset_data()