Skip to content

Commit

Permalink
Merge branch 'virtual-machine-name-pather' into 'develop'
Browse files Browse the repository at this point in the history
move VirtualMachineName into pathers

See merge request open-source/bytemark-client!315
  • Loading branch information
Hannah Pirie committed Feb 6, 2019
2 parents 29203cd + a940b9d commit 796dd5c
Show file tree
Hide file tree
Showing 74 changed files with 637 additions and 425 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ stages:
- VERSION=${CI_BUILD_REF_NAME##$VERSIONPREFIX}
# If the CI_BUILD_REF_NAME is not prefixed with v
# then VERSION will be equal to CI_BUILD_REF_NAME.
- '! [ "$VERSION" = "$CI_BUILD_REF_NAME" ] || VERSION=""'
- "! grep '^v[0-9][0-9.]*$' && VERSION=''"
- CHANGELOG_VERSION=$(sed "s/.*(\([^)]\+\)).*/\1/ ; q" doc/changelog)
- SNAPSHOT_VERSION=${CI_PIPELINE_ID}.git${CI_BUILD_REF:0:7}

Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/BytemarkHosting/bytemark-client/mocks"
)

Expand Down Expand Up @@ -128,7 +128,7 @@ func TestAddIPCommand(t *testing.T) {

config.When("GetVirtualMachine").Return(defVM)

vm := lib.VirtualMachineName{VirtualMachine: "test-server", Group: "default", Account: "default-account"}
vm := pathers.VirtualMachineName{VirtualMachine: "test-server", GroupName: pathers.GroupName{Group: "default", Account: "default-account"}}

ipcr := brain.IPCreateRequest{
Addresses: 1,
Expand Down
7 changes: 3 additions & 4 deletions cmd/bytemark/app/flags/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"net"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
)
Expand Down Expand Up @@ -95,14 +94,14 @@ func Size(c *app.Context, flagname string) int {
return 0
}

// VirtualMachineName returns the named flag as a lib.VirtualMachineName
func VirtualMachineName(c *app.Context, flagname string) (vm lib.VirtualMachineName) {
// VirtualMachineName returns the named flag as a pathers.VirtualMachineName
func VirtualMachineName(c *app.Context, flagname string) (vm pathers.VirtualMachineName) {
vmNameFlag, ok := c.Context.Generic(flagname).(*VirtualMachineNameFlag)
if !ok {
return c.Config().GetVirtualMachine()
}
if vmNameFlag == nil {
return lib.VirtualMachineName{}
return pathers.VirtualMachineName{}
}

return vmNameFlag.VirtualMachineName
Expand Down
14 changes: 11 additions & 3 deletions cmd/bytemark/app/flags/account_name_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/BytemarkHosting/bytemark-client/mocks"
"github.com/urfave/cli"
Expand All @@ -28,8 +27,17 @@ func TestAccountNameSliceFlag(t *testing.T) {
// String()
cfg, client, cliApp := testutil.BaseTestSetup(t, false, []cli.Command{})
cfg.When("GetIgnoreErr", "account").Return("default-account")
cfg.When("GetGroup").Return(pathers.GroupName{Group: "default-group", Account: "default-account"})
cfg.When("GetVirtualMachine").Return(lib.VirtualMachineName{VirtualMachine: "default-server", Group: "default-group", Account: "default-account"})
cfg.When("GetGroup").Return(pathers.GroupName{
Group: "default-group",
Account: "default-account",
})
cfg.When("GetVirtualMachine").Return(pathers.VirtualMachineName{
VirtualMachine: "default-server",
GroupName: pathers.GroupName{
Group: "default-group",
Account: "default-account",
},
})

// now some boilerplate to get a context
// TODO(telyn): this should probably be refactored out since it'll be
Expand Down
15 changes: 11 additions & 4 deletions cmd/bytemark/app/flags/gen/slice_flags/template_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ func Test{{ .TypeName }}SliceFlag(t *testing.T) {
// String()
cfg, client, cliApp := testutil.BaseTestSetup(t, false, []cli.Command{})
cfg.When("GetIgnoreErr", "account").Return("default-account")
cfg.When("GetGroup").Return(pathers.GroupName{Group: "default-group", Account:
"default-account"})
cfg.When("GetVirtualMachine").Return(lib.VirtualMachineName{VirtualMachine:
"default-server", Group: "default-group", Account: "default-account"})
cfg.When("GetGroup").Return(pathers.GroupName{
Group: "default-group",
Account: "default-account",
})
cfg.When("GetVirtualMachine").Return(pathers.VirtualMachineName{
VirtualMachine: "default-server",
GroupName: pathers.GroupName{
Group: "default-group",
Account: "default-account",
},
})


// now some boilerplate to get a context
Expand Down
14 changes: 11 additions & 3 deletions cmd/bytemark/app/flags/group_name_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/BytemarkHosting/bytemark-client/mocks"
"github.com/urfave/cli"
Expand All @@ -28,8 +27,17 @@ func TestGroupNameSliceFlag(t *testing.T) {
// String()
cfg, client, cliApp := testutil.BaseTestSetup(t, false, []cli.Command{})
cfg.When("GetIgnoreErr", "account").Return("default-account")
cfg.When("GetGroup").Return(pathers.GroupName{Group: "default-group", Account: "default-account"})
cfg.When("GetVirtualMachine").Return(lib.VirtualMachineName{VirtualMachine: "default-server", Group: "default-group", Account: "default-account"})
cfg.When("GetGroup").Return(pathers.GroupName{
Group: "default-group",
Account: "default-account",
})
cfg.When("GetVirtualMachine").Return(pathers.VirtualMachineName{
VirtualMachine: "default-server",
GroupName: pathers.GroupName{
Group: "default-group",
Account: "default-account",
},
})

// now some boilerplate to get a context
// TODO(telyn): this should probably be refactored out since it'll be
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/app/flags/privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (args *privArgs) shift() (arg string, err error) {
type PrivilegeFlag struct {
AccountName string
GroupName *pathers.GroupName
VirtualMachineName *lib.VirtualMachineName
VirtualMachineName *pathers.VirtualMachineName
Username string
Level brain.PrivilegeLevel
Value string
Expand All @@ -55,7 +55,7 @@ func (pf *PrivilegeFlag) fillPrivilegeTarget(c *app.Context, args *privArgs) (er
return
}
}
var vmName lib.VirtualMachineName
var vmName pathers.VirtualMachineName
var groupName pathers.GroupName
switch pf.TargetType() {
case brain.PrivilegeTargetTypeVM:
Expand Down
3 changes: 2 additions & 1 deletion cmd/bytemark/app/flags/virtual_machine_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package flags
import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
)

// VirtualMachineNameFlag is used for all --server flags, or should be at least.
type VirtualMachineNameFlag struct {
VirtualMachineName lib.VirtualMachineName
VirtualMachineName pathers.VirtualMachineName
Value string
}

Expand Down
14 changes: 11 additions & 3 deletions cmd/bytemark/app/flags/virtual_machine_name_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/BytemarkHosting/bytemark-client/mocks"
"github.com/urfave/cli"
Expand All @@ -28,8 +27,17 @@ func TestVirtualMachineNameSliceFlag(t *testing.T) {
// String()
cfg, client, cliApp := testutil.BaseTestSetup(t, false, []cli.Command{})
cfg.When("GetIgnoreErr", "account").Return("default-account")
cfg.When("GetGroup").Return(pathers.GroupName{Group: "default-group", Account: "default-account"})
cfg.When("GetVirtualMachine").Return(lib.VirtualMachineName{VirtualMachine: "default-server", Group: "default-group", Account: "default-account"})
cfg.When("GetGroup").Return(pathers.GroupName{
Group: "default-group",
Account: "default-account",
})
cfg.When("GetVirtualMachine").Return(pathers.VirtualMachineName{
VirtualMachine: "default-server",
GroupName: pathers.GroupName{
Group: "default-group",
Account: "default-account",
},
})

// now some boilerplate to get a context
// TODO(telyn): this should probably be refactored out since it'll be
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/app/wait/vm_power_off.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"time"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
)

// VMPowerOff waits for the named virtual machine to power off before returning
// a nil error. This is done by frequently polling the brain for info about the
// VM. If any calls fail, the error is returned.
func VMPowerOff(c *app.Context, name lib.VirtualMachineName) (err error) {
func VMPowerOff(c *app.Context, name pathers.VirtualMachineName) (err error) {
vm := brain.VirtualMachine{PowerOn: true}

for vm.PowerOn {
Expand Down
18 changes: 9 additions & 9 deletions cmd/bytemark/commands/add/api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ type privWithErr struct {
func TestAddApiKey(t *testing.T) {
// here's all the test data for all the servers, groups and accounts we'll
// use in this test
serverNames := []lib.VirtualMachineName{
{VirtualMachine: "myserver", Group: "default", Account: "default-account"},
{VirtualMachine: "myserver2", Group: "test-group", Account: "test-account"},
serverNames := []pathers.VirtualMachineName{
{VirtualMachine: "myserver", GroupName: pathers.GroupName{Group: "default", Account: "default-account"}},
{VirtualMachine: "myserver2", GroupName: pathers.GroupName{Group: "test-group", Account: "test-account"}},
}
servers := []brain.VirtualMachine{
{ID: 1},
{ID: 2},
}
groupNames := []pathers.GroupName{
{Group: "", Account: "default-account"},
{Group: "test-group", Account: "test-account"},
pathers.GroupName{Group: "", Account: "default-account"},
pathers.GroupName{Group: "test-group", Account: "test-account"},
}
groups := []brain.Group{
{ID: 11},
Expand All @@ -74,7 +74,7 @@ func TestAddApiKey(t *testing.T) {
// the map keys are used for the mock BuildRequest calls' URLs
accounts map[string]accountWithErr
groups map[pathers.GroupName]groupWithErr
servers map[lib.VirtualMachineName]serverWithErr
servers map[pathers.VirtualMachineName]serverWithErr
privileges []privWithErr
// apiKey is both the apiKey to return and some of its fields will be
// used to define the mock
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAddApiKey(t *testing.T) {
VirtualMachineID: 1,
},
}},
servers: map[lib.VirtualMachineName]serverWithErr{
servers: map[pathers.VirtualMachineName]serverWithErr{
serverNames[0]: serverWithErr{VirtualMachine: servers[0]},
},
}, {
Expand All @@ -184,7 +184,7 @@ func TestAddApiKey(t *testing.T) {
Label: "test-api-key",
},
},
servers: map[lib.VirtualMachineName]serverWithErr{
servers: map[pathers.VirtualMachineName]serverWithErr{
serverNames[0]: serverWithErr{VirtualMachine: servers[0]},
serverNames[1]: serverWithErr{VirtualMachine: servers[1]},
},
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestAddApiKey(t *testing.T) {
}

test.Run(t, func(t *testing.T, config *mocks.Config, client *mocks.Client, app *cli.App) {
config.When("GetVirtualMachine").Return(lib.VirtualMachineName{Group: "default", Account: "default-account"})
config.When("GetVirtualMachine").Return(pathers.VirtualMachineName{GroupName: pathers.GroupName{Group: "default", Account: "default-account"}})
config.When("GetGroup").Return(pathers.GroupName{Group: "default", Account: "default-account"})
config.When("GetIgnoreErr", "account").Return("default-account")
client.When("GetUser", test.user.Username).Return(test.user, nil)
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/commands/add/disc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/commands"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/cheekybits/is"
)

Expand All @@ -17,7 +17,7 @@ func TestCreateDiskCommand(t *testing.T) {

config.When("GetVirtualMachine").Return(testutil.DefVM)

name := lib.VirtualMachineName{VirtualMachine: "test-server", Group: "default", Account: "default-account"}
name := pathers.VirtualMachineName{VirtualMachine: "test-server", GroupName: pathers.GroupName{Group: "default", Account: "default-account"}}
c.When("GetVirtualMachine", name).Return(&brain.VirtualMachine{Hostname: "test-server.default.default-account.endpoint"})

disc := brain.Disc{Size: 35 * 1024, StorageGrade: "archive"}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bytemark/commands/add/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func createServer(c *app.Context) (err error) {
}
spec.IPs = ipspec

groupName := name.GroupName()
groupName := name.GroupName
err = c.Client().EnsureGroupName(&groupName)
if err != nil {
return
Expand Down
13 changes: 7 additions & 6 deletions cmd/bytemark/commands/add/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/commands"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/commands/add"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/testutil"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
"github.com/urfave/cli"
Expand Down Expand Up @@ -71,7 +70,7 @@ func TestCreateServerHasCorrectFlags(t *testing.T) {
func TestCreateServer(t *testing.T) {
type createTest struct {
Spec brain.VirtualMachineSpec
ConfigVirtualMachine lib.VirtualMachineName
ConfigVirtualMachine pathers.VirtualMachineName
GroupName pathers.GroupName
Args []string
Output string
Expand Down Expand Up @@ -122,7 +121,7 @@ func TestCreateServer(t *testing.T) {
IPv6: "fe80::123",
},
},
ConfigVirtualMachine: lib.VirtualMachineName{Group: "default"},
ConfigVirtualMachine: pathers.VirtualMachineName{GroupName: pathers.GroupName{Group: "default"}},
GroupName: pathers.GroupName{Group: "default"},
Args: []string{
"bytemark", "add", "server",
Expand Down Expand Up @@ -217,10 +216,12 @@ func TestCreateServer(t *testing.T) {
config, c, app := testutil.BaseTestAuthSetup(t, false, commands.Commands)
config.When("GetVirtualMachine").Return(test.ConfigVirtualMachine)

vmname := lib.VirtualMachineName{
vmname := pathers.VirtualMachineName{
VirtualMachine: test.Spec.VirtualMachine.Name,
Group: test.GroupName.Group,
Account: test.GroupName.Account,
GroupName: pathers.GroupName{
Group: test.GroupName.Group,
Account: test.GroupName.Account,
},
}

postGpName := test.GroupName
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/commands/admin/admin_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package admin_test
import (
"math/big"

"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
"github.com/BytemarkHosting/bytemark-client/lib/pathers"
)

// These functions are all deprecated, stop using them please

var defVM = lib.VirtualMachineName{Group: "default", Account: "default-account"}
var defVM = pathers.VirtualMachineName{GroupName: pathers.GroupName{Group: "default", Account: "default-account"}}

func getFixtureVLAN() brain.VLAN {
return brain.VLAN{
Expand Down
Loading

0 comments on commit 796dd5c

Please sign in to comment.