Skip to content

Commit 930eab5

Browse files
authored
Merge pull request #22 from cisco-open/po-evc-mode
Add EVC mode property to VMs
2 parents a0aa651 + 120b438 commit 930eab5

File tree

248 files changed

+809
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+809
-883
lines changed

tbclient/evcMode.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2023 Cisco Systems, Inc. and its affiliates
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
//
7+
// SPDX-License-Identifier: MPL-2.0
8+
9+
package tbclient
10+
11+
func (c *Client) getEvcModeService() *collectionService[EvcMode, evcModeCollection] {
12+
return &collectionService[EvcMode, evcModeCollection]{
13+
client: c,
14+
resourcePath: "/evc-modes",
15+
}
16+
}
17+
18+
func (c *Client) GetAllEvcModes() ([]EvcMode, error) {
19+
return c.getEvcModeService().getAll()
20+
}

tbclient/models.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (n nicTypeCollection) getData() []NicType {
8888
}
8989

9090
// OS Family
91+
9192
type OsFamily struct {
9293
Id string `json:"id"`
9394
Name string `json:"name"`
@@ -101,6 +102,22 @@ func (o osFamilyCollection) getData() []OsFamily {
101102
return o.Data
102103
}
103104

105+
// EVC Mode
106+
107+
type EvcMode struct {
108+
Id string `json:"id"`
109+
Name string `json:"name"`
110+
DisplayOrder int `json:"displayOrder"`
111+
}
112+
113+
type evcModeCollection struct {
114+
Data []EvcMode `json:"evcModes"`
115+
}
116+
117+
func (o evcModeCollection) getData() []EvcMode {
118+
return o.Data
119+
}
120+
104121
// Inventory VM
105122

106123
type InventoryVmNic struct {
@@ -128,6 +145,7 @@ type InventoryVm struct {
128145
OriginalDescription string `json:"originalDescription,omitempty"`
129146
CpuQty uint64 `json:"cpuQty,omitempty"`
130147
MemoryMb uint64 `json:"memoryMb,omitempty"`
148+
EvcMode string `json:"evcMode,omitempty"`
131149
NetworkInterfaces []InventoryVmNic `json:"networkInterfaces,omitempty"`
132150
RemoteAccess *InventoryVmRemoteAccess `json:"remoteAccess,omitempty"`
133151
}
@@ -169,6 +187,7 @@ type VmAdvancedSettings struct {
169187
BiosUuid string `json:"biosUuid,omitempty"`
170188
NotStarted bool `json:"notStarted"`
171189
AllDisksNonPersistent bool `json:"allDisksNonPersistent"`
190+
EvcMode string `json:"evcMode,omitempty"`
172191
}
173192

174193
type VmRemoteAccessDisplayCredentials struct {
@@ -195,7 +214,9 @@ type VmGuestAutomation struct {
195214
}
196215

197216
type VmDhcpConfig struct {
198-
DefaultGatewayIp string `json:"defaultGatewayIp"`
217+
DefaultGatewayIp string `json:"defaultGatewayIp"`
218+
PrimaryDnsIp *string `json:"primaryDnsIp"`
219+
SecondaryDnsIp *string `json:"secondaryDnsIp"`
199220
}
200221

201222
type Vm struct {

tbclient/tbclient_test.go

+89-39
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ var lonTopology = Topology{
4747
Status: "DRAFT",
4848
}
4949

50+
var westmereEvcMode = EvcMode{
51+
Id: "WESTMERE",
52+
Name: "Westmere",
53+
DisplayOrder: 1,
54+
}
55+
5056
var linuxOsFamily = OsFamily{
5157
Id: "LINUX",
5258
Name: "Linux",
@@ -110,6 +116,7 @@ var inventoryVm = InventoryVm{
110116
OriginalDescription: "Collab-mssql1",
111117
CpuQty: 4,
112118
MemoryMb: 8192,
119+
EvcMode: evcModeWestmere,
113120
NetworkInterfaces: []InventoryVmNic{
114121
// TODO - contract needs to specify additional fields
115122
{
@@ -127,6 +134,8 @@ var inventoryVm = InventoryVm{
127134
}
128135

129136
var nestedHypervisor = false
137+
var evcModeHaswell = "HASWELL"
138+
var evcModeWestmere = "WESTMERE"
130139

131140
var vm = Vm{
132141
Uid: "lonvm1",
@@ -174,17 +183,45 @@ var vm = Vm{
174183
},
175184
},
176185
{
177-
Uid: "lonvm1natnic",
178-
IpAddress: "198.18.131.201",
179-
Name: "Network adapter 2",
180-
MacAddress: "00:50:56:00:00:08",
186+
Uid: "lonvm1natnic1",
187+
IpAddress: "198.18.131.211",
188+
Name: "Network adapter 11",
189+
MacAddress: "00:50:56:00:00:11",
181190
Type: "VIRTUAL_E1000",
191+
InUse: true,
192+
AssignDhcp: false,
193+
Network: &Network{
194+
// Contract is missing 'inventoryNetwork' field
195+
Uid: lonDefaultNetwork.Uid,
196+
Name: lonDefaultNetwork.Name,
197+
},
198+
},
199+
{
200+
Uid: "lonvm1natnic2",
201+
IpAddress: "198.18.131.212",
202+
Name: "Network adapter 12",
203+
MacAddress: "00:50:56:00:00:12",
204+
Type: "VIRTUAL_E1000",
205+
InUse: true,
182206
AssignDhcp: false,
183207
Network: &Network{
184208
// Contract is missing 'description' field
185-
Uid: lonDefaultNetwork.Uid,
186-
Name: lonDefaultNetwork.Name,
187-
InventoryNetwork: lonDefaultNetwork.InventoryNetwork,
209+
Uid: lonDefaultNetwork.Uid,
210+
Name: lonDefaultNetwork.Name,
211+
},
212+
},
213+
{
214+
Uid: "lonvm1natnic3",
215+
IpAddress: "198.18.131.213",
216+
Name: "Network adapter 13",
217+
MacAddress: "00:50:56:00:00:13",
218+
Type: "VIRTUAL_E1000",
219+
InUse: true,
220+
AssignDhcp: false,
221+
Network: &Network{
222+
// Contract is missing 'description' field
223+
Uid: lonDefaultNetwork.Uid,
224+
Name: lonDefaultNetwork.Name,
188225
},
189226
},
190227
},
@@ -193,6 +230,10 @@ var vm = Vm{
193230
BiosUuid: "61 62 63 64 65 66 67 68-69 6a 6b 6c 6d 6e 6f 70",
194231
NotStarted: false,
195232
AllDisksNonPersistent: false,
233+
EvcMode: evcModeHaswell,
234+
},
235+
DhcpConfig: &VmDhcpConfig{
236+
DefaultGatewayIp: "198.18.130.2",
196237
},
197238
GuestAutomation: &VmGuestAutomation{
198239
Command: "cd /var/; sh script.sh",
@@ -245,6 +286,7 @@ var createVm = Vm{
245286
BiosUuid: "61 62 63 64 65 66 67 68-69 6a 6b 6c 6d 6e 6f 70",
246287
NotStarted: false,
247288
AllDisksNonPersistent: false,
289+
EvcMode: evcModeWestmere,
248290
},
249291
Topology: &Topology{Uid: lonTopology.Uid},
250292
}
@@ -416,12 +458,12 @@ var ipNatRule = IpNatRule{
416458
}
417459

418460
var vmNatRule = VmNatRule{
419-
Uid: "lonvmnatrule1",
461+
Uid: "lonvmpublicnat",
420462
EastWest: false,
421463
Scope: &publicScope,
422464
Target: VmNatTarget{
423-
VmNic: &VmNic{Uid: "lonvm1natnic"},
424-
IpAddress: "198.18.131.201",
465+
VmNic: &VmNic{Uid: "lonvm1natnic1"},
466+
IpAddress: "198.18.131.211",
425467
Name: "Mail Server 1",
426468
},
427469
Topology: &Topology{Uid: lonTopology.Uid},
@@ -462,7 +504,7 @@ var externalDnsRecord = ExternalDnsRecord{
462504
Hostname: "lonhost",
463505
ARecord: "lonhost.<subdomain>.dc-03.com",
464506
InventoryDnsAsset: &inventoryDnsAsset,
465-
NatRule: &ExternalDnsNatRule{Uid: "lonvmnatrule1"},
507+
NatRule: &ExternalDnsNatRule{Uid: "lonvmpublicnat"},
466508
SrvRecords: []ExternalDnsSrvRecord{
467509
{
468510
Service: "_sip",
@@ -683,11 +725,6 @@ func (suite *ContractTestSuite) TestGetVm() {
683725

684726
// Given
685727
expectedVm := vm
686-
// Work around contract data inconsistencies
687-
nic := vm.VmNetworkInterfaces[1]
688-
nic.InUse = true
689-
nic.Network.InventoryNetwork = nil
690-
expectedVm.VmNetworkInterfaces[1] = nic
691728

692729
// When
693730
actualVm, err := suite.tbClient.GetVm(vm.Uid)
@@ -702,6 +739,8 @@ func (suite *ContractTestSuite) TestUpdateVm() {
702739
// Given
703740
expectedVm := vm
704741
expectedVm.DhcpConfig = &VmDhcpConfig{DefaultGatewayIp: "198.18.130.1"} // Match Contract
742+
expectedVm.DhcpConfig.PrimaryDnsIp = &primaryDnsIp
743+
expectedVm.DhcpConfig.SecondaryDnsIp = &secondaryDnsIp
705744

706745
// Change Value
707746
expectedVm.Name = "New Name"
@@ -713,21 +752,20 @@ func (suite *ContractTestSuite) TestUpdateVm() {
713752
// Then
714753

715754
// Work around contract data inconsistencies
716-
nic0 := vm.VmNetworkInterfaces[0]
717-
nic0.Uid = ""
718-
nic0.Name = ""
719-
nic0.Network.InventoryNetwork = nil
720-
expectedVm.VmNetworkInterfaces[0] = nic0
721-
722-
nic1 := vm.VmNetworkInterfaces[1]
723-
nic1.Uid = ""
724-
nic1.Name = ""
725-
nic1.Network.InventoryNetwork = nil
726-
nic1.InUse = true
727-
expectedVm.VmNetworkInterfaces[1] = nic1
755+
expectedNics := expectedVm.VmNetworkInterfaces
756+
757+
for i := range expectedNics {
758+
expectedNics[i].Uid = ""
759+
expectedNics[i].Name = ""
760+
}
761+
expectedNics[0].Network.InventoryNetwork = nil
762+
728763
suite.Equal(expectedVm, *actualVm)
729764
}
730765

766+
var primaryDnsIp = "198.18.130.111"
767+
var secondaryDnsIp = "198.18.130.112"
768+
731769
func (suite *ContractTestSuite) TestCreateVm() {
732770
// Given
733771
expectedVm := createVm
@@ -1105,8 +1143,9 @@ func (suite *ContractTestSuite) TestGetAllVmNatRules() {
11051143
suite.handleError(err)
11061144

11071145
// Then
1108-
suite.Equal(1, len(vmNatRules))
1109-
suite.Contains(vmNatRules, vmNatRule)
1146+
suite.Equal(2, len(vmNatRules))
1147+
expected := vmNatRule
1148+
suite.Contains(vmNatRules, expected)
11101149
}
11111150

11121151
// TODO - "Get One" Tests when Contracts are updated
@@ -1156,10 +1195,10 @@ func (suite *ContractTestSuite) TestCreateInboundProxyRule() {
11561195
expectedInboundProxyRule.Uid = "newloninboundproxy"
11571196
expectedInboundProxyRule.VmNicTarget = &TrafficVmNicTarget{
11581197
Uid: inboundProxyRule.VmNicTarget.Uid,
1159-
IpAddress: "192.168.0.8",
1198+
IpAddress: "192.168.0.9",
11601199
Vm: &Vm{
1161-
Uid: "pcVmayo2nx7fQr8V21xO",
1162-
Name: "MWRGFTMMILZNATVKXRSM",
1200+
Uid: "HIahoglmRva1DNeuYAII",
1201+
Name: "MHJOGANCZJKHQFWFVSXD",
11631202
},
11641203
}
11651204
suite.Equal(expectedInboundProxyRule, *actualInboundProxyRule)
@@ -1262,10 +1301,10 @@ func (suite *ContractTestSuite) TestCreateMailServer() {
12621301
expectedMailServer := mailServer
12631302
expectedMailServer.VmNicTarget = &TrafficVmNicTarget{
12641303
Uid: expectedMailServer.VmNicTarget.Uid,
1265-
IpAddress: "192.168.0.3",
1304+
IpAddress: "192.168.0.9",
12661305
Vm: &Vm{
1267-
Uid: "LDU9tBp7g5Zd4nZE2aNj",
1268-
Name: "HFDJPRCCGOZGHOMYSZGX",
1306+
Uid: "INLc0eWy1do3Xlk5GOdj",
1307+
Name: "UZARRCZGMJSBXUAGLOLJ",
12691308
},
12701309
}
12711310
expectedMailServer.InventoryDnsAsset = &InventoryDnsAsset{
@@ -1373,6 +1412,17 @@ func (suite *ContractTestSuite) TestGetAllOsFamilies() {
13731412
suite.Contains(osFamilies, linuxOsFamily)
13741413
}
13751414

1415+
func (suite *ContractTestSuite) TestGetAllEvcModes() {
1416+
1417+
// When
1418+
evcModes, err := suite.tbClient.GetAllEvcModes()
1419+
suite.handleError(err)
1420+
1421+
// Then
1422+
suite.Equal(3, len(evcModes))
1423+
suite.Contains(evcModes, westmereEvcMode)
1424+
}
1425+
13761426
func (suite *ContractTestSuite) TestGetAllNicTypes() {
13771427

13781428
// When
@@ -1424,7 +1474,7 @@ func (suite *ContractTestSuite) TestGetAllInventoryVms() {
14241474
suite.handleError(err)
14251475

14261476
// Then
1427-
suite.Equal(4, len(inventoryVms))
1477+
suite.Equal(3, len(inventoryVms))
14281478
suite.Equal(inventoryVms[2], inventoryVm)
14291479
suite.Contains(inventoryVms, inventoryVm)
14301480
}
@@ -1558,8 +1608,8 @@ func createTbClient(suite *ContractTestSuite) Client {
15581608
suite.T().Log("Timeout starting wiremock")
15591609
suite.handleError(err)
15601610
}
1561-
fmt.Println("Waiting another 5s for wiremock...")
1562-
time.Sleep(5 * time.Second)
1611+
fmt.Println("Waiting another 2s for wiremock...")
1612+
time.Sleep(2 * time.Second)
15631613
}
15641614

15651615
return c

tbclient/test_stubs/mappings/datacenter/getDatacenterDemos_dcNotFound.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id" : "2f3379a2-98c1-45a8-961e-87af17617cb5",
2+
"id" : "c6c9835f-8b4f-49a8-9b36-d63e5fbf0c0c",
33
"request" : {
44
"urlPath" : "/datacenters/notfound/inventory-demos",
55
"method" : "GET",
@@ -11,11 +11,11 @@
1111
},
1212
"response" : {
1313
"status" : 404,
14-
"body" : "[{\"logref\":\"YJGAWIXFNWUHSQUTJIMT\",\"message\":\"The requested Datacenter resource 'notfound' was not found\",\"links\":[]}]",
14+
"body" : "[{\"logref\":\"AXMKQBOCJTWHFCELVAKK\",\"message\":\"The requested Datacenter resource 'notfound' was not found\",\"links\":[]}]",
1515
"headers" : {
1616
"Content-Type" : "application/vnd.error+json"
1717
},
1818
"transformers" : [ "response-template", "spring-cloud-contract" ]
1919
},
20-
"uuid" : "2f3379a2-98c1-45a8-961e-87af17617cb5"
20+
"uuid" : "c6c9835f-8b4f-49a8-9b36-d63e5fbf0c0c"
2121
}

tbclient/test_stubs/mappings/datacenter/getDatacenterDemos_lon.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id" : "5ef182bf-9c37-4375-9417-44149fe53a79",
2+
"id" : "bef458b0-7944-4fa2-9ac1-ce0308cc1963",
33
"request" : {
44
"urlPath" : "/datacenters/lon/inventory-demos",
55
"method" : "GET",
@@ -17,5 +17,5 @@
1717
},
1818
"transformers" : [ "response-template", "spring-cloud-contract" ]
1919
},
20-
"uuid" : "5ef182bf-9c37-4375-9417-44149fe53a79"
20+
"uuid" : "bef458b0-7944-4fa2-9ac1-ce0308cc1963"
2121
}

tbclient/test_stubs/mappings/datacenter/getDatacenterDemos_readerUnavailable.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id" : "a352113c-8049-4a0f-877f-75610a3b5288",
2+
"id" : "2193facc-eba4-4f33-b55a-33275b7ff4cd",
33
"request" : {
44
"urlPath" : "/datacenters/sng/inventory-demos",
55
"method" : "GET",
@@ -11,11 +11,11 @@
1111
},
1212
"response" : {
1313
"status" : 503,
14-
"body" : "[{\"logref\":\"THIKFDSVDOZNWAEGEAMK\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
14+
"body" : "[{\"logref\":\"CVFFTYDTUJQWVSLCUSPA\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
1515
"headers" : {
1616
"Content-Type" : "application/vnd.error+json"
1717
},
1818
"transformers" : [ "response-template", "spring-cloud-contract" ]
1919
},
20-
"uuid" : "a352113c-8049-4a0f-877f-75610a3b5288"
20+
"uuid" : "2193facc-eba4-4f33-b55a-33275b7ff4cd"
2121
}

0 commit comments

Comments
 (0)