示例#1
0
func applyConfig(t *testing.T, cfgBytes []byte) {
	cfg := &intent.Config{}
	err := json.Unmarshal(cfgBytes, cfg)
	if err != nil {
		t.Fatalf("error '%s' parsing config '%s'\n", err, cfgBytes)
	}

	_, err = resources.NewStateResourceManager(fakeDriver)
	if err != nil {
		log.Fatalf("state store initialization failed. Error: %s", err)
	}
	defer func() { resources.ReleaseStateResourceManager() }()

	for _, tenant := range cfg.Tenants {
		err = CreateTenant(fakeDriver, &tenant)
		if err != nil {
			t.Fatalf("error '%s' creating tenant\n", err)
		}

		err = CreateNetworks(fakeDriver, &tenant)
		if err != nil {
			t.Fatalf("error '%s' creating networks\n", err)
		}

		err = CreateEndpoints(fakeDriver, &tenant)
		if err != nil {
			t.Fatalf("error '%s' creating endpoints\n", err)
		}
	}

	fakeDriver.DumpState()
}
示例#2
0
func (d *daemon) execOpts() {
	if err := d.parseOpts(); err != nil {
		log.Fatalf("Failed to parse cli options. Error: %s", err)
	}

	if d.opts.help {
		fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]...\n", os.Args[0])
		flagSet.PrintDefaults()
		os.Exit(0)
	}

	if d.opts.debug {
		log.SetLevel(log.DebugLevel)
	}

	sd, err := initStateDriver(&d.opts)
	if err != nil {
		log.Fatalf("Failed to init state-store. Error: %s", err)
	}

	if _, err = resources.NewStateResourceManager(sd); err != nil {
		log.Fatalf("Failed to init resource manager. Error: %s", err)
	}

	// Register netmaster service
	d.registerService()

	// initialize policy manager
	master.InitPolicyMgr()
}
示例#3
0
func main() {
	err := flagSet.Parse(os.Args[1:])
	if err != nil {
		log.Fatalf("Failed to parse command. Error: %s", err)
	}
	opts.idStr = flagSet.Arg(0)

	sd, err := initStateDriver(&opts)
	if err != nil {
		log.Fatalf("state store initialization failed. Error: %s", err)
	}

	_, err = resources.NewStateResourceManager(sd)
	if err != nil {
		log.Fatalf("state store initialization failed. Error: %s", err)
	}

	if opts.cfgDesired || opts.cfgDeletions || opts.cfgAdditions || opts.cfgHostBindings {
		err = executeJSONCfg(&opts)
	} else {
		err = executeOpts(&opts)
	}
	if err != nil {
		log.Fatalf("error executing the command. Opts: %+v. Error: %s", opts, err)
	}

	os.Exit(0)
}
示例#4
0
func (d *daemon) execOpts() {
	if err := d.parseOpts(); err != nil {
		log.Fatalf("Failed to parse cli options. Error: %s", err)
	}

	if d.opts.help {
		fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]...\n", os.Args[0])
		flagSet.PrintDefaults()
		os.Exit(0)
	}

	if d.opts.debug {
		log.SetLevel(log.DebugLevel)
	}

	if err := master.SetClusterMode(d.opts.clusterMode); err != nil {
		log.Fatalf("Failed to set cluster-mode. Error: %s", err)
	}

	sd, err := initStateDriver(&d.opts)
	if err != nil {
		log.Fatalf("Failed to init state-store. Error: %s", err)
	}

	if _, err = resources.NewStateResourceManager(sd); err != nil {
		log.Fatalf("Failed to init resource manager. Error: %s", err)
	}

	d.stateDriver = sd
}
示例#5
0
func TestGlobalConfigAutoVXLAN(t *testing.T) {
	cfgData := []byte(`
        {
            "Version" : "0.01",
            "Tenant"  : "default",
            "Auto" : {
                "SubnetPool"        : "11.5.0.0",
                "SubnetLen"         : 16,
                "AllocSubnetLen"    : 24,
                "VLANs"             : "1-10",
                "VXLANs"            : "15000-17000"
            },
            "Deploy" : {
                "DefaultNetType"    : "vxlan"
            }
        }`)
	var vxlan, localVLAN uint

	gc, err := Parse(cfgData)
	if err != nil {
		t.Fatalf("error '%s' parsing config '%s' \n", err, cfgData)
	}

	gstateSD.Init(nil)
	defer func() { gstateSD.Deinit() }()
	gc.StateDriver = gstateSD
	rm, err := resources.NewStateResourceManager(gstateSD)
	if err != nil {
		t.Fatalf("Failed to instantiate resource manager. Error: %s", err)
	}
	defer func() { resources.ReleaseStateResourceManager() }()

	err = gc.Process(rm)
	if err != nil {
		t.Fatalf("error '%s' processing config %v \n", err, gc)
	}

	vxlan, localVLAN, err = gc.AllocVXLAN(rm)
	if err != nil {
		t.Fatalf("error - allocating vxlan - %s \n", err)
	}
	if vxlan == 0 {
		t.Fatalf("error - invalid vxlan allocated %d \n", vxlan)
	}
	if localVLAN == 0 {
		t.Fatalf("error - invalid vlan allocated %d \n", localVLAN)
	}

	err = gc.FreeVXLAN(rm, vxlan, localVLAN)
	if err != nil {
		t.Fatalf("error freeing allocated vxlan %d localvlan %d - err '%s' \n",
			vxlan, localVLAN, err)
	}
}
示例#6
0
func applyVerifyRangeTag(t *testing.T, cfgBytes []byte, shouldFail bool) {
	initFakeStateDriver(t)
	defer deinitFakeStateDriver()

	cfg := &intent.Config{}
	err := json.Unmarshal(cfgBytes, cfg)
	if err != nil {
		t.Fatalf("error '%s' parsing config '%s'\n", err, cfgBytes)
	}

	_, err = resources.NewStateResourceManager(fakeDriver)
	if err != nil {
		log.Fatalf("state store initialization failed. Error: %s", err)
	}
	defer func() { resources.ReleaseStateResourceManager() }()

	tenant := cfg.Tenants[0]
	err = CreateTenant(fakeDriver, &tenant)
	if err != nil {
		t.Fatalf("error '%s' creating tenant\n", err)
	}

	err = CreateNetworks(fakeDriver, &tenant)
	if shouldFail {

		var expError string
		network := tenant.Networks[0]
		if network.PktTagType == "vlan" {
			expError = fmt.Sprintf("vlan %d does not adhere to tenant's vlan range %s", network.PktTag, tenant.VLANs)
		} else {
			expError = fmt.Sprintf("vxlan %d does not adhere to tenant's vxlan range %s", network.PktTag, tenant.VXLANs)
		}

		if err == nil {
			t.Fatalf("CreateNetworks did not return error\n")
		} else if err.Error() != expError {
			t.Fatalf("CreateNetworks did not return error for OutOfRange\n")
		}
	} else if err != nil {
		t.Fatalf("error '%s' while creating network\n", err)
	}

}
示例#7
0
func TestInvalidGlobalConfigNoLocalVLANs(t *testing.T) {
	cfgData := []byte(`
        {
            "Version" : "0.01",
            "Tenant"  : "default",
            "Auto" : {
                "SubnetPool"        : "11.5.0.0",
                "SubnetLen"         : 16,
                "AllocSubnetLen"    : 24,
                "VLANs"             : "1-4095",
                "VXLANs"            : "10000-10001"
            },
            "Deploy" : {
                "DefaultNetType"    : "vlan"
            }
        }`)

	gc, err := Parse(cfgData)
	if err != nil {
		t.Fatalf("error '%s' parsing config '%s' \n", err, cfgData)
	}

	gstateSD.Init(nil)
	defer func() { gstateSD.Deinit() }()
	gc.StateDriver = gstateSD
	rm, err := resources.NewStateResourceManager(gstateSD)
	if err != nil {
		t.Fatalf("Failed to instantiate resource manager. Error: %s", err)
	}
	defer func() { resources.ReleaseStateResourceManager() }()

	err = gc.Process(rm)
	if err == nil {
		t.Fatalf("Was able to process the config, expected to fail!")
	}
}