当前位置: 首页>>代码示例>>Python>>正文


Python file_server.FileServer类代码示例

本文整理汇总了Python中manager_rest.file_server.FileServer的典型用法代码示例。如果您正苦于以下问题:Python FileServer类的具体用法?Python FileServer怎么用?Python FileServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_put_blueprint_archive_from_url

    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()
开发者ID:01000101,项目名称:cloudify-manager,代码行数:25,代码来源:test_blueprints.py

示例2: setUp

    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()
开发者ID:pkdevboxy,项目名称:cloudify-manager,代码行数:33,代码来源:base_test.py

示例3: test_publish_archive_blueprint_main_file_name

 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)
开发者ID:01000101,项目名称:cloudify-manager,代码行数:20,代码来源:test_blueprints.py

示例4: setUp

 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()
开发者ID:Fewbytes,项目名称:cloudify-manager,代码行数:11,代码来源:base_test.py

示例5: test_put_blueprint_from_url

    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()
开发者ID:codilime,项目名称:cloudify-manager,代码行数:23,代码来源:test_blueprints.py

示例6: test_publish_bz2_archive_from_url

    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()
开发者ID:Acidburn0zzz,项目名称:cloudify-manager,代码行数:24,代码来源:test_workflow.py

示例7: setUp

 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.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
开发者ID:mahak,项目名称:cloudify-manager,代码行数:19,代码来源:base_test.py

示例8: start_fileserver

    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)
开发者ID:Acidburn0zzz,项目名称:cloudify-manager,代码行数:22,代码来源:__init__.py

示例9: setUp

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()
        self.rest_service_log = tempfile.mkstemp()[1]
        self.file_server = FileServer(self.tmpdir)
        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},
                  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())
        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._client = mock_http_client
        self.client.blueprints.api = mock_http_client
        self.client.deployments.api = mock_http_client
        self.client.deployments.outputs.api = mock_http_client
        self.client.deployments.modify.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
        self.client.evaluate.api = mock_http_client
开发者ID:nagyist,项目名称:cloudify-manager,代码行数:38,代码来源:base_test.py

示例10: BaseServerTestCase

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
#.........这里部分代码省略.........
开发者ID:pkdevboxy,项目名称:cloudify-manager,代码行数:101,代码来源:base_test.py

示例11: TestEnvironment


#.........这里部分代码省略.........
        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,
            self.rest_service_log_path,
            self.test_working_dir)
        self.manager_rest_process.start()

    def start_elasticsearch(self):
        # elasticsearch
        self.elasticsearch_process = ElasticSearchProcess()
        self.elasticsearch_process.start()

    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)
开发者ID:nagyist,项目名称:cloudify-manager,代码行数:67,代码来源:__init__.py

示例12: BaseServerTestCase

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

#.........这里部分代码省略.........
开发者ID:boreys,项目名称:cloudify-manager,代码行数:101,代码来源:base_test.py

示例13: BaseServerTestCase

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
#.........这里部分代码省略.........
开发者ID:geokala,项目名称:cloudify-manager,代码行数:101,代码来源:base_test.py

示例14: BaseServerTestCase

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)
#.........这里部分代码省略.........
开发者ID:yashodhank,项目名称:cloudify-manager,代码行数:101,代码来源:base_test.py

示例15: BaseServerTestCase

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)
开发者ID:Fewbytes,项目名称:cloudify-manager,代码行数:93,代码来源:base_test.py


注:本文中的manager_rest.file_server.FileServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。