func newDesiredLRP(guid string) (*models.DesiredLRP, error) {
	myRouterJSON := json.RawMessage(`[{"hostnames":["dora.bosh-lite.com"],"port":8080}]`)
	myRouterJSON2 := json.RawMessage(`{"container_port":2222,"host_fingerprint":"44:00:2b:21:19:1a:42:ab:54:2f:c3:9d:97:d6:c8:0f","private_key":"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCu4BiQh96+AvbYHDxRhfK9Scsl5diUkb/LIbe7Hx7DZg8iTxvr\nkw+de3i1TZG3wH02bdReBnCXrN/u59q0qqsz8ge71BFqnSF0dJaSmXhWizN0NQEy\n5u4WyqM4WJTzUGFnofJxnwFArHBT6QEtDjqCJxyggjuBrF60x3HtSfp4gQIDAQAB\nAoGBAJp/SbSHFXbxz3tmlrO/j5FEHMJCqnG3wqaIB3a+K8Od60j4c0ZRCr6rUx16\nhn69BOKNbc4UCm02QjEjjcmH7u/jLflvKLR/EeEXpGpAd7i3b5bqNn98PP+KwnbS\nPxbot37KErdwLnlF8QYFZMeqHiXQG8nO1nqroiX+fVUDtipBAkEAx8nDxLet6ObJ\nWzdR/8dSQ5qeCqXlfX9PFN6JHtw/OBZjRP5jc2cfGXAAB2h7w5XBy0tak1+76v+Y\nTrdq/rqAdQJBAOAT7W0FpLAZEJusY4sXkhZJvGO0e9MaOdYx53Z2m2gUgxLuowkS\nOmKn/Oj+jqr8r1FAhnTYBDY3k5lzM9p41l0CQEXQ9j6qSXXYIIllvZv6lX7Wa2Ah\nNR8z+/i5A4XrRZReDnavxyUu5ilHgFsWYhmpHb3jKVXS4KJwi1MGubcmiXkCQQDH\nWrNG5Vhpm0MdXLeLDcNYtO04P2BSpeiC2g81Y7xLUsRyWYEPFvp+vznRCHhhQ0Gu\npht5ZJ4KplNYmBev7QW5AkA2PuQ8n7APgIhi8xBwlZW3jufnSHT8dP6JUCgvvon1\nDvUM22k/ZWRo0mUB4BdGctIqRFiGwB8Hd0WSl7gSb5oF\n-----END RSA PRIVATE KEY-----\n"}`)
	modTag := models.NewModificationTag("epoch", 0)
	desiredLRP := &models.DesiredLRP{
		ProcessGuid:          guid,
		Domain:               "benchmark-bbs",
		RootFs:               "some:rootfs",
		Instances:            1,
		EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}},
		Setup:                models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		Action:               models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		StartTimeoutMs:       15000,
		Monitor: models.WrapAction(models.EmitProgressFor(
			models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))),
				10*time.Second,
			),
			"start-message",
			"success-message",
			"failure-message",
		)),
		DiskMb:    512,
		MemoryMb:  1024,
		CpuWeight: 42,
		Routes: &models.Routes{"my-router": &myRouterJSON,
			"diego-ssh": &myRouterJSON2},
		LogSource:   "some-log-source",
		LogGuid:     "some-log-guid",
		MetricsGuid: "some-metrics-guid",
		Annotation:  "some-annotation",
		EgressRules: []*models.SecurityGroupRule{{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"},
			PortRange:    &models.PortRange{Start: 10, End: 16000},
		}},
		ModificationTag: &modTag,
	}
	err := desiredLRP.Validate()
	if err != nil {
		return nil, err
	}

	return desiredLRP, nil
}
Пример #2
0
func NewValidDesiredLRP(guid string) *models.DesiredLRP {
	myRouterJSON := json.RawMessage(`{"foo":"bar"}`)
	modTag := models.NewModificationTag("epoch", 0)
	desiredLRP := &models.DesiredLRP{
		ProcessGuid:          guid,
		Domain:               "some-domain",
		RootFs:               "some:rootfs",
		Instances:            1,
		EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}},
		CachedDependencies: []*models.CachedDependency{
			{Name: "app bits", From: "blobstore.com/bits/app-bits", To: "/usr/local/app", CacheKey: "cache-key", LogSource: "log-source"},
			{Name: "app bits with checksum", From: "blobstore.com/bits/app-bits-checksum", To: "/usr/local/app-checksum", CacheKey: "cache-key", LogSource: "log-source", ChecksumAlgorithm: "md5", ChecksumValue: "checksum-value"},
		},
		Setup:          models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		Action:         models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		StartTimeoutMs: 15000,
		Monitor: models.WrapAction(models.EmitProgressFor(
			models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))),
				10*time.Second,
			),
			"start-message",
			"success-message",
			"failure-message",
		)),
		DiskMb:      512,
		MemoryMb:    1024,
		CpuWeight:   42,
		MaxPids:     1024,
		Routes:      &models.Routes{"my-router": &myRouterJSON},
		LogSource:   "some-log-source",
		LogGuid:     "some-log-guid",
		MetricsGuid: "some-metrics-guid",
		Annotation:  "some-annotation",
		Network: &models.Network{
			Properties: map[string]string{
				"some-key":       "some-value",
				"some-other-key": "some-other-value",
			},
		},
		EgressRules: []*models.SecurityGroupRule{{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"},
			PortRange:    &models.PortRange{Start: 10, End: 16000},
		}},
		ModificationTag:               &modTag,
		LegacyDownloadUser:            "******",
		TrustedSystemCertificatesPath: "/etc/somepath",
		PlacementTags:                 []string{"red-tag", "blue-tag"},
		VolumeMounts: []*models.VolumeMount{
			{
				Driver:       "my-driver",
				ContainerDir: "/mnt/mypath",
				Mode:         "r",
				Shared: &models.SharedDevice{
					VolumeId:    "my-volume",
					MountConfig: `{"foo":"bar"}`,
				},
			},
		},
	}
	err := desiredLRP.Validate()
	Expect(err).NotTo(HaveOccurred())

	return desiredLRP
}
			)

			BeforeEach(func() {
				processGuid = "process-guid-1"
				desiredLRP = model_helpers.NewValidDesiredLRP(processGuid)
				desiredLRP.DeprecatedStartTimeoutS = 15
				desiredLRP.Action = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
					DeprecatedTimeoutNs: 4 * int64(time.Second),
				})

				desiredLRP.Setup = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
					DeprecatedTimeoutNs: 7 * int64(time.Second),
				})
				desiredLRP.Monitor = models.WrapAction(models.EmitProgressFor(
					&models.TimeoutAction{
						Action:              models.WrapAction(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"})))),
						DeprecatedTimeoutNs: 10 * int64(time.Second),
					},
					"start-message",
					"success-message",
					"failure-message",
				))
			})

			JustBeforeEach(func() {
				schedulingInfo, runInfo := desiredLRP.CreateComponents(fakeClock.Now())
				runInfo.DeprecatedStartTimeoutS = 15

				_, err := json.Marshal(desiredLRP.Routes)
				Expect(err).NotTo(HaveOccurred())
Пример #4
0
	Describe("Try", func() {
		itSerializesAndDeserializes(
			`{
					"action": {
						"run": {
							"path": "echo",
							"resource_limits":{},
							"user": "******",
							"suppress_log_output": false
						}
					}
			}`,
			models.WrapAction(models.Try(&models.RunAction{
				Path:           "echo",
				User:           "******",
				ResourceLimits: &models.ResourceLimits{},
			})),
		)

		Describe("Validate", func() {
			var tryAction *models.TryAction

			Context("when the action has 'action' specified", func() {
				It("is valid", func() {
					tryAction = &models.TryAction{
						Action: &models.Action{
							UploadAction: &models.UploadAction{
								From: "local_location",
								To:   "web_location",
								User: "******",