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_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_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 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 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_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 test_5_check_job_in_cloudera(self, admin_user, core_space): step("Connect to bastion") client = DirectSshClient(hostname=config.jumpbox_hostname, username=config.jumpbox_username, path_to_key=config.jumpbox_key_path) client.connect() step("Check job in cloudera manager") app_name = TAP.cdh_broker cdh_broker = next( (app for app in Application.cf_api_get_list_by_space(core_space.guid) if app_name in app.name), None) assert cdh_broker is not None, "{} not available".format(app_name) url = str(json.loads(cdh_broker.cf_api_env()["ENVIRONMENT_JSON"]["CREDENTIALS"])["resource_manager"]).\ replace(config.cdh_master_0_hostname, "cdh-master-1") cluster = str(client.exec_command("curl {}/cluster".format(url))) user_guid_and_job_name = "\"{}\",\"oozie:action:T=sqoop:W={}".format( admin_user.guid, self.test_job.app_name) assert user_guid_and_job_name in cluster, "Job is not visible in log with user guid" client.disconnect()
def test_5_check_app(self, test_space): """ <b>Description:</b> Check that application was successfully pushed to the platform. <b>Input data:</b> No input data. <b>Expected results:</b> Test passes if mongodb api was successfully pushed to the platform. <b>Steps:</b> 1. Check that mongodb api application is in state running. 2. Check that application is on the application list. """ step("Check the application is running") assertions.assert_equal_with_retry(True, self.mongodb_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.mongodb_app in apps
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