def test_cannot_create_service_instance_with_name_of_an_existing_instance( self): existing_name = generate_test_object_name() self.step("Create service instance") instance = ServiceInstance.api_create_with_plan_name( org_guid=TestData.test_org.guid, space_guid=TestData.test_space.guid, service_label=ServiceLabels.KAFKA, name=existing_name, service_plan_name=ServicePlan.SHARED) service_list = ServiceInstance.api_get_list( space_guid=TestData.test_space.guid) self.step("Check that the instance was created") self.assertIn(instance, service_list, "Instance was not created") errors = [] for service_type in self.marketplace: plan_guid = next(iter(service_type.service_plan_guids)) self.step("Try to create {} service instance".format( service_type.label)) with self.assertRaises(UnexpectedResponseError) as e: ServiceInstance.api_create(TestData.test_org.guid, TestData.test_space.guid, service_type.label, existing_name, service_plan_guid=plan_guid) if e is None or e.exception.status != HttpStatus.CODE_CONFLICT: errors.append( "Service '{}' failed to respond with given error status.". format(service_type.label)) assert_no_errors(errors) self.assertUnorderedListEqual( service_list, ServiceInstance.api_get_list(space_guid=TestData.test_space.guid), "Some new services were created")
def test_1_create_service_instance(self): step("Get list of services to retrieve a {} service".format( ServiceTag.K8S)) services = ServiceType.api_get_list_from_marketplace( space_guid=self.test_space.guid) service = next((s for s in services if ServiceTag.K8S in s.tags), None) if service is None: raise AssertionError("No {} service available".format( ServiceTag.K8S)) step("Create instance") self.__class__.test_instance = ServiceInstance.api_create( org_guid=self.test_org.guid, space_guid=self.test_space.guid, name=test_names.generate_test_object_name(short=True), service_label=service.label, service_plan_guid=service.service_plans[0]["guid"]) step("Check that the instance is on the list") instances = ServiceInstance.api_get_list( space_guid=self.test_space.guid) assert self.test_instance in instances step("Check that new cluster is created") self.__class__.cluster = KubernetesCluster.demiurge_api_get( name=self.test_org.guid)
def test_1_create_mongodb_clustered_instance(self, class_context, test_org, test_space): """ <b>Description:</b> Check that mongodb instance can be created with plan clustered. <b>Input data:</b> 1. Test organization. <b>Expected results:</b> Test passes if mongodb service instance is created. <b>Steps:</b> 1. Create mongodb service instance with plan clustered. 2. Check that created service instance is present in service instance list. """ step("Create new mongodb clustered service") self.__class__.mongodb_instance = ServiceInstance.api_create_with_plan_name( context=class_context, org_guid=test_org.guid, space_guid=test_space.guid, service_label=self.MONGODB_SERVICE_LABEL, service_plan_name=ServicePlan.CLUSTERED ) self.mongodb_instance.ensure_created() step("Check that the mongodb clustered is on the instances list") instances = ServiceInstance.api_get_list(space_guid=test_space.guid) assert self.mongodb_instance in instances
def test_cannot_create_instance_without_a_name(self): expected_instance_list = ServiceInstance.api_get_list( TestData.test_space.guid) self.step("Check that instance cannot be created with empty name") self.assertRaisesUnexpectedResponse( HttpStatus.CODE_BAD_REQUEST, HttpStatus.MSG_BAD_REQUEST, ServiceInstance.api_create_with_plan_name, TestData.test_org.guid, TestData.test_space.guid, ServiceLabels.KAFKA, "", service_plan_name=ServicePlan.SHARED) self.assertUnorderedListEqual( expected_instance_list, ServiceInstance.api_get_list(TestData.test_space.guid), "New instance was created")
def core_hdfs_instance(self, core_space): service_instances = ServiceInstance.api_get_list(core_space.guid) hdfs_instance = next( (s for s in service_instances if s.name == self.HDFS_INSTANCE_NAME), None) assert hdfs_instance is not None, "{} not found in core space".format( self.HDFS_INSTANCE_NAME) return hdfs_instance
def create_gearpump(cls, test_org, test_space): step("Create gearpump instance with plan: 1 worker") cls.gearpump = Gearpump(test_org.guid, test_space.guid, service_plan_name=cls.ONE_WORKER_PLAN_NAME) step("Check that gearpump instance has been created") instances = ServiceInstance.api_get_list(space_guid=test_space.guid) if cls.gearpump.instance not in instances: raise AssertionError("gearpump instance is not on list of instances") cls.gearpump.get_credentials() step("Log into gearpump UI") cls.gearpump.login()
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 test_3_create_instance_of_dynamic_kubernetes_service(self, core_org, core_space): step("Create instance of the new service and check it's on the list") self.__class__.test_instance = ServiceInstance.api_create( org_guid=core_org.guid, space_guid=core_space.guid, service_label=self.service_name, service_plan_guid=self.test_service.service_plans[0]["guid"] ) instances = ServiceInstance.api_get_list(space_guid=core_space.guid) self.test_instance.ensure_created() assert self.test_instance in instances
def test_2_delete_gateway_instance(self): self.step("Delete gateway instance") self.gateway_instance.api_delete(client=self.space_developer_client) self.assertNotInWithRetry(self.gateway_instance, ServiceInstance.api_get_list, TestData.test_space.guid) self.step("Check that bound kafka instance was also deleted") service_instances = ServiceInstance.api_get_list( TestData.test_space.guid) self.assertNotIn(self.kafka_instance, service_instances, "Kafka instance was not deleted")
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_create_instance(self, test_org, test_space, space_users_clients, class_context): self.__class__.client = space_users_clients["developer"] step("Create scoring engine instance") self.__class__.instance = ServiceInstance.api_create_with_plan_name( org_guid=test_org.guid, space_guid=test_space.guid, service_label=ServiceLabels.SCORING_ENGINE, service_plan_name=ServicePlan.SIMPLE_ATK, params={"uri": self.atk_model_uri}, client=self.client, context=class_context ) step("Check instance is on the instance list") instances_list = ServiceInstance.api_get_list(test_space.guid, client=self.client) assert self.instance in instances_list, "Scoring Engine was not found on the instance list"
def _create_instance(self, plan, service_type): self.step("Create instance of {} ({} plan). Check it exists.".format(service_type.label, plan["name"])) service_instance_name = service_type.label + datetime.now().strftime('%Y%m%d_%H%M%S_%f') instance = ServiceInstance.api_create( org_guid=self.test_org.guid, space_guid=service_type.space_guid, service_label=service_type.label, name=service_instance_name, service_plan_guid=plan['guid'] ) self.assertIsNotNone(instance, "{} instance was not created".format(service_type)) self.step("Delete the instance and check it no longer exists") instance.api_delete() instances = ServiceInstance.api_get_list(space_guid=service_type.space_guid, service_type_guid=service_type.guid) self.assertNotIn(instance, instances, "{} instance was not deleted".format(service_type))
def test_compare_service_instances_list_with_cf(self, org_space, instance): test_org, test_space = org_space step("Get service instances list from platform") platform_service_instances_list = ServiceInstance.api_get_list( test_space.guid) step("Get service instances list from cf") cf_service_instances_list = ServiceInstance.cf_api_get_list() cf_service_instances_list = [ s for s in cf_service_instances_list if s.space_guid == org_space[1].guid ] assert instance in platform_service_instances_list cf_service_guids = [s.guid for s in cf_service_instances_list] platform_service_guids = [ s.guid for s in platform_service_instances_list ] step("Compare service instances lists from platform and cf") assert cf_service_guids == platform_service_guids
def _create_and_delete_service_instance_and_keys(self, org_guid, space_guid, service_label, plan_guid): self.step("Create service instance") instance = ServiceInstance.api_create(org_guid=org_guid, space_guid=space_guid, service_label=service_label, service_plan_guid=plan_guid) self.step("Check that the instance was created") instance.ensure_created() service_key_exception = None try: self.step( "Check that the instance exists in summary and has no service keys" ) self.assertEqualWithinTimeout(timeout=5, expected_result=[], callable_obj=self._get_service_keys, sleep=1, instance=instance) self.step( "Create a key for the instance and check it's correctness") instance_key = ServiceKey.api_create(instance.guid) summary = ServiceInstance.api_get_keys(space_guid) self.assertEqual(summary[instance][0], instance_key) self.step("Delete key and check that it's deleted") instance_key.api_delete() summary = ServiceInstance.api_get_keys(space_guid) self.assertEqual(summary[instance], []) except AssertionError as e: service_key_exception = e try: self.step("Delete the instance") instance.api_delete() self.step("Check that the instance was deleted") instances = ServiceInstance.api_get_list(space_guid=space_guid) self.assertNotIn(instance, instances) except AssertionError as e: if service_key_exception is not None: raise service_key_exception raise e if service_key_exception is not None: raise service_key_exception
def create_instance_and_key_then_delete_key_and_instance( org_guid, space_guid, service_label, plan_guid, plan_name): step("Create instance ({} - {})".format(service_label, plan_name)) instance = ServiceInstance.api_create(org_guid=org_guid, space_guid=space_guid, service_label=service_label, service_plan_guid=plan_guid) step("Check that the instance was created ({} - {})".format( service_label, plan_name)) instance.ensure_created() service_key_exception = None try: step( "Check that the instance exists in summary and has no keys ({} - {})" .format(service_label, plan_name)) assertions.assert_equal_with_retry(expected_value=[], callableObj=get_service_keys, instance=instance) step("Create a key for the instance and check it's correct ({} - {})". format(service_label, plan_name)) instance_key = ServiceKey.api_create(instance.guid) summary = ServiceInstance.api_get_keys(space_guid) assert summary[instance][0] == instance_key step("Delete key and check that it's deleted ({} - {})".format( service_label, plan_name)) instance_key.api_delete() summary = ServiceInstance.api_get_keys(space_guid) assert summary[instance] == [] except AssertionError as e: service_key_exception = e try: step("Delete the instance ({} - {})".format(service_label, plan_name)) instance.api_delete() step("Check that the instance was deleted ({} - {})".format( service_label, plan_name)) instances = ServiceInstance.api_get_list(space_guid=space_guid) assert instance not in instances except AssertionError as e: if service_key_exception is None: service_key_exception = e if service_key_exception is not None: raise service_key_exception
def test_create_and_delete_marketplace_service_instances( core_org, core_space, context, non_parametrized_marketplace_services): """Create and Delete Marketplace Service Instance""" service_type = non_parametrized_marketplace_services[0] plan = non_parametrized_marketplace_services[1] step("Create instance {} {}".format(service_type.label, plan["name"])) instance = ServiceInstance.api_create(org_guid=core_org.guid, space_guid=core_space.guid, service_label=service_type.label, service_plan_guid=plan["guid"], context=context) step("Check that the instance was created") instance.ensure_created() step("Delete the instance") instance.api_delete() step("Check that the instance was deleted") instances = ServiceInstance.api_get_list( space_guid=core_space.guid, service_type_guid=service_type.guid) assert instance not in instances
def test_9_delete_mongodb_clustered_instance(self, test_space): """ <b>Description:</b> Check that mongodb service instance can be deleted. <b>Input data:</b> No input data. <b>Expected results:</b> Test passes if mongodb service instance is deleted. <b>Steps:</b> 1. Delete mongodb service instance. 2. Get service instances list. 3. Check that mongodb service instance is no longer present in service instances list. """ step("Delete mongodb clustered service") self.mongodb_instance.api_delete() step("Check that the mongodb clustered is not on the instances list") instances = ServiceInstance.api_get_list(space_guid=test_space.guid) assert self.mongodb_instance not in instances
def test_0_create_kerberos_instance(self, class_context, test_org, test_space): step("Check kerberos in marketplace") service_label = ServiceLabels.KERBEROS marketplace = ServiceOffering.get_list() kerberos = next( (service for service in marketplace if service.label == service_label), None) assert kerberos is not None, "{} not available".format(service_label) step("Create instance of kerberos") self.__class__.kerberos_instance = ServiceInstance.api_create_with_plan_name( context=class_context, org_guid=test_org.guid, space_guid=test_space.guid, service_label=service_label, service_plan_name=ServicePlan.SHARED) self.kerberos_instance.ensure_created() step("Check that the kerberos is on the instances list") instances = ServiceInstance.api_get_list(space_guid=test_space.guid) assert self.kerberos_instance in instances
def test_4_delete_instance_of_kubernetes_service(self, core_space): step("Delete instance and check it's no longer on the list") self.test_instance.api_delete() instances = ServiceInstance.api_get_list(space_guid=core_space.guid) assert self.test_instance not in instances
def test_6_delete_instance(self, test_space): self.instance.api_delete(client=self.client) instances = ServiceInstance.api_get_list(space_guid=test_space.guid) assert self.instance not in instances, "Scoring engine instance was not deleted"
def delete_instance(instance, space_guid, client=None): step("Delete the instance") instance.api_delete(client=client) step("Check that the instance was deleted") instances = ServiceInstance.api_get_list(space_guid=space_guid) assert instance not in instances