Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Service does not honor space constraint when searching for service instances #3

Open
krmeda opened this issue Apr 18, 2018 · 4 comments
Assignees

Comments

@krmeda
Copy link

krmeda commented Apr 18, 2018

As seen in the below code:

res = self._cc.request(self._space.service_instances_url)\
.get_by_name(name)
self._service_instance = res.resource

The understanding from the service is that the service instance is restrained to the space resource that is set already. It causes undefined behavior when there are more than one service instance with the same name in multiple spaces in the same Org (and the user has access to both).

@adamjaso
Copy link
Member

adamjaso commented Apr 18, 2018

I believe I understand what you are saying here... You are suggesting that the code you cited is incorrect, because it is looking for a specific service in a specific space, but it appears to be querying without reference to the space, in which case it may match another service of the same name in the same org. Correct? Did you find this because it has caused you problems, or did you find it only by looking at the code? From what I can see, the url for self._space.service_instances_url will look like this /v2/spaces/<SPACEGUID>/service_instances. This would make it so that the search for the service instance is actually scoped to the space, as it should be and would not match a service instance from another org or space. @keerthimr

@adamjaso adamjaso self-assigned this Apr 19, 2018
@adamjaso
Copy link
Member

@keerthimr Can you confirm if this is causing you trouble now?

@krmeda
Copy link
Author

krmeda commented Apr 20, 2018

Sorry looks like i misunderstood the cause of issue.
When I try to create multiple services only the first one gets created and the result for all the other invocations are references to the first created service.

space = Space(cc, org_name=args.cfOrg, space_name=args.cfSpace)
if space.space is None:
    logger.warn("Specified space: %s does not exist", args.cfSpace)
    raise Exception("Specified Space does not exist")

serviceDefs = yaml.load(args.service_def_file)
# logger.debug("Service Definitions: %s", serviceDefs)

serviceDefs = map(deserialize_service_definition, serviceDefs['services'])

logger.debug("Service Definitions: %s", serviceDefs)
svcsToTrack = {}
service = space.get_deploy_service()
for svcDef in serviceDefs:
    logger.debug("Querying Service Info for: %s", svcDef)
    cfSvcInst = service.create(name=svcDef.instance_name, service_name=svcDef.service_name, service_plan_name=svcDef.service_plan,
               tags=svcDef.tags, parameters=svcDef.parameters)
    logger.info("Service Details: %s",cfSvcInst)
    svcsToTrack[svcDef.instance_name]= CfServiceInstance(name=svcDef.instance_name ,service_deploy=service, service_resource=cfSvcInst)

The svcsToTrack dict has the same return values for all of them

@adamjaso
Copy link
Member

adamjaso commented Apr 20, 2018

Ah. I think I see what you are meaning. Sorry for the misunderstanding. I will work on a fix for that. In the mean time, here is a workaround:

# ...
for svcDef in serviceDefs:
    service = space.get_deploy_service()
    cfSvcInst = service.create(name=svcDef.instance_name, service_name=svcDef.service_name, service_plan_name=svcDef.service_plan,
               tags=svcDef.tags, parameters=svcDef.parameters)
# ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants