Esempio n. 1
0
 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()
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
    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
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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(
                    workflow_plugin_workflows_path, app_workflows_path)

            # celery operations worker
            # if using real worker installation workflow then 2 workers are
            # needed on the management queue
            num_of_management_workers = \
                1 if use_mock_workers_installation else 2
            self._celery_operations_worker_process = \
                CeleryOperationsWorkerProcess(
                    self._tempdir,
                    self._plugins_tempdir,
                    MANAGER_REST_PORT,
                    num_of_management_workers)
            self._celery_operations_worker_process.start()

            # celery workflows worker
            self._celery_workflows_worker_process = \
                CeleryWorkflowsWorkerProcess(
                    self._tempdir,
                    self._plugins_tempdir,
                    MANAGER_REST_PORT,
                    use_mock_workers_installation)
            self._celery_workflows_worker_process.start()

            # 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)

            # file server
            fileserver_dir = path.join(self._tempdir, 'fileserver')
            os.mkdir(fileserver_dir)
            from manager_rest.file_server import FileServer
            from manager_rest.file_server import PORT as FS_PORT
            from manager_rest.util import copy_resources
            self._file_server_process = FileServer(fileserver_dir)
            self._file_server_process.start()

            # copy resources (base yaml/radials 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(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
Esempio n. 8
0
    def __init__(self, scope, use_mock_deployment_environment_workflows=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_deployment_environment_workflows:
                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(
                    workflow_plugin_workflows_path, app_workflows_path)

            # celery operations worker
            # if using real deployment environment workflows then 2 workers are
            # needed on the management queue
            num_of_management_workers = \
                1 if use_mock_deployment_environment_workflows else 2
            self._celery_operations_worker_process = \
                CeleryOperationsWorkerProcess(
                    self._tempdir,
                    self._plugins_tempdir,
                    MANAGER_REST_PORT,
                    num_of_management_workers)
            self._celery_operations_worker_process.start()

            # celery workflows worker
            self._celery_workflows_worker_process = \
                CeleryWorkflowsWorkerProcess(
                    self._tempdir,
                    self._plugins_tempdir,
                    MANAGER_REST_PORT,
                    use_mock_deployment_environment_workflows)
            self._celery_workflows_worker_process.start()

            # 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)

            # file server
            fileserver_dir = path.join(self._tempdir, 'fileserver')
            os.mkdir(fileserver_dir)
            from manager_rest.file_server import FileServer
            from manager_rest.file_server import PORT as FS_PORT
            from manager_rest.util import copy_resources
            self._file_server_process = FileServer(fileserver_dir)
            self._file_server_process.start()

            # copy resources (base yaml/radials 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(fileserver_dir, resources_path)

            self.patch_source_urls(fileserver_dir)

            # 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