def _assert_valid_token_authenticates(self): user_pass_header = util.get_auth_header(username='******', password='******') client = CloudifyClient(host=self.env.management_ip, headers=user_pass_header) token_header = util.get_auth_header(token=client.tokens.get().value) client = CloudifyClient(self.env.management_ip, headers=token_header) response = client.manager.get_status() if not response['status'] == 'running': raise RuntimeError('Failed to get manager status using token')
def _get_rest_client(manager_ip): creds = '{0}:{1}'.format(env['manager_user'], env['manager_password']) headers = { 'Authorization': 'Basic {0}'.format(urlsafe_b64encode(creds)), 'Tenant': env['manager_tenant'] } return CloudifyClient(host=manager_ip, headers=headers)
def execute_shared_resource_workflow(workflow_id, parameters, wf_timeout, redirect_logs): if not _verify_shared_resource_node(): raise NonRecoverableError('Tried to execute "{0}" workflow on a non ' 'SharedResource node "{1}"'.format( workflow_id, ctx.target.node.id)) ctx.logger.info("Setting up required input for executing workflow on" "a SharedResource.") # Cloudify client setup client_config = _get_target_shared_resource_client() if client_config: http_client = CloudifyClient(client_config) else: http_client = manager.get_rest_client() target_deployment_id = ( ctx.target.node.properties['resource_config']['deployment']['id']) # Wait for the deployment to finish any executions ctx.logger.info( 'Waiting until all currently running executions on "{0}" ' 'SharedResource deployment finish.'.format(target_deployment_id)) if not poll_with_timeout(lambda: is_all_executions_finished( http_client, target_deployment_id), timeout=wf_timeout, expected_result=True): return ctx.operation.retry( 'The "{0}" deployment is not ready for ' 'workflow execution.'.format(target_deployment_id)) ctx.logger.info('Starting execution of "{0}" workflow for "{1}" ' 'SharedResource deployment'.format(workflow_id, target_deployment_id)) execution = http_client.executions.start( deployment_id=target_deployment_id, workflow_id=workflow_id, parameters=parameters, allow_custom_parameters=True) ctx.logger.debug('Execution for "{0}" on "{1}" deployment response is:' ' {2}.'.format(workflow_id, target_deployment_id, execution)) execution_id = execution['id'] if not verify_execution_state(http_client, execution_id, target_deployment_id, redirect_logs, workflow_state='terminated', instance_ctx=ctx.target.instance): raise NonRecoverableError('Execution "{0}" failed for "{1}" ' 'deployment.'.format(execution_id, target_deployment_id)) ctx.logger.info('Execution succeeded for "{0}" SharedResource ' 'deployment of "{1}" workflow'.format( target_deployment_id, workflow_id)) populate_runtime_with_wf_results(http_client, target_deployment_id, ctx.target.instance) return True
def __init__(self, operation_inputs): """ Sets the properties that all operations need. :param operation_inputs: The inputs from the operation. """ full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() # Cloudify client setup self.client_config = self._get_desired_operation_input( 'client', operation_inputs) if self.client_config: self.client = CloudifyClient(**self.client_config) else: self.client = manager.get_rest_client() self.plugins = self._get_desired_operation_input( 'plugins', operation_inputs) self.secrets = self._get_desired_operation_input( 'secrets', operation_inputs) self.config = self._get_desired_operation_input( 'resource_config', operation_inputs) # Blueprint-related properties self.blueprint = self.config.get('blueprint', {}) self.blueprint_id = self.blueprint.get('id') or ctx.instance.id self.blueprint_file_name = self.blueprint.get('main_file_name') self.blueprint_archive = self.blueprint.get('blueprint_archive') # Deployment-related properties runtime_deployment_prop = ctx.instance.runtime_properties.get( 'deployment', {}) runtime_deployment_id = runtime_deployment_prop.get('id') self.deployment = self.config.get('deployment', {}) self.deployment_id = (runtime_deployment_id or self.deployment.get('id') or ctx.instance.id) self.deployment_inputs = self.deployment.get('inputs', {}) self.deployment_capabilities = self.deployment.get('capabilities') self.deployment_logs = self.deployment.get('logs', {}) self.deployment_auto_suffix = self.deployment.get( 'auto_inc_suffix', False) # Execution-related properties self.workflow_id = operation_inputs.get( 'workflow_id', 'create_deployment_environment') self.workflow_state = operation_inputs.get('workflow_state', 'terminated') # Polling-related properties self.interval = operation_inputs.get('interval', POLLING_INTERVAL) self.state = operation_inputs.get('state', 'terminated') self.timeout = operation_inputs.get('timeout', EXECUTIONS_TIMEOUT) # Inter-Deployment Dependency identifier self._inter_deployment_dependency = create_deployment_dependency( dependency_creator_generator(COMPONENT, ctx.instance.id), ctx.deployment.id)
def get_client(_host, _username, _password, _tenant): config = { 'host': _host, 'username': _username, 'password': _password, 'tenant': _tenant } return CloudifyClient(**config)
def _assert_unauthorized_user_fails(self): client = CloudifyClient(host=self.env.management_ip, headers=util.get_auth_header( username='******', password='******')) self.assertRaisesRegexp(UserUnauthorizedError, '401: user unauthorized', client.manager.get_status)
def __init__(self, operation_inputs): """ Sets the properties that all operations need. :param operation_inputs: The inputs from the operation. """ full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() self.client_config = get_desired_value('client', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) if self.client_config: self.client = CloudifyClient(**self.client_config) else: self.client = manager.get_rest_client() self.config = get_desired_value('resource_config', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) # Blueprint-related properties self.blueprint = self.config.get('blueprint', {}) self.blueprint_id = self.blueprint.get('id') or ctx.instance.id self.blueprint_file_name = self.blueprint.get('main_file_name') self.blueprint_archive = self.blueprint.get('blueprint_archive') # Deployment-related properties self.deployment = self.config.get('deployment', {}) self.deployment_id = self.deployment.get('id') or ctx.instance.id self.deployment_inputs = self.deployment.get('inputs') self.deployment_outputs = self.deployment.get('outputs') self.deployment_logs = self.deployment.get('logs', {}) # Node-instance-related properties self.node_instance_proxy = self.config.get('node_instance') # Execution-related properties self.workflow_id = \ operation_inputs.get('workflow_id', 'create_deployment_environment') self.workflow_state = \ operation_inputs.get( 'workflow_state', 'terminated') self.reexecute = \ self.config.get('reexecute') \ or ctx.instance.runtime_properties.get('reexecute') \ or False # Polling-related properties self.interval = operation_inputs.get('interval', POLLING_INTERVAL) self.state = operation_inputs.get('state', 'terminated') self.timeout = \ operation_inputs.get( 'timeout', EXECUTIONS_TIMEOUT if 'execute_start' else DEPLOYMENTS_TIMEOUT)
def get_cfy_manager4_active(config): for i in config['cloudify_config']['cfy4_ips']: try: rest_client = CloudifyClient( host=i, **config['cloudify_config']['rest_client']) if rest_client.cluster.nodes.list(): return i except: pass
def setUp(self): super(WaitForExecutionTests, self).setUp() self.client = CloudifyClient() time_patcher = patch('cloudify_cli.execution_events_fetcher.time') self.time = time_patcher.start() self.addCleanup(time_patcher.stop) # prepare mock time.time() calls - return 0, 1, 2, 3... self.time.time.side_effect = count(0)
def get_cfy_client(): creds = "{}:{}".format(settings.CFY_MANAGER_USERNAME, settings.CFY_MANAGER_PASSWORD) creds_enc = base64.urlsafe_b64encode(creds.encode("utf-8")) headers = {"Authorization": "Basic {}".format(creds_enc)} return CloudifyClient(host=settings.CFY_MANAGER_URL, protocol=settings.CFY_MANAGER_PROTOCOL, cert=settings.CFY_MANAGER_CACERT, headers=headers)
def test_ssl(cfy, manager, module_tmpdir, attributes, ssh_key, logger): cert_path = join(module_tmpdir, '.cloudify', 'profiles', manager.ip_address, 'public_rest_cert.crt') _generate_external_cert(manager, logger) _download_external_cert(manager, logger, local_cert_path=cert_path) cfy.profiles.set('-c', cert_path) assert 'SSL disabled' in cfy.ssl.status() current_profile = cfy.profiles.show() assert ' 80 ' in current_profile assert ' http ' in current_profile cfy.ssl.enable() cfy.profiles.set('--ssl', 'on', '--skip-credentials-validation') time.sleep(5) assert 'SSL enabled' in cfy.ssl.status() current_profile = cfy.profiles.show() assert ' 443 ' in current_profile assert ' https ' in current_profile _manager_client = manager.client ssl_client = CloudifyClient(username='******', password='******', host=manager.ip_address, tenant='default_tenant', protocol='https', cert=cert_path) manager.client = ssl_client if not is_community(): tenant_name = 'ssl_tenant' cfy.users.create('ssl_user', '-p', 'ssl_pass') cfy.tenants.create(tenant_name) cfy.tenants('add-user', 'ssl_user', '-t', tenant_name, '-r', DEFAULT_TENANT_ROLE) hello_world = centos_hello_world(cfy, manager, attributes, ssh_key, logger, module_tmpdir) hello_world.upload_and_verify_install() cfy.ssl.disable() cfy.profiles.set('--ssl', 'off', '--skip-credentials-validation') time.sleep(5) assert 'SSL disabled' in cfy.ssl.status() current_profile = cfy.profiles.show() assert ' 80 ' in current_profile assert ' http ' in current_profile manager.client = _manager_client hello_world.uninstall() hello_world.delete_deployment()
def create_snapshot(config, active_manager, snapshot_id, logger): client = CloudifyClient(host=active_manager, **config['cloudify_config']['rest_client']) execution = client.snapshots.create( snapshot_id, include_metrics=False, include_credentials=True, # include_logs=True, # include_events=True ) wait_for_terminated_status(client, execution, logger)
def get_rest_client(rest_host, headers, ssl_cert=None, rest_port=constants.DEFAULT_PORT, rest_protocol=constants.DEFAULT_PROTOCOL, trust_all=False): return CloudifyClient(host=rest_host, port=rest_port, protocol=rest_protocol, headers=headers, cert=ssl_cert, trust_all=trust_all)
def _reserve_shared_list_item(ctx, **kwargs): workflow_id = 'execute_operation' reserve_params = { 'operation': 'cloudify.interfaces.operations.reserve', 'allow_kwargs_override': True, 'operation_kwargs': { 'reservation_id': ctx.source.instance.id } } execute_workflow(workflow_id, reserve_params) # Cloudify client setup client_config = _get_target_shared_resource_client() if client_config: http_client = CloudifyClient(**client_config) else: http_client = manager.get_rest_client() resources_list_node_id = kwargs.get('resources_list_node_id', None) target_deployment_id = ( ctx.target.node.properties['resource_config']['deployment']['id']) resources_list_instance = None if resources_list_node_id: resources_list_instance = http_client.node_instances.list( deployment_id=target_deployment_id, node_id=resources_list_node_id)[0] else: # if resources_list_node_id is not specified, first matching node # will be used for node in http_client.nodes.list(deployment_id=target_deployment_id): if node.type == 'cloudify.nodes.resources.List': resources_list_instance = http_client.node_instances.list( deployment_id=target_deployment_id, node_id=node.id)[0] break ctx.source.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = \ resources_list_instance.runtime_properties.get( RESERVATIONS_PROPERTY).get(ctx.source.instance.id) ctx.logger.debug('Reservation successful: {0}\ \nLeft resources: {1}\ \nReservations: {2}'.format( ctx.source.instance.runtime_properties.get( SINGLE_RESERVATION_PROPERTY), resources_list_instance.runtime_properties.get( FREE_RESOURCES_LIST_PROPERTY), resources_list_instance.runtime_properties.get(RESERVATIONS_PROPERTY)))
def __init__(self, operation_inputs): full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() # Cloudify client setup self.client_config = self._get_desired_operation_input( 'client', operation_inputs) if self.client_config: self.client = CloudifyClient(**self.client_config) # for determining an external client: manager_ips = [ mgr.private_ip for mgr in manager.get_rest_client().manager.get_managers() ] internal_hosts = ({'127.0.0.1', 'localhost'} | set(manager_ips)) host = {self.client.host} if type(self.client.host) == str \ else set(self.client.host) self.is_external_host = not (host & internal_hosts) else: self.client = manager.get_rest_client() self.is_external_host = False self.config = self._get_desired_operation_input( 'resource_config', operation_inputs) self.deployment = self.config.get('deployment', '') self.deployment_id = self.deployment.get('id', '') self._inter_deployment_dependency = create_deployment_dependency( dependency_creator_generator(SHARED_RESOURCE, ctx.instance.id), ctx.deployment.id, self.deployment_id) if self.is_external_host: self._local_dependency_params = \ self._inter_deployment_dependency.copy() self._local_dependency_params['target_deployment'] = ' ' self._local_dependency_params['external_target'] = { 'deployment': self.deployment_id, 'client_config': self.client_config } self._inter_deployment_dependency['external_source'] = { 'deployment': ctx.deployment.id, 'tenant': ctx.tenant_name, 'host': manager_ips }
def __init__(self, operation_inputs): full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() # Cloudify client setup self.client_config = self._get_desired_operation_input( 'client', operation_inputs) if self.client_config: self.client = CloudifyClient(**self.client_config) else: self.client = manager.get_rest_client() self.config = self._get_desired_operation_input( 'resource_config', operation_inputs) self.deployment = self.config.get('deployment', '') self.deployment_id = self.deployment.get('id', '')
def get_client_response(_client_name, _client_attribute, _client_args): """request some Cloudify Client method :param _client_name: the name of the client such as `deployments` :param _client_attribute: the name of the method such as `list` :param _client_args: whatever keyword args to send to the client. :type _client_name: string :type _client_attribute: string :type _client_args: dict :returns: returns the request response :rtype: dict """ client = CloudifyClient( host=os.environ['ECOSYSTEM_SESSION_MANAGER_IP'], username=os.environ.get('ECOSYSTEM_SESSION_MANAGER_USER', 'admin'), password=os.environ.get('ECOSYSTEM_SESSION_PASSWORD', 'admin'), tenant=os.environ.get('ECOSYSTEM_SESSION_MANAGER_TENANT', 'default_tenant')) _generic_client = \ getattr(client, _client_name) try: _client_attribute_left, _client_attribute_right = \ _client_attribute.split('.') except ValueError: _special_client = \ getattr(_generic_client, _client_attribute) else: _special_client = \ getattr(_generic_client, _client_attribute_left) _special_client = \ getattr(_special_client, _client_attribute_right) try: response = _special_client(**_client_args) except CloudifyClientError: raise else: return response
def wrapper(*args, **kwargs): manager_host = os.environ[CLOUDIFY_HOST_ENV] manager_user = os.environ[CLOUDIFY_USERNAME_ENV] manager_password = os.environ[CLOUDIFY_PASSWORD_ENV] manager_tenant = os.environ.get(CLOUDIFY_TENANT_ENV, DEFAULT_TENANT_NAME) use_ssl = _use_ssl() ssl_trust_all = get_ssl_trust_all() # If user wants to trust all certificates, then disable the warning # about it and assume (and hope) they know what they're doing. if use_ssl and ssl_trust_all: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) client = CloudifyClient( host=manager_host, username=manager_user, password=manager_password, tenant=manager_tenant, protocol=SECURED_PROTOCOL if use_ssl else DEFAULT_PROTOCOL, trust_all=ssl_trust_all) kwargs['client'] = client return func(*args, **kwargs)
def main(): global binders, binder, worker global database, client, binder_name host, port, tenant, user, password, binder_name, binder_creds = parseargs() if not binder_name in binders: print "Binder "+binder_name+" not found" sys.exit(1) binder = binders[binder_name](logger) binder.connect(binder_creds) database = db.Database('cfy.db') client = CloudifyClient(host=host, port=port, trust_all=True, username=user, password=password, tenant=tenant) worker = Syncworker(database, client, logger) worker.start() signal.signal(signal.SIGINT, signal_handler) app.run(host='0.0.0.0', port=BROKER_PORT, threaded=True)
def _get_external_clients(nodes: list, manager_ips: list): client_config = None target_deployment = None for node in nodes: if node['type'] in [ 'cloudify.nodes.Component', 'cloudify.nodes.SharedResource' ]: client_config = node['properties'].get('client') target_deployment = node['properties'].get('resource_config').get( 'deployment') break external_client = None if client_config: internal_hosts = ({'127.0.0.1', 'localhost'} | set(manager_ips)) host = client_config['host'] host = {host} if type(host) == str else set(host) if not (host & internal_hosts): external_client = CloudifyClient(**client_config) return external_client, client_config, \ target_deployment.get('id') if target_deployment else None
def add_secrets(client, deployment_id, node_id, file, password, **kwargs): with open(file, 'r') as input_file: secrets = yaml.load(input_file) nodes_map = {} node_instances_map = {} nodes = client.nodes.list(deployment_id=deployment_id, sort='id') for node in nodes: nodes_map[node.id] = node all_node_instances = client.node_instances.list( deployment_id=deployment_id) for node_instance in all_node_instances: node_instances_map[node_instance.id] = node_instance node_instances = client.node_instances.list(deployment_id=deployment_id, node_id=node_id) for ni in node_instances: public_ip = None for rel in ni.relationships: target_node_id = rel['target_name'] target_node = nodes_map[target_node_id] if _is_virtual_ip_node(target_node): target_node_instance = node_instances_map[rel['target_id']] public_ip = target_node_instance.runtime_properties[ 'aws_resource_id'] break if not public_ip: raise Exception() current_client = CloudifyClient(host=public_ip, username='******', password=password, tenant='default_tenant') print "Creating on: {}".format(public_ip) for key, value in secrets.iteritems(): print "\t{}...".format(key) current_client.secrets.create(key, value, True)
def run_test(): try: manager_ip = env['manager_ip'] url_version_postfix = env['url_version_postfix'] rest_client = CloudifyClient(host=manager_ip) rest_client_url = rest_client._client.url expected_rest_client_url = 'http://{0}:80{1}'.format( manager_ip, url_version_postfix) if rest_client_url == expected_rest_client_url: return { 'failed': False, 'details': rest_client.manager.get_status() } else: return { 'failed': True, 'details': 'rest client url is {0} instead of {1}'.format( rest_client_url, expected_rest_client_url) } except Exception as e: return {'failed': True, 'details': str(e)}
def __init__(self, operation_inputs): full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() # Cloudify client setup self.client_config = self._get_desired_operation_input( 'client', operation_inputs) if self.client_config: self.client = CloudifyClient(**self.client_config) else: self.client = manager.get_rest_client() self.config = self._get_desired_operation_input( 'resource_config', operation_inputs) self.deployment = self.config.get('deployment', '') self.deployment_id = self.deployment.get('id', '') self._inter_deployment_dependency = create_deployment_dependency( dependency_creator_generator(SHARED_RESOURCE, ctx.instance.id), ctx.deployment.id, self.deployment_id )
def setUp(self): super(ExecutionEventsFetcherTest, self).setUp() self.client = CloudifyClient() self.client.executions.get = MagicMock() self.client.events.list = self._mock_list
def setUp(self): self.client = CloudifyClient() self.client.executions.get = MagicMock() self.client.events.get = self._mock_get
def _get_rest_client(managers, manager_id): manager_desc = managers['managers'][manager_id] return CloudifyClient(**manager_desc)
def __init__(self, operation_inputs): """ Sets the properties that all operations need. :param operation_inputs: The inputs from the operation. """ full_operation_name = ctx.operation.name self.operation_name = full_operation_name.split('.').pop() # These should not make their way into the Operation inputs. os.environ['_PAGINATION_OFFSET'] = \ str(operation_inputs.pop('pagination_offset', 0)) os.environ['_PAGINATION_SIZE'] = \ str(operation_inputs.pop('pagination_size', 1000)) # cloudify client self.client_config = get_desired_value('client', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) if self.client_config: self.client = CloudifyClient(**self.client_config) else: self.client = manager.get_rest_client() # plugins self.plugins = get_desired_value('plugins', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) # secrets self.secrets = get_desired_value('secrets', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) # resource_config self.config = get_desired_value('resource_config', operation_inputs, ctx.instance.runtime_properties, ctx.node.properties) # Blueprint-related properties self.blueprint = self.config.get('blueprint', {}) self.blueprint_id = self.blueprint.get('id') or ctx.instance.id self.blueprint_file_name = self.blueprint.get('main_file_name') self.blueprint_archive = self.blueprint.get('blueprint_archive') # Deployment-related properties self.deployment = self.config.get('deployment', {}) self.deployment_id = self.deployment.get('id') or ctx.instance.id self.deployment_inputs = self.deployment.get('inputs', {}) self.deployment_outputs = self.deployment.get('outputs', {}) self.deployment_logs = self.deployment.get('logs', {}) # Node-instance-related properties self.node_instance_proxy = self.config.get('node_instance') # Execution-related properties self.workflow_id = \ operation_inputs.get('workflow_id', 'create_deployment_environment') self.workflow_state = \ operation_inputs.get( 'workflow_state', 'terminated') self.reexecute = \ self.config.get('reexecute') \ or ctx.instance.runtime_properties.get('reexecute') \ or False # Polling-related properties self.interval = operation_inputs.get('interval', POLLING_INTERVAL) self.state = operation_inputs.get('state', 'terminated') self.timeout = operation_inputs.get('timeout', EXECUTIONS_TIMEOUT) # This ``execution_id`` will be set once execute workflow done # successfully self.execution_id = None
def run_workflow(*args, **kwargs): # get current context ctx = kwargs.get('ctx', CloudifyContext) if ctx.type != context.DEPLOYMENT: raise cfy_exc.NonRecoverableError( "Called with wrong context: {ctx_type}".format(ctx_type=ctx.type)) # register logger file logger_file = kwargs.get('logger_file') if logger_file: fh = logging.FileHandler(logger_file) fh.setLevel(logging.DEBUG) fh.setFormatter( logging.Formatter(fmt="%(asctime)s %(levelname)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")) ctx.logger.addHandler(fh) # check inputs if len(args): inputs = args[0] else: inputs = kwargs.get('inputs', {}) # dump current parameters ctx.logger.debug( "Workflow run called with {inputs} and args '{args}' and kwargs:" " {kwargs}".format(inputs=repr(obfuscate_passwords(inputs)), args=repr(obfuscate_passwords(args)), kwargs=repr(obfuscate_passwords(kwargs)))) # check deployment id, strange if empty but lets check deployment_id = inputs.get('deployment_id') if not deployment_id: ctx.logger.error("Deployment id is undefined") return # get workflow name workflow_name = kwargs.get('workflow_for_run') if not workflow_name: ctx.logger.error("Workflow for run is undefined") return # get workflow params workflow_params = kwargs.get('workflow_params', {}) # get credentials for rest connection to manager, can be used for run # workflow with different user/tenant client_config = kwargs.get('client_config', {}) if client_config: client = CloudifyClient(**client_config) else: # get client from current manager client = manager.get_rest_client() # get deployment information deployment = client.deployments.get(deployment_id=deployment_id) if not deployment: ctx.logger.error("Deployment disappear.") return # get filter dictionary filter_by = kwargs.get('filter_by', []) ctx.logger.debug("Filter {filter_by}".format(filter_by=repr(filter_by))) if filter_by: # get values from deployment information, use _get_ # for support 5+ managers inputs['deployment_inputs'] = deployment.get('inputs', {}) inputs['deployment_outputs'] = deployment.get('outputs', {}) inputs['deployment_capabilities'] = deployment.get('capabilities', {}) if not _check_filter(ctx=ctx, filter_by=filter_by, inputs=inputs): ctx.logger.debug("Event skiped by filter.") return # mark that we going to run to logs ctx.logger.info("Going to {workflow_name} on {deployment_id}".format( workflow_name=workflow_name, deployment_id=deployment_id)) # send uninstall event client.executions.start(deployment_id=deployment_id, workflow_id=workflow_name, **workflow_params)
def set_rest_client(self): self.client = CloudifyClient(host=self.env.management_ip, headers=util.get_auth_header( username='******', password='******'))
def test_concurrent_workflows(cfy, manager, logger): if not envvars_provided: raise RuntimeError('Not all required envvars have been provided') _set_max_workers_num(manager) exec_params = { 'url': url, 'cycle_num': cycle_num, 'cycle_sleep': cycle_sleep } if not os.path.exists(os.path.dirname(STAT_FILE_PATH)): os.makedirs(os.path.dirname(STAT_FILE_PATH)) logger.info('Test parameters:') logger.info('******************') logger.info('Total number of deployments: {0}'.format(num_of_deployments)) logger.info('Create concurrent deployments number: {0}'.format( concurrent_create_deployments)) logger.info( 'Number of concurrent workflows: {0}'.format(concurrent_workflows)) logger.info('Number of cycles in each deployment: {0}'.format(cycle_num)) logger.info('Sleep milisec in each deployment: {0}'.format(cycle_sleep)) logger.info('******************') logger.info('Preparing test environment...') client = CloudifyClient(username='******', password='******', host=manager.ip_address, tenant='default_tenant') deployments = _prepare_test_env(cfy, manager, client, logger) logger.info('Preparing test environment is completed.') time.sleep(5) stat_thread = Thread(target=statistics, args=( manager, client, logger, )) stat_thread.daemon = True stat_thread.start() logger.info('Running concurrent executions ' 'and monitoring manager resources...') workflow_count = 0 for i in range(len(deployments)): threads = [] if workflow_count + concurrent_workflows < len(deployments): for j in range(concurrent_workflows): workflow = _get_workflow() t = Thread(target=execution, args=( client, deployments[workflow_count], workflow, exec_params, logger, )) threads.append(t) workflow_count += 1 logger.info('Running {0} workflow'.format(workflow)) for t in threads: t.start() for t in threads: t.join() time.sleep(cycle_num * cycle_sleep / 1000) logger.info('Terminated workflows: {0}'.format( len([ e for e in client.executions.list(_get_all_results=True, status='terminated') ]))) logger.info('Failed workflows: {0}'.format( len([ e for e in client.executions.list(_get_all_results=True, status='failed') ]))) logger.info('Pending workflows: {0}'.format( len([ e for e in client.executions.list(_get_all_results=True, status='pending') ])))