// TestGetIloIPAddress verify get ip address for hardware
func TestGetIloIPAddress(t *testing.T) {

	var (
		d           *OVTest
		c           *ov.OVClient
		testData    utils.Nstring
		expectsData string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
		expectsData = d.Tc.GetExpectsData(d.Env, "IloIPAddress").(string)
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		s, err := c.GetServerHardware(testData)
		assert.NoError(t, err, "GetServerHardware threw error -> %s", err)
		ip := s.GetIloIPAddress()
		log.Debugf("server -> %+v", s)
		log.Debugf("ip -> %+v", ip)
		assert.Equal(t, expectsData, ip)

	}

}
func TestGetFCNetworks(t *testing.T) {
	var (
		c *ov.OVClient
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_fc_network")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		fcNetworks, err := c.GetFCNetworks("", "")
		assert.NoError(t, err, "GetFCNetworks threw an error -> %s. %+v\n", err, fcNetworks)

		fcNetworks, err = c.GetFCNetworks("", "name:asc")
		assert.NoError(t, err, "GetFCNetworks name:asc error -> %s. %+v\n", err, fcNetworks)

	} else {
		_, c = getTestDriverU("test_fc_network")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetFCNetworks("", "")
		assert.Error(t, err, fmt.Sprintf("All OK, no error, caught as expected: %s,%+v\n", err, data))

	}

	_, c = getTestDriverU("test_fc_network")
	data, err := c.GetFCNetworks("", "")
	assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
}
// GetProfileTemplateByName get a template profile
func TestGetProfileTemplateByName(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testname string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_server_profile_template")
		// determine if we should execute
		testname = d.Tc.GetTestData(d.Env, "Name").(string)
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetProfileTemplateByName(testname)
		assert.NoError(t, err, "GetProfileTemplateByName threw error -> %s", err)
		assert.Equal(t, testname, data.Name)

		data, err = c.GetProfileTemplateByName("foo")
		assert.NoError(t, err, "GetProfileTemplateByName with fake name -> %+v", err)
		assert.Equal(t, "", data.Name)

	} else {
		d, c = getTestDriverU("test_server_profile_template")
		// determine if we should execute
		if c.ProfileTemplatesNotSupported() {
			return
		}

		testname = d.Tc.GetTestData(d.Env, "Name").(string)
		data, err := c.GetProfileTemplateByName(testname)
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}
}
func TestDeleteLogicalInterconnectGroup(t *testing.T) {
	var (
		d                            *OVTest
		c                            *ov.OVClient
		testName                     string
		testLogicalInterconnectGroup ov.LogicalInterconnectGroup
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_logical_interconnect_group")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		err := c.DeleteLogicalInterconnectGroup(testName)
		assert.NoError(t, err, "DeleteLogicalInterconnectGroup err-> %s", err)

		testLogicalInterconnectGroup, err = c.GetLogicalInterconnectGroupByName(testName)
		assert.NoError(t, err, "GetLogicalInterconnectGroupByName with deleted logical interconnect gorup-> %+v", err)
		assert.Equal(t, "", testLogicalInterconnectGroup.Name, fmt.Sprintf("Problem getting logicalInterconnectGroup name, %+v", testLogicalInterconnectGroup))
	} else {
		_, c = getTestDriverU("test_logical_interconnect_group")
		err := c.DeleteLogicalInterconnectGroup("footest")
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, testLogicalInterconnectGroup))
	}

}
func TestDeleteNetworkSet(t *testing.T) {
	var (
		d          *OVTest
		c          *ov.OVClient
		testName   string
		testNetSet ov.NetworkSet
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_network_set")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		err := c.DeleteNetworkSet(testName)
		assert.NoError(t, err, "DeleteNetworkSet err-> %s", err)

		testNetSet, err = c.GetNetworkSetByName(testName)
		assert.NoError(t, err, "GetNetworkSetByName with deleted network set-> %+v", err)
		assert.Equal(t, "", testNetSet.Name, fmt.Sprintf("Problem getting netset name, %+v", testNetSet))
	} else {
		_, c = getTestDriverU("test_network_set")
		err := c.DeleteNetworkSet("footest")
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, testNetSet))
	}

}
func TestGetServerHardwareByName(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_server_hardware")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testServerHardware, err := c.GetServerHardwareByName(testName)
		assert.NoError(t, err, "GetServerHardwareByName thew an error -> %s", err)
		assert.Equal(t, testName, testServerHardware.Name)

		testServerHardware, err = c.GetServerHardwareByName("bad")
		assert.NoError(t, err, "GetServerHardwareByName with fake name -> %s", err)
		assert.Equal(t, "", testServerHardware.Name)

	} else {
		d, c = getTestDriverU("test_server_hardware")
		testName = d.Tc.GetTestData(d.Env, "Name").(string)
		data, err := c.GetServerHardwareByName(testName)
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}
}
func TestDeleteStorageVolume(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
		testSVol ov.StorageVolumeV3
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_storage_volume")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		err := c.DeleteStorageVolume(testName)
		assert.NoError(t, err, "DeleteStorageVolume err-> %s", err)

		testSVol, err = c.GetStorageVolumeByName(testName)
		assert.NoError(t, err, "GetStorageVolumeByName with deleted storage volume -> %+v", err)
		assert.Equal(t, "", testSVol.Name, fmt.Sprintf("Problem getting storage volume name, %+v", testSVol))
	} else {
		_, c = getTestDriverU("test_storage_volume")
		err := c.DeleteStorageVolume("footest")
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, testSVol))
	}
}
func TestCreateStorageVolume(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_storage_volume")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// find out if the test ethernet network already exist
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testSVol, err := c.GetStorageVolumeByName(testName)
		assert.NoError(t, err, "CreateStorageVolume get the Storage Volume error -> %s", err)

		pMap := d.Tc.GetTestData(d.Env, "ProvisioningParameters").(map[string]interface{})

		provParams := ov.ProvisioningParameters{StoragePoolUri: utils.NewNstring(pMap["storagePoolUri"].(string)), RequestedCapacity: pMap["requestedCapacity"].(string), ProvisionType: pMap["provisionType"].(string), Shareable: pMap["shareable"].(bool)}

		if testSVol.URI.IsNil() {
			testSVol = ov.StorageVolumeV3{
				Name:             testName,
				StorageSystemUri: utils.NewNstring(d.Tc.GetTestData(d.Env, "StorageSystemUri").(string)),
				Type:             d.Tc.GetTestData(d.Env, "Type").(string),
				ProvisioningParameters: provParams,
			}

			// not changed after this TODO: update to storage volume tests
			err := c.CreateStorageVolume(testSVol)
			assert.NoError(t, err, "CreateStorageVolume error -> %s", err)

			err = c.CreateStorageVolume(testSVol)
			assert.Error(t, err, "CreateStorageVolume should error because the Storage volume already exists, err-> %s", err)

		} else {
			log.Warnf("The storage volume already exist, so skipping CreateStorageVolume test for %s", testName)
		}

		// reload the test profile that we just created
		testSVol, err = c.GetStorageVolumeByName(testName)
		assert.NoError(t, err, "GetStorageVolumeByName error -> %s", err)
	}

}
// testing power state type
func TestPowerState(t *testing.T) {
	var (
		d           *OVTest
		c           *ov.OVClient
		testData    utils.Nstring
		expectsData string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
		expectsData = d.Tc.GetExpectsData(d.Env, "SerialNumber").(string)
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// get a blade object
		blade, err := c.GetServerHardware(testData)
		assert.NoError(t, err, "GetServerHardware threw error -> %s", err)
		assert.Equal(t, expectsData, blade.SerialNumber.String())
		// get a power state object
		var pt *ov.PowerTask
		pt = pt.NewPowerTask(blade)
		pt.Timeout = 46 // timeout is 20 sec
		assert.Equal(t, expectsData, pt.Blade.SerialNumber.String())

		// Test the power state executor to off
		log.Info("------- Setting Power to Off")
		err = pt.PowerExecutor(ov.P_OFF)
		assert.NoError(t, err, "PowerExecutor threw no errors -> %s", err)

		// Test the power state executor to on
		log.Info("------- Setting Power to On")
		err = pt.PowerExecutor(ov.P_ON)
		assert.NoError(t, err, "PowerExecutor threw no errors -> %s", err)

		// Test the power state executor to off and leave off
		log.Info("------- Setting Power to Off")
		err = pt.PowerExecutor(ov.P_OFF)
		assert.NoError(t, err, "PowerExecutor threw no errors -> %s", err)

	}
}
// get server hardware test
func TestServerHardware(t *testing.T) {
	var (
		d           *OVTest
		c           *ov.OVClient
		testData    utils.Nstring
		expectsData string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
		expectsData = d.Tc.GetExpectsData(d.Env, "SerialNumber").(string)
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetServerHardware(testData)
		log.Debugf("%+v", data)
		assert.NoError(t, err, "GetServerHardware threw error -> %s", err)
		// fmt.Printf("data.Connections -> %+v\n", data)
		assert.Equal(t, expectsData, data.SerialNumber.String())

	}
}
Ejemplo n.º 11
0
// TestCreateMachine - simulate first part of create
func TestCreateMachine(t *testing.T) {
	var (
		driver             Driver
		d                  *OneViewTest
		c                  *ov.OVClient
		ic                 *icsp.ICSPClient
		template, hostname string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") != "true" {
		return
	}
	d, c, ic = d.GetTestDriverA()

	template = d.Tc.GetTestData(d.Env, "TemplateProfile").(string)
	hostname = d.Tc.GetTestData(d.Env, "HostName").(string)
	driver = Driver{
		ClientICSP: ic,
		ClientOV:   c,
		BaseDriver: &drivers.BaseDriver{
			MachineName: hostname,
			StorePath:   "",
		},
	}

	err := c.CreateMachine(hostname, template)
	assert.NoError(t, err, "CreateMachine threw error -> %s\n", err)

	err = driver.getBlade()
	assert.NoError(t, err, "getBlade threw error -> %s\n", err)

	// power on the server, and leave it in that state
	err = driver.Hardware.PowerOn()
	assert.NoError(t, err, "PowerOn threw error -> %s\n", err)

	// power on the server, and leave it in that state
	err = driver.Hardware.PowerOff()
	assert.NoError(t, err, "PowerOff threw error -> %s\n", err)
}
func TestCreateEthernetNetwork(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_ethernet_network")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// find out if the test ethernet network already exist
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testEthNet, err := c.GetEthernetNetworkByName(testName)
		assert.NoError(t, err, "CreateEthernetNetwork get the EthernetNetwork error -> %s", err)

		if testEthNet.URI.IsNil() {
			testEthNet = ov.EthernetNetwork{
				Name:                testName,
				VlanId:              7,
				Purpose:             d.Tc.GetTestData(d.Env, "Purpose").(string),
				SmartLink:           d.Tc.GetTestData(d.Env, "SmartLink").(bool),
				PrivateNetwork:      d.Tc.GetTestData(d.Env, "PrivateNetwork").(bool),
				EthernetNetworkType: d.Tc.GetTestData(d.Env, "EthernetNetworkType").(string),
				Type:                d.Tc.GetTestData(d.Env, "Type").(string),
			}
			err := c.CreateEthernetNetwork(testEthNet)
			assert.NoError(t, err, "CreateEthernetNetwork error -> %s", err)

			err = c.CreateEthernetNetwork(testEthNet)
			assert.Error(t, err, "CreateEthernetNetwork should error because the EthernetNetwork already exists, err-> %s", err)

		} else {
			log.Warnf("The ethernetNetwork already exist, so skipping CreateEthernetNetwork test for %s", testName)
		}

		// reload the test profile that we just created
		testEthNet, err = c.GetEthernetNetworkByName(testName)
		assert.NoError(t, err, "GetEthernetNetwork error -> %s", err)
	}

}
// get server hardware test
func TestGetAvailableHardware(t *testing.T) {
	var (
		d               *OVTest
		c               *ov.OVClient
		testHwType_URI  utils.Nstring
		testHWGroup_URI utils.Nstring
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		testHwType_URI = utils.Nstring(d.Tc.GetTestData(d.Env, "HardwareTypeURI").(string))
		testHWGroup_URI = utils.Nstring(d.Tc.GetTestData(d.Env, "GroupURI").(string))
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		data, err := c.GetAvailableHardware(testHwType_URI, testHWGroup_URI)
		assert.NoError(t, err, "GetAvailableHardware threw error -> %s", err)
		// fmt.Printf("data.Connections -> %+v\n", data)
		log.Debugf("Abailable server -> %+v", data)
		log.Infof("Server Name -> %+v", data.Name)
		assert.NotEqual(t, "", data.Name)

	}
}
// TestGetAPIVersion get the version from endpoints
func TestGetAPIVersion(t *testing.T) {
	var (
		d *OVTest
		c *ov.OVClient
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		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, "CurrentVersion")))
		assert.True(t, d.Tc.IsGreaterEqual(data.MinimumVersion, d.Tc.GetExpectsData(d.Env, "MinimumVersion")))
	} else {
		_, c = getTestDriverU("dev")
		data, err := c.GetAPIVersion()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}

}
func TestCreateLogicalFCNetwork(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_fc_network")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		fcNetwork, err := c.GetFCNetworkByName(testName)
		assert.NoError(t, err, "getFcNetworkByName error -> %s", err)

		if fcNetwork.URI.IsNil() {
			falseVar := false
			fcNetwork := ov.FCNetwork{
				AutoLoginRedistribution: falseVar,
				Description:             "Test FC Network",
				LinkStabilityTime:       30,
				FabricType:              d.Tc.GetTestData(d.Env, "FabricType").(string),
				Name:                    testName,
				Type:                    d.Tc.GetTestData(d.Env, "Type").(string),
			}
			err := c.CreateFCNetwork(fcNetwork)
			assert.NoError(t, err, "CreateFCNetwork error -> %s", err)

			err = c.CreateFCNetwork(fcNetwork)
			assert.Error(t, err, "CreateFCNetwork should error becaue the network already exists, err -> %s", err)
		} else {
			log.Warnf("The FCNetwork already exists so skipping CreateFCNetwork test for %s", testName)
		}

		//Reload the the test profile
		fcNetwork, err = c.GetFCNetworkByName(testName)
		assert.NoError(t, err, "GetFCNetwork error -> %s", err)
	}
}
func TestCreateNetworkSet(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_network_set")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// find out if the test network set already exist
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testNetSet, err := c.GetNetworkSetByName(testName)
		assert.NoError(t, err, "CreateNetworkSet get the NetworkSet error -> %s", err)

		networkUris := make([]utils.Nstring, 0)

		if testNetSet.URI.IsNil() {
			testNetSet = ov.NetworkSet{
				Name:        testName,
				Type:        d.Tc.GetTestData(d.Env, "Type").(string),
				NetworkUris: networkUris,
			}
			err := c.CreateNetworkSet(testNetSet)
			assert.NoError(t, err, "CreateNetworkSet error -> %s", err)

			err = c.CreateNetworkSet(testNetSet)
			assert.Error(t, err, "CreateNetworkSet should error because the Network Set already exists, err-> %s", err)

		} else {
			log.Warnf("The networkSet already exist, so skipping CreateNetworkSet test for %s", testName)
		}

		// reload the test profile that we just created
		testNetSet, err = c.GetNetworkSetByName(testName)
		assert.NoError(t, err, "CreateNetworkSet get the server profile error -> %s", err)
	}
}
func TestCreateFCoENetwork(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_fcoe_network")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		//find out if the test fcoe network already exists
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testFcoeNet, err := c.GetFCoENetworkByName(testName)
		assert.NoError(t, err, "CreateFCoENetwork get the FCoENetwork error --> %s", err)

		if testFcoeNet.URI.IsNil() {
			testFcoeNet = ov.FCoENetwork{
				Name:   testName,
				VlanId: 143,
				Type:   d.Tc.GetTestData(d.Env, "Type").(string),
			}
			err := c.CreateFCoENetwork(testFcoeNet)
			assert.NoError(t, err, "CreateFCoENetwork error --> %s", err)

			err = c.CreateFCoENetwork(testFcoeNet)
			assert.Error(t, err, "CreateFCoENetwork should error because FCoENetwork already exists, err --> %s ", err)

		} else {
			log.Warnf("The fcoeNetwork already exists, so skipping CreateFCoENetwork test for %s", testName)
		}
		//reload the profile we just created
		testFcoeNet, err = c.GetFCoENetworkByName(testName)
		assert.NoError(t, err, "GetFCoENetworks error --> %s", err)
	}
}
func TestGetStorageVolumes(t *testing.T) {
	var (
		c *ov.OVClient
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_storage_volume")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		sVols, err := c.GetStorageVolumes("", "")
		assert.NoError(t, err, "GetStorageVolumes threw error -> %s, %+v\n", err, sVols)

		sVols, err = c.GetStorageVolumes("", "name:asc")
		assert.NoError(t, err, "GetStorageVolumes name:asc error -> %s, %+v\n", err, sVols)

	} else {
		_, c = getTestDriverU("test_storage_volume")
		data, err := c.GetStorageVolumes("", "")
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}
}
func TestGetLogicalInterconnectGroups(t *testing.T) {
	var (
		c *ov.OVClient
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_logical_interconnect_group")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		logicalInterconnectGroups, err := c.GetLogicalInterconnectGroups("", "")
		assert.NoError(t, err, "GetLogicalInterconnectGroup threw error -> %s, %+v\n", err, logicalInterconnectGroups)

		logicalInterconnectGroups, err = c.GetLogicalInterconnectGroups("", "name:asc")
		assert.NoError(t, err, "GetLogicalInterconnectGroup name:asc error -> %s, %+v\n", err, logicalInterconnectGroups)

	} else {
		_, c = getTestDriverU("test_logical_interconnect_group")
		data, err := c.GetLogicalInterconnectGroups("", "")
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
	}
}
func TestCreateProfileTemplate(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_server_profile_template")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// find out if the test Server Profile Template already exist
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testServerProfileTemplate, err := c.GetProfileTemplateByName(testName)
		assert.NoError(t, err, "CreateServerProfileTemplate get the ServerProfileTemplate error -> %s", err)

		if testServerProfileTemplate.URI.IsNil() {
			testServerProfileTemplate = ov.ServerProfile{
				Name: testName,
				Type: d.Tc.GetTestData(d.Env, "Type").(string),
				ServerHardwareTypeURI: utils.NewNstring(d.Tc.GetTestData(d.Env, "ServerHardwareTypeUri").(string)),
				EnclosureGroupURI:     utils.NewNstring(d.Tc.GetTestData(d.Env, "EnclosureGroupUri").(string)),
			}

			err := c.CreateProfileTemplate(testServerProfileTemplate)
			assert.NoError(t, err, "CreateServerProfileTemplate error -> %s", err)

			//err = c.CreateProfileTemplate(testServerProfileTemplate)
			//assert.Error(t, err, "CreateServerProfileTemplate should error because the Server Profile Template already exists, err-> %s", err)

		} else {
			log.Warnf("The serverProfileTemplate already exist, so skipping CreateServerProfileTemplate test for %s", testName)
		}

		// reload the test profile that we just created
		testServerProfileTemplate, err = c.GetProfileTemplateByName(testName)
		assert.NoError(t, err, "GetServerProfileTemplate error -> %s", err)
	}
}
func TestDeleteProfileTemplateNotFound(t *testing.T) {
	var (
		c                         *ov.OVClient
		testName                  = "fake"
		testServerProfileTemplate ov.ServerProfile
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_server_profile_template")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		err := c.DeleteProfileTemplate(testName)
		assert.NoError(t, err, "DeleteServerProfileTemplate err-> %s", err)

		testServerProfileTemplate, err = c.GetProfileTemplateByName(testName)
		assert.NoError(t, err, "GetServerProfileTemplateByName with deleted serverProfileTemplate -> %+v", err)
		assert.Equal(t, "", testServerProfileTemplate.Name, fmt.Sprintf("Problem getting serverProfileTemplate name, %+v", testServerProfileTemplate))
	} else {
		_, c = getTestDriverU("test_server_profile_template")
		err := c.DeleteProfileTemplate(testName)
		assert.Error(t, err, fmt.Sprintf("All ok, no error, caught as expected: %s,%+v\n", err, testServerProfileTemplate))
	}
}
func TestDeleteLogicalSwitchGroupNotFound(t *testing.T) {
	var (
		c                      *ov.OVClient
		testName               = "fake"
		testLogicalSwitchGroup ov.LogicalSwitchGroup
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_logical_switch_group")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		err := c.DeleteLogicalSwitchGroup(testName)
		assert.NoError(t, err, "DeleteLogicalSwitchGroup err-> %s", err)

		testLogicalSwitchGroup, err = c.GetLogicalSwitchGroupByName(testName)
		assert.NoError(t, err, "GetLogicalSwitchGroupByName with deleted logical switch group -> %+v", err)
		assert.Equal(t, "", testLogicalSwitchGroup.Name, fmt.Sprintf("Problem getting logical switch group name, %+v", testLogicalSwitchGroup))
	} else {
		_, c = getTestDriverU("test_logical_switch_group")
		err := c.DeleteLogicalSwitchGroup(testName)
		assert.Error(t, err, fmt.Sprintf("All ok, no error, caught as expected: %s,%+v\n", err, testLogicalSwitchGroup))
	}
}
func TestDeleteNetworkSetNotFound(t *testing.T) {
	var (
		c          *ov.OVClient
		testName   = "fake"
		testNetSet ov.NetworkSet
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		_, c = getTestDriverA("test_network_set")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		err := c.DeleteNetworkSet(testName)
		assert.NoError(t, err, "DeleteNetworkSet err-> %s", err)

		testNetSet, err = c.GetNetworkSetByName(testName)
		assert.NoError(t, err, "GetNetworkSetByName with deleted network set -> %+v", err)
		assert.Equal(t, "", testNetSet.Name, fmt.Sprintf("Problem getting network set wtih name, %+v", testNetSet))
	} else {
		_, c = getTestDriverU("test_network_set")
		err := c.DeleteNetworkSet(testName)
		assert.Error(t, err, fmt.Sprintf("All ok, no error, caught as expected: %s,%+v\n", err, testNetSet))
	}
}
// TestRefreshVersion get the latest version being used from api
func TestRefreshVersion(t *testing.T) {
	var (
		d *OVTest
		c *ov.OVClient
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("dev")
		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, "CurrentVersion"), c.APIVersion))
	} else {
		_, c = getTestDriverU("dev")
		err := c.RefreshVersion()
		assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s", err))
	}

}
func TestCreateLogicalInterconnectGroup(t *testing.T) {
	var (
		d                *OVTest
		interconnectData *OVTest
		c                *ov.OVClient
		testName         string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_logical_interconnect_group")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}

		interconnectData, c = getTestDriverA("test_interconnect_type")
		if c == nil || interconnectData == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		testName = d.Tc.GetTestData(d.Env, "Name").(string)
		testLogicalInterconnectGroup, err := c.GetLogicalInterconnectGroupByName(testName)
		assert.NoError(t, err, "CreateLogicalInterconnectGroup get the LogicalInterconnectError error -> %s", err)

		if testLogicalInterconnectGroup.URI.IsNil() {
			/*
				interconnectMapEntryTemplates := make([]ov.InterconnectMapEntryTemplate, 8)
				for i := 0; i < 8; i++ {
					locationEntry1 := ov.LocationEntry{
						RelativeValue: i + 1,
						Type:          "Bay",
					}
					locationEntry2 := ov.LocationEntry{
						RelativeValue: i + 2,
						Type:          "Enclosure",
					}
					locationEntries := make([]ov.LocationEntry, 2)
					locationEntries[0] = locationEntry1
					locationEntries[1] = locationEntry2
					logicalLocation := ov.LogicalLocation{
						LocationEntries: locationEntries,
					}

					interconnectMapEntryTemplate := ov.InterconnectMapEntryTemplate{
						LogicalLocation:              logicalLocation,
						PermittedInterconnectTypeUri: utils.NewNstring(interconnectData.Tc.GetTestData(interconnectData.Env, "URI").(string)),
					}
					interconnectMapEntryTemplates[i] = interconnectMapEntryTemplate
				}
				interconnectMapTemplate := ov.InterconnectMapTemplate{
					InterconnectMapEntryTemplates: interconnectMapEntryTemplates,
				}

				f := false
				tr := true
				ethernetSettings := ov.EthernetSettings{
					Type: "EthernetInterconnectSettingsV3",
					EnableFastMacCacheFailover: &f,
					EnableIgmpSnooping:         &tr,
					EnableRichTLV:              &tr,
					MacRefreshInterval:         10,
					IgmpIdleTimeoutInterval:    250,
				}

				telemetryConfig := ov.TelemetryConfiguration{
					Type:            "telemetry-configuration",
					EnableTelemetry: &tr,
					SampleCount:     12,
					SampleInterval:  150,
				}

				snmpConfiguration := ov.SnmpConfiguration{
					Type:          "snmp-configuration",
					Enabled:       &f,
					ReadCommunity: "test",
					SystemContact: "sys contact",
					SnmpAccess:    []string{"192.168.1.0/24"},
				}

				qosTrafficClassifiers := make([]ov.QosTrafficClassifier, 4)
				qosTrafficClass := ov.QosTrafficClass{
					BandwidthShare:   "10",
					EgressDot1pValue: 5,
					MaxBandwidth:     10,
					RealTime:         &tr,
					ClassName:        "RealTime",
					Enabled:          &tr,
				}
				qosClassificationMap1 := ov.QosClassificationMap{
					Dot1pClassMapping: []int{5, 6, 7},
					DscpClassMapping:  []string{"DSCP 46, EF", "DSCP 40, CS5", "DSCP 48, CS6", "DSCP 56, CS7"},
				}
				qosTrafficClassifier := ov.QosTrafficClassifier{
					QosTrafficClass:          qosTrafficClass,
					QosClassificationMapping: &qosClassificationMap1,
				}
				qosTrafficClassifiers[0] = qosTrafficClassifier

				qosTrafficClass = ov.QosTrafficClass{
					BandwidthShare:   "fcoe",
					EgressDot1pValue: 3,
					MaxBandwidth:     100,
					RealTime:         &f,
					ClassName:        "FCoE lossless",
					Enabled:          &tr,
				}
				qosClassificationMap2 := ov.QosClassificationMap{
					Dot1pClassMapping: []int{3},
					DscpClassMapping:  []string{},
				}
				qosTrafficClassifier = ov.QosTrafficClassifier{
					QosTrafficClass:          qosTrafficClass,
					QosClassificationMapping: &qosClassificationMap2,
				}
				qosTrafficClassifiers[1] = qosTrafficClassifier

				qosTrafficClass = ov.QosTrafficClass{
					BandwidthShare:   "65",
					EgressDot1pValue: 0,
					MaxBandwidth:     100,
					RealTime:         &f,
					ClassName:        "Best effort",
					Enabled:          &tr,
				}
				qosClassificationMap3 := ov.QosClassificationMap{
					Dot1pClassMapping: []int{1, 0},
					DscpClassMapping:  []string{"DSCP 10, AF11", "DSCP 12, AF12", "DSCP 14, AF13", "DSCP 8, CS1", "DSCP 0, CS0"},
				}
				qosTrafficClassifier = ov.QosTrafficClassifier{
					QosTrafficClass:          qosTrafficClass,
					QosClassificationMapping: &qosClassificationMap3,
				}
				qosTrafficClassifiers[2] = qosTrafficClassifier

				qosTrafficClass = ov.QosTrafficClass{
					BandwidthShare:   "25",
					EgressDot1pValue: 2,
					MaxBandwidth:     100,
					RealTime:         &f,
					ClassName:        "Medium",
					Enabled:          &tr,
				}
				qosClassificationMap4 := ov.QosClassificationMap{
					Dot1pClassMapping: []int{4, 3, 2},
					DscpClassMapping: []string{"DSCP 18, AF21",
						"DSCP 20, AF22",
						"DSCP 22, AF23",
						"DSCP 26, AF31",
						"DSCP 28, AF32",
						"DSCP 30, AF33",
						"DSCP 34, AF41",
						"DSCP 36, AF42",
						"DSCP 38, AF43",
						"DSCP 16, CS2",
						"DSCP 24, CS3",
						"DSCP 32, CS4"},
				}
				qosTrafficClassifier = ov.QosTrafficClassifier{
					QosTrafficClass:          qosTrafficClass,
					QosClassificationMapping: &qosClassificationMap4,
				}
				qosTrafficClassifiers[3] = qosTrafficClassifier

				activeQosConfig := ov.ActiveQosConfig{
					Type:                       "QosConfiguration",
					ConfigType:                 "CustomWithFCoE",
					QosTrafficClassifiers:      qosTrafficClassifiers,
					UplinkClassificationType:   "DOT1P",
					DownlinkClassificationType: "DOT1P_AND_DSCP",
				}

				qosConfiguration := ov.QosConfiguration{
					Type:            "qos-aggregated-configuration",
					ActiveQosConfig: activeQosConfig,
				}*/

			testLogicalInterconnectGroup := ov.LogicalInterconnectGroup{
				Name:          testName,
				Type:          d.Tc.GetTestData(d.Env, "Type").(string),
				EnclosureType: d.Tc.GetTestData(d.Env, "EnclosureType").(string),
				//InterconnectMapTemplate: &interconnectMapTemplate,
				//EthernetSettings:        &ethernetSettings,
				//TelemetryConfiguration:  &telemetryConfig,
				//SnmpConfiguration:       &snmpConfiguration,
				//QosConfiguration:        &qosConfiguration,
			}

			err := c.CreateLogicalInterconnectGroup(testLogicalInterconnectGroup)
			assert.NoError(t, err, "CreateLogicalInterconnectGroup error -> %s", err)

			err = c.CreateLogicalInterconnectGroup(testLogicalInterconnectGroup)
			assert.Error(t, err, "CreateLogicalInterconnectGroup should error because the LogicalInterconnectGroup already exists, err-")
		} else {
			log.Warnf("The logicalInterconnectGroup already exists, so skipping CreateLogicalInterconnectGroup test for %s", testName)
		}
	}

}
func TestCreateLogicalSwitchGroup(t *testing.T) {
	var (
		d        *OVTest
		c        *ov.OVClient
		testName string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
		d, c = getTestDriverA("test_logical_switch_group")
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		// find out if the test logicalSwitchGroup already exist
		testName = d.Tc.GetTestData(d.Env, "Name").(string)

		testLogicalSwitchGroup, err := c.GetLogicalSwitchGroupByName(testName)
		assert.NoError(t, err, "CreateLogicalSwitchGroup get the LogicalSwitchError error -> %s", err)

		if testLogicalSwitchGroup.URI.IsNil() {

			switchMapData := d.Tc.GetTestData(d.Env, "SwitchMapTemplate").(map[string]interface{})

			locationEntry := ov.LocationEntry{
				RelativeValue: 1,
				Type:          switchMapData["SwitchMapEntryTemplates"].([]interface{})[0].(map[string]interface{})["LogicalLocation"].(map[string]interface{})["LocationEntries"].([]interface{})[0].(map[string]interface{})["Type"].(string),
			}
			locationEntries := make([]ov.LocationEntry, 1)
			locationEntries[0] = locationEntry
			logicalLocation := ov.LogicalLocation{
				LocationEntries: locationEntries,
			}

			switchMapEntry := ov.SwitchMapEntry{
				PermittedSwitchTypeUri: utils.NewNstring(switchMapData["SwitchMapEntryTemplates"].([]interface{})[0].(map[string]interface{})["PermittedSwitchTypeUri"].(string)),
				LogicalLocation:        logicalLocation,
			}
			switchMapEntries := make([]ov.SwitchMapEntry, 1)
			switchMapEntries[0] = switchMapEntry

			switchMapTemplate := ov.SwitchMapTemplate{
				SwitchMapEntryTemplates: switchMapEntries,
			}
			//log.Warnf("%s", switchMapData["SwitchMapEntryTemplates"].([]interface{})[0].(map[string]interface{})["LogicalLocation"].(map[string]interface{})["LocationEntries"].([]interface{})[0].(map[string]interface{})["RelativeValue"])
			testLogicalSwitchGroup = ov.LogicalSwitchGroup{
				Name:              testName,
				Type:              d.Tc.GetTestData(d.Env, "Type").(string),
				Category:          d.Tc.GetTestData(d.Env, "Category").(string),
				SwitchMapTemplate: switchMapTemplate,
			}
			err := c.CreateLogicalSwitchGroup(testLogicalSwitchGroup)
			assert.NoError(t, err, "CreateLogicalSwitchGroup error -> %s", err)

			err = c.CreateLogicalSwitchGroup(testLogicalSwitchGroup)
			assert.Error(t, err, "CreateLogicalSwitchGroup should error because the LogicalSwitchGroup already exists, err-> %s", err)

		} else {
			log.Warnf("The logicalSwitchGroup already exists, so skipping CreateLogicalSwitchGroup test for %s", testName)
		}

		// reload the test profile that we just created
		testLogicalSwitchGroup, err = c.GetLogicalSwitchGroupByName(testName)
		assert.NoError(t, err, "GetLogicalSwitchGroupByName error -> %s", err)
	}

}