コード例 #1
0
    def test_create_service_with_tag(self, context, app_jar, manifest_json):
        """
        <b>Description:</b>
        Create new service offering with tag.

        <b>Input data:</b>
        1. application jar file
        2. manifest.json file

        <b>Expected results:</b>
        Test passes when new offering is created with tags.

        <b>Steps:</b>
        1. Prepare offering json file with tags.
        2. Create service offering.
        3. Check that created offering is present on the offering list.
        4. Check that offering has custom tags.
        """
        step("Prepare offering json")
        tags = [generate_test_object_name(short=True)]
        offering_file = ServiceOffering.create_offering_json(tags=tags)
        step("Register in marketplace")
        service = ServiceOffering.create_from_binary(
            context,
            jar_path=app_jar,
            manifest_path=manifest_json,
            offering_path=offering_file)
        step("Check that service is in marketplace")
        assert_in_with_retry(service, ServiceOffering.get_list)
        step("Check that tags names are the same")
        assert tags == service.tags
コード例 #2
0
    def test_cannot_create_the_same_offering_twice(self, context,
                                                   api_service_admin_client):
        """
        <b>Description:</b>
        Attempts to create offering twice via api service

        <b>Input data:</b>
        - Admin credentials

        <b>Expected results:</b>
        - It's not possible to create the same offering twice

        <b>Steps:</b>
        - Create the offering via api service and verify it's on the list
        - Try to create that offering again
        - Verify that catalog has not changed
        """
        step("Create new offering")
        test_offering = ServiceOffering.create(context,
                                               client=api_service_admin_client)
        step("Check that the offering exists")
        catalog = ServiceOffering.get_list(client=api_service_admin_client)
        assert test_offering in catalog
        step("Try creating offering with name of an already existing offering")
        assert_raises_http_exception(
            ApiServiceHttpStatus.CODE_CONFLICT,
            ApiServiceHttpStatus.MSG_SERVICE_ALREADY_EXISTS.format(
                test_offering.label),
            ServiceOffering.create,
            context,
            label=test_offering.label,
            client=api_service_admin_client)
        step("Check that catalog has not changed")
        assert sorted(ServiceOffering.get_list(
            client=api_service_admin_client)) == sorted(catalog)
コード例 #3
0
def sample_service(class_context, sample_app_jar):
    log_fixture("Prepare mainfest and offering json")
    offering_json = ServiceOffering.create_offering_json()
    manifest_json = ServiceOffering.create_manifest_json(app_type=TapApplicationType.JAVA)
    log_fixture("Create new example service from binary")
    sample_service = ServiceOffering.create_from_binary(class_context, jar_path=sample_app_jar,
                                                        manifest_path=manifest_json, offering_path=offering_json)
    log_fixture("Check the service is ready")
    sample_service.ensure_ready()
    return sample_service
コード例 #4
0
    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()
コード例 #5
0
    def test_cannot_create_service_with_no_name(self, context, app_jar,
                                                manifest_json):
        """
        <b>Description:</b>
        Try to create service offering without a name.

        <b>Input data:</b>
        1. jar application
        2. manifest.json file

        <b>Expected results:</b>
        Test passes when platform returns a 402 http status with meaningful message.

        <b>Steps:</b>
        1. Try to create service offering without a name.
        """
        step("Prepare offering json")
        offering_file = ServiceOffering.create_offering_json(name="")
        step("Attempt to create service with empty name")
        assert_raises_http_exception(HttpStatus.CODE_BAD_REQUEST,
                                     HttpStatus.MSG_SERVICE_NAME_IS_EMPTY,
                                     ServiceOffering.create_from_binary,
                                     context,
                                     jar_path=app_jar,
                                     manifest_path=manifest_json,
                                     offering_path=offering_file)
コード例 #6
0
    def test_app_register_as_offering_as_admin(self, context, app_jar,
                                               offering_json, manifest_json,
                                               test_user_clients):
        """
        <b>Description:</b>
        Checks if an offering can be created from an application.

        <b>Input data:</b>
        1. Sample application.
        2. Organization id

        <b>Expected results:</b>
        An offering can be created from an application as admin

        <b>Steps:</b>
        1. Create offering.
        2. Verify is on the offerings list.
        """
        client = test_user_clients["admin"]
        step("Register in marketplace as admin")
        offering = ServiceOffering.create_from_binary(
            context,
            jar_path=app_jar,
            manifest_path=manifest_json,
            offering_path=offering_json,
            client=client)
        offering.ensure_ready()
        assertions.assert_in_with_retry(offering, ServiceOffering.get_list)
コード例 #7
0
 def test_one_service_plan_in_offering(self, response):
     offering = ServiceOffering._from_response(response, client=mock.Mock())
     assert len(offering.service_plans) == 1
     plan = offering.service_plans[0]
     assert plan.id == PLAN_0_ID
     assert plan.name == PLAN_0_NAME
     assert plan.description == PLAN_0_DESCRIPTION
コード例 #8
0
 def offering(cls, api_service_admin_client):
     marketplace = ServiceOffering.get_list(client=api_service_admin_client)
     usable_offerings = (
         o for o in marketplace
         if o.state == TapEntityState.READY and len(o.service_plans) > 0)
     reliable_offerings = (o for o in usable_offerings
                           if o.label in RELIABLE_OFFERINGS)
     offering = next(reliable_offerings, None)
     assert offering is not None, "No available offerings in marketplace"
     return offering
コード例 #9
0
 def test_create_manifest_json_with_default_name(self):
     default_name = "manifest.json"
     app_type = "TEST_TYPE"
     manifest_dict = {
         "type": app_type
     }
     self.mock_file_utils.save_text_file.return_value = MANIFEST_PATH
     manifest_json = ServiceOffering.create_manifest_json(app_type=app_type)
     assert manifest_json == MANIFEST_PATH
     self.mock_file_utils.save_text_file.assert_called_with(data=json.dumps(manifest_dict), file_name=default_name)
コード例 #10
0
    def test_create_and_delete_service_offering_admin(
            self, context, app_jar, offering_json, manifest_json,
            api_service_admin_client):
        """
        <b>Description:</b>
        Create service offering, create an instance of it, delete instance and delete offering.

        <b>Input data:</b>
        1. application jar file
        2. manifest.json file
        3. offering.json file
        4. admin client

        <b>Expected results:</b>
        Test passes when:
        - New offering is created from application jar file.
        - Instance of newly created offering is created.
        - Instance can be deleted.
        - New offering can be deleted from marketplace.

        <b>Steps:</b>
        1. Create service offering from a application jar file.
        2. Create service instance.
        3. Stop service instance.
        4. Delete service instance.
        5. Delete service offering.
        """
        step("Register in marketplace")
        service = ServiceOffering.create_from_binary(
            context,
            jar_path=app_jar,
            manifest_path=manifest_json,
            offering_path=offering_json,
            client=api_service_admin_client)
        step("Check that service is in marketplace")
        assert_in_with_retry(service, ServiceOffering.get_list)
        step("Check that service is in state 'READY'")
        service.ensure_ready()
        step("Create service instance")
        instance = ServiceInstance.create_with_name(
            context, offering_label=service.label, plan_name=ServicePlan.FREE)
        step("Check created instance")
        instance.ensure_running()
        assert instance.offering_id == service.id
        assert instance.offering_label == service.label
        step("Stop service instance")
        instance.stop()
        instance.ensure_stopped()
        step("Delete service instance")
        instance.delete()
        instance.ensure_deleted()
        step("Delete service")
        service.delete(client=api_service_admin_client)
        step("Check that service isn't in marketplace")
        assert_not_in_with_retry(service, ServiceOffering.get_list)
コード例 #11
0
 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
コード例 #12
0
 def test_one_service_plan_in_offering(self, response):
     offering = ServiceOffering._from_response(response, client=mock.Mock())
     assert len(offering.service_plans) == 2
     plan_0 = next(p for p in offering.service_plans if p.id == PLAN_0_ID)
     plan_1 = next(p for p in offering.service_plans if p.id == PLAN_1_ID)
     assert plan_0.id == PLAN_0_ID
     assert plan_0.name == PLAN_0_NAME
     assert plan_0.description == PLAN_0_DESCRIPTION
     assert plan_1.id == PLAN_1_ID
     assert plan_1.name == PLAN_1_NAME
     assert plan_1.description == PLAN_1_DESCRIPTION
コード例 #13
0
 def test_metadata_to_dict(self):
     keys = ["test_key_a", "test_key_b"]
     values = ["test_value_a", "test_value_b"]
     expected_metadata_dict = {
         keys[0]: values[0],
         keys[1]: values[1]
     }
     metadata = [{"key": keys[0], "value": values[0]},
                 {"key": keys[1], "value": values[1]}]
     metadata_dict = ServiceOffering._metadata_to_dict(metadata)
     assert expected_metadata_dict == metadata_dict
コード例 #14
0
 def test_create_from_binary(self):
     context = Context()
     self.mock_api_service.create_offering_from_binary.return_value = POST_RESPONSE_ONE_PLAN
     offering = ServiceOffering.create_from_binary(context, jar_path=JAR_PATH, manifest_path=MANIFEST_PATH,
                                                   offering_path=OFFERING_PATH)
     assert type(offering) == ServiceOffering
     assert offering.label == OFFERING_LABEL
     self.mock_api_service.create_offering_from_binary.assert_called_with(jar_path=JAR_PATH,
                                                                          manifest_path=MANIFEST_PATH,
                                                                          offering_path=OFFERING_PATH,
                                                                          client=offering._client)
コード例 #15
0
    def test_create_and_delete_new_offering(self, context,
                                            api_service_admin_client):
        """
        <b>Description:</b>
        Create and later remove offering via api service

        <b>Input data:</b>
        - Admin credentials

        <b>Expected results:</b>
        - It's possible to create offering
        - It's possible to remove the offering

        <b>Steps:</b>
        - Create the offering via api service
        - Verify the offering is on list
        - Verify it's possible to retrieve offering via id
        - Remove the offering
        - Verify the offering was removed
        """
        step("Create new offering")
        test_offering = ServiceOffering.create(context,
                                               client=api_service_admin_client)
        step("Check that the new offering is in catalog")
        catalog = ServiceOffering.get_list(client=api_service_admin_client)
        assert test_offering in catalog
        step("Get the offering")
        offering = ServiceOffering.get(offering_id=test_offering.id,
                                       client=api_service_admin_client)
        assert test_offering == offering
        step("Delete the offering")
        test_offering.delete(client=api_service_admin_client)
        step("Check that the offering is no longer in catalog")
        catalog = ServiceOffering.get_list(client=api_service_admin_client)
        assert test_offering not in catalog
        step("Check that requesting the deleted offering returns an error")
        assert_raises_http_exception(ApiServiceHttpStatus.CODE_NOT_FOUND,
                                     ApiServiceHttpStatus.MSG_KEY_NOT_FOUND,
                                     test_offering.delete,
                                     client=api_service_admin_client,
                                     force=True)
コード例 #16
0
 def offering_nats(self, class_context, api_service_admin_client):
     test_offering = ServiceOffering.create(
         class_context,
         template_body=template_example.nats_template["body"],
         client=api_service_admin_client)
     catalog_offerings = CatalogService.get_list()
     offering = next(
         (o for o in catalog_offerings if o.name == test_offering.label),
         None)
     assert offering is not None, "No such offering {}".format(
         test_offering.label)
     return offering
コード例 #17
0
def pytest_generate_tests(metafunc):
    """Parametrize marketplace fixture with tuples of ServiceOffering and plan dict."""
    if "non_parametrized_marketplace_services" in metafunc.funcargnames:
        marketplace = ServiceOffering.get_list()
        test_cases = []
        ids = []
        for offering in marketplace:
            if offering.service_plans is not None:
                for plan in offering.service_plans:
                    if not ParametrizedService.is_parametrized(label=offering.label, plan_name=plan.name):
                        test_cases.append((offering, plan))
                        ids.append("{}_{}".format(offering.label, plan.name))
        metafunc.parametrize("non_parametrized_marketplace_services", test_cases, ids=ids)
コード例 #18
0
    def test_create_service_with_icon(self, context, app_jar, manifest_json,
                                      example_image):
        """
        <b>Description:</b>
        Create new service offering with custom icon.

        <b>Input data:</b>
        1. application jar file
        2. manifest.json file
        3. example image

        <b>Expected results:</b>
        Test passes when new offering is created with custom icon.

        <b>Steps:</b>
        1. Prepare offering json file with custom icon.
        2. Create service offering.
        3. Check that created offering is present on the offering list.
        4. Check that offering has a custom icon.
        """
        step("Prepare offering json")
        metadata = [
            {
                "key": "imageUrl",
                "value": example_image.decode()
            },
        ]
        offering_file = ServiceOffering.create_offering_json(metadata=metadata)
        step("Register in marketplace")
        service = ServiceOffering.create_from_binary(
            context,
            jar_path=app_jar,
            manifest_path=manifest_json,
            offering_path=offering_file)
        step("Check that service is in marketplace")
        assert_in_with_retry(service, ServiceOffering.get_list)
        step("Check that images are the same")
        assert example_image == bytes(service.image, "utf8")
コード例 #19
0
    def test_create_service_with_display_name(self, context, app_jar,
                                              manifest_json):
        """
        <b>Description:</b>
        Create new service offering with display name.

        <b>Input data:</b>
        1. application jar file
        2. manifest.json file

        <b>Expected results:</b>
        Test passes when new offering is created with display name.

        <b>Steps:</b>
        1. Prepare offering json file with display name.
        2. Create service offering.
        3. Check that created offering is present on the offering list.
        4. Check that offering has custom display name.
        """
        step("Prepare offering json")
        display_name = generate_test_object_name()
        metadata = [
            {
                "key": "displayName",
                "value": display_name
            },
        ]
        offering_file = ServiceOffering.create_offering_json(metadata=metadata)
        step("Register in marketplace")
        service = ServiceOffering.create_from_binary(
            context,
            jar_path=app_jar,
            manifest_path=manifest_json,
            offering_path=offering_file)
        step("Check that service is in marketplace")
        assert_in_with_retry(service, ServiceOffering.get_list)
        step("Check that display names are the same")
        assert display_name == service.display_name
コード例 #20
0
def cleanup_test_data():
    core_org_guid = core_org().guid
    test_object_models = [
        {'name': 'data set', 'objects_list': DataSet.api_get_list(), 'name_attribute': 'title'},
        {'name': 'transfer', 'objects_list': Transfer.api_get_list(), 'name_attribute': 'title'},
        {'name': 'user', 'objects_list': User.get_list_in_organization(org_guid=core_org_guid), 'name_attribute': 'username'},
        {'name': 'invitation', 'objects_list': Invitation.api_get_list(), 'name_attribute': 'username'},
        {'name': 'application', 'objects_list': Application.get_list(), 'name_attribute': 'name'},
        {'name': 'service', 'objects_list': ServiceInstance.get_list(), 'name_attribute': 'name'},
        {'name': 'offering', 'objects_list': ServiceOffering.get_list(), 'name_attribute': 'label'},
        {'name': 'scoring engine model', 'objects_list': ScoringEngineModel.get_list(org_guid=core_org_guid),
         'name_attribute': 'name'}
    ]
    for model in test_object_models:
        _cleanup_test_data(**model)
コード例 #21
0
    def from_reference(cls, org_guid):
        from modules.tap_object_model import Application, User, Organization, ServiceOffering, ServiceInstance, DataSet
        metrics = []
        app_down_states = [TapEntityState.FAILURE, TapEntityState.STOPPED]

        apps = Application.get_list()
        apps_count = len(apps)
        apps_running_count = len(
            [app for app in apps if app.state == TapEntityState.RUNNING])
        apps_down_count = len(
            [app for app in apps if app.state in app_down_states])
        user_count = len(User.get_all_users(org_guid))
        orgs_count = len(Organization.get_list())
        services_count = len(ServiceOffering.get_list())
        services_inst = len([
            instance for instance in ServiceInstance.get_list()
            if instance.state == TapEntityState.RUNNING
        ])

        nodes = KubernetesNode.get_list()
        for node in nodes:
            metrics.append(node.get_metrics())

        cpu_usage_org = cls.parse_cpu(metrics) / (cls.CPU_RATE_FOR_REF *
                                                  cls.NODE)
        cpu_usage_platform = cls.parse_cpu(metrics) / (cls.CPU_RATE_FOR_REF *
                                                       cls.NODE)
        memory_usage_org = cls.parse_memory(metrics)
        memory_usage_platform = cls.parse_memory(metrics)

        datasets = DataSet.api_get_list(org_guid_list=[org_guid])

        return cls(apps=apps_count,
                   apps_running=apps_running_count,
                   apps_down=apps_down_count,
                   users_org=user_count,
                   users_platform=user_count,
                   orgs=orgs_count,
                   services=services_count,
                   service_instances=services_inst,
                   service_usage=services_inst,
                   cpu_usage_org=cpu_usage_org,
                   memory_usage_org=memory_usage_org,
                   cpu_usage_platform=cpu_usage_platform,
                   memory_usage_platform=memory_usage_platform,
                   datasets=datasets)
コード例 #22
0
    def test_0_check_mongodb_in_marketplace(self, test_space):
        """
        <b>Description:</b>
        Check that mongodb offering is present in marketplace.

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

        <b>Expected results:</b>
        Test passes if mongodb offering is present in marketplace.

        <b>Steps:</b>
        1. Get list of all service offerings from marketplace.
        2. Check that mongodb offering is present in retrieved list.
        """
        step("Check if mongodb clustered service is in marketplace")
        marketplace = ServiceOffering.get_list()
        mongodb = next((service for service in marketplace if service.label == self.MONGODB_SERVICE_LABEL), None)
        assert mongodb is not None, "{} not available".format(self.MONGODB_SERVICE_LABEL)
コード例 #23
0
    def test_0_create_atk_instance(self, class_context, test_org, test_space, add_admin_to_test_org):
        step("Check that atk service is available in Marketplace")
        marketplace = ServiceOffering.get_list()
        atk_service = next((s for s in marketplace if s.label == ServiceLabels.ATK), None)
        assert atk_service is not None, "No atk service found in marketplace."
        step("Create atk service instance")

        atk_instance_name = generate_test_object_name()
        atk_instance = ServiceInstance.api_create_with_plan_name(
            context=class_context,
            org_guid=test_org.guid,
            space_guid=test_space.guid,
            service_label=ServiceLabels.ATK,
            name=atk_instance_name,
            service_plan_name=ServicePlan.SIMPLE_ATK
        )

        validator = ApplicationStackValidator(atk_instance)
        validator.validate()
        self.__class__.atk_url = validator.application.urls[0]
コード例 #24
0
 def test_create_offering_json_with_default_data(self):
     random_name = "test_name"
     file_name = "offering.json"
     default_plan = [{
         "name": ServicePlanNames.FREE,
         "description": ServicePlanNames.FREE,
         "cost": ServicePlanNames.FREE
     }]
     offering_dict = {
         "name": random_name,
         "description": random_name,
         "metadata": [],
         "bindable": True,
         "tags": [],
         "plans": default_plan
     }
     self.mock_generate_test_object_name.return_value = random_name
     self.mock_file_utils.save_text_file.return_value = OFFERING_PATH
     offering_json = ServiceOffering.create_offering_json()
     assert offering_json == OFFERING_PATH
     self.mock_file_utils.save_text_file.assert_called_with(data=json.dumps(offering_dict), file_name=file_name)
コード例 #25
0
 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
コード例 #26
0
 def test_create_offering_json_witd_custom_data(self):
     custom_name = "test_name"
     file_name = "offering.json"
     metadata = [{"key": "test_key", "value": "test_value"}]
     tags = ["test_tag_a", "test_tag_b"]
     custom_plan = [{
         "name": ServicePlanNames.BARE,
         "description": ServicePlanNames.CLUSTERED,
         "cost": ServicePlanNames.ENCRYPTED
     }]
     offering_dict = {
         "name": custom_name,
         "description": custom_name,
         "metadata": metadata,
         "bindable": False,
         "tags": tags,
         "plans": custom_plan
     }
     self.mock_file_utils.save_text_file.return_value = OFFERING_PATH
     offering_json = ServiceOffering.create_offering_json(name=custom_name, description=custom_name,
                                                          metadata=metadata, bindable=False, tags=tags,
                                                          plans=custom_plan)
     assert offering_json == OFFERING_PATH
     self.mock_file_utils.save_text_file.assert_called_with(data=json.dumps(offering_dict), file_name=file_name)
コード例 #27
0
 def public_service(self):
     services = ServiceOffering.get_list()
     return next(s for s in services if s.label == ServiceLabels.ZOOKEEPER)
コード例 #28
0
 def etcd_offering(cls, api_service_admin_client):
     offerings = ServiceOffering.get_list(client=api_service_admin_client)
     offering = next(
         (o for o in offerings if o.label == ServiceLabels.KAFKA), None)
     assert offering is not None, "{} not found".format(ServiceLabels.KAFKA)
     return offering
コード例 #29
0
 def offering_json(self):
     return ServiceOffering.create_offering_json()
コード例 #30
0
 def manifest_json(self):
     return ServiceOffering.create_manifest_json(self.APP_TYPE)