Beispiel #1
0
    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_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")
Beispiel #3
0
    def test_cannot_create_service_instance_with_name_of_an_existing_instance(
            self, context):
        """
        <b>Description:</b>
        Check that it's impossible to create a service instance
        with name that is already used by another instance.

        <b>Input data:</b>
        1. Rabbit mq offering
        2. Redis offering

        <b>Expected results:</b>
        Test passes if platform returns 409 http code.

        <b>Steps:</b>
        1. Create rabbit mq service instance.
        2. Check that instance is running.
        3. Try to create redis service insance with same name as rabbit mq instance.
        4. Check that platform returns 409 http code.
        """
        step("Create service instance")
        instance = ServiceInstance.create_with_name(
            context,
            offering_label=ServiceLabels.RABBIT_MQ,
            plan_name=ServicePlan.SINGLE_SMALL)
        step("Ensure that instance is running")
        instance.ensure_running()
        step("Try to create service instance with already taken name")
        with pytest.raises(UnexpectedResponseError) as e:
            ServiceInstance.create_with_name(
                context,
                offering_label=ServiceLabels.REDIS,
                plan_name=ServicePlan.SINGLE_SMALL,
                name=instance.name)
        assert e.value.status == HttpStatus.CODE_CONFLICT, "Created service instance with already taken name"
Beispiel #4
0
 def test_failed_instance_creation_event(self, org, space, events_before):
     step("Trigger failed instance creation")
     with pytest.raises(AssertionError):
         ServiceInstance.api_create_with_plan_name(
             org.guid,
             space.guid,
             ServiceLabels.SCORING_ENGINE,
             service_plan_name=ServicePlan.SIMPLE_ATK)
     step(
         "Retrieve latest events. Check there are two new events related to failed instance creation"
     )
     events_after = LatestEvent.api_get_latest_events(org_guid=org.guid)
     assert len(events_after) == len(events_before) + 2
     self._assert_event_is_correct(
         events_after[1],
         category=EventCategory.service_creation,
         org_guid=org.guid,
         message=EventMessage.create_service_started.format(
             Urls.test_transfer_link))
     self._assert_event_is_correct(
         events_after[0],
         category=EventCategory.service_creation,
         org_guid=org.guid,
         message=EventMessage.create_service_failed.format(
             Urls.test_transfer_link))
    def test_expose_urls_twice(self, api_service_admin_client, offering_from_python_app):
        """ Verify if try to expose exposed service results conflict.

            Push sample app, create new offering using image of sample app and create service instance of new offering.
            Expose service instance URLS and try to expose URLS once again.

            Input data:
                Offering: offering created based on python application image

            Expected results:
                It is possible to expose service URLS, second try results conflict (409 Conflict).

            Steps:
                1. Create instance of new offering
                2. Expose URLS
                3. Try to expose URLS once again
        """
        step("Create offering from sample_python_app")
        service = offering_from_python_app
        step("Expose urls")
        ServiceInstance.expose_urls(service_id=service.id, client=api_service_admin_client)
        step("Try to expose urls once again")
        assert_raises_http_exception(status=ApiServiceHttpStatus.CODE_CONFLICT,
                                     callableObj=ServiceInstance.expose_urls, error_message_phrase='already exists',
                                     client=api_service_admin_client, service_id=service.id)
    def test_1_send_message_to_gateway_instance(self, test_org_user_client):
        """
        <b>Description:</b>
        Check that it's possible to send messages to gateway instance.

        <b>Input data:</b>
        1. gateway app

        <b>Expected results:</b>
        Test passes when message is sent to gateway instance without errors.

        <b>Steps:</b>
        1. Expose service instance url.
        2. Send message to gateway instance.
        3. Check that no error is raised.
        """
        step("Expose service instance url")
        urls = ServiceInstance.expose_urls(service_id=self.gateway_instance.id,
                                           client=test_org_user_client)
        ServiceInstance.ensure_responding(url=urls[0])
        step("Retrieve oauth token")
        http_client = HttpClientFactory.get(ServiceConfigurationProvider.get())
        token = http_client._auth._token_header
        step("Check communication with gateway instance")
        header = {"Authorization": "{}".format(token)}
        ws_url = "{}/ws".format(urls[0].replace("http", WebsocketClient.WS))
        try:
            ws = WebsocketClient(ws_url, headers=header)
            ws.send("test")
            ws.close()
        except Exception as e:
            raise AssertionError(str(e))
    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
Beispiel #8
0
    def test_cannot_create_instance_without_a_name(self, context):
        """
        <b>Description:</b>
        Check that it's impossible to create a service instance without a name.

        <b>Input data:</b>
        1. Rabbit mq offering

        <b>Expected results:</b>
        Test passes if platform returns 402 http code.

        <b>Steps:</b>
        1. Get current service instance list.
        2. Try to create a rabbit mq service instance without a name.
        3. Check that platform returns 402 http status code.
        4. Check that no new service instances were created.
        """
        expected_instance_list = ServiceInstance.get_list()
        step("Check that instance cannot be created with empty name")
        expected_msg = ApiServiceHttpStatus.MSG_FIELD_ZERO_VALUE.format("Name")
        assert_raises_http_exception(HttpStatus.CODE_BAD_REQUEST,
                                     expected_msg,
                                     ServiceInstance.create_with_name,
                                     context=context,
                                     offering_label=ServiceLabels.RABBIT_MQ,
                                     plan_name=ServicePlan.SINGLE_SMALL,
                                     name="")
        assert_unordered_list_equal(expected_instance_list,
                                    ServiceInstance.get_list(),
                                    "New instance was created")
Beispiel #9
0
 def test_4_create_service_key(self, test_space):
     step("Check that the instance exists in summary and has no keys")
     summary = ServiceInstance.api_get_keys(test_space.guid, client=self.client)
     assert self.instance in summary, "Instance not found in summary"
     assert summary[self.instance] == [], "There are keys for the instance"
     step("Create a key for the scoring engine instance and check it")
     self.__class__.instance_key = ServiceKey.api_create(self.instance.guid, client=self.client)
     summary = ServiceInstance.api_get_keys(test_space.guid)
     assert self.instance_key in summary[self.instance], "Key not found"
 def test_successful_instance_creation_event(self, context, org, space, events_before, test_data_urls):
     step("Create example instance")
     ServiceInstance.api_create_with_plan_name(context, org.guid, space.guid, ServiceLabels.ATK,
                                               service_plan_name=ServicePlan.SIMPLE_ATK)
     step("Retrieve latest events. Check there are two new events related to successful instance creation")
     events_after = LatestEvent.api_get_latest_events(org_guid=org.guid)
     assert len(events_after) == len(events_before) + 2
     self._assert_event_is_correct(events_after[1], category=EventCategory.service_creation, org_guid=org.guid,
                                   message=EventMessage.create_service_started.format(test_data_urls.test_transfer.url))
     self._assert_event_is_correct(events_after[0], category=EventCategory.service_creation, org_guid=org.guid,
                                   message=EventMessage.create_service_succeded)
 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 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
Beispiel #13
0
 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 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_0_create_mysql_clustered_service(self, class_context, test_org,
                                              test_space):
        """
        <b>Description:</b>
        Check that mysql service instance can be created with plan clustered.

        <b>Input data:</b>
        1. test organization

        <b>Expected results:</b>
        Test passes if mysql service instance is successfully created and in state running.

        <b>Steps:</b>
        1. Get marketplace offering list.
        2. Check that mysql offering is present in marketplace.
        3. Create mysql service instance.
        4. Check that created mysql service instance is in state running.
        """
        marketplace = ServiceOffering.get_list()
        self.__class__.k8s_service = next(
            (s for s in marketplace if s.label == self.service_label), None)
        assert self.k8s_service is not None, "{} not available".format(
            self.service_label)
        self.__class__.instance = ServiceInstance.api_create_with_plan_name(
            class_context,
            test_org.guid,
            test_space.guid,
            self.service_label,
            service_plan_name=ServicePlan.CLUSTERED)
        self.instance.ensure_running()
Beispiel #16
0
    def test_3_delete_se_instance(self, se_instance):
        """
        <b>Description:</b>
        Check that scoring engine instance can be deleted.

        <b>Input data:</b>
        No input data.

        <b>Expected results:</b>
        Test passes if scoring engine instance is successfully deleted.

        <b>Steps:</b>
        1. Stop scoring engine instance.
        2. Check that scoring engine instance was stopped.
        3. Delete scoring engine instance.
        4. Check that scoring engine instance was successfully deleted.
        """
        step("Stop service instance")
        se_instance.stop()
        step("Check that scoring engine instance was stopped.")
        se_instance.ensure_stopped()
        step("Delete scoring engine instance.")
        se_instance.delete()
        step("Check that scoring engine instance was deleted.")
        se_instance.ensure_deleted()
        instances = ServiceInstance.get_list()
        assert se_instance not in instances, "Scoring engine instance was not deleted"
    def test_0_create_gateway_instance(self, class_context,
                                       test_org_user_client):
        """
        <b>Description:</b>
        Check that by creating a gateway instance the gateway application is created.

        <b>Input data:</b>
        1. user client

        <b>Expected results:</b>
        Test passes when gateway instance is successfully created.

        <b>Steps:</b>
        1. Create gateway instance with plan single.
        2. Check that gateway instance is running.
        3. Check that gateway application was created.
        """
        step("Create gateway instance")
        gateway_instance = ServiceInstance.create_with_name(
            class_context,
            name=test_names.generate_test_object_name(separator="",
                                                      short=True),
            offering_label=ServiceLabels.GATEWAY,
            plan_name=ServicePlan.SINGLE,
            client=test_org_user_client)
        gateway_instance.ensure_running()
        validator = ApplicationStackValidator(gateway_instance)
        self.__class__.gateway_instance = gateway_instance
        self.__class__.gateway_app = validator.application
Beispiel #18
0
def kerberos_instance(session_context, api_service_admin_client):
    log_fixture("create_kerberos_instance")
    kerberos = ServiceInstance.create_with_name(context=session_context, offering_label=ServiceLabels.KERBEROS,
                                     plan_name=ServicePlan.SHARED, client=api_service_admin_client)
    log_fixture("Check the service instance is running")
    kerberos.ensure_running()
    return kerberos
Beispiel #19
0
def mysql_instance(session_context, api_service_admin_client):
    log_fixture("create_mysql_instance")
    mysql = ServiceInstance.create_with_name(context=session_context, client=api_service_admin_client,
                                             offering_label=ServiceLabels.MYSQL, plan_name=ServicePlan.SINGLE_SMALL)
    log_fixture("Check the service instance is running")
    mysql.ensure_running()
    return mysql
    def test_create_and_delete_service_instance(self, instance):
        """
        <b>Description:</b>
        Check that service instance can be created and deleted.

        <b>Input data:</b>
        No input data.

        <b>Expected results:</b>
        Test passes if service instance can be created and deleted.

        <b>Steps:</b>
        1. Create service instance.
        2. Check that instance is on the service instance list.
        3. Stop service instance.
        4. Delete service instance.
        5. Check that service instance on the list.
        """
        step("Get service instances list from ApiService")
        api_service_instances_list = ServiceInstance.get_list()
        step("Check if instance is on the list")
        assert instance in api_service_instances_list
        step("Stop service instance")
        instance.stop()
        instance.ensure_stopped()
        step("Delete service instance")
        instance.delete()
        step("Ensure instance is not on the list")
        assertions.assert_not_in_with_retry(instance, ServiceInstance.get_list)
Beispiel #21
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))
Beispiel #22
0
def test_create_and_delete_marketplace_service_instances(
        context, service_label, plan_name):
    """
    <b>Description:</b>
    Checks if a service instance can be created and deleted from the platform.

    <b>Input data:</b>
    1. Offering names.

    <b>Expected results:</b>
    Test passes when a service instance was successfully created and removed from the platform for every marketplace
    official offering and its plans.

    <b>Steps:</b>
    1. Create service instance of every offering and its plans.
    2. Verify that the service instance is in state RUNNING.
    3. Delete the service instance of an offering.
    4. Verify the service instance was deleted from the platform.
    """
    step("Create instance {} {}".format(service_label, plan_name))
    instance = ServiceInstance.create_with_name(context,
                                                offering_label=service_label,
                                                plan_name=plan_name)
    step("Check that the instance is running")
    instance.ensure_running()
    step("Stop service instance")
    instance.stop()
    instance.ensure_stopped()
    step("Delete the instance")
    instance.delete()
    step("Check that the instance was deleted")
    instance.ensure_deleted()
    def __init__(self, context, org_uuid, space_uuid, tap_http_client):
        self.service_instance = ServiceInstance.api_create_with_plan_name(
            context,
            org_uuid,
            space_uuid,
            ServiceLabels.SEAHORSE,
            name=generate_test_object_name(short=True,
                                           prefix=ServiceLabels.SEAHORSE),
            service_plan_name=ServicePlan.FREE)
        self.service_instance.ensure_running()
        self.seahorse_url = "{}-{}.{}".format(
            self.service_instance.name.replace("_", "-"),
            self.service_instance.guid, self.tap_domain)
        self.seahorse_http_url = "https://{}".format(self.seahorse_url)

        http_client_configuration = HttpClientConfiguration(
            client_type=HttpClientType.NO_AUTH,
            url="https://{}".format(self.seahorse_url),
            username=self.username,
            password=self.password)
        self.http_client = HttpClientFactory.get(http_client_configuration)
        self.http_client.session = tap_http_client.session

        self._ensure_seahorse_accessible()
        self._ensure_authorized()
        self._ensure_wm_accessible()
        self._ensure_sm_accessible()

        self._ws = None
    def test_get_stable_state(self, class_context):
        """
        <b>Description:</b>
        Checks catalog stable state

        <b>Input data:</b>
        No input data.

        <b>Expected results:</b>
        Test checks if catalog state is stable or unstable.

        <b>Steps:</b>
        1. Get catalog state.
        2. If catalog is stable, add unstable instance and check if state is unstable.
        3. If catalog is unstable, skip test.
        """
        step("Get catalog stable state")
        response = CatalogState.get_stable_state()
        stable = response["stable"]
        message = response["message"]
        if stable is True:
            step("Stable is true, add unstable instance")
            instance = ServiceInstance.create_with_name(
                class_context,
                offering_label=ServiceLabels.RABBIT_MQ,
                plan_name=ServicePlan.SINGLE_SMALL)
            response = CatalogState.get_stable_state()
            stable = response["stable"]
            assert stable is False
            instance.ensure_running()
        else:
            pytest.skip("Instances are unstable:{}".format(message))
 def instance(self, context):
     instance = ServiceInstance.create_with_name(
         context=context,
         offering_label=ServiceLabels.KAFKA,
         plan_name=ServicePlan.SHARED)
     instance.ensure_running()
     return instance
Beispiel #26
0
def hdfs_instance(session_context, api_service_admin_client):
    log_fixture("create_hdfs_instance")
    hdfs = ServiceInstance.create_with_name(context=session_context, offering_label=ServiceLabels.HDFS,
                                            plan_name=ServicePlan.ENCRYPTED_DIR, client=api_service_admin_client)
    log_fixture("Check the service instance is running")
    hdfs.ensure_running()
    return hdfs
 def instance(self, org_space):
     instance = ServiceInstance.api_create_with_plan_name(
         org_guid=org_space[0].guid,
         space_guid=org_space[1].guid,
         service_label=ServiceLabels.KAFKA,
         service_plan_name=ServicePlan.SHARED)
     return instance
Beispiel #28
0
 def instance(self, context, sample_service):
     step("Create an instance")
     instance = ServiceInstance.create(context, offering_id=sample_service.id,
                                       plan_id=sample_service.service_plans[0]["entity"]["id"])
     step("Ensure that instance is running")
     instance.ensure_running()
     return instance
 def instance(cls, class_context, api_service_admin_client):
     instance = ServiceInstance.create_with_name(
         context=class_context,
         offering_label=ServiceLabels.KAFKA,
         plan_name=ServicePlan.SHARED,
         client=api_service_admin_client)
     instance.ensure_running(client=api_service_admin_client)
     return instance
 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())