//TestNetConfigAddAllDHCP - verify we can convert a servers interfaces to dhcp
func TestNetConfigAddAllDHCP(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		for _, neti := range n.Interfaces {
			assert.True(t, neti.DHCPv4, fmt.Sprintf("Should have interface, %s, dhcpv4 enabled", neti.MACAddr))
			assert.False(t, neti.IPv6Autoconfig, "Should have ipv6 auto config as false")
		}
	}
}
// TestNetConfigSave - save netconfig to hpsa_netconfig
func TestNetConfigSave(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		s, err = n.Save(s)
		assert.NoError(t, err, "should Save -> %s, %+v", err, s)
		// place those strings into custom attributes
		_, err = c.SaveServer(s)
		assert.NoError(t, err, "should SaveServer -> %s, %+v", err, s)
	}
}
// Test SessionLogout
func TestSessionLogout(t *testing.T) {
	var (
		//d *OVTest
		c *icsp.ICSPClient
		//testSerial string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		//data, err := c.SessionLogin()
		// this is needed so we can "copy" the session id to the ov client
		err := c.RefreshLogin()
		//log.Debugf(" login key -> %s, session data -> %+v", c.APIKey, data)
		log.Debugf(" login key -> %s", c.APIKey)
		assert.NoError(t, err, "SessionLogin threw error -> %s", err)
		//assert.NotEmpty(t, data.ID, fmt.Sprintf("SessionLogin is empty! something went wrong, err -> %s, data -> %+v\n", err, data))
		//assert.Equal(t, "none", c.APIKey)
		err = c.SessionLogout()
		log.Debugf(" login key after logout -> %s", c.APIKey)
		assert.NoError(t, err, "SessionLogout threw error -> %s", err)
		// test if we can perform an op after logout
		//_, err = c.GetProfileBySN(testSerial)
		//assert.Error(t, err, "SessionLogin threw error -> %s", err)
	} else {
		/*_, c = getTestDriverU()
		data, err := c.SessionLogin()
		assert.Error(t,err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n",err, data))
		assert.Equal(t, "none", c.APIKey)
		*/
	}
}
// TODO TestSetStaticInterface - verify we can set one of the servers interface to static
// TesttoJSON - verify we can return a json string of the NetConfig object
func TestToJSON(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "should GetServerBySerialNumber -> %s, %+v", err, s)

		err = GetNetConfigTestData()
		assert.NoError(t, err, "should GetNetConfigTestData -> %s", err)

		var emptyconfig utils.Nstring
		emptyconfig.Nil()
		n.AddAllDHCP(s.Interfaces, false, emptyconfig)
		data, err := n.ToJSON()
		assert.NoError(t, err, "Should convert object to json, %s", err)
		log.Infof("n JSON -> %s", data)
		assert.True(t, len(data) > 0, "Should have some data")
	}
}
// func (s Server) GetPublicIPV4() (string, error) {
// TestGetPublicIPV4 try to test for getting interface from custom attribute
func TestGetPublicIPV4(t *testing.T) {
	var (
		d            *ICSPTest
		c            *icsp.ICSPClient
		serialNumber string
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		log.Debug("implements acceptance test for TestGetPublicIPV4")
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
			serialNumber = d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		} else {
			serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
		}
		s, err := c.GetServerBySerialNumber(serialNumber)
		testIP, err := s.GetPublicIPV4()
		assert.NoError(t, err, "Should GetPublicIPV4 without error -> %s, %+v\n", err, s)
		log.Debugf(" testIP -> %s", testIP)
		assert.True(t, (len(testIP) > 0), "Should return an ip address string")
	} else {
		// TODO: implement a test
		// need to simplate createing public_interface custom attribute object
		// need to read custom attribute object, see server_customattribute_test.go
		log.Debug("implements unit test for TestGetPublicIPV4")
	}
}
// Test SessionLogin
func TestSessionLogin(t *testing.T) {
	var (
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.SessionLogin()
		// fmt.Printf("after SessionLogin: %s -> (err) %+v", data.ID, err)
		assert.NoError(t, err, "SessionLogin threw error -> %s", err)
		assert.NotEmpty(t, data.ID, fmt.Sprintf("SessionLogin is empty! something went wrong, err -> %s, data -> %+v\n", err, data))
		assert.Equal(t, "none", c.APIKey)

		c.APIKey = data.ID
		err = c.SessionLogout()
		assert.NoError(t, err, "SessionLogout threw error -> %s", err)
		data, err = c.SessionLogin()
		assert.NoError(t, err, "SessionLogin threw error -> %s", err)
	} else {
		_, c = getTestDriverU()
		data, err := c.SessionLogin()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
		assert.Equal(t, "none", c.APIKey)
	}
}
// TestIsServerManaged test if server is managed
func TestIsServerManaged(t *testing.T) {
	var (
		d            *ICSPTest
		c            *icsp.ICSPClient
		serialNumber string
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
		data, err := c.IsServerManaged(serialNumber)
		log.Debugf("server managed : %v", data)
		assert.NoError(t, err, "IsServerManaged -> %s, %+v\n", err, data)
		assert.True(t, data)
		if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
			serialNumber = d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
			data, err := c.IsServerManaged(serialNumber)
			log.Debugf("test : %v", data)
			assert.NoError(t, err, "IsServerManaged -> %s, %+v\n", err, data)
			assert.True(t, data)
		}
	}
}
//TestPostApplyDeploymentJobs test job Task
//TODO: This test requires a server profile to have been created
func TestPostApplyDeploymentJobs(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		serialNumber := d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number

		// (c *ICSPClient) GetJob(u ODSUri) (Job, error) {
		// create a jt *JobTask object
		// JobURI
		var jt *icsp.JobTask
		var testURL utils.Nstring
		testURL = "/rest/os-deployment-jobs/5350001"
		jt = &icsp.JobTask{
			JobURI: icsp.ODSUri{URI: testURL},
			Client: c,
		}
		var findprops []string
		findprops = append(findprops, "public_ip")
		err = c.PostApplyDeploymentJobs(jt, s, findprops)
		assert.NoError(t, err, "PostApplyDeploymentJobs threw error -> %s, %+v\n", err, jt)
	}
}
// Test for expired key and see if RefreshLogin can restore the key if we have a bad key
func TestSessionExpiredKey(t *testing.T) {
	var (
		c *icsp.ICSPClient
		d *ICSPTest
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		err := c.RefreshLogin()
		log.Debugf(" login key -> %s", c.APIKey)
		assert.NoError(t, err, "RefreshLogin threw error -> %s", err)
		// force key to timeout
		err = c.SetIdleTimeout(800)
		assert.NoError(t, err, "SetIdleTimeout threw error -> %s", err)

		// 1 millisecond and we should be timeout with the current key
		time.Sleep(1 * time.Millisecond)

		// verify we are timed out
		_, err = c.GetIdleTimeout()
		assert.Error(t, err, "should be 404 not found -> %s ", err)

		// verify that we can access something from icps with this client
		// This should not fail because it uses RefreshLogin to get a new login session and avoid timeout
		serialNumber := d.Tc.GetTestData(d.Env, "SerialNumber").(string)
		s, err := c.GetServerBySerialNumber(serialNumber)
		assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, server -> %+v", err, s)
	}

}
// TestGetInterfaces  verify that interfaces works
func TestGetInterfaces(t *testing.T) {

	var (
		d            *ICSPTest
		c            *icsp.ICSPClient
		s            icsp.Server
		serialNumber string
		err          error
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		log.Debug("implements acceptance test for TestGetInterfaces")
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
			serialNumber = d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
			s, err = c.GetServerBySerialNumber(serialNumber)
		} else {
			serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
			s, err = c.GetServerBySerialNumber(serialNumber)
		}
		data := s.GetInterfaces()
		assert.NoError(t, err, "GetInterfaces threw error -> %s, %+v\n", err, data)
		assert.True(t, len(data) > 0, "Failed to get a valid list of interfaces -> %+v", data)
		for _, inet := range data {
			log.Infof("inet -> %+v", inet)
			log.Infof("inet ip -> %+v", inet.IPV4Addr)
			log.Infof("inet ip -> %+v", inet.Slot)
			log.Infof("inet ip -> %+v", inet.MACAddr)
		}
	} else {
		log.Debug("implements unit test for TestGetInterfaces")
		d, c = getTestDriverU()
		jsonServerData := d.Tc.GetTestData(d.Env, "ServerJSONString").(string)
		log.Debugf("jsonServerData => %s", jsonServerData)
		err := json.Unmarshal([]byte(jsonServerData), &s)
		assert.NoError(t, err, "Unmarshal Server threw error -> %s, %+v\n", err, jsonServerData)

		log.Debugf("server -> %v", s)

		data := s.GetInterfaces()
		log.Debugf("Interfaces -> %+v", data)
		assert.True(t, len(data) > 0, "Failed to get a valid list of interfaces -> %+v", data)
		for _, inet := range data {
			log.Debugf("inet -> %+v", inet)
			log.Debugf("inet ip -> %+v", inet.IPV4Addr)
			log.Debugf("inet ip -> %+v", inet.Slot)
			log.Debugf("inet ip -> %+v", inet.MACAddr)
		}
	}
}
示例#11
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")
		}

	}
}
示例#12
0
// integrated acceptance test
// TestSaveServer implement save server
//TODO: a workaround to figuring out how to bubble up public ip address information from the os to icsp after os build plan provisioning
// @docker_user@ "@public_key@" @docker_hostname@ "@proxy_config@" "@proxy_enable@" "@interface@"
func TestApplyDeploymentJobs(t *testing.T) {
	var (
		d            *ICSPTest
		c            *icsp.ICSPClient
		serialNumber 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() ")
		}
		// get a Server
		osBuildPlans := make([]string, 1)
		osBuildPlans[0] = d.Tc.GetTestData(d.Env, "OSBuildPlan").(string)
		if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
			serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
		} else {
			serialNumber = d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
		}
		s, err := c.GetServerBySerialNumber(serialNumber)
		assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, s)
		// set a custom attribute
		s.SetCustomAttribute("docker_user", "server", "docker")
		s.SetCustomAttribute("docker_hostname", "server", d.Tc.GetTestData(d.Env, "HostName").(string))
		// use test keys like from https://github.com/mitchellh/vagrant/tree/master/keys
		// private key from https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant
		s.SetCustomAttribute("public_key", "server", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==")

		// save a server
		news, err := c.SaveServer(s)
		assert.NoError(t, err, "SaveServer threw error -> %s, %+v\n", err, news)
		assert.Equal(t, s.UUID, news.UUID, "Should return a server with the same UUID")

		// verify that the server attribute was saved by getting the server again and checking the value
		_, testValue2 := s.GetValueItem("docker_user", "server")
		assert.Equal(t, "docker", testValue2.Value, "Should return the saved custom attribute")

		if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
			log.Info("env ONEVIEW_TEST_PROVISION != ture for ApplyDeploymentJobs")
			log.Infof("Skipping OS build for : %s, %s", osBuildPlans, serialNumber)
			return
		}
		_, err = c.ApplyDeploymentJobs(osBuildPlans, nil, s)
		assert.NoError(t, err, "ApplyDeploymentJobs threw error -> %s, %+v\n", err, news)
	} else {
		var s icsp.Server
		_, c = getTestDriverU()
		log.Debug("implements unit test for ApplyDeploymentJobs")
		testPlans := make([]string, 1)
		testPlans[0] = "testbuildplan"
		_, err := c.ApplyDeploymentJobs(testPlans, nil, s)
		assert.Error(t, err, "ApplyDeploymentJobs threw error -> %s, %+v\n", err, s)
	}
}
// TestGetServerByID test getting a server from id
func TestGetServerByID(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		saObjectID := d.Tc.GetTestData(d.Env, "SAObjectID").(string)
		data, err := c.GetServerByID(saObjectID)
		assert.NoError(t, err, "GetServerByName threw error -> %s, %+v\n", err, data)
	}
}
func TestGetServerByName(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		IcspName := d.Tc.GetTestData(d.Env, "IcspName").(string)
		expectsIcspName := d.Tc.GetExpectsData(d.Env, "IcspName").(string)
		data, err := c.GetServerByName(IcspName)
		assert.NoError(t, err, "GetServerByName threw error -> %s, %+v\n", err, data)
		assert.Equal(t, expectsIcspName, data.Name, "GetServerByName should return a valid icsp server")
	}
}
//TODO: implement test for delete
func TestDeleteServer(t *testing.T) {
	var c *icsp.ICSPClient
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		log.Debug("implements acceptance test for TestDeleteServer")
		// check if the server exist
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// mid: A unique ID assigned to the Server by Server Automation
		data, err := c.DeleteServer("510001")
		assert.True(t, data)
		assert.NoError(t, err, "DeleteServer threw error -> %s, %+v\n", err, data)
	} else {
		log.Debug("implements unit test for TestDeleteServer")
	}
}
示例#16
0
// Set idle timeout
func TestSetIdleTimeout(t *testing.T) {
	var (
		c *icsp.ICSPClient
		// d *ICSPTest
		testtime int64
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		testtime = 25000
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		err := c.RefreshLogin()
		log.Debugf(" login key -> %s", c.APIKey)
		assert.NoError(t, err, "RefreshLogin threw error -> %s", err)

		err = c.SetIdleTimeout(testtime)
		assert.NoError(t, err, "SetIdleTimeout threw error -> %s", err)

		timeout, err := c.GetIdleTimeout()
		assert.NoError(t, err, "GetIdleTimeout threw error -> %s", err)
		assert.Equal(t, testtime, timeout, "Should get timeout equal, %s", timeout)
		log.Debugf(" idle timeout -> %d", timeout)
	}

}
// TestGetProfiles
func TestGetServers(t *testing.T) {
	var (
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetServers()
		assert.NoError(t, err, "GetServers threw error -> %s, %+v\n", err, data)

	} else {
		_, c = getTestDriverU()
		data, err := c.GetServers()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}
}
// TestGetProfiles
func TestGetBuildPlanByName(t *testing.T) {
	var (
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetBuildPlanByName("ProLiant OS - RHEL 7.0 x64 Scripted Install")
		assert.NoError(t, err, "GetServers threw error -> %s, %+v\n", err, data)
		if assert.NotNil(t, data.URI) {
			log.Debug(fmt.Sprintf("plan uri: %v", data.URI))
		}

	} else {
		_, c = getTestDriverU()
		data, err := c.GetServers()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))

	}
}
// Test GetAPIVersion
func TestGetAPIVersion(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetAPIVersion()
		// fmt.Printf("after GetAPIVersion: %s -> (err) %s", data.CurrentVersion, err)
		// assert.Error(t,err, fmt.Sprintf("Error caught as expected: %s",err))
		assert.NoError(t, err, "GetAPIVersion threw error -> %s", err)
		assert.True(t, d.Tc.IsGreaterEqual(data.CurrentVersion, d.Tc.GetExpectsData(d.Env+"_icsp", "CurrentVersion")))
		assert.True(t, d.Tc.IsGreaterEqual(data.MinimumVersion, d.Tc.GetExpectsData(d.Env+"_icsp", "MinimumVersion")))
	} else {
		_, c = getTestDriverU()
		data, err := c.GetAPIVersion()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}

}
示例#20
0
// implement create server unt test
//TODO: This test requires a server profile to have been created
func TestCreateServer(t *testing.T) {
	var (
		d              *ICSPTest
		c              *icsp.ICSPClient
		user, pass, ip string
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		user = os.Getenv("ONEVIEW_ILO_USER")
		pass = os.Getenv("ONEVIEW_ILO_PASSWORD")
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		ip = d.Tc.GetTestData(d.Env, "IloIPAddress").(string)
		serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
		log.Debug("implements acceptance test for TestCreateServer")
		s, err := c.GetServerBySerialNumber(serialNumber) // fake serial number
		assert.NoError(t, err, "GetServerBySerialNumber fake threw error -> %s, %+v\n", err, s)
		if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
			log.Info("env ONEVIEW_TEST_PROVISION != true for TestCreateServer")
			log.Infof("Skipping test create for : %s, %s", serialNumber, ip)
			return
		}
		if s.URI.IsNil() {
			// create the server
			err := c.CreateServer(user, pass, ip, 443)
			assert.NoError(t, err, "CreateServer threw error -> %s\n", err)
		} else {
			// create the server
			err := c.CreateServer(user, pass, ip, 443)
			assert.Error(t, err, "CreateServer should throw conflict error  -> %s\n", err)
		}
		// check if the server now exist
	} else {
		_, c = getTestDriverU()
		log.Debug("implements unit test for TestCreateServer")
		err := c.CreateServer("foo", "bar", "127.0.0.1", 443)
		assert.Error(t, err, "CreateServer should throw error  -> %s\n", err)
	}
}
// TestGetInterfaceFromMac verify that getting an inerface with mac address works
func TestGetInterfaceFromMac(t *testing.T) {
	var (
		d            *ICSPTest
		c            *icsp.ICSPClient
		s            icsp.Server
		serialNumber string
		macAddr      string
		err          error
		data         icsp.Interface
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		log.Debug("implements acceptance test for TestGetInterfaceFromMac")
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
			serialNumber = d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
			macAddr = d.Tc.GetTestData(d.Env, "FreeMacAddr").(string)
			s, err = c.GetServerBySerialNumber(serialNumber)
		} else {
			serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
			macAddr = d.Tc.GetTestData(d.Env, "MacAddr").(string)
			s, err = c.GetServerBySerialNumber(serialNumber)
		}

		s, err = c.GetServerBySerialNumber(serialNumber)
		assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, serialNumber)

		log.Debugf("server -> %v", s)
		data, err = s.GetInterfaceFromMac(macAddr)
		assert.NoError(t, err, "GetInterfaceFromMac threw error -> %s, %+v\n", err, data)
		assert.Equal(t, macAddr, data.MACAddr, "Failed to get interface -> %+v", data)
		log.Infof("Found interface -> %+v", data)
	} else {
		log.Debug("implements unit test for TestGetInterfaces")
		d, c = getTestDriverU()
		jsonServerData := d.Tc.GetTestData(d.Env, "ServerJSONString").(string)
		log.Debugf("jsonServerData => %s", jsonServerData)
		err := json.Unmarshal([]byte(jsonServerData), &s)
		assert.NoError(t, err, "Unmarshal Server threw error -> %s, %+v\n", err, jsonServerData)
		// macAddr = d.Tc.GetTestData(d.Env, "ServerMacAddr").(string)
		// TODO: find a way to unit test this
	}

}
func TestGetServerBySerialNumber(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
		data, err := c.GetServerBySerialNumber(serialNumber)
		assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, data)

		data, err = c.GetServerBySerialNumber("2M25090RMW")
		log.Infof("server -> %+v", strings.ToLower(data.Name))

		// negative test
		data, err = c.GetServerBySerialNumber("SXXXX33333") // fake serial number
		assert.NoError(t, err, "GetServerBySerialNumber fake threw error -> %s, %+v\n", err, data)
		assert.Equal(t, data.URI.String(), "null", "GetServerBySerialNumber on fake should be nil")
	}
}
// TestRefreshVersion get the latest version being used from api
func TestRefreshVersion(t *testing.T) {
	var (
		d *ICSPTest
		c *icsp.ICSPClient
	)
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		c.APIVersion = -1
		assert.Equal(t, -1, c.APIVersion)
		err := c.RefreshVersion()
		assert.NoError(t, err, "RefreshVersion threw error -> %s", err)
		assert.True(t, d.Tc.EqualFaceI(d.Tc.GetExpectsData(d.Env+"_icsp", "CurrentVersion"), c.APIVersion))
	} else {
		_, c = getTestDriverU()
		err := c.RefreshVersion()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s", err))
	}

}
// TestCustomizeServer - simulate second part of create
func TestCustomizeServer(t *testing.T) {
	var (
		err                                                 error
		driver                                              Driver
		d                                                   *OneViewTest
		c                                                   *ov.OVClient
		ic                                                  *icsp.ICSPClient
		serialNumber, osbuildplan, hostname, user, pass, ip string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") != "true" {
		return
	}
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		user = os.Getenv("ONEVIEW_ILO_USER")
		pass = os.Getenv("ONEVIEW_ILO_PASSWORD")
		d, c, ic = d.GetTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		ip = d.Tc.GetTestData(d.Env, "IloIPAddress").(string)
		// serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
		hostname = d.Tc.GetTestData(d.Env, "HostName").(string)
		driver = Driver{
			ClientICSP: ic,
			ClientOV:   c,
			BaseDriver: &drivers.BaseDriver{
				MachineName: hostname,
				StorePath:   "",
			},
		}
		err = driver.getBlade()
		assert.NoError(t, err, "getBlade threw error -> %s\n", err)
		serialNumber = driver.Profile.SerialNumber.String()

		osbuildplan = d.Tc.GetTestData(d.Env, "OSBuildPlan").(string)

		var sp *icsp.CustomServerAttributes
		sp = sp.New()
		sp.Set("docker_user", "docker")
		// TODO: make a util for this
		if len(os.Getenv("proxy_enable")) > 0 {
			sp.Set("proxy_enable", os.Getenv("proxy_enable"))
		} else {
			sp.Set("proxy_enable", "false")
		}

		strProxy := os.Getenv("proxy_config")
		sp.Set("proxy_config", strProxy)

		sp.Set("docker_hostname", hostname+"-@server_name@")
		// interface
		sp.Set("interface", fmt.Sprintf("eno%d", 50)) // TODO: what argument should we call 50 besides slotid ??

		// check if the server now exist
		cs := icsp.CustomizeServer{
			HostName:         hostname,     // machine-rack-enclosure-bay
			SerialNumber:     serialNumber, // get it
			ILoUser:          user,
			IloPassword:      pass,
			IloIPAddress:     ip,
			IloPort:          443,
			OSBuildPlan:      osbuildplan, // name of the OS build plan
			PublicSlotID:     1,           // this is the slot id of the public interface
			ServerProperties: sp,
		}
		// create d.Server and apply a build plan and configure the custom attributes
		err := ic.CustomizeServer(cs)
		assert.NoError(t, err, "CustomizeServer threw error -> %s\n", err)

	}
}