Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LVM module #184

Merged
merged 71 commits into from Nov 10, 2016
Merged

LVM module #184

merged 71 commits into from Nov 10, 2016

Conversation

avnik
Copy link
Contributor

@avnik avnik commented Aug 22, 2016

This is straight rewrite of mantl-storage-setup.py (at the moment)

Architecture caveats:
1 we need to install lvm tools, and start lvm-metad service before we start
and we can't issue install requirement in lvm module.
2 we need to express all LVM structure in single hcl expression, otherwise we
can't plan/check VG/LV part, until PV/VG part commited.

Possible future ways:

  • all storage/lvm structure as single expression
  • step-by-step executing to eliminate difference between "desired state" (by hcl expression) and "current state" (which exposed by lvs/pvs/vgs commands)

Funny go language issues:
we can exec.Command(name, args...) but not `exec.Command(name, arg, more_args...)``

So let discuss it

@avnik
Copy link
Contributor Author

avnik commented Aug 22, 2016

suggestions how to make LVM related code testable also welcomed

}
}
return "", fmt.Errorf("too many symlinks for %s", dev)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use filepath.EvalSymlinks here?

https://golang.org/pkg/path/filepath/#EvalSymlinks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definelly yes

@rebeccaskinner
Copy link
Contributor

Could we consider using LogicalVolume, PhysicalVolume and VolumeGroup instead of lv, pv and vg? I know that's more verbose than the tool itself but might make scripts more readable for people who aren't as familiar with lvm?

@avnik avnik force-pushed the feature/lvm branch 2 times, most recently from ced335a to 8768f24 Compare September 15, 2016 13:28
@stevendborrelli stevendborrelli added this to the 0.3 milestone Sep 17, 2016
@avnik avnik force-pushed the feature/lvm branch 2 times, most recently from 1911304 to af116b9 Compare October 6, 2016 18:24
@stevendborrelli stevendborrelli changed the title [WIP] LVM proof-of-concept LVM module Oct 6, 2016
@stevendborrelli
Copy link
Member

please make sure your example has a check for the pvs, etc. commands or it will fail

@stevendborrelli
Copy link
Member

Errors are not clear during a failure. You are logging tasks in INFO but it is not clear why this is failing:

root/lvm.lv.lv-test:
    Messages:
    Has Changes: no
    Changes: No changes

root/lvm.fs.mnt-me:
    Error: exit status 2
    Messages:
    Has Changes: no
    Changes: No changes

root/lvm.vg.mantl:
    Messages:
    Has Changes: no
    Changes: No changes

Summary: 2 errors, 0 changes

 * root: error in dependency "root/lvm.fs.mnt-me"
 * root/lvm.fs.mnt-me: exit status 2

}

lvm.fs "mnt-me" {
device = "/dev/mapper/mantl-test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be /dev/mapper/lv-test

@stevendborrelli
Copy link
Member

stevendborrelli commented Oct 6, 2016

  1. The module should check for the lvm commands (pvs, lvs, .etc.) before trying to execute.
  2. errors are not propagated back to the user
  3. I think some of the checks are not working. I am getting a clear on the /mnt/ filesystem even though it is not mounted. Perhaps the checks needs to go a little deeper and confirm the right configuration.

We really need to throw a lot of errors at it and make sure it is providing helpful feedback.

@stevendborrelli
Copy link
Member

Are pvs created automatically? I think it would be helpful to separate that out as a module

root/lvm.vg.mantl:
    Messages:
    Has Changes: yes
    Changes:
        /dev/sdb: "<none>" => "member of volume group mantl"
        mantl: "<not exists>" => "/dev/sdb"

Not really clear what is happening here. Is the lv being created or the vg?

root/lvm.lv.lv-test:
    Messages:
    Has Changes: yes
    Changes:
        group: mantl: "<not exists>" => "created"

@arichardet
Copy link
Contributor

@avnik You have failing tests - please take a look and make appropriate changes. Thanks!

@@ -0,0 +1,18 @@
lvm.vg "mantl" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove "mantl" in all places and replace with "test" or something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (also reoved from history)

@@ -0,0 +1,18 @@
lvm.vg "mantl" {
name = "mantl"
devices = [ "/dev/sdb" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this to a parameter so users can provide the value; you could set "/dev/sdb" as default.

)

type ResourceFS struct {
mount *Mount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mount, lvm, etc. should be capitalized since the struct is exported

device, err := render.Render("device", p.Device)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary and is handled for you. You can simply set "What" to p.device in Mount, etc.

group, err := render.Render("group", p.Group)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are now done for you; just use the value of p.Group, etc.

func (*OsExec) Run(prog string, args []string) error {
log.WithField("module", "lvm").Infof("Executing %s: %v", prog, args)
e := exec.Command(prog, args...).Run()
if e == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably only need the err != nil case here.

"testing"
)

func TestExecRun(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier to follow if you have one Test[FuncName], and then use t.Run to test the different cases of success and failure resulting in error. Using t.Run is what we are trying to do now, so updating throughout is probably a good idea.

)

type ResourceLV struct {
group string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group, name, etc. should be capitalized since this struct is exported.

status := &Status{}
ok, err := r.checkVG()
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to wrap the errors with "check", "apply", etc. to give the user more information.


pvs, err := r.lvm.QueryPhysicalVolumes()
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping errors here in check and apply would be helpful for the user.

@avnik avnik force-pushed the feature/lvm branch 5 times, most recently from 5ecc8c0 to 092c008 Compare October 24, 2016 19:58
@arichardet arichardet merged commit 11beb43 into master Nov 10, 2016
@arichardet arichardet deleted the feature/lvm branch November 10, 2016 20:17
@arichardet arichardet mentioned this pull request Nov 14, 2016
BrianHicks pushed a commit that referenced this pull request Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants