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_get_service_instance_summary_from_empty_space(self): self.step("Create a service instance in one space") service_type = next(s for s in self.marketplace if s.label == ServiceLabels.KAFKA) ServiceInstance.api_create( org_guid=TestData.test_org.guid, space_guid=TestData.test_space.guid, service_label=service_type.label, service_plan_guid=service_type.service_plan_guids[0]) test_space = Space.api_create(TestData.test_org) self.step("Get service instance summary in another space") summary = ServiceInstance.api_get_keys(test_space.guid) self.step( "Check that service instance summary is empty in the second space") self.assertEqual(summary, {})
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 psql_instance(test_org, test_space): log_fixture("create_postgres_instance") marketplace = ServiceType.api_get_list_from_marketplace(test_space.guid) psql = next(service for service in marketplace if service.label == ServiceLabels.PSQL) TestData.psql_instance = ServiceInstance.api_create( org_guid=test_org.guid, space_guid=test_space.guid, service_label=ServiceLabels.PSQL, service_plan_guid=psql.service_plan_guids[0]) return TestData.psql_instance
def test_1_create_atk_instance(self, test_org, test_space): step("Get tested service type") service_type = next(s for s in self.marketplace if s.label == ServiceLabels.ATK) plan = next(iter(service_type.service_plans)) step("Create atk instance") self.__class__.atk_instance = ServiceInstance.api_create( org_guid=test_org.guid, space_guid=test_space.guid, service_label=service_type.label, service_plan_guid=plan["guid"] )
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_cannot_create_instance_as_non_space_developer(self): test_clients = { "space_auditor": self.space_auditor_client, "space_manager": self.space_manager_client } errors = [] for service_type, (name, client) in itertools.product( self.marketplace, test_clients.items()): for plan in service_type.service_plans: with self.assertRaises(UnexpectedResponseError) as e: ServiceInstance.api_create(TestData.test_org.guid, TestData.test_space.guid, service_type.label, service_plan_guid=plan["guid"], client=client) if e is None or e.exception.status != HttpStatus.CODE_FORBIDDEN: errors.append( "Service '{}' failed to respond with given error status." .format(service_type.label)) assert_no_errors(errors)
def postgres_instance(self, request, test_org, test_space): step("Create postgres service instance") marketplace = ServiceType.api_get_list_from_marketplace( test_space.guid) psql = next(service for service in marketplace if service.label == ServiceLabels.PSQL) instance_name = generate_test_object_name() psql_instance = ServiceInstance.api_create( org_guid=test_org.guid, space_guid=test_space.guid, service_label=ServiceLabels.PSQL, name=instance_name, service_plan_guid=psql.service_plan_guids[0]) request.addfinalizer(lambda: psql_instance.cleanup()) return psql_instance
def orientdb_service(self, test_org, test_space): """SetUp: OrientDB service creation.""" step("Create OrientDB service instance.") marketplace = ServiceType.api_get_list_from_marketplace( test_space.guid) orient_db = next((service for service in marketplace if service.label == ServiceLabels.ORIENT_DB), None) assert orient_db is not None, "{} service is not available in Marketplace".format( ServiceLabels.ORIENT_DB) instance_name = generate_test_object_name() return ServiceInstance.api_create( org_guid=test_org.guid, space_guid=test_space.guid, service_label=ServiceLabels.ORIENT_DB, name=instance_name, service_plan_guid=orient_db.service_plan_guids[0])
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_create_and_delete_service_instances(self, service_label): service_type = next( (s for s in self.marketplace if s.label == service_label), None) assert service_type is not None, "{} service is not available in Marketplace".format( service_label) plan = next(iter(service_type.service_plans)) step("Create service instance") instance = ServiceInstance.api_create( org_guid=TestData.test_org.guid, space_guid=TestData.test_space.guid, service_label=service_type.label, service_plan_guid=plan["guid"]) validator = ApplicationStackValidator(instance) validator.validate(validate_application=False) instance.api_delete() validator.validate_removed()
def create_service_and_instance(self, request, test_org, test_space, sample_service): step("Create an instance") instance = ServiceInstance.api_create( test_org.guid, test_space.guid, sample_service.label, service_plan_guid=sample_service.service_plans[0]["guid"]) step("Check that service instance is present") assert_in_with_retry(instance, ServiceInstance.api_get_list, test_space.guid, sample_service.guid) def fin(): step("Delete instance") instance.api_delete() request.addfinalizer(fin)
def test_create_instance_as_authorized_user(space_users_clients, role, test_org, test_space, sample_service): client = space_users_clients[role] step("Create an instance") instance = ServiceInstance.api_create( test_org.guid, test_space.guid, sample_service.label, service_plan_guid=sample_service.service_plans[0]["guid"], client=client) step("Check that service instance is present") assert_in_with_retry(instance, ServiceInstance.api_get_list, test_space.guid, sample_service.guid, client=client) step("Delete instance") instance.api_delete()
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 create_instance(context, org_guid, space_guid, service_label, plan_guid, name=None, params=None, client=None): step("Create service instance") instance = ServiceInstance.api_create(context=context, org_guid=org_guid, space_guid=space_guid, client=client, service_label=service_label, name=name, service_plan_guid=plan_guid, params=params) step("Check that the instance was created") instance.ensure_running() return instance
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_0_create_instance_of_kubernetes_service(self, test_org, test_space): step("Retrieve example kubernetes service from marketplace") marketplace = ServiceType.api_get_list_from_marketplace(space_guid=test_space.guid) k8s_service = next((s for s in marketplace if s.label == self.service_label), None) assert k8s_service is not None, "{} not available".format(self.service_label) plan_guid = next((p["guid"] for p in k8s_service.service_plans if p["name"] == self.plan_name), None) assert plan_guid is not None, "Plan {} not available".format(self.plan_name) step("Create instance of the k8s service") self.__class__.test_instance = ServiceInstance.api_create( org_guid=test_org.guid, space_guid=test_space.guid, service_label=self.service_label, service_plan_guid=plan_guid ) step("Wait until the instance is running") self.__class__.k8s_instance = KubernetesInstance.from_service_instance( guid=self.test_instance.guid, plan_guid=plan_guid, space_guid=test_space.guid, org_guid=test_org.guid ) self.k8s_instance.ensure_running_in_cluster() step("Check instance has correct status on TAP") self.test_instance.ensure_created()