Exemplo n.º 1
0
					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))
		})
	})
			It("attaches MAC address information from the RackHD API", func() {
				nodeCatalog := helpers.LoadNodeCatalog("../spec_assets/dummy_node_catalog_response.json")

				prevSpec := bosh.Network{}

				netSpec, err := attachMAC(nodeCatalog.Data.NetworkData.Networks, prevSpec)
				Expect(err).ToNot(HaveOccurred())
				Expect(netSpec.MAC).To(Equal("00:1e:67:c4:e1:a0"))
			})
		})
	})

	Describe("SelectNodeFromRackHD", func() {
		Context("with a nodeID", func() {
			It("selects the node with the nodeID", func() {
				node := helpers.LoadNode("../spec_assets/dummy_create_vm_with_disk_response.json")

				nodeResponse, err := json.Marshal(node)
				Expect(err).ToNot(HaveOccurred())

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/5665a65a0561790005b77b85")),
						ghttp.RespondWith(http.StatusOK, nodeResponse),
					),
				)

				node, err = SelectNodeFromRackHD(cpiConfig, "5665a65a0561790005b77b85", allowFilter)
				Expect(err).ToNot(HaveOccurred())
				Expect(node.ID).To(Equal("5665a65a0561790005b77b85"))
			})
			Expect(w.Tasks[2].TaskName).To(Equal("Task.Linux.Bootstrap.Ubuntu"))
			Expect(w.Tasks[3].TaskName).To(Equal(r.Name))
		})
	})

	Describe("buildReserveNodeWorkflowOptions", func() {
		var server *ghttp.Server
		var cpiConfig config.Cpi

		BeforeEach(func() {
			server, _, cpiConfig, _ = helpers.SetUp("")
		})

		Context("when the node uses IPMI", func() {
			It("sets the OBM settings to IPMI", func() {
				expectedNode := helpers.LoadNode("../spec_assets/dummy_one_node_with_ipmi_response.json")
				expectedNodeData, err := json.Marshal(expectedNode)
				Expect(err).ToNot(HaveOccurred())

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

				ipmiServiceName := rackhdapi.OBMSettingIPMIServiceName
				expectedOptions := reserveNodeWorkflowOptions{
					OBMServiceName: &ipmiServiceName,
				}
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/api/common/nodes"),
					ghttp.RespondWith(http.StatusOK, expectedNodesData),
				),
			)

			node, err := rackhdapi.GetNodeByVMCID(cpiConfig, "vm-5678")

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

	Describe("Getting a single node by nodeID", func() {
		It("returns node with the nodeID specified", func() {
			expectedNode := helpers.LoadNode("../spec_assets/dummy_create_vm_with_disk_response.json")
			expectedNodeData, err := json.Marshal(expectedNode)
			Expect(err).ToNot(HaveOccurred())
			server.AppendHandlers(
				ghttp.CombineHandlers(
					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))
		})
	})