def test_compare_app_list_with_cf(self, core_space): step("Get application list from platform") platform_app_list = Application.api_get_list(core_space.guid) step("Get application list from cf") cf_app_list = Application.cf_api_get_list_by_space(core_space.guid) step("Compare app lists from platform and cf") assert sorted(platform_app_list) == sorted(cf_app_list)
def test_cannot_push_application_twice(self, context, test_sample_apps, sample_app, api_service_admin_client): """ <b>Description:</b> Tries to push the same application twice <b>Input data:</b> - Sample application that will be pushed twice <b>Expected results:</b> - The second push is not possible <b>Steps:</b> - Application is pushed - Application is pushed again in the test itself - The second push is blocked """ step("Check that pushing the same application again causes an error") log_fixture("sample_application: update manifest") p_a = PrepApp(test_sample_apps.tapng_python_app.filepath) manifest_params = { "type": TapApplicationType.PYTHON27, "name": sample_app.name } manifest_path = p_a.update_manifest(params=manifest_params) with pytest.raises(UnexpectedResponseError) as e: Application.push( context, app_path=test_sample_apps.tapng_python_app.filepath, name=sample_app.name, manifest_path=manifest_path, client=api_service_admin_client) assert self.EXPECTED_MESSAGE_WHEN_APP_PUSHED_TWICE in str(e)
def test_non_developer_cannot_manage_app(self, context, test_org, test_space, test_org_manager, test_org_manager_client): step("Push example app as admin") cf.cf_login(test_org.name, test_space.name) example_app_path = ApplicationPath.SAMPLE_PYTHON_APP test_app = Application.push(context, space_guid=test_space.guid, source_directory=example_app_path) apps = Application.cf_api_get_list_by_space(test_space.guid) assert test_app in apps step("Add user to space as manager") space_manager = test_org_manager space_manager_client = test_org_manager_client space_manager.api_add_to_space(space_guid=test_space.guid, org_guid=test_org.guid, roles=User.SPACE_ROLES["manager"]) step("Check that manager cannot stop app") assertions.assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, test_app.api_stop, client=space_manager_client) step("Check that manager cannot start app") assertions.assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, test_app.api_start, client=space_manager_client) step("Check that manager cannot delete app") assertions.assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, test_app.api_delete, client=space_manager_client) apps = Application.cf_api_get_list_by_space(test_space.guid) assert test_app in apps
def test_step_0_push_ws2kafka2hdfs(self, test_space, class_context): step("Clone and compile ingestion app sources") github_auth = config.github_credentials() ingestion_repo = AppSources.from_github(repo_name=TapGitHub.ws_kafka_hdfs, repo_owner=self.REPO_OWNER, gh_auth=github_auth) ws2kafka_path = os.path.join(ingestion_repo.path, TapGitHub.ws2kafka) kafka2hdfs_path = os.path.join(ingestion_repo.path, TapGitHub.kafka2hdfs) ingestion_repo.compile_gradle(working_directory=kafka2hdfs_path) postfix = str(int(time.time())) self.__class__.topic_name = "topic-{}".format(postfix) step("Push application ws2kafka") self.__class__.app_ws2kafka = Application.push(class_context, space_guid=test_space.guid, source_directory=ws2kafka_path, name="ws2kafka-{}".format(postfix), bound_services=(self.KAFKA_INSTANCE_NAME,)) step("Push application kafka2hdfs") self.__class__.app_kafka2hdfs = Application.push(class_context, space_guid=test_space.guid, source_directory=kafka2hdfs_path, name="kafka2hdfs-{}".format(postfix), bound_services=(self.KAFKA_INSTANCE_NAME, self.ZOOKEEPER_INSTANCE_NAME, self.HDFS_INSTANCE_NAME, self.KERBEROS_INSTANCE_NAME), env={"TOPICS": self.topic_name, "CONSUMER_GROUP": "group-{}".format(postfix)}) assert self.app_ws2kafka.is_started is True, "ws2kafka app is not started" assert self.app_kafka2hdfs.is_started is True, "kafka2hdfs app is not started"
def test_change_app_state_in_catalog_and_delete_it( self, context, test_sample_apps, api_service_admin_client): """ <b>Description:</b> Change the application state in catalog and later delete it <b>Input data:</b> - Path to application - Admin credentials <b>Expected results:</b> - Application state can be changed in catalog - Application state can be set back via api service <b>Steps:</b> - Prepare the application and push it - Make sure the application is running - Change the state of the application via catalog - Make sure the state has changed - Stop the application via api service client and remove it - Verify the application was removed """ log_fixture("sample_application: update manifest") p_a = PrepApp(test_sample_apps.tapng_python_app.filepath) manifest_params = {"type": TapApplicationType.PYTHON27} manifest_path = p_a.update_manifest(params=manifest_params) log_fixture("Push sample application and check it's running") application = Application.push( context, app_path=test_sample_apps.tapng_python_app.filepath, name=p_a.app_name, manifest_path=manifest_path, client=api_service_admin_client) application.ensure_running() step("Check that the application has only one instance") instances = CatalogApplicationInstance.get_list_for_application( application_id=application.id) assert len(instances) == 1 updated_state = TapEntityState.FAILURE step("Update app state to {} using catalog api".format(updated_state)) catalog_api.update_instance(instance_id=instances[0].id, field_name="state", value=updated_state) step("Check that the app state was updated") app = Application.get(app_inst_id=application.id, client=api_service_admin_client) assert app.state == updated_state, "Application is not in the expected state. App state: {}".format( app.state) step("Check that the application can be deleted") application.delete() step("Check that application has been removed") apps = Application.get_list(client=api_service_admin_client) assert application not in apps
def appstack(cls, core_space): cls.step("Retrieve apps, services, and brokers present in cf") cls.cf_apps = Application.cf_api_get_list_by_space(core_space.guid) cls.cf_upsi = [ s for s in Upsi.cf_api_get_list() if s.space_guid == core_space.guid ] cls.cf_brokers = ServiceBroker.cf_api_get_list(core_space.guid) cls.step("Retrieve apps and services present on the Platform") cls.platform_apps = Application.api_get_list(core_space.guid) cls.platform_instances = ServiceInstance.api_get_list(core_space.guid)
def test_scale_application_with_zero_instances_number( self, sample_app, api_service_admin_client): """ <b>Description:</b> Tries to scale the application with zero instances number <b>Input data:</b> - Sample application - Admin credentials <b>Expected results:</b> - After scaling the application down to zero, it should stop <b>Steps:</b> - Download the application and push it to platform - Scale the app by providing zero amount of replicas - Make sure the application has stopped - Verify the number of replication and running instances """ step("Scale application with zero replicas number") replicas_number = 0 sample_app.scale(replicas=replicas_number, client=api_service_admin_client) step( "Check that application is stopped, there are zero replicas and there are no running instances" ) app = Application.get(app_inst_id=sample_app.id, client=api_service_admin_client) app.ensure_stopped() assert app.replication == replicas_number, "Application does not have expected number of replication. App " \ "replicas number: {}".format(app.replication) assert app.running_instances == replicas_number, "Application does not have expected number of running " \ "instances. App running instances number: {}"\ .format(app.running_instances)
def app_bound_psql(module_context, psql_instance, api_service_admin_client): log_fixture("psql_app: Download libraries") app_src = AppSources.from_local_path(ApplicationPath.SQL_API_EXAMPLE) p_a = PrepApp(app_src.path) log_fixture("psql_app: package sample application") if os.path.exists(ApplicationPath.SQL_API_EXAMPLE_TAR): gzipped_app_path = ApplicationPath.SQL_API_EXAMPLE_TAR else: gzipped_app_path = p_a.package_app(module_context) log_fixture("psql_app: update manifest") manifest_params = {"type": TapApplicationType.PYTHON27, "bindings": [psql_instance.name]} manifest_path = p_a.update_manifest(params=manifest_params) log_fixture("psql_app: push sample application") db_app = Application.push(module_context, app_path=gzipped_app_path, name=p_a.app_name, manifest_path=manifest_path, client=api_service_admin_client) log_fixture("psql_app: Check the application is running") db_app.ensure_running() log_fixture("psq_app: Check the application is responding") db_app.ensure_responding() return db_app
def kafka2hdfs_app(class_context, kafka_instance, hdfs_instance, kerberos_instance, api_service_admin_client): log_fixture("kafka2hdfs: download libraries") ingestion_repo = AppSources.get_repository(repo_name=TapGitHub.ws_kafka_hdfs, repo_owner=TapGitHub.intel_data) kafka2hdfs_path = os.path.join(ingestion_repo.path, TapGitHub.kafka2hdfs) log_fixture("Package kafka2hdfs app") ingestion_repo.compile_gradle(working_directory=kafka2hdfs_path) build_path = os.path.join(kafka2hdfs_path, "deploy") ingestion_repo.run_build_sh(cwd=build_path, command="./pack.sh") app_path = os.path.join(build_path, "kafka2hdfs.tar") log_fixture("kafka2hdfs: update manifest") p_a = PrepApp(build_path) manifest_params = {"bindings": [kafka_instance.name, hdfs_instance.name, kerberos_instance.name]} manifest_path = p_a.update_manifest(params=manifest_params) log_fixture("kafka2hdfs: push application") app = Application.push(class_context, app_path=app_path, name=p_a.app_name, manifest_path=manifest_path, client=api_service_admin_client) log_fixture("kafka2hdfs: Check the application is running") app.ensure_running() return app
def test_create_transfer_from_atk_model_file(self, context, test_org, ref_space, atk_virtualenv, initial_dataset): step("Get atk app from core space") atk_app = next( (app for app in Application.cf_api_get_list_by_space(ref_space.guid) if app.name == "atk"), None) if atk_app is None: raise AssertionError("Atk app not found in core space") step("Install atk client package in virtualenv") atk_virtualenv.create() atk_virtualenv.pip_install(ATKtools.get_atk_client_url( atk_app.urls[0])) step("Run atk create model script") atk_test_script_path = os.path.join("fixtures", "atk_test_scripts", "atk_create_model.py") response = atk_virtualenv.run_atk_script( atk_test_script_path, atk_app.urls[0], arguments={"--target_uri": initial_dataset.target_uri}) step("Retrieve path to model file created by atk") hdfs_model_path = response.split("hdfs_model_path: ", 1)[1] step("Create dataset by providing retrieved model file path") _, ds = data_catalog.create_dataset_from_link(context, org=test_org, source=hdfs_model_path) assert ds.source_uri == hdfs_model_path
def test_data_urls(session_context): """ Fixture with files from tests/fixtures/data_repo.py::DATA_FILES. They are accessible by url or filepath. Eg.: test_data_urls.test_transfer.url test_data_urls['test_transfer'].url test_data_urls.test_transfer.filepath """ if config.data_repo_url: return Urls(config.data_repo_url) else: log_fixture("data_repo: package sample application") p_a = PrepApp(DATA_REPO_PATH) if os.path.exists(DATA_REPO_TAR_PATH): gzipped_app_path = DATA_REPO_TAR_PATH else: gzipped_app_path = p_a.package_app(session_context) log_fixture("data_repo: update manifest") manifest_path = p_a.update_manifest(params={}) log_fixture("data_repo: Push data_repo application") app = Application.push(context=session_context, app_path=gzipped_app_path, name=p_a.app_name, manifest_path=manifest_path) log_fixture("data_repo: Check application is running") app.ensure_running() return Urls(app.urls[0])
def test_0_push_hdfs_hive_demo(self, dataset_target_uri, hdfs_instance, kerberos_instance, hive_instance, cups_sso_instance, login_to_cf, class_context): """ <b>Description:</b> Check that hdfs hive demo can run on platform. <b>Input data:</b> 1. hdfs hive demo sources 2. hdfs instance 3. kerberos instance 4. hive instance 5. cups sso instance <b>Expected results:</b> Test passes when hdfs hive demo is successfully pushed to platform and app has an url. <b>Steps:</b> 1. Get hdfs hive demo sources from repository. 2. Push hdfs hive demo to platform. 3. Check that pushed app has an url address. """ step("Get app sources") repo = AppSources.get_repository(repo_name=TapGitHub.hdfs_hive_demo, repo_owner=TapGitHub.intel_data) repo.compile_mvn() step("Push hdfs-hive-demo app to cf") self.__class__.hdfs_reader_app = Application.push(class_context, source_directory=repo.path, bound_services=[hdfs_instance.name, kerberos_instance.name, hive_instance.name, cups_sso_instance.name]) step("Check hdfs-hive-demo app has url") assert len(self.hdfs_reader_app.urls) == 1
def test_scale_application(self, sample_application, api_service_admin_client): """ <b>Description:</b> Scales the application and verifies that it was scaled and it is running after that operation <b>Input data:</b> - Sample application - Admin credentials <b>Expected results:</b> - It's possible to scale application <b>Steps:</b> - Download and push sample application - scale application and verifies that application was scaled by checking the replication amount. - check is state of app after scale is RUNNING """ step("Scale application") replicas_number = 3 sample_application.scale(replicas=replicas_number, client=api_service_admin_client) step("Check number of application instances") app_info = Application.get(sample_application.id, client=api_service_admin_client) assert app_info.running_instances == replicas_number step("Check application is running after scaling") app_info.ensure_running()
def space_shuttle_application(class_context): SPACE_SHUTTLE_DEMO_APP_NAME = "space-shuttle-demo" log_fixture(SPACE_SHUTTLE_DEMO_APP_NAME + ": Get all information about application") app = Application.get_by_name(SPACE_SHUTTLE_DEMO_APP_NAME) return app
def test_get_application(self, sample_app, api_service_admin_client): """ <b>Description:</b> Tries to retrieve the application by its id <b>Input data:</b> - Pushed sample application - Admin credentials <b>Expected results:</b> It's possible to retrieve the application by id <b>Steps:</b> - Pushed the sample app - Make sure the application has received id - Retrieve the application by it's id - Compare the application that was pushed and received by id """ step("Make sure the sample app has updated id") sample_app._ensure_has_id() step("Get application") app = Application.get(app_inst_id=sample_app.id, client=api_service_admin_client) step("Check that the apps are the same") assert sample_app == app
def __init__(self): self.apps = len(Application.cf_api_get_list()) self.service_instances = len(ServiceInstance.cf_api_get_list()) self.services = len(ServiceType.cf_api_get_list()) self.buildpacks = len(Buildpack.cf_api_get_list()) self.orgs = len(Organization.cf_api_get_list()) self.spaces = len(Space.cf_api_get_list()) self.users = len(User.cf_api_get_all_users())
def test_1_push_app_to_cf(self, class_context, test_space, psql_instance, login_to_cf): step("Push application to cf") sql_api_sources = AppSources.get_repository( repo_name=TapGitHub.sql_api_example, repo_owner=TapGitHub.intel_data) self.__class__.psql_app = Application.push( context=class_context, source_directory=sql_api_sources.path, space_guid=test_space.guid, bound_services=(psql_instance.name, self.kerberos_instance.name)) step("Check the application is running") assertions.assert_equal_with_retry(True, self.psql_app.cf_api_app_is_running) step("Check that application is on the list") apps = Application.cf_api_get_list_by_space(test_space.guid) assert self.psql_app in apps
def orientdb_app(cls, test_space, login_to_cf, orientdb_service, class_context): """SetUp: OrientDB API application creation.""" step("Push OrientDB Api application to cf.") app = Application.push(class_context, space_guid=test_space.guid, source_directory=ApplicationPath.ORIENTDB_API, bound_services=(orientdb_service.name, )) cls._API = OrientDbApi(app)
def check_bindings(self, sample_java_app, service_instance, api_service_admin_client): step("Check whether bindings sections is available in application") app = Application.get(sample_java_app.id, client=api_service_admin_client) assert len(app.bindings) == 1 step("Check whether bindings section is available in service") svc = ServiceInstance.get(service_id=service_instance.id, client=api_service_admin_client) assert len(svc.bindings) == 1
def test_delete_app_with_bound_service(self, test_space, sample_python_app, test_instance): step("Check that the app can be deleted") sample_python_app.api_delete() apps = Application.api_get_list(test_space.guid) assert sample_python_app not in apps step("Check that the instance can be deleted") test_instance.api_delete() instances = ServiceInstance.api_get_list(space_guid=test_space.guid) assert test_instance not in instances
def target_uri(cls, test_org, add_admin_to_test_org, core_space): step("Get target uri from hdfs instance") hdfs = next( app for app in Application.cf_api_get_list_by_space(core_space.guid) if "hdfs-downloader" in app.name) cls.target_uri = hdfs.cf_api_env( )['VCAP_SERVICES']['hdfs'][0]['credentials']['uri'] cls.target_uri = cls.target_uri.replace("%{organization}", test_org.guid)
def org_space_app(self, context): step("Create test organization and space") test_org = Organization.api_create(context) test_space = Space.api_create(test_org) step("Login to cf targeting test org and test space") cf.cf_login(test_org.name, test_space.name) step("Push example app") example_app_path = ApplicationPath.SAMPLE_PYTHON_APP test_app = Application.push(context, space_guid=test_space.guid, source_directory=example_app_path) return test_org, test_space, test_app
def test_non_developer_cannot_push_app(self, context, test_org, test_space, test_org_manager): step("Add user to space as manager") space_manager = test_org_manager space_manager.api_add_to_space(space_guid=test_space.guid, org_guid=test_org.guid, roles=User.SPACE_ROLES["manager"]) step("Login as this user") cf.cf_login(test_org.name, test_space.name, credentials=(space_manager.username, space_manager.password)) step("Check that manager cannot push app") example_app_path = ApplicationPath.SAMPLE_PYTHON_APP with pytest.raises(CommandExecutionException): Application.push(context, space_guid=test_space.guid, source_directory=example_app_path)
def offering_from_python_app(self, context, api_service_admin_client, sample_python_app): app = sample_python_app image = Application.get_image(app_inst_id=app.id, client=api_service_admin_client) offering_json = template_example.sample_python_app_offering offering_json['body'][0]['deployments'][0]['spec']['template']['spec']['containers'][0]['image'] = image offering = ServiceOffering.create(context, client=api_service_admin_client, template_body=offering_json['body']) service = ServiceInstance.create_with_name(context, offering_label=offering.label, plan_name=offering.service_plans[0].name) ServiceInstance.ensure_running(service, client=api_service_admin_client) return service
def psql_app(psql_instance): sql_api_sources = AppSources.from_github( repo_name=TapGitHub.sql_api_example, repo_owner=TapGitHub.intel_data, gh_auth=config.github_credentials()) context = Context() TestData.psql_app = Application.push(context=context, space_guid=TestData.test_space.guid, source_directory=sql_api_sources.path, bound_services=(psql_instance.name, )) return TestData.psql_app
def sample_application(self, class_context, test_sample_apps, api_service_admin_client): log_fixture("sample_application: update manifest") p_a = PrepApp(test_sample_apps[self.SAMPLE_APP].filepath) manifest_params = {"type" : self.APP_TYPE} manifest_path = p_a.update_manifest(params=manifest_params) log_fixture("Push sample application and check it's running") application = Application.push(class_context, app_path=test_sample_apps[self.SAMPLE_APP].filepath, name=p_a.app_name, manifest_path=manifest_path, client=api_service_admin_client) application.ensure_running() return application
def _check_user_can_do_app_flow(self, test_space, client, context): step("Push example application") example_app_path = ApplicationPath.SAMPLE_PYTHON_APP test_app = Application.push(context, space_guid=test_space.guid, source_directory=example_app_path) step("Check the application is running") assertions.assert_equal_with_retry(True, test_app.cf_api_app_is_running) step("Stop the application and check that it is stopped") test_app.api_stop(client=client) assertions.assert_equal_with_retry(False, test_app.cf_api_app_is_running) step("Start the application and check that it has started") test_app.api_start(client=client) assertions.assert_equal_with_retry(True, test_app.cf_api_app_is_running) step("Delete the application and check that it doesn't exist") test_app.api_delete(client=client) apps = Application.cf_api_get_list_by_space(test_space.guid) assert test_app not in apps
def test_0_push_dataset_reader_app(self, test_space, dataset_target_uri, hdfs_instance, kerberos_instance, login_to_cf, class_context): step("Get app sources") repo = AppSources.from_github(repo_name=TapGitHub.dataset_reader_sample, repo_owner=TapGitHub.trustedanalytics) repo.compile_mvn() step("Push dataset-reader app to cf") self.__class__.hdfs_reader_app = Application.push(class_context, space_guid=test_space.guid, source_directory=repo.path, bound_services=(hdfs_instance.name, kerberos_instance.name), env={"FILE": dataset_target_uri}) step("Check dataset reader app has url") assert len(self.hdfs_reader_app.urls) == 1
def setup_psql_api_app(cls, test_space, login_to_cf, postgres_instance, class_context): step("Get sql api app sources") sql_api_sources = AppSources.from_github( repo_name=TapGitHub.sql_api_example, repo_owner=TapGitHub.intel_data, gh_auth=config.github_credentials()) step("Push psql api app to cf") cls.psql_app = Application.push( class_context, space_guid=test_space.guid, source_directory=sql_api_sources.path, bound_services=(postgres_instance.name, ))
def push_app_from_tar(context, app_path): archive_path = os.path.join(app_path, 'app.tar.gz') log_fixture('using existing archive to push app: {}'.format(archive_path)) app_name = generate_test_object_name(separator='') manifest_path = os.path.join(app_path, 'manifest.json') with open(manifest_path) as manifest_file: manifest = json.load(manifest_file) manifest['name'] = app_name return Application.push(context, app_path=archive_path, name=app_name, manifest=manifest, client=api_service_admin_client())