Пример #1
0
func TestDaoGetHostIPsWithIPs(t *testing.T) {
	hostIPs := dao.HostIPs{}
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}

	//store a HostIPs object
	hostIPs.Id = HOSTIPSID
	hostIPs.HostId = HOSTID
	hostIPs.IPs = []dao.HostIPResource{dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}}}
	_, err = newHostIPs(hostIPs.Id, hostIPs)
	defer deleteHostIPs(HOSTIPSID)
	if err != nil {
		t.Errorf("Error creating newHostIPs")
		return
	}

	err = controlPlaneDao.GetHostIPs(HOSTID, &hostIPs)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}
	if hostIPs.Id != HOSTIPSID {
		t.Errorf("Expected host ips id %v , got %v", HOSTIPSID, hostIPs.Id)
	}
	if hostIPs.HostId != HOSTID {
		t.Errorf("Expected host id %v, got %v", HOSTID, hostIPs.Id)
	}
	if hostIPs.PoolId != "" {
		t.Errorf("Expected uninitialzed poolid, got %v", hostIPs.PoolId)
	}
	if hostIPs.PoolId != "" {
		t.Errorf("Expected uninitialzed id, got %v", hostIPs.Id)
	}
	if len(hostIPs.IPs) != 1 {
		t.Errorf("Expected %v IPs, got %v", 1, len(hostIPs.IPs))
	}

}
Пример #2
0
func testDaoHostExists(t *testing.T) {
	found, err := hostExists("blam")
	if found || err != nil {
		t.Errorf("Found %v; error: %v", found, err)
		t.FailNow()
	}

	host := dao.Host{}
	host.Id = "existsTest"
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost("existsTest", &unused)

	found, err = hostExists(id)
	if !found || err != nil {
		t.Errorf("Found %v; error: %v", found, err)
	}

}
Пример #3
0
func TestDaoGetHostIPsNotFound(t *testing.T) {
	hostIPs := dao.HostIPs{}

	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}

	err = controlPlaneDao.GetHostIPs(HOSTID, &hostIPs)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if hostIPs.Id != "" {
		t.Errorf("Expected uninitialzed id, got %v", hostIPs.Id)
	}
}
Пример #4
0
func TestDaoRegisterHostIPs(t *testing.T) {
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)

	ips := dao.HostIPs{}
	ips.HostId = HOSTID
	ips.IPs = []dao.HostIPResource{dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}}}

	err := controlPlaneDao.RegisterHostIPs(ips, &unused)
	//remove any registered
	defer removeHostIPs(HOSTID)

	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	//verify registration
	ips = dao.HostIPs{}
	controlPlaneDao.GetHostIPs(HOSTID, &ips)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if len(ips.IPs) != 1 {
		t.Errorf("Expected 1 HostIPResource, found: %v", len(ips.IPs))
	}
	ipResource := ips.IPs[0]
	if ipResource.State != "valid" {
		t.Errorf("Unexpected state: %v", ipResource.State)
	}
	if ipResource.IPAddress != "testip" {
		t.Errorf("Unexpected IPAddress: %v", ipResource.IPAddress)
	}
	if ipResource.InterfaceName != "ifname" {
		t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
	}

}
Пример #5
0
func TestDao_AddHost(t *testing.T) {
	host := dao.Host{}
	controlPlaneDao.RemoveHost("default", &unused)
	err := controlPlaneDao.AddHost(host, &id)
	if err == nil {
		t.Errorf("Expected failure to create host %-v", host)
		t.Fail()
	}

	host.Id = "default"
	err = controlPlaneDao.AddHost(host, &id)
	if err != nil {
		t.Errorf("Failure creating host %-v with error: %s", host, err)
		t.Fail()
	}

	err = controlPlaneDao.AddHost(host, &id)
	if err == nil {
		t.Errorf("Expected error creating redundant host %-v", host)
		t.Fail()
	}
}
Пример #6
0
func TestDaoRegisterHostIPsMerge(t *testing.T) {
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)

	ips := dao.HostIPs{}
	ips.HostId = HOSTID
	ips.IPs = []dao.HostIPResource{
		dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}},
		dao.HostIPResource{"deleted", "testip1", "ifname", []dao.AssignedPort{}},
	}

	err := controlPlaneDao.RegisterHostIPs(ips, &unused)
	//remove any registered
	defer removeHostIPs(HOSTID)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	ips.IPs = []dao.HostIPResource{
		dao.HostIPResource{"valid", "testip2", "ifname2", []dao.AssignedPort{}},
		dao.HostIPResource{"valid", "testip1", "ifname", []dao.AssignedPort{}},
	}
	err = controlPlaneDao.RegisterHostIPs(ips, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	//verify registration
	ips = dao.HostIPs{}
	controlPlaneDao.GetHostIPs(HOSTID, &ips)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if len(ips.IPs) != 3 {
		t.Errorf("Expected 3 HostIPResources, found: %v", len(ips.IPs))
	}
	for _, ipResource := range ips.IPs {
		addr := ipResource.IPAddress
		switch addr {
		case "testip":
			{
				if ipResource.State != "deleted" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		case "testip1":
			{
				if ipResource.State != "valid" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		case "testip2":
			{
				if ipResource.State != "valid" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname2" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		default:
			{
				t.Errorf("Unexpected IP resource %v", ipResource)
			}
		}

	}
}