Skip to content

Commit e4ce3b4

Browse files
author
Joshua Reed
committed
Init.
1 parent 90af4a9 commit e4ce3b4

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

pkg/cloud/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Client interface {
3737
ResolveLoadBalancerRuleDetails(*infrav1.CloudStackCluster) error
3838
GetOrCreateLoadBalancerRule(*infrav1.CloudStackCluster) error
3939
AffinityGroupIFace
40+
TagIFace
4041
}
4142

4243
type client struct {

pkg/cloud/tags.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cloud
18+
19+
type TagIFace interface {
20+
TagNetwork(string, map[string]string) error
21+
}
22+
23+
// TagNetwork adds tags to a network by network id.
24+
func (c *client) TagNetwork(networkId string, tag map[string]string) error {
25+
p := c.cs.Resourcetags.NewCreateTagsParams([]string{"someid"}, "network", map[string]string{"some": "tag"})
26+
_, err := c.cs.Resourcetags.CreateTags(p)
27+
return err
28+
}

pkg/cloud/tags_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cloud_test
18+
19+
import (
20+
infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
21+
"github.com/aws/cluster-api-provider-cloudstack/pkg/cloud"
22+
"github.com/golang/mock/gomock"
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
)
26+
27+
var _ = Describe("AffinityGroup Unit Tests", func() {
28+
var ( // Declare shared vars.
29+
mockCtrl *gomock.Controller
30+
// mockClient *cloudstack.CloudStackClient
31+
// ags *cloudstack.MockAffinityGroupServiceIface
32+
// fakeAG *cloud.AffinityGroup
33+
cluster *infrav1.CloudStackCluster
34+
// machine *infrav1.CloudStackMachine
35+
// capiMachine *capiv1.Machine
36+
// client cloud.Client
37+
)
38+
39+
BeforeEach(func() {
40+
// // Setup new mock services.
41+
// mockCtrl = gomock.NewController(GinkgoT())
42+
// mockClient = cloudstack.NewMockClient(mockCtrl)
43+
// ags = mockClient.AffinityGroup.(*cloudstack.MockAffinityGroupServiceIface)
44+
// client = cloud.NewClientFromCSAPIClient(mockClient)
45+
// fakeAG = &cloud.AffinityGroup{
46+
// Name: "FakeAffinityGroup",
47+
// Type: cloud.AffinityGroupType}
48+
cluster = &infrav1.CloudStackCluster{Spec: infrav1.CloudStackClusterSpec{
49+
Zone: "Zone1", Network: "SharedGuestNet1"}}
50+
// machine = &infrav1.CloudStackMachine{Spec: infrav1.CloudStackMachineSpec{
51+
// Offering: "Medium Instance", Template: "Ubuntu20"}}
52+
// machine.ObjectMeta.SetName("rejoshed-affinity-group-test-vm")
53+
// capiMachine = &capiv1.Machine{}
54+
})
55+
56+
AfterEach(func() {
57+
mockCtrl.Finish()
58+
})
59+
60+
// It("fetches an affinity group", func() {
61+
// ags.EXPECT().GetAffinityGroupByName(fakeAG.Name).Return(&cloudstack.AffinityGroup{}, 1, nil)
62+
63+
// Ω(client.GetOrCreateAffinityGroup(cluster, fakeAG)).Should(Succeed())
64+
// })
65+
// It("creates an affinity group", func() {
66+
// fakeAG.Id = "FakeID"
67+
// cluster.Spec.Account = "FakeAccount"
68+
// cluster.Status.DomainID = "FakeDomainId"
69+
// ags.EXPECT().GetAffinityGroupByID(fakeAG.Id).Return(nil, -1, errors.New("FakeError"))
70+
// ags.EXPECT().NewCreateAffinityGroupParams(fakeAG.Name, fakeAG.Type).
71+
// Return(&cloudstack.CreateAffinityGroupParams{})
72+
// ags.EXPECT().CreateAffinityGroup(ParamMatch(And(AccountEquals("FakeAccount"), DomainIdEquals("FakeDomainId")))).
73+
// Return(&cloudstack.CreateAffinityGroupResponse{}, nil)
74+
75+
// Ω(client.GetOrCreateAffinityGroup(cluster, fakeAG)).Should(Succeed())
76+
// })
77+
78+
Context("Tag Integ Tests", func() {
79+
client, connectionErr := cloud.NewClient("../../cloud-config")
80+
81+
var ( // Declare shared vars.
82+
arbitraryTag *map[string]string
83+
networkId string
84+
)
85+
86+
BeforeEach(func() {
87+
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
88+
Skip("Could not connect to ACS instance.")
89+
}
90+
arbitraryTag = &map[string]string{"Arbitrary": "Tag"}
91+
client.GetOrCreateNetwork(cluster)
92+
networkId = cluster.Status.NetworkID
93+
})
94+
95+
AfterEach(func() {
96+
mockCtrl.Finish()
97+
})
98+
99+
PIt("Tags a network with an arbitrary tag.", func() {
100+
// https://cloudstack.apache.org/api/apidocs-4.16/apis/createTags.html
101+
Ω(client.TagNetwork(networkId, *arbitraryTag)).Should(Succeed())
102+
})
103+
PIt("Fethes said tag.", func() {
104+
// It's hard to say what exactly the best method here is. I assume there are many ways to fetch a tag.
105+
// Maybe something like GetNetworkTags, GetLBTags, etc...
106+
// https://cloudstack.apache.org/api/apidocs-4.16/apis/listTags.html
107+
// Ω(client.FetchTag(*arbitraryTag)).Should(Succeed())
108+
})
109+
PIt("Deletes said tag.", func() {
110+
// Same, need some design through around how to delete tags.
111+
// https://cloudstack.apache.org/api/apidocs-4.16/apis/deleteTags.html
112+
// Ω(client.DeleteTags(networkId, *arbitraryTag)).Should(Succeed())
113+
})
114+
})
115+
})

0 commit comments

Comments
 (0)