def _manager_env(self): port = 8756 fs = FileServer(root_path=self.temp_folder, port=port) fs.start() if os.name == 'nt': package_name = 'cloudify-windows-agent.exe' else: dist = platform.dist() package_name = '{0}-{1}-agent.tar.gz'.format( dist[0].lower(), dist[2].lower()) resources_dir = os.path.join(self.temp_folder, 'resources') agent_dir = os.path.join(resources_dir, 'packages', 'agents') agent_script_dir = os.path.join(resources_dir, 'cloudify_agent') os.makedirs(agent_dir) os.makedirs(agent_script_dir) os.makedirs(os.path.join(self.temp_folder, 'cloudify')) agent_path = os.path.join(agent_dir, package_name) shutil.copyfile(agent_package.get_package_path(), agent_path) new_env = { constants.REST_HOST_KEY: 'localhost', constants.MANAGER_FILE_SERVER_URL_KEY: 'http://localhost:{0}'.format(port), constants.MANAGER_FILE_SERVER_ROOT_KEY: resources_dir, constants.REST_PORT_KEY: str(port), } with patch.dict(os.environ, new_env): try: yield finally: fs.stop()
def _manager_env(self): port = 8756 fs = FileServer( root_path=self.temp_folder, port=port) fs.start() if os.name == 'nt': package_name = 'cloudify-windows-agent.exe' else: dist = platform.dist() package_name = '{0}-{1}-agent.tar.gz'.format(dist[0].lower(), dist[2].lower()) agent_dir = os.path.join(self.temp_folder, 'packages', 'agents') os.makedirs(agent_dir) agent_path = os.path.join(agent_dir, package_name) shutil.copyfile(agent_package.get_package_path(), agent_path) resources_dir = os.path.join(self.temp_folder, 'cloudify') os.makedirs(resources_dir) if os.getenv('AGENT_INSTALL_SCRIPT'): install_script_url = os.getenv('AGENT_INSTALL_SCRIPT') else: install_script_url = _INSTALL_SCRIPT_URL urllib.urlretrieve(install_script_url, os.path.join(resources_dir, 'install_agent.py')) new_env = { constants.MANAGER_IP_KEY: 'localhost', constants.MANAGER_FILE_SERVER_URL_KEY: 'http://localhost:{0}'.format(port) } with patch.dict(os.environ, new_env): try: yield finally: fs.stop()
def _manager_env(self): port = 8756 fs = FileServer(root_path=self.temp_folder, port=port) fs.start() if os.name == 'nt': package_name = 'cloudify-windows-agent.exe' else: dist = platform.dist() package_name = '{0}-{1}-agent.tar.gz'.format(dist[0].lower(), dist[2].lower()) resources_dir = os.path.join(self.temp_folder, 'resources') agent_dir = os.path.join(resources_dir, 'packages', 'agents') agent_script_dir = os.path.join(resources_dir, 'cloudify_agent') os.makedirs(agent_dir) os.makedirs(agent_script_dir) os.makedirs(os.path.join(self.temp_folder, 'cloudify')) agent_path = os.path.join(agent_dir, package_name) shutil.copyfile(agent_package.get_package_path(), agent_path) new_env = { constants.REST_HOST_KEY: 'localhost', constants.MANAGER_FILE_SERVER_URL_KEY: 'http://localhost:{0}'.format(port), constants.MANAGER_FILE_SERVER_ROOT_KEY: resources_dir, constants.REST_PORT_KEY: str(port), } with patch.dict(os.environ, new_env): try: yield finally: fs.stop()
def _manager_env(self): port = 8756 fs = FileServer(root_path=self.temp_folder, port=port) fs.start() if os.name == 'nt': package_name = 'cloudify-windows-agent.exe' else: dist = platform.dist() package_name = '{0}-{1}-agent.tar.gz'.format( dist[0].lower(), dist[2].lower()) agent_dir = os.path.join(self.temp_folder, 'packages', 'agents') os.makedirs(agent_dir) agent_path = os.path.join(agent_dir, package_name) shutil.copyfile(agent_package.get_package_path(), agent_path) resources_dir = os.path.join(self.temp_folder, 'cloudify') os.makedirs(resources_dir) if os.getenv('AGENT_INSTALL_SCRIPT'): install_script_url = os.getenv('AGENT_INSTALL_SCRIPT') else: install_script_url = _INSTALL_SCRIPT_URL urllib.urlretrieve(install_script_url, os.path.join(resources_dir, 'install_agent.py')) new_env = { constants.MANAGER_IP_KEY: 'localhost', constants.MANAGER_FILE_SERVER_URL_KEY: 'http://localhost:{0}'.format(port) } with patch.dict(os.environ, new_env): try: yield finally: fs.stop()
def _manager_env(self): port = 8756 fs = FileServer(root_path=self.temp_folder, port=port) fs.start() self.addCleanup(fs.stop) if os.name == 'nt': package_name = 'cloudify-windows-agent.exe' else: dist = platform.dist() package_name = '{0}-{1}-agent.tar.gz'.format( dist[0].lower(), dist[2].lower()) resources_dir = os.path.join(self.temp_folder, 'resources') agent_dir = os.path.join(resources_dir, 'packages', 'agents') agent_script_dir = os.path.join(resources_dir, 'cloudify_agent') os.makedirs(agent_dir) os.makedirs(agent_script_dir) os.makedirs(os.path.join(self.temp_folder, 'cloudify')) agent_path = os.path.join(agent_dir, package_name) shutil.copyfile(agent_package.get_package_path(), agent_path) self.addCleanup(agent_package.cleanup) new_env = { constants.MANAGER_FILE_SERVER_ROOT_KEY: resources_dir, constants.REST_PORT_KEY: str(port), constants.MANAGER_NAME: 'cloudify' } original_create_op_context = operations._get_cloudify_context def mock_create_op_context(agent, task_name): context = original_create_op_context(agent, task_name) context['__cloudify_context']['local'] = True return context # Need to patch, to avoid broker_ssl_enabled being True @contextmanager def get_amqp_client(agent): yield get_client() managers = [ ManagerItem({ 'networks': { 'default': '127.0.0.1' }, 'ca_cert_content': agent_ssl_cert.DUMMY_CERT, 'hostname': 'cloudify' }) ] patches = [ patch.dict(os.environ, new_env), patch('cloudify_agent.operations._get_amqp_client', get_amqp_client), patch('cloudify.endpoint.LocalEndpoint.get_managers', return_value=managers), patch('cloudify_agent.operations._get_cloudify_context', mock_create_op_context), get_tenant_mock() ] for p in patches: p.start() try: yield finally: for p in patches: p.stop() fs.stop()