Skip to content

Commit

Permalink
Add plug collection
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-samfira committed Sep 25, 2018
1 parent 2e6cf12 commit 7011244
Show file tree
Hide file tree
Showing 119 changed files with 2,922 additions and 448 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
name = "github.com/juju/bundlechanges"

[[constraint]]
revision = "25349c35a6b1c9244c24045c9b5faab5932eae63"
revision = "1f9306d91eb3958fef5c2c8741e7049d1dda08b6"
name = "github.com/juju/description"

[[constraint]]
Expand Down
2 changes: 1 addition & 1 deletion agent/agentbootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func initBootstrapMachine(c agent.ConfigSetter, st *state.State, args Initialize
Constraints: args.BootstrapMachineConstraints,
InstanceId: args.BootstrapMachineInstanceId,
HardwareCharacteristics: hardware,
Jobs: jobs,
Jobs: jobs,
})
if err != nil {
return nil, errors.Annotate(err, "cannot create bootstrap machine in state")
Expand Down
4 changes: 2 additions & 2 deletions api/common/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,8 @@ func (s *NetworkSuite) TestGetObservedNetworkConfigInterfacesError(c *gc.C) {

func (s *NetworkSuite) TestGetObservedNetworkConfigInterfaceAddressesError(c *gc.C) {
s.stubConfigSource.SetErrors(
nil, // Interfaces
nil, // DefaultRoute
nil, // Interfaces
nil, // DefaultRoute
errors.New("no addresses"), // InterfaceAddressses
)

Expand Down
1 change: 1 addition & 0 deletions api/facadeversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var facadeVersions = map[string]int{
"UpgradeSeries": 1,
"UserManager": 2,
"VolumeAttachmentsWatcher": 2,
"VolumeAttachmentPlansWatcher": 1,
}

// bestVersion tries to find the newest version in the version list that we can
Expand Down
4 changes: 2 additions & 2 deletions api/logstream/logstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (s *LogReaderSuite) TestNextOneRecord(c *gc.C) {
Name: "99",
Software: logfwd.Software{
PrivateEnterpriseNumber: 28978,
Name: "jujud-machine-agent",
Version: version.Current,
Name: "jujud-machine-agent",
Version: version.Current,
},
},
Timestamp: ts,
Expand Down
56 changes: 56 additions & 0 deletions api/storageprovisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ func (st *State) WatchVolumeAttachments(scope names.Tag) (watcher.MachineStorage
return st.watchAttachments("WatchVolumeAttachments", scope, apiwatcher.NewVolumeAttachmentsWatcher)
}

// WatchVolumeAttachmentPlans watches for changes to volume attachments
// scoped to the entity with the tag passed to NewState.
func (st *State) WatchVolumeAttachmentPlans(scope names.Tag) (watcher.MachineStorageIdsWatcher, error) {
return st.watchAttachments("WatchVolumeAttachmentPlans", scope, apiwatcher.NewVolumeAttachmentPlansWatcher)
}

// WatchFilesystemAttachments watches for changes to filesystem attachments
// scoped to the entity with the specified tag.
func (st *State) WatchFilesystemAttachments(scope names.Tag) (watcher.MachineStorageIdsWatcher, error) {
Expand Down Expand Up @@ -188,6 +194,30 @@ func (st *State) Filesystems(tags []names.FilesystemTag) ([]params.FilesystemRes
return results.Results, nil
}

func (st *State) VolumeAttachmentPlans(ids []params.MachineStorageId) ([]params.VolumeAttachmentPlanResult, error) {
args := params.MachineStorageIds{ids}
var results params.VolumeAttachmentPlanResults
err := st.facade.FacadeCall("VolumeAttachmentPlans", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != len(ids) {
return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results))
}
return results.Results, nil
}

func (st *State) RemoveVolumeAttachmentPlan(ids []params.MachineStorageId) ([]params.ErrorResult, error) {
var results params.ErrorResults
args := params.MachineStorageIds{
Ids: ids,
}
if err := st.facade.FacadeCall("RemoveVolumeAttachmentPlan", args, &results); err != nil {
return nil, err
}
return results.Results, nil
}

// VolumeAttachments returns details of volume attachments with the specified IDs.
func (st *State) VolumeAttachments(ids []params.MachineStorageId) ([]params.VolumeAttachmentResult, error) {
args := params.MachineStorageIds{ids}
Expand Down Expand Up @@ -369,6 +399,32 @@ func (st *State) SetFilesystemInfo(filesystems []params.Filesystem) ([]params.Er
return results.Results, nil
}

func (st *State) CreateVolumeAttachmentPlans(volumeAttachmentPlans []params.VolumeAttachmentPlan) ([]params.ErrorResult, error) {
args := params.VolumeAttachmentPlans{VolumeAttachmentPlans: volumeAttachmentPlans}
var results params.ErrorResults
err := st.facade.FacadeCall("CreateVolumeAttachmentPlans", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != len(volumeAttachmentPlans) {
return nil, errors.Errorf("expected %d result(s), got %d", len(volumeAttachmentPlans), len(results.Results))
}
return results.Results, nil
}

func (st *State) SetVolumeAttachmentPlanBlockInfo(volumeAttachmentPlans []params.VolumeAttachmentPlan) ([]params.ErrorResult, error) {
args := params.VolumeAttachmentPlans{VolumeAttachmentPlans: volumeAttachmentPlans}
var results params.ErrorResults
err := st.facade.FacadeCall("SetVolumeAttachmentPlanBlockInfo", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != len(volumeAttachmentPlans) {
return nil, errors.Errorf("expected %d result(s), got %d", len(volumeAttachmentPlans), len(results.Results))
}
return results.Results, nil
}

// SetVolumeAttachmentInfo records the details of newly provisioned volume attachments.
func (st *State) SetVolumeAttachmentInfo(volumeAttachments []params.VolumeAttachment) ([]params.ErrorResult, error) {
args := params.VolumeAttachments{VolumeAttachments: volumeAttachments}
Expand Down
240 changes: 240 additions & 0 deletions api/storageprovisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ func (s *provisionerSuite) TestWatchVolumeAttachments(c *gc.C) {
c.Check(callCount, gc.Equals, 1)
}

func (s *provisionerSuite) TestWatchVolumeAttachmentPlans(c *gc.C) {
var callCount int
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "StorageProvisioner")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "WatchVolumeAttachmentPlans")
c.Check(arg, jc.DeepEquals, params.Entities{
Entities: []params.Entity{{Tag: "machine-123"}},
})
c.Assert(result, gc.FitsTypeOf, &params.MachineStorageIdsWatchResults{})
*(result.(*params.MachineStorageIdsWatchResults)) = params.MachineStorageIdsWatchResults{
Results: []params.MachineStorageIdsWatchResult{{
Error: &params.Error{Message: "FAIL"},
}},
}
callCount++
return nil
})

st, err := storageprovisioner.NewState(apiCaller)
c.Assert(err, jc.ErrorIsNil)
_, err = st.WatchVolumeAttachmentPlans(names.NewMachineTag("123"))
c.Check(err, gc.ErrorMatches, "FAIL")
c.Check(callCount, gc.Equals, 1)
}

func (s *provisionerSuite) TestWatchFilesystemAttachments(c *gc.C) {
var callCount int
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
Expand Down Expand Up @@ -297,6 +324,56 @@ func (s *provisionerSuite) TestVolumeAttachments(c *gc.C) {
c.Assert(volumes, jc.DeepEquals, volumeAttachmentResults)
}

func (s *provisionerSuite) TestVolumeAttachmentPlans(c *gc.C) {
volumeAttachmentPlanResults := []params.VolumeAttachmentPlanResult{{
Result: params.VolumeAttachmentPlan{
MachineTag: "machine-100",
VolumeTag: "volume-100",
PlanInfo: params.VolumeAttachmentPlanInfo{
DeviceType: storage.DeviceTypeISCSI,
DeviceAttributes: map[string]string{
"iqn": "bogusIQN",
"address": "192.168.1.1",
"port": "9999",
"chap-user": "example",
"chap-secret": "supersecretpassword",
},
},
BlockDevice: storage.BlockDevice{
DeviceName: "sda",
},
},
}}

var callCount int
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "StorageProvisioner")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "VolumeAttachmentPlans")
c.Check(arg, gc.DeepEquals, params.MachineStorageIds{
Ids: []params.MachineStorageId{{
MachineTag: "machine-100", AttachmentTag: "volume-100",
}},
})
c.Assert(result, gc.FitsTypeOf, &params.VolumeAttachmentPlanResults{})
*(result.(*params.VolumeAttachmentPlanResults)) = params.VolumeAttachmentPlanResults{
Results: volumeAttachmentPlanResults,
}
callCount++
return nil
})

st, err := storageprovisioner.NewState(apiCaller)
c.Assert(err, jc.ErrorIsNil)
volumes, err := st.VolumeAttachmentPlans([]params.MachineStorageId{{
MachineTag: "machine-100", AttachmentTag: "volume-100",
}})
c.Check(err, jc.ErrorIsNil)
c.Check(callCount, gc.Equals, 1)
c.Assert(volumes, jc.DeepEquals, volumeAttachmentPlanResults)
}

func (s *provisionerSuite) TestVolumeBlockDevices(c *gc.C) {
blockDeviceResults := []params.BlockDeviceResult{{
Result: storage.BlockDevice{
Expand Down Expand Up @@ -626,6 +703,169 @@ func (s *provisionerSuite) TestSetVolumeInfo(c *gc.C) {
c.Assert(errorResults[0].Error, gc.IsNil)
}

func (s *provisionerSuite) TestCreateVolumeAttachmentPlan(c *gc.C) {
var callCount int

attachmentPlan := []params.VolumeAttachmentPlan{
{
MachineTag: "machine-100",
VolumeTag: "volume-100",
PlanInfo: params.VolumeAttachmentPlanInfo{
DeviceType: storage.DeviceTypeISCSI,
DeviceAttributes: map[string]string{
"iqn": "bogusIQN",
"address": "192.168.1.1",
"port": "9999",
"chap-user": "example",
"chap-secret": "supersecretpassword",
},
},
BlockDevice: storage.BlockDevice{
DeviceName: "sda",
},
},
}

apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "StorageProvisioner")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "CreateVolumeAttachmentPlans")
c.Check(arg, gc.DeepEquals, params.VolumeAttachmentPlans{
VolumeAttachmentPlans: []params.VolumeAttachmentPlan{
{
MachineTag: "machine-100",
VolumeTag: "volume-100",
PlanInfo: params.VolumeAttachmentPlanInfo{
DeviceType: storage.DeviceTypeISCSI,
DeviceAttributes: map[string]string{
"iqn": "bogusIQN",
"address": "192.168.1.1",
"port": "9999",
"chap-user": "example",
"chap-secret": "supersecretpassword",
},
},
BlockDevice: storage.BlockDevice{
DeviceName: "sda",
},
},
},
})
c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{Error: nil}},
}
callCount++
return nil
})

st, err := storageprovisioner.NewState(apiCaller)
c.Assert(err, jc.ErrorIsNil)
errorResults, err := st.CreateVolumeAttachmentPlans(attachmentPlan)
c.Check(err, jc.ErrorIsNil)
c.Check(callCount, gc.Equals, 1)
c.Assert(errorResults, gc.HasLen, 1)
c.Assert(errorResults[0].Error, gc.IsNil)
}

func (s *provisionerSuite) TestSetVolumeAttachmentPlanBlockInfo(c *gc.C) {
var callCount int

attachmentPlan := []params.VolumeAttachmentPlan{
{
MachineTag: "machine-100",
VolumeTag: "volume-100",
PlanInfo: params.VolumeAttachmentPlanInfo{
DeviceType: storage.DeviceTypeISCSI,
DeviceAttributes: map[string]string{
"iqn": "bogusIQN",
"address": "192.168.1.1",
"port": "9999",
"chap-user": "example",
"chap-secret": "supersecretpassword",
},
},
BlockDevice: storage.BlockDevice{
DeviceName: "sda",
},
},
}

apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "StorageProvisioner")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "SetVolumeAttachmentPlanBlockInfo")
c.Check(arg, gc.DeepEquals, params.VolumeAttachmentPlans{
VolumeAttachmentPlans: []params.VolumeAttachmentPlan{
{
MachineTag: "machine-100",
VolumeTag: "volume-100",
PlanInfo: params.VolumeAttachmentPlanInfo{
DeviceType: storage.DeviceTypeISCSI,
DeviceAttributes: map[string]string{
"iqn": "bogusIQN",
"address": "192.168.1.1",
"port": "9999",
"chap-user": "example",
"chap-secret": "supersecretpassword",
},
},
BlockDevice: storage.BlockDevice{
DeviceName: "sda",
},
},
},
})
c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{Error: nil}},
}
callCount++
return nil
})

st, err := storageprovisioner.NewState(apiCaller)
c.Assert(err, jc.ErrorIsNil)
errorResults, err := st.SetVolumeAttachmentPlanBlockInfo(attachmentPlan)
c.Check(err, jc.ErrorIsNil)
c.Check(callCount, gc.Equals, 1)
c.Assert(errorResults, gc.HasLen, 1)
c.Assert(errorResults[0].Error, gc.IsNil)
}

func (s *provisionerSuite) TestRemoveVolumeAttachmentPlan(c *gc.C) {
var callCount int
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "StorageProvisioner")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "RemoveVolumeAttachmentPlan")
c.Check(arg, gc.DeepEquals, params.MachineStorageIds{
Ids: []params.MachineStorageId{{
MachineTag: "machine-100", AttachmentTag: "volume-100",
}},
})
c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{Error: nil}},
}
callCount++
return nil
})

st, err := storageprovisioner.NewState(apiCaller)
c.Assert(err, jc.ErrorIsNil)
errorResults, err := st.RemoveVolumeAttachmentPlan([]params.MachineStorageId{{
MachineTag: "machine-100", AttachmentTag: "volume-100",
}})
c.Check(err, jc.ErrorIsNil)
c.Check(callCount, gc.Equals, 1)
c.Assert(errorResults, gc.HasLen, 1)
c.Assert(errorResults[0].Error, gc.IsNil)
}

func (s *provisionerSuite) TestSetFilesystemInfo(c *gc.C) {
var callCount int
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
Expand Down
Loading

0 comments on commit 7011244

Please sign in to comment.