def test_list_agents_all_tenants(self): self.client.tenants.create('mike') mike_client = create_rest_client(tenant='mike') deployment1, _ = self.deploy_application(resource( "dsl/agent_tests/with_agent.yaml"), deployment_id='at1') deployment2 = self.deploy(resource("dsl/agent_tests/with_agent.yaml"), deployment_id='at2', client=mike_client) execution2 = mike_client.executions.start(deployment2.id, 'install') self.wait_for_execution_to_end(execution2, client=mike_client) # all_tenants is false by default agent_list = self.client.agents.list() self.assertEqual(len(agent_list.items), 1) self.assertEqual(agent_list.metadata['pagination']['total'], 1) self.assertEqual(agent_list.items[0]['deployment'], 'at1') self.assertEqual(agent_list.items[0]['tenant_name'], 'default_tenant') # all_tenants is true agent_list = self.client.agents.list(_all_tenants=True) self.assertEqual(len(agent_list.items), 2) self.assertEqual(agent_list.metadata['pagination']['total'], 2) self.assertEqual({agent['deployment'] for agent in agent_list.items}, {'at1', 'at2'}) self.assertEqual({agent['tenant_name'] for agent in agent_list.items}, {'default_tenant', 'mike'}) self.undeploy_application(deployment1.id) uninstall2 = mike_client.executions.start(deployment2.id, 'uninstall') self.wait_for_execution_to_end(uninstall2, client=mike_client) self.delete_deployment(deployment2.id, validate=True, client=mike_client)
def test_snapshot_with_agents_multitenant(self): self.client.tenants.create('mike') mike_client = create_rest_client(tenant='mike') self._deploy_with_agents_multitenant(mike_client) snapshot_id = self._create_snapshot() self._undeploy_multitenant(mike_client) self._restore_snapshot_multitenant(snapshot_id)
def execute_workflow(workflow_name, deployment_id, parameters=None, timeout_seconds=240, wait_for_execution=True, force=False, queue=False, **kwargs): """ A blocking method which runs the requested workflow """ client = test_utils.create_rest_client() execution = client.executions.start(deployment_id, workflow_name, parameters=parameters or {}, force=force, queue=queue, **kwargs) if wait_for_execution: BaseTestCase.wait_for_execution_to_end( execution, timeout_seconds=timeout_seconds) return execution
def _create_rest_client(**kwargs): if kwargs.get('ssl'): kwargs['port'] = constants.SECURED_REST_PORT kwargs['protocol'] = constants.SECURED_REST_PROTOCOL else: kwargs['port'] = constants.DEFAULT_REST_PORT kwargs['protocol'] = constants.DEFAULT_REST_PROTOCOL return test_utils.create_rest_client(**kwargs)
def test_resume_retried_user(self): # like test_resume_cancelled_resumable, but with a non-admin user username = '******' password = '******' self._create_user(username, password, 'default_tenant') user_client = create_rest_client(username=username, password=password, tenant='default_tenant') self._resume_no_duplicates_test(user_client)
def delete_deployment(deployment_id, ignore_live_nodes=False, validate=False): client = test_utils.create_rest_client() result = client.deployments.delete(deployment_id, ignore_live_nodes=ignore_live_nodes) if validate: wait_for_deployment_deletion_to_complete(deployment_id) return result
def delete_deployment(deployment_id, ignore_live_nodes=False, validate=False, client=None): client = client or test_utils.create_rest_client() result = client.deployments.delete(deployment_id, ignore_live_nodes=ignore_live_nodes, with_logs=True) if validate: wait_for_deployment_deletion_to_complete(deployment_id, client=client) return result
def deploy(dsl_path, blueprint_id=None, deployment_id=None, inputs=None): client = test_utils.create_rest_client() if not blueprint_id: blueprint_id = str(uuid.uuid4()) blueprint = client.blueprints.upload(dsl_path, blueprint_id) if deployment_id is None: deployment_id = str(uuid.uuid4()) deployment = client.deployments.create(blueprint.id, deployment_id, inputs=inputs) test_utils.wait_for_deployment_creation_to_complete( deployment_id=deployment_id) return deployment
def deploy(dsl_path, blueprint_id=None, deployment_id=None, inputs=None): client = test_utils.create_rest_client() if not blueprint_id: blueprint_id = 'b{0}'.format(uuid.uuid4()) blueprint = client.blueprints.upload(dsl_path, blueprint_id) if deployment_id is None: deployment_id = 'd{0}'.format(uuid.uuid4()) deployment = client.deployments.create(blueprint.id, deployment_id, inputs=inputs, skip_plugins_validation=True) wait_for_deployment_creation_to_complete(deployment_id=deployment_id) return deployment
def wait_for_execution_to_end(execution, timeout_seconds=240): client = test_utils.create_rest_client() deadline = time.time() + timeout_seconds while execution.status not in Execution.END_STATES: time.sleep(0.5) execution = client.executions.get(execution.id) if time.time() > deadline: raise utils.TimeoutException( 'Execution timed out: \n{0}'.format( json.dumps(execution, indent=2))) if execution.status == Execution.FAILED: raise RuntimeError('Workflow execution failed: {0} [{1}]'.format( execution.error, execution.status)) return execution
def deploy(dsl_path, blueprint_id=None, deployment_id=None, inputs=None, wait=True, client=None, runtime_only_evaluation=False): client = client or test_utils.create_rest_client() resource_id = uuid.uuid4() blueprint_id = blueprint_id or 'blueprint_{0}'.format(resource_id) blueprint = client.blueprints.upload(dsl_path, blueprint_id) deployment_id = deployment_id or 'deployment_{0}'.format(resource_id) deployment = client.deployments.create( blueprint.id, deployment_id, inputs=inputs, skip_plugins_validation=True, runtime_only_evaluation=runtime_only_evaluation) if wait: wait_for_deployment_creation_to_complete(deployment_id, client=client) return deployment
def deploy(dsl_path=None, blueprint_id=None, deployment_id=None, inputs=None, wait=True, client=None, runtime_only_evaluation=False, blueprint_visibility=None, deployment_visibility=None): if not (dsl_path or blueprint_id): raise RuntimeWarning('Please supply blueprint path ' 'or blueprint id for deploying') client = client or test_utils.create_rest_client() resource_id = uuid.uuid4() blueprint_id = blueprint_id or 'blueprint_{0}'.format(resource_id) if dsl_path: blueprint_upload_kw = { 'path': dsl_path, 'entity_id': blueprint_id } # If not provided, use the client's default if blueprint_visibility: blueprint_upload_kw['visibility'] = blueprint_visibility blueprint = client.blueprints.upload(**blueprint_upload_kw) else: blueprint = None deployment_id = deployment_id or 'deployment_{0}'.format(resource_id) deployment_create_kw = { 'blueprint_id': blueprint.id if blueprint else blueprint_id, 'deployment_id': deployment_id, 'inputs': inputs, 'skip_plugins_validation': True, 'runtime_only_evaluation': runtime_only_evaluation } # If not provided, use the client's default if deployment_visibility: deployment_create_kw['visibility'] = deployment_visibility deployment = client.deployments.create(**deployment_create_kw) if wait: wait_for_deployment_creation_to_complete(deployment_id, client=client) return deployment
def undeploy_application(deployment_id, timeout_seconds=240, is_delete_deployment=False, parameters=None): """ A blocking method which undeploys an application from the provided dsl path. """ client = test_utils.create_rest_client() execution = client.executions.start(deployment_id, 'uninstall', parameters=parameters) BaseTestCase.wait_for_execution_to_end(execution, timeout_seconds=timeout_seconds) if execution.error and execution.error != 'None': raise RuntimeError('Workflow execution failed: {0}'.format( execution.error)) if is_delete_deployment: BaseTestCase.delete_deployment(deployment_id)
def test_ssl(self): local_cert_path = join(self.workdir, 'cert.pem') docl.copy_file_from_manager( '/etc/cloudify/ssl/cloudify_internal_ca_cert.pem', local_cert_path) ssl_client = create_rest_client( rest_port='443', cert_path=local_cert_path) # only non-ssl client works self.assertEquals('SSL disabled', self.client.manager.ssl_status()) self.assertRaises(ConnectionError, ssl_client.manager.ssl_status) # change to ssl - now only ssl client works self.client.manager.set_ssl(True) sleep(2) self.assertRaises(CloudifyClientError, self.client.manager.ssl_status) self.assertEquals('SSL enabled', ssl_client.manager.ssl_status()) # change back to non-ssl - now only non-ssl client works ssl_client.manager.set_ssl(False) sleep(2) self.assertEquals('SSL disabled', self.client.manager.ssl_status()) self.assertRaises(ConnectionError, ssl_client.manager.ssl_status)
def test_ssl(self): local_cert_path = join(self.workdir, 'cert.pem') docl.copy_file_from_manager( '/etc/cloudify/ssl/cloudify_external_cert.pem', local_cert_path) ssl_client = create_rest_client( rest_port='443', cert_path=local_cert_path) # only non-ssl client works self.assertEquals('SSL disabled', self.client.manager.ssl_status()) self.assertRaises(ConnectionError, ssl_client.manager.ssl_status) # change to ssl - now only ssl client works self.client.manager.set_ssl(True) sleep(2) self.assertRaises(CloudifyClientError, self.client.manager.ssl_status) self.assertEquals('SSL enabled', ssl_client.manager.ssl_status()) # change back to non-ssl - now only non-ssl client works ssl_client.manager.set_ssl(False) sleep(2) self.assertEquals('SSL disabled', self.client.manager.ssl_status()) self.assertRaises(ConnectionError, ssl_client.manager.ssl_status)
def upload_blueprint_resource(dsl_resource_path, blueprint_id, client=None): client = client or test_utils.create_rest_client() blueprint = get_resource(dsl_resource_path) client.blueprints.upload(blueprint, entity_id=blueprint_id)
def is_node_started(node_id): client = test_utils.create_rest_client() node_instance = client.node_instances.get(node_id) return node_instance['state'] == 'started'
def _setup_running_manager_attributes(self): self.client = test_utils.create_rest_client(host=self.env.container_ip)
def _assert_hello_world_events(self, deployment_id): rest_client = test_utils.create_rest_client() events = rest_client.events.list( deployment_id=deployment_id) self.test_case.assertGreater(len(events.items), 0)
def _setup_running_manager_attributes(self): self.client = test_utils.create_rest_client()
def _assert_hello_world_events(self, deployment_id): rest_client = test_utils.create_rest_client() events = rest_client.events.list( deployment_id=deployment_id) self.test_case.assertGreater(len(events.items), 0)
def delete_deployment(deployment_id, ignore_live_nodes=False): client = test_utils.create_rest_client() return client.deployments.delete(deployment_id, ignore_live_nodes=ignore_live_nodes)