Пример #1
0
func TestRequiredPoolCreateOpts(t *testing.T) {
	res := pools.Create(fake.ServiceClient(), pools.CreateOpts{})
	if res.Err == nil {
		t.Fatalf("Expected error, got none")
	}
	res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
		LBMethod:       pools.LBMethod("invalid"),
		Protocol:       pools.ProtocolHTTPS,
		LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a",
	})
	if res.Err == nil {
		t.Fatalf("Expected error, but got none")
	}

	res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
		LBMethod:       pools.LBMethodRoundRobin,
		Protocol:       pools.Protocol("invalid"),
		LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a",
	})
	if res.Err == nil {
		t.Fatalf("Expected error, but got none")
	}

	res = pools.Create(fake.ServiceClient(), pools.CreateOpts{
		LBMethod: pools.LBMethodRoundRobin,
		Protocol: pools.ProtocolHTTPS,
	})
	if res.Err == nil {
		t.Fatalf("Expected error, but got none")
	}
}
Пример #2
0
// CreatePool will create a pool with a random name with a specified listener
// and loadbalancer. An error will be returned if the pool could not be
// created.
func CreatePool(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*pools.Pool, error) {
	poolName := tools.RandomString("TESTACCT-", 8)

	t.Logf("Attempting to create pool %s", poolName)

	createOpts := pools.CreateOpts{
		Name:           poolName,
		Protocol:       pools.ProtocolTCP,
		LoadbalancerID: lb.ID,
		LBMethod:       pools.LBMethodLeastConnections,
	}

	pool, err := pools.Create(client, createOpts).Extract()
	if err != nil {
		return pool, err
	}

	t.Logf("Successfully created pool %s", poolName)

	if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
		return pool, fmt.Errorf("Timed out waiting for loadbalancer to become active")
	}

	return pool, nil
}
func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	networkingClient, err := config.networkingV2Client(d.Get("region").(string))
	if err != nil {
		return fmt.Errorf("Error creating OpenStack networking client: %s", err)
	}

	adminStateUp := d.Get("admin_state_up").(bool)
	var persistence pools.SessionPersistence
	if p, ok := d.GetOk("persistence"); ok {
		pV := (p.([]interface{}))[0].(map[string]interface{})

		persistence = pools.SessionPersistence{
			Type:       pV["type"].(string),
			CookieName: pV["cookie_name"].(string),
		}
	}
	createOpts := pools.CreateOpts{
		TenantID:       d.Get("tenant_id").(string),
		Name:           d.Get("name").(string),
		Description:    d.Get("description").(string),
		Protocol:       pools.Protocol(d.Get("protocol").(string)),
		LoadbalancerID: d.Get("loadbalancer_id").(string),
		ListenerID:     d.Get("listener_id").(string),
		LBMethod:       pools.LBMethod(d.Get("lb_method").(string)),
		AdminStateUp:   &adminStateUp,
	}
	// Must omit if not set
	if persistence != (pools.SessionPersistence{}) {
		createOpts.Persistence = &persistence
	}

	log.Printf("[DEBUG] Create Options: %#v", createOpts)
	pool, err := pools.Create(networkingClient, createOpts).Extract()
	if err != nil {
		return fmt.Errorf("Error creating OpenStack LBaaSV2 pool: %s", err)
	}
	log.Printf("[INFO] pool ID: %s", pool.ID)

	log.Printf("[DEBUG] Waiting for Openstack LBaaSV2 pool (%s) to become available.", pool.ID)

	stateConf := &resource.StateChangeConf{
		Pending:    []string{"PENDING_CREATE"},
		Target:     []string{"ACTIVE"},
		Refresh:    waitForPoolActive(networkingClient, pool.ID),
		Timeout:    2 * time.Minute,
		Delay:      5 * time.Second,
		MinTimeout: 3 * time.Second,
	}

	_, err = stateConf.WaitForState()
	if err != nil {
		return err
	}

	d.SetId(pool.ID)

	return resourcePoolV2Read(d, meta)
}
Пример #4
0
func TestCreatePool(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandlePoolCreationSuccessfully(t, SinglePoolBody)

	actual, err := pools.Create(fake.ServiceClient(), pools.CreateOpts{
		LBMethod:       pools.LBMethodRoundRobin,
		Protocol:       "HTTP",
		Name:           "Example pool",
		TenantID:       "2ffc6e22aae24e4795f87155d24c896f",
		LoadbalancerID: "79e05663-7f03-45d2-a092-8b94062f22ab",
	}).Extract()
	th.AssertNoErr(t, err)

	th.CheckDeepEquals(t, PoolDb, *actual)
}