Skip to content

Commit

Permalink
adept broker acceptance to display binding configs
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Oct 22, 2024
1 parent 979581a commit dec3f28
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"configuration": {
"custom_metrics": {
"metric_submission_strategy": {
"allow_from": "same_app"
}
}
},
"instance_min_count": 1,
"instance_max_count": 4,
"scaling_rules": [
{
"metric_type": "memoryused",
"breach_duration_secs": 600,
"threshold": 30,
"operator": "<",
"cool_down_secs": 300,
"adjustment": "-1"
},
{
"metric_type": "memoryused",
"breach_duration_secs": 600,
"threshold": 90,
"operator": ">=",
"cool_down_secs": 300,
"adjustment": "+1"
}
],
"schedules": {
"timezone": "Asia/Shanghai",
"recurring_schedule": [
{
"start_time": "10:00",
"end_time": "18:00",
"days_of_week": [
1,
2,
3
],
"instance_min_count": 1,
"instance_max_count": 10,
"initial_min_instance_count": 5
},
{
"start_date": "2099-06-27",
"end_date": "2099-07-23",
"start_time": "11:00",
"end_time": "19:30",
"days_of_month": [
5,
15,
25
],
"instance_min_count": 3,
"instance_max_count": 10,
"initial_min_instance_count": 5
},
{
"start_time": "10:00",
"end_time": "18:00",
"days_of_week": [
4,
5,
6
],
"instance_min_count": 1,
"instance_max_count": 10
},
{
"start_time": "11:00",
"end_time": "19:30",
"days_of_month": [
10,
20,
30
],
"instance_min_count": 1,
"instance_max_count": 10
}
],
"specific_date": [
{
"start_date_time": "2099-06-02T10:00",
"end_date_time": "2099-06-15T13:59",
"instance_min_count": 1,
"instance_max_count": 4,
"initial_min_instance_count": 2
},
{
"start_date_time": "2099-01-04T20:00",
"end_date_time": "2099-02-19T23:15",
"instance_min_count": 2,
"instance_max_count": 5,
"initial_min_instance_count": 3
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"configuration": {
"custom_metrics": {
"metric_submission_strategy": {
"allow_from": "same_app"
}
}
},
"instance_min_count": 1,
"instance_max_count": 4,
"scaling_rules": [
{
"metric_type": "memoryused",
"breach_duration_secs": 600,
"threshold": 30,
"operator": "<",
"cool_down_secs": 300,
"adjustment": "-1"
},
{
"metric_type": "memoryused",
"breach_duration_secs": 600,
"threshold": 90,
"operator": ">=",
"cool_down_secs": 300,
"adjustment": "+1"
}
],
"schedules": {
"timezone": "Asia/Shanghai",
"recurring_schedule": [
{
"start_time": "10:00",
"end_time": "18:00",
"days_of_week": [
1,
2,
3
],
"instance_min_count": 1,
"instance_max_count": 10,
"initial_min_instance_count": 5
},
{
"start_date": "2099-06-27",
"end_date": "2099-07-23",
"start_time": "11:00",
"end_time": "19:30",
"days_of_month": [
5,
15,
25
],
"instance_min_count": 3,
"instance_max_count": 10,
"initial_min_instance_count": 5
},
{
"start_time": "10:00",
"end_time": "18:00",
"days_of_week": [
4,
5,
6
],
"instance_min_count": 1,
"instance_max_count": 10
},
{
"start_time": "11:00",
"end_time": "19:30",
"days_of_month": [
10,
20,
30
],
"instance_min_count": 1,
"instance_max_count": 10
}
],
"specific_date": [
{
"start_date_time": "2099-06-02T10:00",
"end_date_time": "2099-06-15T13:59",
"instance_min_count": 1,
"instance_max_count": 4,
"initial_min_instance_count": 2
},
{
"start_date_time": "2099-01-04T20:00",
"end_date_time": "2099-02-19T23:15",
"instance_min_count": 2,
"instance_max_count": 5,
"initial_min_instance_count": 3
}
]
}
}


42 changes: 30 additions & 12 deletions src/acceptance/broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ var _ = Describe("AutoScaler Service Broker", func() {

It("binds&unbinds with policy", func() {
policyFile := "../assets/file/policy/all.json"
policy, err := os.ReadFile(policyFile)
Expect(err).NotTo(HaveOccurred())

err = helpers.BindServiceToAppWithPolicy(cfg, appName, instance.name(), policyFile)
err := helpers.BindServiceToAppWithPolicy(cfg, appName, instance.name(), policyFile)
Expect(err).NotTo(HaveOccurred())
expectedPolicyFile := "../assets/file/policy/policy-with-configuration-same-app.json"
expectedPolicyWithConfig, err := os.ReadFile(expectedPolicyFile)
Expect(err).NotTo(HaveOccurred())

bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName)
Expect(bindingParameters).Should(MatchJSON(policy))
Expect(bindingParameters).Should(MatchJSON(expectedPolicyWithConfig))

instance.unbind(appName)
})
Expand All @@ -114,7 +114,7 @@ var _ = Describe("AutoScaler Service Broker", func() {

err = helpers.BindServiceToAppWithPolicy(cfg, appName, instance.name(), policyFile)
Expect(err).NotTo(HaveOccurred())

By("checking broker bind parameter response should have policy and configuration")
bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName)
Expect(bindingParameters).Should(MatchJSON(policy))

Expand Down Expand Up @@ -142,10 +142,21 @@ var _ = Describe("AutoScaler Service Broker", func() {
instance.unbind(appName)
})

It("bind&unbinds without policy", func() {
It("bind&unbinds without policy and gives only configuration", func() {
helpers.BindServiceToApp(cfg, appName, instance.name())
By("checking broker bind parameter response does not have policy but configuration only")
bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName)
Expect(bindingParameters).Should(MatchJSON("{}"))
expectedJSON := `{
"configuration": {
"custom_metrics": {
"metric_submission_strategy": {
"allow_from": "same_app"
}
}
}
}`

Expect(bindingParameters).Should(MatchJSON(expectedJSON))
instance.unbind(appName)
})

Expand All @@ -157,7 +168,7 @@ var _ = Describe("AutoScaler Service Broker", func() {
Describe("allows setting default policies", func() {
var instance serviceInstance
var defaultPolicy []byte
var policy []byte
var expectedDefaultPolicyWithConfigsJSON []byte

BeforeEach(func() {
instance = createServiceWithParameters(cfg.ServicePlan, "../assets/file/policy/default_policy.json")
Expand All @@ -173,7 +184,13 @@ var _ = Describe("AutoScaler Service Broker", func() {
err = json.Unmarshal(defaultPolicy, &serviceParameters)
Expect(err).NotTo(HaveOccurred())

policy, err = json.Marshal(serviceParameters.DefaultPolicy)
expectedDefaultPolicyWithConfigsJSON, err = os.ReadFile("../assets/file/policy/default_policy-with-configuration.json")
Expect(err).NotTo(HaveOccurred())
var serviceParametersWithConfigs = struct {
Configuration interface{} `json:"configuration"`
DefaultPolicy interface{} `json:"default_policy"`
}{}
err = json.Unmarshal(expectedDefaultPolicyWithConfigsJSON, &serviceParametersWithConfigs)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -184,9 +201,9 @@ var _ = Describe("AutoScaler Service Broker", func() {

It("sets the default policy if no policy is set during binding and allows retrieving the policy via the binding parameters", func() {
helpers.BindServiceToApp(cfg, appName, instance.name())

By("checking broker bind parameter response should have default policy and configuration")
bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName)
Expect(bindingParameters).Should(MatchJSON(policy))
Expect(bindingParameters).Should(MatchJSON(expectedDefaultPolicyWithConfigsJSON))

unbindService := cf.Cf("unbind-service", appName, instance.name()).Wait(cfg.DefaultTimeoutDuration())
Expect(unbindService).To(Exit(0), "failed unbinding service from app")
Expand All @@ -206,6 +223,7 @@ var _ = Describe("AutoScaler Service Broker", func() {
var instance serviceInstance
It("should update a service instance from one plan to another plan", func() {
servicePlans := GetServicePlans(cfg)
fmt.Println("servicePlans", servicePlans)
source, target, err := servicePlans.getSourceAndTargetForPlanUpdate()
Expect(err).NotTo(HaveOccurred(), "failed getting source and target service plans")
instance = createService(source.Name)
Expand Down

0 comments on commit dec3f28

Please sign in to comment.