forked from cloudfoundry/cf-acceptance-tests
/
instance_reporting.go
89 lines (74 loc) · 2.57 KB
/
instance_reporting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package windows
import (
"fmt"
"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
. "github.com/cloudfoundry-incubator/cf-test-helpers/workflowhelpers"
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
const EXCEED_CELL_MEMORY = "900g"
var _ = WindowsDescribe("Getting instance information", func() {
var appName string
BeforeEach(func() {
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-s", Config.GetWindowsStack(),
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().WindowsWebapp,
"-c", ".\\webapp.exe",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
})
AfterEach(func() {
app_helpers.AppReport(appName)
Eventually(cf.Cf("delete", appName, "-f")).Should(Exit(0))
})
Context("scaling memory", func() {
BeforeEach(func() {
setTotalMemoryLimit(RUNAWAY_QUOTA_MEM_LIMIT)
})
AfterEach(func() {
setTotalMemoryLimit("10G")
})
It("fails when scaled beyond available resources", func() {
scale := cf.Cf("scale", appName, "-m", EXCEED_CELL_MEMORY, "-f")
Eventually(scale, Config.CfPushTimeoutDuration()).Should(Or(Say("insufficient resources"), Say("down")))
scale.Kill()
app := cf.Cf("app", appName)
Eventually(app).Should(Exit(0))
Expect(app.Out).NotTo(Say("instances: 1/1"))
})
})
})
func setTotalMemoryLimit(memoryLimit string) {
type quotaDefinitionUrl struct {
Resources []struct {
Entity struct {
QuotaDefinitionUrl string `json:"quota_definition_url"`
} `json:"entity"`
} `json:"resources"`
}
orgEndpoint := fmt.Sprintf("/v2/organizations?q=name%%3A%s", TestSetup.GetOrganizationName())
var org quotaDefinitionUrl
ApiRequest("GET", orgEndpoint, &org, Config.DefaultTimeoutDuration())
Expect(org.Resources).ToNot(BeEmpty())
type quotaDefinition struct {
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
var quota quotaDefinition
ApiRequest("GET", org.Resources[0].Entity.QuotaDefinitionUrl, "a, Config.DefaultTimeoutDuration())
Expect(quota.Entity.Name).ToNot(BeEmpty())
AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
Expect(cf.Cf("update-quota", quota.Entity.Name,
"-m", memoryLimit).Wait()).To(Exit(0))
})
}