Skip to content

Commit

Permalink
Merge pull request #22 from cisco-open/po-evc-mode
Browse files Browse the repository at this point in the history
Add EVC mode property to VMs
  • Loading branch information
philipowen authored Dec 16, 2024
2 parents a0aa651 + 120b438 commit 930eab5
Show file tree
Hide file tree
Showing 248 changed files with 809 additions and 883 deletions.
20 changes: 20 additions & 0 deletions tbclient/evcMode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Cisco Systems, Inc. and its affiliates
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// SPDX-License-Identifier: MPL-2.0

package tbclient

func (c *Client) getEvcModeService() *collectionService[EvcMode, evcModeCollection] {
return &collectionService[EvcMode, evcModeCollection]{
client: c,
resourcePath: "/evc-modes",
}
}

func (c *Client) GetAllEvcModes() ([]EvcMode, error) {
return c.getEvcModeService().getAll()
}
23 changes: 22 additions & 1 deletion tbclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (n nicTypeCollection) getData() []NicType {
}

// OS Family

type OsFamily struct {
Id string `json:"id"`
Name string `json:"name"`
Expand All @@ -101,6 +102,22 @@ func (o osFamilyCollection) getData() []OsFamily {
return o.Data
}

// EVC Mode

type EvcMode struct {
Id string `json:"id"`
Name string `json:"name"`
DisplayOrder int `json:"displayOrder"`
}

type evcModeCollection struct {
Data []EvcMode `json:"evcModes"`
}

func (o evcModeCollection) getData() []EvcMode {
return o.Data
}

// Inventory VM

type InventoryVmNic struct {
Expand Down Expand Up @@ -128,6 +145,7 @@ type InventoryVm struct {
OriginalDescription string `json:"originalDescription,omitempty"`
CpuQty uint64 `json:"cpuQty,omitempty"`
MemoryMb uint64 `json:"memoryMb,omitempty"`
EvcMode string `json:"evcMode,omitempty"`
NetworkInterfaces []InventoryVmNic `json:"networkInterfaces,omitempty"`
RemoteAccess *InventoryVmRemoteAccess `json:"remoteAccess,omitempty"`
}
Expand Down Expand Up @@ -169,6 +187,7 @@ type VmAdvancedSettings struct {
BiosUuid string `json:"biosUuid,omitempty"`
NotStarted bool `json:"notStarted"`
AllDisksNonPersistent bool `json:"allDisksNonPersistent"`
EvcMode string `json:"evcMode,omitempty"`
}

type VmRemoteAccessDisplayCredentials struct {
Expand All @@ -195,7 +214,9 @@ type VmGuestAutomation struct {
}

type VmDhcpConfig struct {
DefaultGatewayIp string `json:"defaultGatewayIp"`
DefaultGatewayIp string `json:"defaultGatewayIp"`
PrimaryDnsIp *string `json:"primaryDnsIp"`
SecondaryDnsIp *string `json:"secondaryDnsIp"`
}

type Vm struct {
Expand Down
128 changes: 89 additions & 39 deletions tbclient/tbclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var lonTopology = Topology{
Status: "DRAFT",
}

var westmereEvcMode = EvcMode{
Id: "WESTMERE",
Name: "Westmere",
DisplayOrder: 1,
}

var linuxOsFamily = OsFamily{
Id: "LINUX",
Name: "Linux",
Expand Down Expand Up @@ -110,6 +116,7 @@ var inventoryVm = InventoryVm{
OriginalDescription: "Collab-mssql1",
CpuQty: 4,
MemoryMb: 8192,
EvcMode: evcModeWestmere,
NetworkInterfaces: []InventoryVmNic{
// TODO - contract needs to specify additional fields
{
Expand All @@ -127,6 +134,8 @@ var inventoryVm = InventoryVm{
}

var nestedHypervisor = false
var evcModeHaswell = "HASWELL"
var evcModeWestmere = "WESTMERE"

var vm = Vm{
Uid: "lonvm1",
Expand Down Expand Up @@ -174,17 +183,45 @@ var vm = Vm{
},
},
{
Uid: "lonvm1natnic",
IpAddress: "198.18.131.201",
Name: "Network adapter 2",
MacAddress: "00:50:56:00:00:08",
Uid: "lonvm1natnic1",
IpAddress: "198.18.131.211",
Name: "Network adapter 11",
MacAddress: "00:50:56:00:00:11",
Type: "VIRTUAL_E1000",
InUse: true,
AssignDhcp: false,
Network: &Network{
// Contract is missing 'inventoryNetwork' field
Uid: lonDefaultNetwork.Uid,
Name: lonDefaultNetwork.Name,
},
},
{
Uid: "lonvm1natnic2",
IpAddress: "198.18.131.212",
Name: "Network adapter 12",
MacAddress: "00:50:56:00:00:12",
Type: "VIRTUAL_E1000",
InUse: true,
AssignDhcp: false,
Network: &Network{
// Contract is missing 'description' field
Uid: lonDefaultNetwork.Uid,
Name: lonDefaultNetwork.Name,
InventoryNetwork: lonDefaultNetwork.InventoryNetwork,
Uid: lonDefaultNetwork.Uid,
Name: lonDefaultNetwork.Name,
},
},
{
Uid: "lonvm1natnic3",
IpAddress: "198.18.131.213",
Name: "Network adapter 13",
MacAddress: "00:50:56:00:00:13",
Type: "VIRTUAL_E1000",
InUse: true,
AssignDhcp: false,
Network: &Network{
// Contract is missing 'description' field
Uid: lonDefaultNetwork.Uid,
Name: lonDefaultNetwork.Name,
},
},
},
Expand All @@ -193,6 +230,10 @@ var vm = Vm{
BiosUuid: "61 62 63 64 65 66 67 68-69 6a 6b 6c 6d 6e 6f 70",
NotStarted: false,
AllDisksNonPersistent: false,
EvcMode: evcModeHaswell,
},
DhcpConfig: &VmDhcpConfig{
DefaultGatewayIp: "198.18.130.2",
},
GuestAutomation: &VmGuestAutomation{
Command: "cd /var/; sh script.sh",
Expand Down Expand Up @@ -245,6 +286,7 @@ var createVm = Vm{
BiosUuid: "61 62 63 64 65 66 67 68-69 6a 6b 6c 6d 6e 6f 70",
NotStarted: false,
AllDisksNonPersistent: false,
EvcMode: evcModeWestmere,
},
Topology: &Topology{Uid: lonTopology.Uid},
}
Expand Down Expand Up @@ -416,12 +458,12 @@ var ipNatRule = IpNatRule{
}

var vmNatRule = VmNatRule{
Uid: "lonvmnatrule1",
Uid: "lonvmpublicnat",
EastWest: false,
Scope: &publicScope,
Target: VmNatTarget{
VmNic: &VmNic{Uid: "lonvm1natnic"},
IpAddress: "198.18.131.201",
VmNic: &VmNic{Uid: "lonvm1natnic1"},
IpAddress: "198.18.131.211",
Name: "Mail Server 1",
},
Topology: &Topology{Uid: lonTopology.Uid},
Expand Down Expand Up @@ -462,7 +504,7 @@ var externalDnsRecord = ExternalDnsRecord{
Hostname: "lonhost",
ARecord: "lonhost.<subdomain>.dc-03.com",
InventoryDnsAsset: &inventoryDnsAsset,
NatRule: &ExternalDnsNatRule{Uid: "lonvmnatrule1"},
NatRule: &ExternalDnsNatRule{Uid: "lonvmpublicnat"},
SrvRecords: []ExternalDnsSrvRecord{
{
Service: "_sip",
Expand Down Expand Up @@ -683,11 +725,6 @@ func (suite *ContractTestSuite) TestGetVm() {

// Given
expectedVm := vm
// Work around contract data inconsistencies
nic := vm.VmNetworkInterfaces[1]
nic.InUse = true
nic.Network.InventoryNetwork = nil
expectedVm.VmNetworkInterfaces[1] = nic

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

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

// Work around contract data inconsistencies
nic0 := vm.VmNetworkInterfaces[0]
nic0.Uid = ""
nic0.Name = ""
nic0.Network.InventoryNetwork = nil
expectedVm.VmNetworkInterfaces[0] = nic0

nic1 := vm.VmNetworkInterfaces[1]
nic1.Uid = ""
nic1.Name = ""
nic1.Network.InventoryNetwork = nil
nic1.InUse = true
expectedVm.VmNetworkInterfaces[1] = nic1
expectedNics := expectedVm.VmNetworkInterfaces

for i := range expectedNics {
expectedNics[i].Uid = ""
expectedNics[i].Name = ""
}
expectedNics[0].Network.InventoryNetwork = nil

suite.Equal(expectedVm, *actualVm)
}

var primaryDnsIp = "198.18.130.111"
var secondaryDnsIp = "198.18.130.112"

func (suite *ContractTestSuite) TestCreateVm() {
// Given
expectedVm := createVm
Expand Down Expand Up @@ -1105,8 +1143,9 @@ func (suite *ContractTestSuite) TestGetAllVmNatRules() {
suite.handleError(err)

// Then
suite.Equal(1, len(vmNatRules))
suite.Contains(vmNatRules, vmNatRule)
suite.Equal(2, len(vmNatRules))
expected := vmNatRule
suite.Contains(vmNatRules, expected)
}

// TODO - "Get One" Tests when Contracts are updated
Expand Down Expand Up @@ -1156,10 +1195,10 @@ func (suite *ContractTestSuite) TestCreateInboundProxyRule() {
expectedInboundProxyRule.Uid = "newloninboundproxy"
expectedInboundProxyRule.VmNicTarget = &TrafficVmNicTarget{
Uid: inboundProxyRule.VmNicTarget.Uid,
IpAddress: "192.168.0.8",
IpAddress: "192.168.0.9",
Vm: &Vm{
Uid: "pcVmayo2nx7fQr8V21xO",
Name: "MWRGFTMMILZNATVKXRSM",
Uid: "HIahoglmRva1DNeuYAII",
Name: "MHJOGANCZJKHQFWFVSXD",
},
}
suite.Equal(expectedInboundProxyRule, *actualInboundProxyRule)
Expand Down Expand Up @@ -1262,10 +1301,10 @@ func (suite *ContractTestSuite) TestCreateMailServer() {
expectedMailServer := mailServer
expectedMailServer.VmNicTarget = &TrafficVmNicTarget{
Uid: expectedMailServer.VmNicTarget.Uid,
IpAddress: "192.168.0.3",
IpAddress: "192.168.0.9",
Vm: &Vm{
Uid: "LDU9tBp7g5Zd4nZE2aNj",
Name: "HFDJPRCCGOZGHOMYSZGX",
Uid: "INLc0eWy1do3Xlk5GOdj",
Name: "UZARRCZGMJSBXUAGLOLJ",
},
}
expectedMailServer.InventoryDnsAsset = &InventoryDnsAsset{
Expand Down Expand Up @@ -1373,6 +1412,17 @@ func (suite *ContractTestSuite) TestGetAllOsFamilies() {
suite.Contains(osFamilies, linuxOsFamily)
}

func (suite *ContractTestSuite) TestGetAllEvcModes() {

// When
evcModes, err := suite.tbClient.GetAllEvcModes()
suite.handleError(err)

// Then
suite.Equal(3, len(evcModes))
suite.Contains(evcModes, westmereEvcMode)
}

func (suite *ContractTestSuite) TestGetAllNicTypes() {

// When
Expand Down Expand Up @@ -1424,7 +1474,7 @@ func (suite *ContractTestSuite) TestGetAllInventoryVms() {
suite.handleError(err)

// Then
suite.Equal(4, len(inventoryVms))
suite.Equal(3, len(inventoryVms))
suite.Equal(inventoryVms[2], inventoryVm)
suite.Contains(inventoryVms, inventoryVm)
}
Expand Down Expand Up @@ -1558,8 +1608,8 @@ func createTbClient(suite *ContractTestSuite) Client {
suite.T().Log("Timeout starting wiremock")
suite.handleError(err)
}
fmt.Println("Waiting another 5s for wiremock...")
time.Sleep(5 * time.Second)
fmt.Println("Waiting another 2s for wiremock...")
time.Sleep(2 * time.Second)
}

return c
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id" : "2f3379a2-98c1-45a8-961e-87af17617cb5",
"id" : "c6c9835f-8b4f-49a8-9b36-d63e5fbf0c0c",
"request" : {
"urlPath" : "/datacenters/notfound/inventory-demos",
"method" : "GET",
Expand All @@ -11,11 +11,11 @@
},
"response" : {
"status" : 404,
"body" : "[{\"logref\":\"YJGAWIXFNWUHSQUTJIMT\",\"message\":\"The requested Datacenter resource 'notfound' was not found\",\"links\":[]}]",
"body" : "[{\"logref\":\"AXMKQBOCJTWHFCELVAKK\",\"message\":\"The requested Datacenter resource 'notfound' was not found\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "2f3379a2-98c1-45a8-961e-87af17617cb5"
"uuid" : "c6c9835f-8b4f-49a8-9b36-d63e5fbf0c0c"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id" : "5ef182bf-9c37-4375-9417-44149fe53a79",
"id" : "bef458b0-7944-4fa2-9ac1-ce0308cc1963",
"request" : {
"urlPath" : "/datacenters/lon/inventory-demos",
"method" : "GET",
Expand All @@ -17,5 +17,5 @@
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "5ef182bf-9c37-4375-9417-44149fe53a79"
"uuid" : "bef458b0-7944-4fa2-9ac1-ce0308cc1963"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id" : "a352113c-8049-4a0f-877f-75610a3b5288",
"id" : "2193facc-eba4-4f33-b55a-33275b7ff4cd",
"request" : {
"urlPath" : "/datacenters/sng/inventory-demos",
"method" : "GET",
Expand All @@ -11,11 +11,11 @@
},
"response" : {
"status" : 503,
"body" : "[{\"logref\":\"THIKFDSVDOZNWAEGEAMK\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
"body" : "[{\"logref\":\"CVFFTYDTUJQWVSLCUSPA\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "a352113c-8049-4a0f-877f-75610a3b5288"
"uuid" : "2193facc-eba4-4f33-b55a-33275b7ff4cd"
}
Loading

0 comments on commit 930eab5

Please sign in to comment.