Beispiel #1
0
func TestOvsDriverCreateEndpointStatefulStateMismatch(t *testing.T) {
	driver := initOvsDriver(t)
	defer func() { driver.Deinit() }()
	id := createEpIDStatefulMismatch

	// create network
	err := driver.CreateNetwork(testOvsNwID)
	if err != nil {
		t.Fatalf("network creation failed. Error: %s", err)
	}
	defer func() { driver.DeleteNetwork(testOvsNwID, "", "", testPktTag, testExtPktTag, testGateway, testTenant) }()

	// create second network
	err = driver.CreateNetwork(testOvsNwIDStateful)
	if err != nil {
		t.Fatalf("network creation failed. Error: %s", err)
	}
	defer func() {
		driver.DeleteNetwork(testOvsNwIDStateful, "", "", testPktTagStateful, testExtPktTag, testGateway, testTenant)
	}()

	// create endpoint
	err = driver.CreateEndpoint(id)
	if err != nil {
		t.Fatalf("endpoint creation failed. Error: %s", err)
	}

	cfgEp := mastercfg.CfgEndpointState{}
	cfgEp.StateDriver = driver.oper.StateDriver
	err = cfgEp.Read(id)
	if err != nil {
		t.Fatalf("failed to read ep config. Error: %s", err)
	}
	cfgEp.NetID = testOvsNwIDStateful

	err = cfgEp.Write()
	if err != nil {
		t.Fatalf("failed to write ep config. Error: %s", err)
	}

	err = driver.CreateEndpoint(id)
	if err != nil {
		t.Fatalf("stateful endpoint creation failed. Error: %s", err)
	}

	defer func() { driver.DeleteEndpoint(id) }()

	output, err := exec.Command("ovs-vsctl", "list", "Port").CombinedOutput()
	expectedPortName := fmt.Sprintf("port%d", driver.oper.CurrPortNum)
	if err != nil || !strings.Contains(string(output), expectedPortName) {
		t.Fatalf("port lookup failed. Error: %s expected port: %s Output: %s",
			err, expectedPortName, output)
	}

	output, err = exec.Command("ovs-vsctl", "list", "Interface").CombinedOutput()
	if err != nil || !strings.Contains(string(output), expectedPortName) {
		t.Fatalf("interface lookup failed. Error: %s expected port: %s Output: %s",
			err, expectedPortName, output)
	}
}
Beispiel #2
0
func handleEndpointEvents(netPlugin *plugin.NetPlugin, crt *crt.CRT,
	opts cliOpts, retErr chan error) {
	rsps := make(chan core.WatchState)
	go processStateEvent(netPlugin, crt, opts, rsps)
	cfg := mastercfg.CfgEndpointState{}
	cfg.StateDriver = netPlugin.StateDriver
	retErr <- cfg.WatchAll(rsps)
	return
}
Beispiel #3
0
//RestoreServiceProviderLBDb restores provider and servicelb db
func RestoreServiceProviderLBDb() {

	log.Infof("Restoring ProviderDb and ServiceDB cache")

	svcLBState := &mastercfg.CfgServiceLBState{}
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		log.Errorf("Error Restoring Service and ProviderDb Err:%s", err)
		return
	}
	svcLBState.StateDriver = stateDriver
	svcLBCfgs, err := svcLBState.ReadAll()

	if err == nil {
		mastercfg.SvcMutex.Lock()
		for _, svcLBCfg := range svcLBCfgs {
			svcLB := svcLBCfg.(*mastercfg.CfgServiceLBState)
			//mastercfg.ServiceLBDb = make(map[string]*mastercfg.ServiceLBInfo)
			serviceID := GetServiceID(svcLB.ServiceName, svcLB.Tenant)
			mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
				IPAddress:   svcLB.IPAddress,
				Tenant:      svcLB.Tenant,
				ServiceName: svcLB.ServiceName,
				Network:     svcLB.Network,
			}
			mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, svcLB.Ports...)

			mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
			mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)

			for k, v := range svcLB.Selectors {
				mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
			}

			for providerID, providerInfo := range svcLB.Providers {
				mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
				providerDBId := providerInfo.ContainerID
				mastercfg.ProviderDb[providerDBId] = providerInfo
			}
		}
		mastercfg.SvcMutex.Unlock()
	}

	//Recover from endpoint state as well .
	epCfgState := mastercfg.CfgEndpointState{}
	epCfgState.StateDriver = stateDriver
	epCfgs, err := epCfgState.ReadAll()
	if err == nil {
		for _, epCfg := range epCfgs {
			ep := epCfg.(*mastercfg.CfgEndpointState)
			providerDBId := ep.ContainerID
			if ep.Labels != nil && mastercfg.ProviderDb[providerDBId] == nil {
				//Create provider info and store it in provider db
				providerInfo := &mastercfg.Provider{}
				providerInfo.ContainerID = ep.ContainerID
				providerInfo.Network = strings.Split(ep.NetID, ".")[0]
				providerInfo.Tenant = strings.Split(ep.NetID, ".")[1]
				providerInfo.Labels = make(map[string]string)
				providerInfo.IPAddress = ep.IPAddress

				for k, v := range ep.Labels {
					providerInfo.Labels[k] = v
				}
				mastercfg.SvcMutex.Lock()
				mastercfg.ProviderDb[providerDBId] = providerInfo
				mastercfg.SvcMutex.Unlock()
			}
		}
	}
}