def set_default_values(self): self._set_name() self.setdefault('network', constants.DEFAULT_NETWORK_NAME) self._set_ips() self._set_broker_cert() # Remove the networks dict as it's no longer needed if 'networks' in self: self.pop('networks') self.setdefault('node_instance_id', ctx.instance.id) self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', defaults.MIN_WORKERS) self.setdefault('max_workers', defaults.MAX_WORKERS) self.setdefault('disable_requiretty', True) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version()) self.setdefault('log_level', defaults.LOG_LEVEL) self.setdefault('log_max_bytes', defaults.LOG_FILE_SIZE) self.setdefault('log_max_history', defaults.LOG_BACKUPS)
def set_default_values(self): self._set_name() self.setdefault('network', constants.DEFAULT_NETWORK_NAME) self._set_ips_and_certs() self._set_tenant() # Remove the networks dict as it's no longer needed if 'networks' in self: self.pop('networks') self.setdefault('node_instance_id', ctx.instance.id) self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', defaults.MIN_WORKERS) self.setdefault('max_workers', defaults.MAX_WORKERS) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version()) self.setdefault('log_level', defaults.LOG_LEVEL) self.setdefault('log_max_bytes', defaults.LOG_FILE_SIZE) self.setdefault('log_max_history', defaults.LOG_BACKUPS) # detach agents dont use sudo, so they don't need disable-requiretty self.setdefault( 'disable_requiretty', self.get('process_management', {}).get('name') != 'detach' )
def show_version(ctx, param, value): if not value or ctx.resilient_parsing: return ver = get_agent_version() logger = get_logger() logger.info('Cloudify Agent {0}'.format(ver)) ctx.exit()
def show_version(ctx, param, value): if not value or ctx.resilient_parsing: return ver = get_agent_version() logger = get_logger() logger.info('Cloudify Agent {0}'.format(ver)) ctx.exit()
def _test_prepare(self, agent_config, expected_values, context=None): user = getpass.getuser() basedir = utils.get_home_dir(user) agent_dir = os.path.join(basedir, 'test_deployment') envdir = os.path.join(agent_dir, 'env') workdir = os.path.join(agent_dir, 'work') # This test needs to be adapted to security settings expected = { 'agent_dir': agent_dir, 'process_management': { 'name': 'init.d' if os.name == 'posix' else 'nssm' }, 'basedir': basedir, 'name': 'test_deployment', 'rest_host': 'localhost', 'broker_ip': ['localhost'], 'broker_ssl_cert': '', 'heartbeat': None, 'queue': 'test_deployment', 'envdir': envdir, 'user': user, 'local': True, 'install_method': 'local', 'disable_requiretty': True, 'env': {}, 'fabric_env': {}, 'max_workers': 5, 'min_workers': 0, 'workdir': workdir, 'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH], 'windows': os.name == 'nt', 'system_python': 'python', 'bypass_maintenance': False, 'network': 'default', 'version': utils.get_agent_version(), 'node_instance_id': 'test_node', 'log_level': 'info', 'log_max_bytes': 5242880, 'log_max_history': 7 } expected.update(expected_values) self.maxDiff = None context = context or {} ctx = mock_context(**context) with patch('cloudify_agent.installer.config.agent_config.ctx', ctx), \ patch('cloudify.utils.ctx', mock_context()): cloudify_agent = CloudifyAgentConfig() cloudify_agent.set_initial_values(True, agent_config=agent_config) cloudify_agent.set_execution_params() cloudify_agent.set_default_values() cloudify_agent.set_installation_params(None) self.assertDictEqual(expected, cloudify_agent)
def set_default_values(self): self._set_name() self._set_network() self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', 0) self.setdefault('max_workers', 20) self.setdefault('disable_requiretty', True) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version())
def _test_prepare(self, agent_config, expected_values): cloudify_agent = CloudifyAgentConfig() cloudify_agent.set_initial_values(True, agent_config=agent_config) cloudify_agent.set_execution_params() cloudify_agent.set_default_values() cloudify_agent.set_installation_params(None) user = getpass.getuser() basedir = utils.get_home_dir(user) agent_dir = os.path.join(basedir, 'test_deployment') envdir = os.path.join(agent_dir, 'env') workdir = os.path.join(agent_dir, 'work') # This test needs to be adapted to security settings expected = { 'agent_dir': agent_dir, 'process_management': { 'name': 'init.d' if os.name == 'posix' else 'nssm' }, 'basedir': basedir, 'name': 'test_deployment', 'rest_host': 'localhost', 'broker_ip': 'localhost', 'heartbeat': None, 'queue': 'test_deployment', 'envdir': envdir, 'user': user, 'local': True, 'install_method': 'local', 'disable_requiretty': True, 'env': {}, 'fabric_env': {}, 'max_workers': 20, 'min_workers': 0, 'workdir': workdir, 'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH], 'windows': os.name == 'nt', 'system_python': 'python', 'bypass_maintenance': False, 'network': 'default', 'version': utils.get_agent_version() } expected.update(expected_values) self.maxDiff = None self.assertDictEqual(expected, cloudify_agent)
def install_script(self, add_ssl_cert=True): """Render the agent installation script. :return: Install script content :rtype: str """ template = self._get_template(self.install_script_template) # Called before creating the agent env to populate all the variables if add_ssl_cert: rest_cert = self.cloudify_agent['rest_ssl_cert'].strip() broker_cert = self.cloudify_agent['broker_ssl_cert'].strip() certs = [rest_cert] if broker_cert and broker_cert != rest_cert: certs.append(broker_cert) cert_content = '\n'.join(certs) else: cert_content = '' remote_ssl_cert_path = self._get_remote_ssl_cert_path() # Called before rendering the template to populate all the variables daemon_env = self._create_agent_env() return template.render( conf=self.cloudify_agent, daemon_env=daemon_env, pm_options=self._create_process_management_options(), process_management=self.cloudify_agent['process_management'], custom_env=self.custom_env, custom_env_path=self.custom_env_path, file_server_url=self.file_server_url, configure_flags=self._configure_flags(), ssl_cert_content=cert_content, ssl_cert_path=remote_ssl_cert_path, auth_token_header=CLOUDIFY_TOKEN_AUTHENTICATION_HEADER, auth_token_value=ctx.rest_token, install=not self.cloudify_agent.is_provided, configure=True, start=True, add_ssl_cert=add_ssl_cert, tmpdir=self.cloudify_agent.tmpdir, debug_flag='--debug' if self.cloudify_agent.get( 'log_level', '').lower() == 'debug' else '', version=utils.get_agent_version() )
def create_windows_installer(config, logger): version_info = get_agent_version().split('-') version = version_info[0] if len(version_info) == 1: prerelease = 'ga' agent_name_suffix = version else: prerelease = version_info[1] agent_name_suffix = '{0}-{1}'.format(version, prerelease) temp_agent_path = os.path.join( os.getcwd(), 'cloudify-windows-agent-{0}.exe'.format(agent_name_suffix)) if not os.path.exists(get_windows_built_agent_path()): runner = LocalCommandRunner() agent_builder = os.path.join(get_source_uri(), 'packaging', 'windows', 'win_agent_builder.ps1') # Run the agent builder with current version and prerelease, '.' dev # branch (so that the repo won't be redownloaded) and no upload flag. runner.run( [ 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\' 'powershell.exe', agent_builder, version, prerelease, '.', '', ], cwd=os.path.join(get_source_uri(), '..'), stdout_pipe=False, stderr_pipe=False, ) shutil.copy( get_windows_built_agent_path(), temp_agent_path, )
def create_agent_package(directory, config, package_logger=None): if package_logger is None: package_logger = logger package_logger.info('Changing directory into {0}'.format(directory)) original = os.getcwd() try: package_logger.info('Creating Agent Package') os.chdir(directory) if platform.system() == 'Linux': packager.create(config=config, config_file=None, force=False, verbose=False) distname, _, distid = platform.dist() return '{0}-{1}-agent.tar.gz'.format(distname, distid) elif platform.system() == 'Windows': create_windows_installer(config, logger) return 'cloudify-windows-agent-{}.exe'.format(get_agent_version()) else: raise NonRecoverableError('Platform not supported: {0}'.format( platform.system())) finally: os.chdir(original)
def _test_prepare(self, agent_config, expected_values, context=None): user = getpass.getuser() basedir = utils.get_home_dir(user) agent_dir = os.path.join(basedir, 'test_deployment') envdir = os.path.join(agent_dir, 'env') workdir = os.path.join(agent_dir, 'work') # This test needs to be adapted to security settings expected = { 'agent_dir': agent_dir, 'process_management': { 'name': 'init.d' if os.name == 'posix' else 'nssm' }, 'basedir': basedir, 'name': 'test_deployment', 'rest_host': ['127.0.0.1'], 'broker_ip': ['127.0.0.1'], 'broker_ssl_cert': agent_ssl_cert.DUMMY_CERT, 'heartbeat': None, 'queue': 'test_deployment', 'envdir': envdir, 'user': user, 'local': True, 'install_method': 'local', 'disable_requiretty': True, 'env': {}, 'fabric_env': {}, 'file_server_url': 'http://127.0.0.1:80/resources', 'max_workers': 5, 'min_workers': 0, 'workdir': workdir, 'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH], 'windows': os.name == 'nt', 'system_python': 'python', 'bypass_maintenance': False, 'network': 'default', 'version': utils.get_agent_version(), 'node_instance_id': 'test_node', 'log_level': 'info', 'log_max_bytes': 5242880, 'log_max_history': 7, 'rest_ssl_cert': agent_ssl_cert.DUMMY_CERT, 'tenant': { 'name': 'default_tenant', 'rabbitmq_username': '******', 'rabbitmq_password': '******', 'rabbitmq_vhost': '/' } } expected.update(expected_values) self.maxDiff = None context = context or {} ctx = mock_context(**context) patches = [ patch('cloudify_agent.installer.config.agent_config.ctx', ctx), patch('cloudify.utils.ctx', mock_context()), patch('cloudify.utils.get_manager_name', return_value='cloudify') ] # it's originally a string because it comes from envvars if expected['rest_port'] != '443': patches.append( patch('cloudify.utils.get_manager_file_server_scheme', return_value='http') ) for p in patches: p.start() self.addCleanup(p.stop) cloudify_agent = CloudifyAgentConfig() cloudify_agent.set_initial_values( True, agent_config=agent_config) cloudify_agent.set_execution_params() cloudify_agent.set_default_values() cloudify_agent.set_installation_params(None) self.assertDictEqual(expected, cloudify_agent)
def get_windows_built_agent_path(): return ('C:\\projects\\cloudify-agent\\packaging\\windows\\packaging\\' 'output\\cloudify-windows-agent_{}.exe'.format( get_agent_version()))
def _test_prepare(agent_ssl_cert, agent_config, expected_values, context=None): user = getpass.getuser() is_windows = os.name == 'nt' basedir = utils.get_agent_basedir(is_windows) agent_dir = os.path.join(basedir, 'test_deployment') envdir = os.path.join(agent_dir, 'env') workdir = os.path.join(agent_dir, 'work') # This test needs to be adapted to security settings expected = { 'agent_dir': agent_dir, 'process_management': { 'name': 'init.d' if os.name == 'posix' else 'nssm' }, 'basedir': basedir, 'name': 'test_deployment', 'rest_host': ['127.0.0.1'], 'broker_ip': ['127.0.0.1'], 'broker_ssl_cert': agent_ssl_cert.DUMMY_CERT, 'heartbeat': None, 'queue': 'test_deployment', 'envdir': envdir, 'user': user, 'local': True, 'install_method': 'local', 'disable_requiretty': True, 'env': {}, 'fabric_env': {}, 'file_server_url': 'https://127.0.0.1:80/resources', 'max_workers': 5, 'min_workers': 0, 'workdir': workdir, 'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH], 'windows': is_windows, 'system_python': 'python', 'bypass_maintenance': False, 'network': 'default', 'version': utils.get_agent_version(), 'node_instance_id': 'test_node', 'log_level': 'info', 'log_max_bytes': 5242880, 'log_max_history': 7, 'rest_ssl_cert': agent_ssl_cert.DUMMY_CERT, 'tenant': { 'name': 'default_tenant', 'rabbitmq_username': '******', 'rabbitmq_password': '******', 'rabbitmq_vhost': '/' } } expected.update(expected_values) # port is originally a string because it comes from envvars with agent_config_patches(agent_ssl_cert, expected['rest_port'] == '443', context): cloudify_agent = CloudifyAgentConfig() cloudify_agent.set_initial_values( True, agent_config=agent_config) cloudify_agent.set_execution_params() cloudify_agent.set_default_values() cloudify_agent.set_installation_params(None) assert expected == cloudify_agent
def cfy_agent_path(self): version = utils.get_agent_version() return ('"C:\\Program Files\\' 'Cloudify {} Agents\\Scripts\\cfy-agent"'.format(version))