Skip to content

Commit

Permalink
added openstack authentication test with clouds yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
azhry committed Apr 26, 2023
1 parent 4c715df commit 89ff345
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions model/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type (

OpenstackAuth struct {
AuthUrl string `yaml:"auth_url" json:"auth_url"`
NetworkUrl string `yaml:"network_url" json:"network_url"`
MagnumUrl string `yaml:"magnum_url" json:"magnum_url"`
ImageUrl string `yaml:"image_url" json:"image_url"`
ComputeUrl string `yaml:"compute_url" json:"compute_url"`
ProjectId string `yaml:"project_id" json:"project_id"`
ProjectName string `yaml:"project_name" json:"project_name"`
UserDomainName string `yaml:"user_domain_name" json:"user_domain_name"`
Expand Down
28 changes: 16 additions & 12 deletions test/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,26 +897,30 @@ func TestSubnetList(t *testing.T) {

// go test ./test -v -run ^TestFlavorList$
func TestFlavorList(t *testing.T) {
yamlByte, _ := os.ReadFile("./data/elitery-clouds.yaml")
cloudsYaml := model.CloudsYaml{}
cloudsYaml.Parse(yamlByte)
auth := cloudsYaml.Clouds.Openstack.Auth

cl := api.OpenstackClient{
MagnumEndpoint: os.Getenv("VT_MAGNUM_ENDPOINT"),
NetworkEndpoint: os.Getenv("VT_NETWORK_ENDPOINT"),
AuthEndpoint: os.Getenv("VT_AUTH_ENDPOINT"),
ImageEndpoint: os.Getenv("VT_IMAGE_ENDPOINT"),
ComputeEndpoint: os.Getenv("VT_COMPUTE_ENDPOINT"),
AuthToken: os.Getenv("OS_TOKEN"),
ProjectId: os.Getenv("VT_PROJECT_ID"),
MagnumEndpoint: auth.MagnumUrl,
NetworkEndpoint: auth.NetworkUrl,
AuthEndpoint: auth.AuthUrl,
ImageEndpoint: auth.ImageUrl,
ComputeEndpoint: auth.ComputeUrl,
ProjectId: auth.ProjectId,
}

projectName := os.Getenv("VT_PROJECT_NAME")
projectName := auth.ProjectName
credential := api.OpenstackAuth{
Identity: api.OpenstackIdentity{
Methods: []string{"password"},
Password: api.OpenstackPassword{
User: map[string]interface{}{
"name": os.Getenv("VT_USERNAME"),
"password": os.Getenv("VT_PASSWORD"),
"name": auth.Username,
"password": auth.Password,
"domain": map[string]string{
"id": os.Getenv("VT_DOMAIN_ID"),
"id": auth.UserDomainId,
},
},
},
Expand All @@ -925,7 +929,7 @@ func TestFlavorList(t *testing.T) {
Project: &api.OpenstackProject{
Name: &projectName,
Domain: &map[string]interface{}{
"id": os.Getenv("VT_DOMAIN_ID"),
"id": auth.UserDomainId,
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions test/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ func TestUpdateChartYaml(t *testing.T) {

defer os.RemoveAll("./data/zipped")
}

// go test ./test -v -run ^TestAnotherCloudsYaml$
func TestAnotherCloudsYaml(t *testing.T) {
yamlByte, _ := os.ReadFile("./data/elitery-clouds.yaml")
cloudsYaml := model.CloudsYaml{}
cloudsYaml.Parse(yamlByte)
t.Log(cloudsYaml)
}

0 comments on commit 89ff345

Please sign in to comment.