예제 #1
0
// TestPreApplyDeploymentJobs - setup some information from icsp
//TODO: This test requires a server profile to have been created
func TestPreApplyDeploymentJobs(t *testing.T) {
	var (
		d                     *ICSPTest
		c                     *icsp.ICSPClient
		serialNumber, macAddr string
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		log.Debug("implements acceptance test for ApplyDeploymentJobs")
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
			log.Info("env ONEVIEW_TEST_PROVISION != true")
			log.Info("Skipping FreeBlade testing")
			serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
			macAddr = d.Tc.GetTestData(d.Env, "MacAddr").(string)
		} else {
			// serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
			serialNumber = d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
			macAddr = d.Tc.GetTestData(d.Env, "FreeMacAddr").(string)
		}
		s, err := c.GetServerBySerialNumber(serialNumber)
		assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, s)

		pubinet, err := s.GetInterface(1)
		assert.NoError(t, err, "GetInterface(1) threw error -> %s, %+v\n", err, s)
		assert.Equal(t, macAddr, pubinet.MACAddr, fmt.Sprintf("should get a valid interface -> %+v", pubinet))

		s, err = c.PreApplyDeploymentJobs(s, pubinet) // responsible for configuring the Pulbic IP CustomAttributes
		assert.NoError(t, err, "ApplyDeploymentJobs threw error -> %+v, %+v", err, s)
		s, err = s.ReloadFull(c)
		assert.NoError(t, err, "ReloadFull threw error -> %+v, %+v", err, s)

		// verify that the server attribute was saved by getting the server again and checking the value
		_, testValue2 := s.GetValueItem("public_interface", "server")
		// unmarshal the custom attribute
		var inet *icsp.Interface
		log.Debugf("public_interface value -> %+v", testValue2.Value)
		assert.NotEqual(t, "", testValue2.Value,
			fmt.Sprintf("public_interface for %s Should have a value", serialNumber))

		if testValue2.Value != "" {
			err = json.Unmarshal([]byte(testValue2.Value), &inet)
			assert.NoError(t, err, "Unmarshal Interface threw error -> %s, %+v\n", err, testValue2.Value)

			log.Infof("We got public ip addr -> %s", inet.MACAddr)
			assert.Equal(t, macAddr, inet.MACAddr, "Should return the saved custom attribute for mac address")
		}

	}
}