本文整理汇总了Python中manager_rest.file_server.FileServer.start方法的典型用法代码示例。如果您正苦于以下问题:Python FileServer.start方法的具体用法?Python FileServer.start怎么用?Python FileServer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类manager_rest.file_server.FileServer
的用法示例。
在下文中一共展示了FileServer.start方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_put_blueprint_archive_from_url
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import start [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 start [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 start [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 start [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 start [as 别名]
class TestEnvironment(object):
manager_rest_process = None
elasticsearch_process = None
riemann_process = None
file_server_process = None
celery_management_worker_process = None
def __init__(self, test_working_dir):
super(TestEnvironment, self).__init__()
self.test_working_dir = test_working_dir
self.plugins_storage_dir = os.path.join(
self.test_working_dir,
'plugins-storage'
)
os.makedirs(self.plugins_storage_dir)
self.fileserver_dir = path.join(self.test_working_dir, 'fileserver')
self.maintenance_folder = path.join(self.test_working_dir,
'maintenance')
self.rest_service_log_level = 'DEBUG'
self.rest_service_log_path = path.join(
self.test_working_dir, 'cloudify-rest-service.log')
self.rest_service_log_file_size_MB = 100
self.rest_service_log_files_backup_count = 20
self.securest_log_level = 'DEBUG'
self.securest_log_file = path.join(
self.test_working_dir, 'rest-security-audit.log')
self.securest_log_file_size_MB = 100
self.securest_log_files_backup_count = 20
self.amqp_username = 'guest'
self.amqp_password = 'guest'
self.events_and_logs_dir = \
path.join(self.test_working_dir, 'tests-events-and-logs')
os.mkdir(self.events_and_logs_dir)
def create(self):
try:
logger.info('Setting up test environment... workdir=[{0}]'
.format(self.test_working_dir))
# events/logs polling
start_events_and_logs_polling(
logs_handler_retriever=self._logs_handler_retriever)
self.start_elasticsearch()
self.start_riemann()
self.start_fileserver()
self.start_manager_rest()
self.create_management_worker()
except BaseException as error:
s_traceback = StringIO.StringIO()
traceback.print_exc(file=s_traceback)
logger.error("Error in test environment setup: %s", error)
logger.error(s_traceback.getvalue())
self.destroy()
raise
def create_management_worker(self):
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
os.environ['MOCK_PLUGINS_PATH'] = mock_plugins_path
self.celery_management_worker_process = CeleryWorkerProcess(
queues=['cloudify.management'],
test_working_dir=self.test_working_dir,
# we need high concurrency since all management and
# central deployment operations/workflow will be executed
# by this worker
concurrency=10
)
# copy plugins to worker env
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
shutil.copytree(
src=mock_plugins_path,
dst=self.celery_management_worker_process.envdir,
ignore=shutil.ignore_patterns('*.pyc')
)
def start_riemann(self):
riemann_config_path = self._get_riemann_config()
libs_path = self._get_libs_path()
self.riemann_process = RiemannProcess(riemann_config_path,
libs_path)
self.riemann_process.start()
def start_manager_rest(self):
from manager_rest.file_server import PORT as FS_PORT
file_server_base_uri = 'http://localhost:{0}'.format(FS_PORT)
self.manager_rest_process = ManagerRestProcess(
MANAGER_REST_PORT,
self.fileserver_dir,
file_server_base_uri,
FILE_SERVER_BLUEPRINTS_FOLDER,
FILE_SERVER_DEPLOYMENTS_FOLDER,
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER,
#.........这里部分代码省略.........
示例6: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import start [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 start [as 别名]
class TestEnvironment(object):
manager_rest_process = None
elasticsearch_process = None
riemann_process = None
file_server_process = None
celery_management_worker_process = None
def __init__(self, test_working_dir):
super(TestEnvironment, self).__init__()
self.test_working_dir = test_working_dir
self.plugins_storage_dir = os.path.join(
self.test_working_dir,
'plugins-storage'
)
os.makedirs(self.plugins_storage_dir)
self.fileserver_dir = path.join(self.test_working_dir, 'fileserver')
self.rest_service_log_path = path.join(
self.test_working_dir, 'cloudify-rest-service.log')
def create(self):
try:
logger.info('Setting up test environment... workdir=[{0}]'
.format(self.test_working_dir))
# events/logs polling
start_events_and_logs_polling()
self.start_elasticsearch()
self.start_riemann()
self.start_fileserver()
self.start_manager_rest()
self.create_management_worker()
except BaseException as error:
s_traceback = StringIO.StringIO()
traceback.print_exc(file=s_traceback)
logger.error("Error in test environment setup: %s", error)
logger.error(s_traceback.getvalue())
self.destroy()
raise
def create_management_worker(self):
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
os.environ['MOCK_PLUGINS_PATH'] = mock_plugins_path
self.celery_management_worker_process = CeleryWorkerProcess(
queues=['cloudify.management'],
test_working_dir=self.test_working_dir,
# these plugins are already installed.
# so we just need to append to the includes.
# note that these are not mocks, but the actual production
# code plugins.
additional_includes=[
'riemann_controller.tasks',
'cloudify_system_workflows.deployment_environment',
'cloudify.plugins.workflows',
'diamond_agent.tasks',
'script_runner.tasks'
],
# we need higher concurrency since
# 'deployment_environment.create' calls
# 'plugin_installer.install' as a sub-task
# and they are both executed inside
# this worker
concurrency=2
)
# copy plugins to worker env
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
shutil.copytree(
src=mock_plugins_path,
dst=self.celery_management_worker_process.envdir,
ignore=shutil.ignore_patterns('*.pyc')
)
def start_riemann(self):
riemann_config_path = self._get_riemann_config()
libs_path = self._get_libs_path()
self.riemann_process = RiemannProcess(riemann_config_path,
libs_path)
self.riemann_process.start()
def start_manager_rest(self):
from manager_rest.file_server import PORT as FS_PORT
file_server_base_uri = 'http://localhost:{0}'.format(FS_PORT)
self.manager_rest_process = ManagerRestProcess(
MANAGER_REST_PORT,
self.fileserver_dir,
file_server_base_uri,
FILE_SERVER_BLUEPRINTS_FOLDER,
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER,
FILE_SERVER_RESOURCES_URI,
#.........这里部分代码省略.........
示例8: BaseServerTestCase
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import start [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 start [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 start [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 start [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 start [as 别名]
class TestEnvironment(object):
"""
Creates the cosmo test environment:
- Riemann server.
- Elasticsearch server.
- Celery worker.
- Ruote service.
- Prepares celery app dir with plugins from cosmo module and official
riemann configurer and plugin installer.
"""
_instance = None
_celery_operations_worker_process = None
_celery_workflows_worker_process = None
_riemann_process = None
_elasticsearch_process = None
_manager_rest_process = None
_tempdir = None
_plugins_tempdir = None
_scope = None
_file_server_process = None
def __init__(self, scope, use_mock_workers_installation=True):
try:
TestEnvironmentScope.validate(scope)
logger.info("Setting up test environment... [scope={0}]".format(
scope))
self._scope = scope
# temp directory
self._tempdir = tempfile.mkdtemp(suffix="test", prefix="cloudify")
self._plugins_tempdir = path.join(self._tempdir, "cosmo-work")
self._riemann_tempdir = path.join(self._tempdir, "riemann")
logger.info("Test environment will be stored in: %s",
self._tempdir)
if not path.exists(self._plugins_tempdir):
os.makedirs(self._plugins_tempdir)
if not path.exists(self._riemann_tempdir):
os.makedirs(self._riemann_tempdir)
# events/logs polling
start_events_and_logs_polling()
# riemann
riemann_config_path = self._get_riemann_config()
libs_path = self._get_libs_path()
self._riemann_process = RiemannProcess(riemann_config_path,
libs_path)
self._riemann_process.start()
# elasticsearch
self._elasticsearch_process = ElasticSearchProcess()
self._elasticsearch_process.start()
# copy all plugins to app path
try:
import workflows
# workflows/__init__.py(c)
workflow_plugin_path = path.abspath(workflows.__file__)
# workflows/
workflow_plugin_path = path.dirname(workflow_plugin_path)
# package / egg folder
workflow_plugin_path = path.dirname(workflow_plugin_path)
except ImportError:
# cloudify-manager/tests/plugins/__init__.py(c)
workflow_plugin_path = path.abspath(plugins.__file__)
# cloudify-manager/tests/plugins
workflow_plugin_path = path.dirname(workflow_plugin_path)
# cloudify-manager/tests
workflow_plugin_path = path.dirname(workflow_plugin_path)
# cloudify-manager
workflow_plugin_path = path.dirname(workflow_plugin_path)
# cloudify-manager/workflows
workflow_plugin_path = path.join(workflow_plugin_path,
'workflows')
plugins_path = path.dirname(path.realpath(plugins.__file__))
mock_workflow_plugins = path.dirname(path.realpath(
mock_workflows.__file__))
app_path = path.join(self._tempdir, "plugins")
# copying plugins
if not use_mock_workers_installation:
for plugin_path in [plugins_path, workflow_plugin_path]:
logger.info("Copying %s to %s", plugin_path, app_path)
distutils.dir_util.copy_tree(plugin_path, app_path)
else:
# copying plugins and mock workflows
for plugin_path in [plugins_path, mock_workflow_plugins]:
logger.info("Copying %s to %s", plugin_path, app_path)
distutils.dir_util.copy_tree(plugin_path, app_path)
# copying the actual default install/uninstall workflow
# plugin manually
workflow_plugin_workflows_path = path.join(
workflow_plugin_path, 'workflows')
app_workflows_path = path.join(app_path, 'workflows')
logger.info("Copying %s to %s",
workflow_plugin_workflows_path,
app_workflows_path)
distutils.dir_util.copy_tree(
#.........这里部分代码省略.........
示例13: TestEnvironment
# 需要导入模块: from manager_rest.file_server import FileServer [as 别名]
# 或者: from manager_rest.file_server.FileServer import start [as 别名]
class TestEnvironment(object):
manager_rest_process = None
elasticsearch_process = None
riemann_process = None
file_server_process = None
celery_management_worker_process = None
def __init__(self, test_working_dir):
super(TestEnvironment, self).__init__()
self.test_working_dir = test_working_dir
self.plugins_storage_dir = os.path.join(self.test_working_dir, "plugins-storage")
os.makedirs(self.plugins_storage_dir)
self.fileserver_dir = path.join(self.test_working_dir, "fileserver")
self.rest_service_log_level = "DEBUG"
self.rest_service_log_path = path.join(self.test_working_dir, "cloudify-rest-service.log")
self.rest_service_log_file_size_MB = 100
self.rest_service_log_files_backup_count = 20
self.securest_log_level = "DEBUG"
self.securest_log_file = path.join(self.test_working_dir, "rest-security-audit.log")
self.securest_log_file_size_MB = 100
self.securest_log_files_backup_count = 20
self.amqp_username = "guest"
self.amqp_password = "guest"
self.events_and_logs_dir = path.join(self.test_working_dir, "tests-events-and-logs")
os.mkdir(self.events_and_logs_dir)
def create(self):
try:
logger.info("Setting up test environment... workdir=[{0}]".format(self.test_working_dir))
# events/logs polling
start_events_and_logs_polling(logs_handler_retriever=self._logs_handler_retriever)
self.start_elasticsearch()
self.start_riemann()
self.start_fileserver()
self.start_manager_rest()
self.create_management_worker()
except BaseException as error:
s_traceback = StringIO.StringIO()
traceback.print_exc(file=s_traceback)
logger.error("Error in test environment setup: %s", error)
logger.error(s_traceback.getvalue())
self.destroy()
raise
def create_management_worker(self):
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
os.environ["MOCK_PLUGINS_PATH"] = mock_plugins_path
self.celery_management_worker_process = CeleryWorkerProcess(
queues=["cloudify.management"],
test_working_dir=self.test_working_dir,
# these plugins are already installed.
# so we just need to append to the includes.
# note that these are not mocks, but the actual production
# code plugins.
additional_includes=[
"riemann_controller.tasks",
"cloudify_system_workflows.deployment_environment",
"cloudify.plugins.workflows",
"diamond_agent.tasks",
"script_runner.tasks",
# modules in the agent intended for backwards compatibility
"worker_installer.tasks",
"windows_agent_installer.tasks",
"plugin_installer.tasks",
"windows_plugin_installer.tasks",
],
# we need higher concurrency since
# 'deployment_environment.create' calls
# 'plugin_installer.install' as a sub-task
# and they are both executed inside
# this worker
concurrency=2,
)
# copy plugins to worker env
mock_plugins_path = os.path.dirname(mock_plugins.__file__)
shutil.copytree(
src=mock_plugins_path,
dst=self.celery_management_worker_process.envdir,
ignore=shutil.ignore_patterns("*.pyc"),
)
def start_riemann(self):
riemann_config_path = self._get_riemann_config()
libs_path = self._get_libs_path()
self.riemann_process = RiemannProcess(riemann_config_path, libs_path)
self.riemann_process.start()
def start_manager_rest(self):
from manager_rest.file_server import PORT as FS_PORT
file_server_base_uri = "http://localhost:{0}".format(FS_PORT)
#.........这里部分代码省略.........