Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Tackle "plan not found" issues #450

Merged
merged 16 commits into from
Mar 3, 2023
Merged
30 changes: 3 additions & 27 deletions libs/python/btp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def check_if_account_can_cover_use_case(self):
log.success("Use case supported in your global account!")

def create_directory(self):

if self.usedirectory is False:
# Do not create a directory for the use case
return
Expand All @@ -202,7 +201,6 @@ def create_directory(self):
or accountMetadata["directoryid"] == ""
or accountMetadata["directoryid"] is None
):

log.warning("no directory id provided and tool will make up one for you")

directory = createDirectoryName(self)
Expand Down Expand Up @@ -337,7 +335,6 @@ def executeAfterEnvironmentAvailability(self):
environment.name == "kymaruntime"
and self.waitForKymaEnvironmentCreation is True
):

accountMetadata = self.accountMetadata
kymaClusterName = environment.parameters["name"]

Expand Down Expand Up @@ -379,7 +376,6 @@ def executeAfterEnvironmentAvailability(self):
getKymaEnvironmentStatusFromEnvironmentDataEntry(entryOfKymaEnv)
== "OK"
):

log.info("Kyma Environment created - extracting kubeconfig URL")
self.accountMetadata = addKeyValuePair(
accountMetadata,
Expand Down Expand Up @@ -437,7 +433,6 @@ def entitle_subaccount(self):
doAllEntitlements(self, self.definedAppSubscriptions)

def create_subaccount(self):

accountMetadata = self.accountMetadata
subaccountid = self.subaccountid
self.accountMetadata = addKeyValuePair(
Expand All @@ -453,7 +448,6 @@ def create_subaccount(self):
or accountMetadata["subaccountid"] == ""
or accountMetadata["subaccountid"] is None
):

log.warning("no subaccount id provided and tool will make up one for you")
usecaseRegion = self.region

Expand Down Expand Up @@ -572,11 +566,9 @@ def create_subaccount(self):
save_collected_metadata(self)

def initialize_environments(self):

self.create_environments()

def create_environments(self):

accountMetadata = self.accountMetadata
environments = self.definedEnvironments

Expand All @@ -588,14 +580,11 @@ def create_environments(self):
self.accountMetadata = addKeyValuePair(accountMetadata, "orgid", self.orgid)

if self.orgid is None or self.orgid == "":

for environment in environments:

if environment.name == "cloudfoundry":
orgid, org = checkIfCFEnvironmentAlreadyExists(self)

if org is None or orgid is None:

envName = environment.name
envPlan = environment.plan

Expand Down Expand Up @@ -860,7 +849,6 @@ def create_environments(self):
foundOrg = False
for environment in environments:
if environment.name == "cloudfoundry":

command = (
"btp --format json list accounts/environment-instances --subaccount '"
+ subaccountid
Expand Down Expand Up @@ -910,7 +898,6 @@ def create_new_cf_space(self, environment):
cfEnvironment = True

if cfEnvironment is True:

accountMetadata = self.accountMetadata

cfspacename = self.cfspacename
Expand Down Expand Up @@ -960,7 +947,6 @@ def create_new_cf_space(self, environment):

def create_and_assign_quota_plan(self, environment):
if environment.name == "cloudfoundry" and self.cfspacequota is not None:

if self.cfspacequota.get("createQuotaPlan") is True:
command = "cf create-space-quota " + self.cfspacequota.get(
"spaceQuotaName"
Expand Down Expand Up @@ -1079,7 +1065,6 @@ def createRoleCollections(self):
assignUsersToCustomRoleCollections(self)

def create_configured_app_subscriptions_and_services(self):

##################################################################################
# Initiate all app subscriptions
##################################################################################
Expand Down Expand Up @@ -1109,7 +1094,8 @@ def createServiceKeys(self):
accountMetadata = self.accountMetadata

if (
accountMetadata is not None and "createdServiceInstances" in accountMetadata
accountMetadata is not None
and "createdServiceInstances" in accountMetadata
and len(accountMetadata["createdServiceInstances"]) > 0
):
log.header("Create service keys if configured")
Expand Down Expand Up @@ -1204,7 +1190,6 @@ def getServiceCategoryItemsFromUsecaseFile(
def check_if_account_can_cover_use_case_for_serviceType(
btpUsecase: BTPUSECASE, availableForAccount
):

usecaseRegion = btpUsecase.region
fallbackServicePlan = None

Expand All @@ -1222,7 +1207,6 @@ def check_if_account_can_cover_use_case_for_serviceType(
if service.category != "CF_CUP_SERVICE":
allServices.append(service)
for app in btpUsecase.definedAppSubscriptions:

if app.customerDeveloped is True:
continue

Expand Down Expand Up @@ -1330,18 +1314,15 @@ def check_if_account_can_cover_use_case_for_serviceType(
def check_if_account_can_cover_use_case_for_customapps(
btpUsecase: BTPUSECASE, availableCustomApps
):

usecaseSupported = True

customApps = []
# Only check custom apps as they need special handling
for app in btpUsecase.definedAppSubscriptions:

if app.customerDeveloped is True and app.category == "APPLICATION":
customApps.append(app)

if len(customApps) != 0 and len(availableCustomApps) != 0:

for customApp in customApps:
supported = False

Expand Down Expand Up @@ -1747,7 +1728,6 @@ def subscribe_app_to_subaccount(btpUsecase: BTPUSECASE, app, plan, parameters):

runShellCommand(btpUsecase, command, "INFO", message)
else:

message = "subscription already there for >" + app + "<"
if plan is not None:
# (Optional) The subscription plan of the multitenant application. You can omit this parameter if the multitenant application is in the current global account.
Expand Down Expand Up @@ -1784,7 +1764,6 @@ def checkIfAppIsSubscribed(btpUsecase: BTPUSECASE, appName, appPlan):


def doAllEntitlements(btpUsecase: BTPUSECASE, allItems):

# Ensure to have a list of all entitlements as combination of service name and plan
entitlements = []
for service in allItems:
Expand Down Expand Up @@ -1821,7 +1800,6 @@ def initiateAppSubscriptions(btpUsecase: BTPUSECASE):
btpUsecase.definedAppSubscriptions is not None
and len(btpUsecase.definedAppSubscriptions) > 0
):

log.header("Initiate subscriptions to apps")

# Now do all the subscriptions
Expand Down Expand Up @@ -1874,7 +1852,6 @@ def checkIfAllSubscriptionsAreAvailable(btpUsecase: BTPUSECASE):

allSubscriptionsAvailable = True
for app in btpUsecase.definedAppSubscriptions:

if app.entitleonly is False:
for thisJson in resultCommand["applications"]:
name = thisJson.get("appName")
Expand Down Expand Up @@ -1961,7 +1938,7 @@ def track_creation_of_subscriptions_and_services(btpUsecase: BTPUSECASE):
log.error(
"Could not get all services and/or app subscriptions up and running. Sorry."
)
sys.exit(os.EX_NOTFOUND)
sys.exit(os.EX_DATAERR)


def addCreatedServicesToMetadata(btpUsecase: BTPUSECASE):
Expand Down Expand Up @@ -1995,7 +1972,6 @@ def addCreatedServicesToMetadata(btpUsecase: BTPUSECASE):


def checkConfigurationInfo(btpUsecase: BTPUSECASE):

# checkEmailsinUsecaseConfig(btpUsecase)
None

Expand Down
2 changes: 0 additions & 2 deletions libs/python/helperArgParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
def setupParams(myArguments):
parser = argparse.ArgumentParser()
if myArguments is not None and myArguments != "":

# local arguments: no remote file access possible, no authentication parameters needed
allJsonParameters = getJsonFromFile(myArguments)
for key, value in allJsonParameters.get("properties").items():
Expand Down Expand Up @@ -178,7 +177,6 @@ def checkProvidedArguments(btpUsecase):
log.header("Checking provided arguments and files")

if btpUsecase.loginmethod == "envVariables":

if btpUsecase.myemail is None or btpUsecase.myemail == "":
param = "BTPSA_PARAM_MYEMAIL"
paramValue = getEnvVariableValue(param)
Expand Down
3 changes: 0 additions & 3 deletions libs/python/helperCommandExecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def runShellCommand(btpUsecase, command, format, info):


def login_cf(btpUsecase):

cfDefined = checkIfCfEnvironmentIsDefined(btpUsecase)
if cfDefined is True:
accountMetadata = btpUsecase.accountMetadata
Expand Down Expand Up @@ -83,7 +82,6 @@ def login_btp(btpUsecase):
runShellCommandFlex(btpUsecase, command, "INFO", message, True, True)
fetchEmailAddressFromBtpConfigFile(btpUsecase)
else:

password = escapePassword(password)

message = (
Expand Down Expand Up @@ -277,7 +275,6 @@ def executeCommandsFromUsecaseFile(btpUsecase, message, jsonSection):


def escapePassword(password) -> str:

if '"' in password or "'" in password:
log.info("escaping special characters in password")
password = password.replace('"', '"')
Expand Down
27 changes: 24 additions & 3 deletions libs/python/helperEnvBTP.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from libs.python.helperGeneric import getTimingsForStatusRequest
from libs.python.helperCommandExecution import runShellCommand, runShellCommandFlex
from libs.python.helperJson import convertStringToJson, dictToString
import logging
import os
import sys
import time

from libs.python.helperCommandExecution import runShellCommand, runShellCommandFlex
from libs.python.helperEnvironments import (
check_if_service_plan_supported_in_environment,
)
from libs.python.helperGeneric import getTimingsForStatusRequest
from libs.python.helperJson import convertStringToJson, dictToString

log = logging.getLogger(__name__)


Expand All @@ -27,6 +31,13 @@ def get_btp_service_status(btpUsecase, service):
return result


def check_if_service_plan_supported_in_sapbtp(btpUsecase, service):
result = check_if_service_plan_supported_in_environment(
btpUsecase, service, "sapbtp"
)
return result


def create_btp_service(btpUsecase, service):
if is_service_instance_already_existing(btpUsecase, service) is True:
log.info(
Expand All @@ -36,6 +47,16 @@ def create_btp_service(btpUsecase, service):
)
return

if check_if_service_plan_supported_in_sapbtp(btpUsecase, service) is False:
log.error(
"Plan not supported in environment >sapbtp<: service >"
+ service.name
+ "< and plan >"
+ service.plan
+ "<."
)
sys.exit(os.EX_DATAERR)

command = (
"btp --format json create services/instance --subaccount "
+ btpUsecase.accountMetadata.get("subaccountid")
Expand Down
Loading