示例#1
0
func TestTwoHostsVxlanAddDelNetwork_sanity(t *testing.T) {
	defer func() {
		utils.ConfigCleanupCommon(t, testbed.GetNodes())
		utils.StopOnError(t.Failed())
	}()

	jsonCfg :=
		`{
        "Hosts" : [{
            "Name"                      : "host1",
            "VtepIp"                    : "192.168.2.10"
        },
        {
            "Name"                      : "host2",
            "VtepIp"                    : "192.168.2.11"
        }],
        "Tenants" : [ {
            "Name"                      : "tenant-one",
            "DefaultNetType"            : "vxlan",
            "SubnetPool"                : "11.1.0.0/16",
            "AllocSubnetLen"            : 24,
            "VXlans"                    : "10001-14000",
            "Networks"  : [ 
            {
                "Name"                  : "orange",
                "Endpoints" : [
                {
                    "Container"         : "myContainer1",
                    "Host"              : "host1"
                },
                {
                    "Container"         : "myContainer2",
                    "Host"              : "host2"
                } ]
            },
            {
                "Name"                  : "purple",
                "Endpoints" : [
                {
                    "Container"         : "myContainer3",
                    "Host"              : "host1"
                },
                {
                    "Container"         : "myContainer4",
                    "Host"              : "host2"
                } ]
            } ]
        } ]
        }`

	utils.ConfigSetupCommon(t, jsonCfg, testbed.GetNodes())

	node1 := testbed.GetNodes()[0]
	node2 := testbed.GetNodes()[1]

	utils.StartServer(t, node1, "myContainer1")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer1")
	}()

	utils.StartServer(t, node1, "myContainer3")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer3")
	}()

	ipAddress := utils.GetIPAddress(t, node1, "orange-myContainer1", u.EtcdNameStr)
	utils.StartClient(t, node2, "myContainer2", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer2")
	}()

	ipAddress = utils.GetIPAddress(t, node1, "purple-myContainer3", u.EtcdNameStr)
	utils.StartClient(t, node2, "myContainer4", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer4")
	}()

	jsonCfg = `
	{
	"Tenants" : [ {
		"Name"                      : "tenant-one",
		"Networks"  : [
		{
			"Name"                  : "green",
			"Endpoints" : [
			{
				"Container"         : "myContainer5",
				"Host"              : "host1"
			},
			{
				"Container"         : "myContainer6",
				"Host"              : "host2"
			}
			]
		}
		]
	} ]
	}`
	utils.AddConfig(t, jsonCfg, testbed.GetNodes()[0])

	utils.StartServer(t, node1, "myContainer5")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer5")
	}()

	ipAddress = utils.GetIPAddress(t, node1, "green-myContainer5", u.EtcdNameStr)
	utils.StartClient(t, node2, "myContainer6", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer6")
	}()

	utils.DelConfig(t, jsonCfg, testbed.GetNodes()[0])

	utils.DockerCleanup(t, node2, "myContainer6")
	utils.StartClientFailure(t, node2, "myContainer6", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer6")
	}()

	jsonCfg = `
	{
	"Tenants" : [ {
		"Name"                      : "tenant-one",
		"Networks"  : [
		{
			"Name"                  : "green"
		}
		]
	} ]
	}`

	utils.DelConfig(t, jsonCfg, testbed.GetNodes()[0])
	time.Sleep(1 * time.Second)
	if utils.NetworkStateExists(node2, "green", "") == nil {
		t.Fatalf("Error - network %s doesn't seem to be deleted \n", "green")
	}
}
示例#2
0
func TestTwoHostsVxlanAddDelEp_sanity(t *testing.T) {
	defer func() {
		utils.ConfigCleanupCommon(t, testbed.GetNodes())
		utils.StopOnError(t.Failed())
	}()

	jsonCfg :=
		`{
        "Hosts" : [{
            "Name"                      : "host1",
            "VtepIp"                    : "192.168.2.10"
        },
        {
            "Name"                      : "host2",
            "VtepIp"                    : "192.168.2.11"
        }],
        "Tenants" : [ {
            "Name"                      : "tenant-one",
            "DefaultNetType"            : "vxlan",
            "SubnetPool"                : "11.1.0.0/16",
            "AllocSubnetLen"            : 24,
            "VXlans"                    : "10001-11000",
            "Networks"  : [
            {
                "Name"                  : "orange",
                "Endpoints" : [
                {
                    "Container"         : "myContainer1",
                    "Host"              : "host1"
                },
                {
                    "Container"         : "myContainer2",
                    "Host"              : "host2"
                } ]
            },
            {
                "Name"                  : "purple",
                "Endpoints" : [
                {
                    "Container"         : "myContainer3",
                    "Host"              : "host1"
                },
                {
                    "Container"         : "myContainer4",
                    "Host"              : "host2"
                } ]
            } ]
        } ]
        }`

	utils.ConfigSetupCommon(t, jsonCfg, testbed.GetNodes())

	node1 := testbed.GetNodes()[0]
	node2 := testbed.GetNodes()[1]

	utils.StartServer(t, node1, "myContainer1")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer1")
	}()

	utils.StartServer(t, node1, "myContainer3")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer3")
	}()

	ipAddress := utils.GetIPAddress(t, node1, "orange.tenant-one-myContainer1", u.EtcdNameStr)
	utils.StartClient(t, node2, "myContainer2", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer2")
	}()

	ipAddress = utils.GetIPAddress(t, node1, "purple.tenant-one-myContainer3", u.EtcdNameStr)
	utils.StartClient(t, node2, "myContainer4", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer4")
	}()

	jsonCfg = `
	{
	"Tenants" : [ {
		"Name"                      : "tenant-one",
		"Networks"  : [
		{
			"Name"                  : "orange",
			"Endpoints" : [
			{
				"Container"         : "myContainer5",
				"Host"              : "host1"
			}
			]
		}
		]
	} ]
	}`
	utils.AddConfig(t, jsonCfg, testbed.GetNodes()[0])

	utils.StartServer(t, node1, "myContainer5")
	defer func() {
		utils.DockerCleanup(t, node1, "myContainer5")
	}()

	ipAddress = utils.GetIPAddress(t, node1, "orange.tenant-one-myContainer5", u.EtcdNameStr)
	utils.DockerCleanup(t, node2, "myContainer2")
	utils.StartClient(t, node2, "myContainer2", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer2")
	}()

	utils.DelConfig(t, jsonCfg, testbed.GetNodes()[0])

	utils.DockerCleanup(t, node2, "myContainer2")
	utils.StartClientFailure(t, node2, "myContainer2", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer2")
	}()

	jsonCfg = `
	{
	"Tenants" : [ {
		"Name"                      : "tenant-one",
		"Networks"  : [
		{
			"Name"                  : "purple",
			"Endpoints" : [
			{
				"Container"         : "myContainer5",
				"Host"              : "host1"
			}
			]
		}
		]
	} ]
	}`

	utils.AddConfig(t, jsonCfg, testbed.GetNodes()[0])
	ipAddress = utils.GetIPAddress(t, node1, "purple.tenant-one-myContainer5", u.EtcdNameStr)
	utils.DockerCleanup(t, node2, "myContainer4")
	utils.StartClient(t, node2, "myContainer4", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node2, "myContainer4")
	}()
}
示例#3
0
// Default Network Assignment and freeing
func TestSingleHostDefaultNetwork_sanity(t *testing.T) {
	defer func() {
		utils.ConfigCleanupCommon(t, testbed.GetNodes())
		utils.StopOnError(t.Failed())
	}()

	//create a single vlan network, with two endpoints
	jsonCfg :=
		`{
        "Tenants" : [ {
            "Name"                      : "tenant-one",
            "DefaultNetType"            : "vlan",
            "DefaultNetwork"            : "orange",
            "SubnetPool"                : "100.1.0.0/16",
            "AllocSubnetLen"            : 24,
            "Vlans"                     : "11-48",
            "Networks"  : [ {
                "Name"                  : "orange",
                "Endpoints" : [
                {
                    "Container"         : "myContainer1",
                    "Host"              : "host1"
                } ]
            },
            {
                "Name"                  : "purple",
                "Endpoints" : [
                {
                    "Container"         : "myContainer2",
                    "Host"              : "host1"
                } ]
            } ]
        } ]
        }`

	utils.ConfigSetupCommon(t, jsonCfg, testbed.GetNodes())

	node := testbed.GetNodes()[0]

	utils.StartServer(t, node, "myContainer1")
	defer func() {
		utils.DockerCleanup(t, node, "myContainer1")
	}()

	ipAddress := utils.GetIPAddress(t, node, "orange.tenant-one-myContainer1", u.EtcdNameStr)
	utils.StartClientFailure(t, node, "myContainer2", ipAddress)
	defer func() {
		utils.DockerCleanup(t, node, "myContainer2")
	}()

	// confirm the default gateway in one of the containers
	output, err := node.RunCommandWithOutput("docker exec myContainer1 /sbin/ip route")
	if err != nil {
		t.Fatalf("Error - unable to get default ip route, output = '%s'", output)
	}
	if !strings.Contains(output, "default via 100.1.0.254") {
		t.Fatalf("Error - unable to confirm container's default ip route, output = '%s'", output)
	}

	jsonCfg = `
    {
      "Tenants" : [ {
        "Name"                      : "tenant-one",
        "Networks"  : [ {
          "Name"                    : "orange",
          "Endpoints" : [ {
            "Container"             : "myContainer1",
            "Host"                  : "host1"
          } ]
        } ]
      } ]
    }`

	// deletion would result into unassignment
	utils.DelConfig(t, jsonCfg, testbed.GetNodes()[0])
	time.Sleep(1 * time.Second)

	// confirm the default gateway in one of the containers
	output, err = node.RunCommandWithOutput("docker exec myContainer1 /sbin/ip route")
	if err != nil {
		t.Fatalf("Error - unable to get default ip route, output = '%s'", output)
	}
	if strings.Contains(output, "default via 100.1.0.254") {
		t.Fatalf("Error - able to still find the default rout after network is deleted output = '%s'", output)
	}

}