def test_list_by_svc_share_uuids(): tenant_id = "6d1c06e1d9e84d57aeb42ea80d49018a" service_id = "560ca84003254737a426d0bd5f513afd" service_cname = "WordPress" group_id = 20 service = TenantServiceInfo() service.tenant_id = tenant_id service.service_id = service_id service.service_cname = service_cname service.save() service_source = ServiceSourceInfo() service_source.team_id = tenant_id service_source.service_id = service_id service_source.service_share_uuid = "2669c2cec6bc7bf5aab29a0ea2703d66" service_source.save() group_relation = ServiceGroupRelation() group_relation.service_id = service_id group_relation.group_id = group_id group_relation.save() from console.repositories.app import service_repo result = service_repo.list_by_svc_share_uuids( group_id, ["2669c2cec6bc7bf5aab29a0ea2703d66"]) service = result[0] assert service.get("service_id") == service_id assert service.get("service_cname") == service_cname
def dep_services_changes(self, component, dep_uuids, component_names={}, level="svc"): """ find out the dependencies that need to be created and the dependencies that need to be removed """ dep_relations = dep_relation_repo.get_service_dependencies(self.service.tenant_id, self.service.service_id) service_ids = [item.dep_service_id for item in dep_relations] # get service_share_uuid by service_id service_share_uuids = service_source_repo.get_service_sources_by_service_ids(service_ids).values_list( "service_share_uuid", flat=True) group_id = service_group_relation_repo.get_group_id_by_service(self.service) # dep services from exist service new_dep_services = service_repo.list_by_svc_share_uuids(group_id, dep_uuids) if level == "app": exist_uuids = [svc["service_share_uuid"] for svc in new_dep_services] # dep services from apps # combine two types of dep_services for new_dep_service in self.new_dep_services_from_apps(component, dep_uuids, component_names): if new_dep_service["service_share_uuid"] not in exist_uuids: new_dep_services.append(new_dep_service) # filter existing dep services def dep_service_existed(service): if service.get("service_id", None) is None: return service["service_share_uuid"] in service_share_uuids return service["service_id"] in service_ids add = [svc for svc in new_dep_services if not dep_service_existed(svc)] if not add: return None return { "add": add, }
def get_service_by_service_key(self, service, dep_service_key): """ get service according to service_key that is sometimes called service_share_uuid. """ group_id = service_group_relation_repo.get_group_id_by_service(service) dep_services = service_repo.list_by_svc_share_uuids(group_id, [dep_service_key]) if not dep_services: logger.warning("service share uuid: {}; failed to get dep service: \ service not found".format(dep_service_key)) return None return dep_services[0]
def dep_services_changes(self, dep_uuids): """ find out the dependencies that need to be created and the dependencies that need to be removed """ dep_relations = dep_relation_repo.get_service_dependencies(self.service.tenant_id, self.service.service_id) service_ids = [item.dep_service_id for item in dep_relations] group_id = service_group_relation_repo.get_group_id_by_service(self.service) new_dep_services = service_repo.list_by_svc_share_uuids(group_id, dep_uuids) add = [svc for svc in new_dep_services if svc.service_id not in service_ids] if not add: return None return { "add": add, }