Exemplo n.º 1
0
					ghttp.VerifyRequest("GET", "/api/common/nodes"),
					ghttp.RespondWith(http.StatusOK, expectedNodesData),
				),
			)

			node, err := rackhdapi.GetNodeByDiskCID(cpiConfig, "disk-1234")

			Expect(err).ToNot(HaveOccurred())
			Expect(node).To(Equal(expectedNodes[0]))
		})
	})

	Describe("GetOBMSettings", func() {
		It("returns a node's OBM settings", func() {
			dummy_response_path := "../spec_assets/dummy_one_node_response.json"
			httpResponse := helpers.LoadJSON(dummy_response_path)
			expectedResponse := helpers.LoadNode(dummy_response_path)

			nodeID := "nodeID"
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s", nodeID)),
					ghttp.RespondWith(http.StatusOK, httpResponse),
				),
			)

			response, err := rackhdapi.GetOBMSettings(cpiConfig, nodeID)
			Expect(err).ToNot(HaveOccurred())
			Expect(server.ReceivedRequests()).To(HaveLen(1))
			Expect(response).To(Equal(expectedResponse.OBMSettings))
		})
				server.RouteToHandler("GET", fmt.Sprintf("/api/common/nodes/%s", nodes[1].ID),
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s", nodes[1].ID)),
						ghttp.RespondWith(http.StatusOK, node1HttpResponse),
					),
				)

				_, err = randomSelectAvailableNode(cpiConfig, nodes, allowFilter)
				Expect(err).To(MatchError("all nodes have been reserved"))
			})
		})

		Context("when a node has an active workflow", func() {
			It("skips the node", func() {
				rawWorkflow := helpers.LoadJSON("../spec_assets/dummy_workflow_response.json")
				httpWorkflowsResponse := []byte(fmt.Sprintf("%s", string(rawWorkflow)))
				var expectedResponse rackhdapi.WorkflowResponse
				err := json.Unmarshal(httpWorkflowsResponse, &expectedResponse)
				Expect(err).ToNot(HaveOccurred())

				httpNodeResponse := helpers.LoadJSON("../spec_assets/dummy_one_node_response.json")

				nodeID := "5665a65a0561790005b77b85"
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", fmt.Sprintf("/api/1.1/nodes/%s/workflows/active", nodeID)),
						ghttp.RespondWith(http.StatusOK, httpWorkflowsResponse),
					),
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s", nodeID)),
		server = ghttp.NewServer()
		serverURL, err := url.Parse(server.URL())
		Expect(err).ToNot(HaveOccurred())
		jsonReader = strings.NewReader(fmt.Sprintf(`{"apiserver":"%s", "agent":{"blobstore": {"provider":"local","some": "options"}, "mbus":"localhost"}, "max_create_vm_attempts":1}`, serverURL.Host))
		cpiConfig, err = config.New(jsonReader, bosh.CpiRequest{})
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		server.Close()
	})

	Describe("GetActiveWorkflows", func() {
		Context("there is a running workflow", func() {
			It("returns a node's active workflow", func() {
				rawWorkflow := helpers.LoadJSON("../spec_assets/dummy_workflow_response.json")
				httpResponse := []byte(fmt.Sprintf("%s", string(rawWorkflow)))
				var expectedResponse rackhdapi.WorkflowResponse
				err := json.Unmarshal(httpResponse, &expectedResponse)
				Expect(err).ToNot(HaveOccurred())

				nodeID := "nodeID"
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", fmt.Sprintf("/api/1.1/nodes/%s/workflows/active", nodeID)),
						ghttp.RespondWith(http.StatusOK, httpResponse),
					),
				)

				response, err := rackhdapi.GetActiveWorkflows(cpiConfig, nodeID)
				Expect(err).ToNot(HaveOccurred())
					ghttp.VerifyRequest("GET", "/api/common/nodes/5665a65a0561790005b77b85"),
					ghttp.RespondWith(http.StatusOK, expectedNodeData),
				),
			)

			node, err := rackhdapi.GetNode(cpiConfig, "5665a65a0561790005b77b85")

			Expect(err).ToNot(HaveOccurred())
			Expect(node).To(Equal(expectedNode))
		})
	})

	Describe("GetOBMSettings", func() {
		It("returns a node's OBM settings", func() {
			dummyResponsePath := "../spec_assets/dummy_one_node_response.json"
			httpResponse := helpers.LoadJSON(dummyResponsePath)
			expectedResponse := helpers.LoadNode(dummyResponsePath)

			nodeID := "nodeID"
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s", nodeID)),
					ghttp.RespondWith(http.StatusOK, httpResponse),
				),
			)

			response, err := rackhdapi.GetOBMSettings(cpiConfig, nodeID)
			Expect(err).ToNot(HaveOccurred())
			Expect(server.ReceivedRequests()).To(HaveLen(1))
			Expect(response).To(Equal(expectedResponse.OBMSettings))
		})