Example #1
0
func TestUpdate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleUpdate(t)

	options := UpdateOpts{
		UpdateOptsBuilder: ports.UpdateOpts{
			Name: "new_port_name",
			FixedIPs: []ports.IP{
				{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
			},
			SecurityGroups: []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"},
		},
		HostID:   "HOST1",
		VNICType: "normal",
	}

	s, err := Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, s.Name, "new_port_name")
	th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{
		{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
	})
	th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"})
	th.AssertEquals(t, s.HostID, "HOST1")
	th.AssertEquals(t, s.VNICType, "normal")
}
Example #2
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleGet(t)

	n, err := Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, n.Status, "ACTIVE")
	th.AssertEquals(t, n.Name, "")
	th.AssertEquals(t, n.AdminStateUp, true)
	th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
	th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177")
	th.AssertEquals(t, n.DeviceOwner, "network:router_interface")
	th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7")
	th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{
		{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"},
	})
	th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
	th.AssertDeepEquals(t, n.SecurityGroups, []string{})
	th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")

	th.AssertEquals(t, n.HostID, "devstack")
	th.AssertEquals(t, n.VNICType, "normal")
	th.AssertEquals(t, n.VIFType, "ovs")
	th.AssertDeepEquals(t, n.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true})
}
Example #3
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
    "port": {
        "status": "ACTIVE",
        "name": "",
        "admin_state_up": true,
        "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7",
        "tenant_id": "7e02058126cc4950b75f9970368ba177",
        "device_owner": "network:router_interface",
        "mac_address": "fa:16:3e:23:fd:d7",
        "fixed_ips": [
            {
                "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2",
                "ip_address": "10.0.0.1"
            }
        ],
        "id": "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
        "security_groups": [],
        "device_id": "5e3898d7-11be-483e-9732-b2f5eccd2b2e",
        "binding:host_id": "HOST1",
        "binding:vnic_type": "normal"
    }
}
			`)
	})

	n, err := Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, n.Status, "ACTIVE")
	th.AssertEquals(t, n.Name, "")
	th.AssertEquals(t, n.AdminStateUp, true)
	th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
	th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177")
	th.AssertEquals(t, n.DeviceOwner, "network:router_interface")
	th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7")
	th.AssertDeepEquals(t, n.FixedIPs, []IP{
		{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"},
	})
	th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
	th.AssertDeepEquals(t, n.SecurityGroups, []string{})
	th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
	th.AssertEquals(t, n.HostID, "HOST1")
	th.AssertEquals(t, n.VNICType, "normal")
}
Example #4
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/subnets/54d6f61d-db07-451c-9ab3-b9609b6b6f0b", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
    "subnet": {
        "name": "my_subnet",
        "enable_dhcp": true,
        "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
        "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
        "dns_nameservers": [],
        "allocation_pools": [
            {
                "start": "192.0.0.2",
                "end": "192.255.255.254"
            }
        ],
        "host_routes": [],
        "ip_version": 4,
        "gateway_ip": "192.0.0.1",
        "cidr": "192.0.0.0/8",
        "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
    }
}
      `)
	})

	s, err := Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, s.Name, "my_subnet")
	th.AssertEquals(t, s.EnableDHCP, true)
	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
	th.AssertDeepEquals(t, s.DNSNameservers, []string{})
	th.AssertDeepEquals(t, s.AllocationPools, []os.AllocationPool{
		os.AllocationPool{
			Start: "192.0.0.2",
			End:   "192.255.255.254",
		},
	})
	th.AssertDeepEquals(t, s.HostRoutes, []os.HostRoute{})
	th.AssertEquals(t, s.IPVersion, 4)
	th.AssertEquals(t, s.GatewayIP, "192.0.0.1")
	th.AssertEquals(t, s.CIDR, "192.0.0.0/8")
	th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0b")
}
Example #5
0
func TestListGlobalParams(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, globalParamListURL, "GET", "", ListParamsJSON, 200)

	pages := 0
	err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractParams(page)
		if err != nil {
			return false, err
		}

		expected := []Param{
			Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
			Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
			Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
			Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
		}

		th.AssertDeepEquals(t, actual, expected)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
Example #6
0
func TestGetStats(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockGetStatsResponse(t, id1)

	content, err := GetStats(client.ServiceClient(), id1).Extract()
	th.AssertNoErr(t, err)

	expected := &Stats{
		ConnectTimeout:        10,
		ConnectError:          20,
		ConnectFailure:        30,
		DataTimedOut:          40,
		KeepAliveTimedOut:     50,
		MaxConnections:        60,
		CurrentConnections:    40,
		SSLConnectTimeout:     10,
		SSLConnectError:       20,
		SSLConnectFailure:     30,
		SSLDataTimedOut:       40,
		SSLKeepAliveTimedOut:  50,
		SSLMaxConnections:     60,
		SSLCurrentConnections: 40,
	}
	th.AssertDeepEquals(t, expected, content)
}
Example #7
0
func TestListInstances(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL+"/instances", "GET", "", ListInstancesJSON, 200)

	expectedInstance := instances.Instance{
		ID:   "d4603f69-ec7e-4e9b-803f-600b9205576f",
		Name: "json_rack_instance",
	}

	pages := 0
	err := ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := instances.ExtractInstances(page)
		if err != nil {
			return false, err
		}

		th.AssertDeepEquals(t, actual, []instances.Instance{expectedInstance})

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
Example #8
0
func TestShowMemberDetails(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleImageMemberDetails(t)
	md, err := Get(fakeclient.ServiceClient(),
		"da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		"8989447062e04a818baf9e073fd04fa7").Extract()

	th.AssertNoErr(t, err)
	th.AssertNotNil(t, md)

	createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
	th.AssertNoErr(t, err)

	updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, ImageMember{
		CreatedAt: createdAt,
		ImageID:   "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		MemberID:  "8989447062e04a818baf9e073fd04fa7",
		Schema:    "/v2/schemas/member",
		Status:    "pending",
		UpdatedAt: updatedAt,
	}, *md)
}
Example #9
0
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 200)

	opts := CreateOpts{
		Name:      "json_rack_instance",
		FlavorRef: "1",
		Databases: osDBs.BatchCreateOpts{
			osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
			osDBs.CreateOpts{Name: "nextround"},
		},
		Users: osUsers.BatchCreateOpts{
			osUsers.CreateOpts{
				Name:     "demouser",
				Password: "******",
				Databases: osDBs.BatchCreateOpts{
					osDBs.CreateOpts{Name: "sampledb"},
				},
			},
		},
		Size:         2,
		RestorePoint: "1234567890",
	}

	instance, err := Create(fake.ServiceClient(), opts).Extract()

	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expectedInstance, instance)
}
Example #10
0
func TestGetCloudNetwork(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	th.Mux.HandleFunc("/cloud_networks/07426958-1ebf-4c38-b032-d456820ca21a", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.TestHeader(t, r, "Accept", "application/json")

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `{
      "cidr": "192.168.100.0/24",
      "created": "2014-05-25T01:23:42Z",
      "id": "07426958-1ebf-4c38-b032-d456820ca21a",
      "name": "RC-CLOUD",
      "updated": "2014-05-25T02:28:44Z"
    }`)
	})

	expected := &CloudNetwork{
		CIDR:      "192.168.100.0/24",
		CreatedAt: time.Date(2014, 5, 25, 1, 23, 42, 0, time.UTC),
		ID:        "07426958-1ebf-4c38-b032-d456820ca21a",
		Name:      "RC-CLOUD",
		UpdatedAt: time.Date(2014, 5, 25, 2, 28, 44, 0, time.UTC),
	}

	actual, err := Get(fake.ServiceClient(), "07426958-1ebf-4c38-b032-d456820ca21a").Extract()
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, expected, actual)
}
Example #11
0
func TestAddRuleICMPZero(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockAddRuleResponseICMPZero(t)

	opts := CreateRuleOpts{
		ParentGroupID: groupID,
		FromPort:      0,
		ToPort:        0,
		IPProtocol:    "ICMP",
		CIDR:          "0.0.0.0/0",
	}

	rule, err := CreateRule(client.ServiceClient(), opts).Extract()
	th.AssertNoErr(t, err)

	expected := &Rule{
		FromPort:      0,
		ToPort:        0,
		Group:         Group{},
		IPProtocol:    "ICMP",
		ParentGroupID: groupID,
		IPRange:       IPRange{CIDR: "0.0.0.0/0"},
		ID:            ruleID,
	}

	th.AssertDeepEquals(t, expected, rule)
}
Example #12
0
func TestListBackups(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL+"/backups", "GET", "", listBackupsResp, 200)

	pages := 0

	err := ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
		pages++
		actual, err := backups.ExtractBackups(page)
		th.AssertNoErr(t, err)

		expected := []backups.Backup{
			backups.Backup{
				Created:     timeVal,
				Description: "Backup from Restored Instance",
				ID:          "87972694-4be2-40f5-83f8-501656e0032a",
				InstanceID:  "29af2cd9-0674-48ab-b87a-b160f00208e6",
				LocationRef: "http://localhost/path/to/backup",
				Name:        "restored_backup",
				ParentID:    "",
				Size:        0.141026,
				Status:      "COMPLETED",
				Updated:     timeVal,
				Datastore:   datastores.DatastorePartial{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
			},
		}

		th.AssertDeepEquals(t, expected, actual)
		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
Example #13
0
func TestGetReplica(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", getReplicaResp, 200)

	replica, err := Get(fake.ServiceClient(), instanceID).Extract()
	th.AssertNoErr(t, err)

	expectedReplica := &Instance{
		Status:  "ACTIVE",
		Updated: timeVal,
		Name:    "t1_ALT_GUEST",
		Created: timeVal,
		IP: []string{
			"10.0.0.2",
		},
		Replicas: []Instance{
			Instance{ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
		},
		ID: "8b499b45-52d6-402d-b398-f9d8f279c69a",
		Volume: os.Volume{
			Used: 0.54,
			Size: 1,
		},
		Flavor: flavors.Flavor{ID: "9"},
		Datastore: datastores.DatastorePartial{
			Version: "5.6",
			Type:    "mysql",
		},
	}

	th.AssertDeepEquals(t, replica, expectedReplica)
}
Example #14
0
func TestCreateHandleFlags(t *testing.T) {
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("metadata", "", "")
	flagset.String("container-read", "", "")
	flagset.String("container-write", "", "")
	flagset.Set("metadata", "key=val,foo=bar")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandCreate{
		Ctx: &handler.Context{
			CLIContext: c,
		},
	}
	expected := &handler.Resource{
		Params: &paramsCreate{
			opts: containers.CreateOpts{
				Metadata: map[string]string{
					"key": "val",
					"foo": "bar",
				},
			},
		},
	}
	actual := &handler.Resource{}
	err := cmd.HandleFlags(actual)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expected.Params.(*paramsCreate).opts, actual.Params.(*paramsCreate).opts)
}
Example #15
0
func TestListFlavors(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleList(t)

	pages := 0
	err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractFlavors(page)
		if err != nil {
			return false, err
		}

		expected := []Flavor{
			Flavor{
				ID:   "1",
				Name: "m1.tiny",
				RAM:  512,
				Links: []gophercloud.Link{
					gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
					gophercloud.Link{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
				},
			},
			Flavor{
				ID:   "2",
				Name: "m1.small",
				RAM:  1024,
				Links: []gophercloud.Link{
					gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
					gophercloud.Link{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
				},
			},
			Flavor{
				ID:   "3",
				Name: "m1.medium",
				RAM:  2048,
				Links: []gophercloud.Link{
					gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
					gophercloud.Link{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
				},
			},
			Flavor{
				ID:   "4",
				Name: "m1.large",
				RAM:  4096,
				Links: []gophercloud.Link{
					gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
					gophercloud.Link{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
				},
			},
		}

		th.AssertDeepEquals(t, expected, actual)
		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
Example #16
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", getResp, 200)

	instance, err := Get(fake.ServiceClient(), backupID).Extract()
	th.AssertNoErr(t, err)

	expected := &Backup{
		Created:     timeVal,
		Description: "My Backup",
		ID:          "61f12fef-edb1-4561-8122-e7c00ef26a82",
		InstanceID:  "d4603f69-ec7e-4e9b-803f-600b9205576f",
		LocationRef: "",
		Name:        "snapshot",
		ParentID:    "",
		Size:        100,
		Status:      "NEW",
		Updated:     timeVal,
		Datastore: datastores.DatastorePartial{
			Version:   "5.1",
			Type:      "MySQL",
			VersionID: "20000000-0000-0000-0000-000000000002",
		},
	}

	th.AssertDeepEquals(t, expected, instance)
}
Example #17
0
func TestMemberUpdateSuccessfully(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	counter := HandleImageMemberUpdate(t)
	im, err := Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		"8989447062e04a818baf9e073fd04fa7",
		UpdateOpts{
			Status: "accepted",
		}).Extract()
	th.AssertEquals(t, 1, counter.Counter)
	th.AssertNoErr(t, err)

	createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
	th.AssertNoErr(t, err)

	updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, ImageMember{
		CreatedAt: createdAt,
		ImageID:   "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		MemberID:  "8989447062e04a818baf9e073fd04fa7",
		Schema:    "/v2/schemas/member",
		Status:    "accepted",
		UpdatedAt: updatedAt,
	}, *im)

}
Example #18
0
func TestCreateMemberSuccessfully(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleCreateImageMemberSuccessfully(t)
	im, err := Create(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		"8989447062e04a818baf9e073fd04fa7").Extract()
	th.AssertNoErr(t, err)

	createdAt, err := time.Parse(time.RFC3339, createdAtString)
	th.AssertNoErr(t, err)

	updatedAt, err := time.Parse(time.RFC3339, updatedAtString)
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, ImageMember{
		CreatedAt: createdAt,
		ImageID:   "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		MemberID:  "8989447062e04a818baf9e073fd04fa7",
		Schema:    "/v2/schemas/member",
		Status:    "pending",
		UpdatedAt: updatedAt,
	}, *im)

}
Example #19
0
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockCreateRuleResponse(t)

	opts := CreateOpts{
		IPProtocol: "TCP",
		FromPort:   80,
		ToPort:     80,
		CIDR:       "10.10.12.0/24",
	}

	group, err := Create(client.ServiceClient(), opts).Extract()
	th.AssertNoErr(t, err)

	expected := &DefaultRule{
		ID:         ruleID,
		FromPort:   80,
		ToPort:     80,
		IPProtocol: "TCP",
		IPRange:    secgroups.IPRange{CIDR: "10.10.12.0/24"},
	}
	th.AssertDeepEquals(t, expected, group)
}
Example #20
0
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreate(t)

	opts := CreateOpts{
		Name:      "json_rack_instance",
		FlavorRef: "1",
		Databases: db.BatchCreateOpts{
			db.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
			db.CreateOpts{Name: "nextround"},
		},
		Users: users.BatchCreateOpts{
			users.CreateOpts{
				Name:     "demouser",
				Password: "******",
				Databases: db.BatchCreateOpts{
					db.CreateOpts{Name: "sampledb"},
				},
			},
		},
		Size: 2,
	}

	instance, err := Create(fake.ServiceClient(), opts).Extract()

	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, &expectedInstance, instance)
}
Example #21
0
func TestUploadHandleFlags(t *testing.T) {
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("name", "", "")
	flagset.String("file", "", "")
	flagset.String("public-key", "", "")
	flagset.Set("name", "keypair1Name")
	flagset.Set("public-key", "ssh public key data here")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandUpload{
		Ctx: &handler.Context{
			CLIContext: c,
		},
	}
	expected := &handler.Resource{
		Params: &paramsUpload{
			opts: &osKeypairs.CreateOpts{
				Name:      "keypair1Name",
				PublicKey: "ssh public key data here",
			},
		},
	}
	actual := &handler.Resource{}
	err := cmd.HandleFlags(actual)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, *expected.Params.(*paramsUpload).opts, *actual.Params.(*paramsUpload).opts)
}
Example #22
0
func TestListHandleFlags(t *testing.T) {
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("image", "", "")
	flagset.String("flavor", "", "")
	flagset.String("name", "", "")
	flagset.String("status", "", "")
	flagset.String("marker", "", "")
	flagset.Set("image", "13ba-75c0-4483-acf9")
	flagset.Set("flavor", "1234-b95f-ac5b-cd23")
	flagset.Set("name", "server*")
	flagset.Set("status", "AVAILABLE")
	flagset.Set("marker", "1fd3-4f9f-44df-1b5c")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandList{
		Ctx: &handler.Context{
			CLIContext: c,
		},
	}
	expected := &handler.Resource{
		Params: &paramsList{
			opts: &osServers.ListOpts{
				Image:  "13ba-75c0-4483-acf9",
				Flavor: "1234-b95f-ac5b-cd23",
				Name:   "server*",
				Status: "AVAILABLE",
				Marker: "1fd3-4f9f-44df-1b5c",
			},
		},
	}
	actual := &handler.Resource{}
	err := cmd.HandleFlags(actual)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, *expected.Params.(*paramsList).opts, *actual.Params.(*paramsList).opts)
}
Example #23
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockGetGroupsResponse(t, groupID)

	group, err := Get(client.ServiceClient(), groupID).Extract()
	th.AssertNoErr(t, err)

	expected := &SecurityGroup{
		ID:          groupID,
		Description: "default",
		Name:        "default",
		TenantID:    "openstack",
		Rules: []Rule{
			Rule{
				FromPort:      80,
				ToPort:        85,
				IPProtocol:    "TCP",
				IPRange:       IPRange{CIDR: "0.0.0.0"},
				Group:         Group{TenantID: "openstack", Name: "default"},
				ParentGroupID: groupID,
				ID:            ruleID,
			},
		},
	}

	th.AssertDeepEquals(t, expected, group)
}
Example #24
0
func TestValidateTemplate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleValidateSuccessfully(t, os.ValidateOutput)

	opts := os.ValidateOpts{
		Template: `{
			"Description": "Simple template to test heat commands",
			"Parameters": {
				"flavor": {
					"Default": "m1.tiny",
					"Type": "String",
					"NoEcho": "false",
					"Description": "",
					"Label": "flavor"
				}
			}
		}`,
	}
	actual, err := Validate(fake.ServiceClient(), opts).Extract()
	th.AssertNoErr(t, err)

	expected := os.ValidateExpected
	th.AssertDeepEquals(t, expected, actual)
}
Example #25
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	os.HandleGetCDNFlavorSuccessfully(t)

	expected := &os.Flavor{
		ID: "asia",
		Providers: []os.Provider{
			os.Provider{
				Provider: "ChinaCache",
				Links: []gophercloud.Link{
					gophercloud.Link{
						Href: "http://www.chinacache.com",
						Rel:  "provider_url",
					},
				},
			},
		},
		Links: []gophercloud.Link{
			gophercloud.Link{
				Href: "https://www.poppycdn.io/v1.0/flavors/asia",
				Rel:  "self",
			},
		},
	}

	actual, err := Get(fake.ServiceClient(), "asia").Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expected, actual)
}
Example #26
0
func TestListVersions(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
    "versions": [
        {
            "status": "CURRENT",
            "id": "v1.0",
            "links": [
                {
                    "href": "http://23.253.228.211:8000/v1",
                    "rel": "self"
                }
            ]
        }
    ]
}`)
	})

	count := 0

	ListVersions(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractAPIVersions(page)
		if err != nil {
			t.Errorf("Failed to extract API versions: %v", err)
			return false, err
		}

		expected := []APIVersion{
			APIVersion{
				Status: "CURRENT",
				ID:     "v1.0",
				Links: []gophercloud.Link{
					gophercloud.Link{
						Href: "http://23.253.228.211:8000/v1",
						Rel:  "self",
					},
				},
			},
		}

		th.AssertDeepEquals(t, expected, actual)

		return true, nil
	})

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}
Example #27
0
func TestUpdateUser(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockUpdateUserResponse(t)

	id := "c39e3de9be2d4c779f1dfd6abacc176d"
	opts := UpdateOpts{
		Name:    "new_name",
		Enabled: Enabled,
		Email:   "*****@*****.**",
	}

	user, err := Update(client.ServiceClient(), id, opts).Extract()

	th.AssertNoErr(t, err)

	expected := &User{
		Name:     "new_name",
		ID:       id,
		Email:    "*****@*****.**",
		Enabled:  true,
		TenantID: "12345",
	}

	th.AssertDeepEquals(t, expected, user)
}
Example #28
0
func TestCreateUser(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockCreateUserResponse(t)

	opts := CreateOpts{
		Name:     "new_user",
		TenantID: "12345",
		Enabled:  Disabled,
		Email:    "*****@*****.**",
	}

	user, err := Create(client.ServiceClient(), opts).Extract()

	th.AssertNoErr(t, err)

	expected := &User{
		Name:     "new_user",
		ID:       "c39e3de9be2d4c779f1dfd6abacc176d",
		Email:    "*****@*****.**",
		Enabled:  false,
		TenantID: "12345",
	}

	th.AssertDeepEquals(t, expected, user)
}
Example #29
0
func TestCreateStackNewTemplateFormat(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreateSuccessfully(t, CreateOutput)
	template := new(Template)
	template.Bin = []byte(`
		{
			"heat_template_version": "2013-05-23",
			"description": "Simple template to test heat commands",
			"parameters": {
				"flavor": {
					"default": "m1.tiny",
					"type": "string"
				}
			}
		}`)
	createOpts := CreateOpts{
		Name:            "stackcreated",
		Timeout:         60,
		TemplateOpts:    template,
		DisableRollback: Disable,
	}
	actual, err := Create(fake.ServiceClient(), createOpts).Extract()
	th.AssertNoErr(t, err)

	expected := CreateExpected
	th.AssertDeepEquals(t, expected, actual)
}
Example #30
0
func TestResizeContext(t *testing.T) {
	cmd := &commandResize{
		Ctx: &handler.Context{},
	}
	expected := cmd.Ctx
	actual := cmd.Context()
	th.AssertDeepEquals(t, expected, actual)
}