Example #1
0
func (s *FileTestSuite) TestSetUserConfig_Present(c *C) {
	args := haiconf.CommandArgs{
		"Path":   "/foo.txt",
		"Ensure": haiconf.ENSURE_PRESENT,
		"Mode":   "0777",
		"Owner":  "nobody",
		"Group":  "nogroup",
		"Source": "/foo",
	}

	err := s.f.SetUserConfig(args)
	c.Assert(err, IsNil)

	u, err := user.Lookup("nobody")
	c.Assert(err, IsNil)

	g, err := hacks.LookupSystemGroup("nogroup")
	c.Assert(err, IsNil)

	c.Assert(s.f.Path, Equals, args["Path"])
	c.Assert(s.f.Mode, Equals, os.FileMode(0777))
	c.Assert(s.f.Owner, DeepEquals, u)
	c.Assert(s.f.Group, DeepEquals, g)
	c.Assert(s.f.Source, DeepEquals, args["Source"])
	c.Assert(s.f.Ensure, Equals, args["Ensure"])
}
Example #2
0
func (s *DirectoryTestSuite) TestSetUserConfig_Complete(c *C) {
	args := haiconf.CommandArgs{
		"Path":    "/foo",
		"Ensure":  haiconf.ENSURE_PRESENT,
		"Recurse": true,
		"Mode":    "0777",
		"Owner":   "nobody",
		"Group":   "nogroup",
	}

	err := s.d.SetUserConfig(args)
	c.Assert(err, IsNil)

	u, err := user.Lookup("nobody")
	c.Assert(err, IsNil)

	g, err := hacks.LookupSystemGroup("nogroup")
	c.Assert(err, IsNil)

	c.Assert(s.d.Path, Equals, args["Path"])
	c.Assert(s.d.Mode, Equals, os.FileMode(0777))
	c.Assert(s.d.Owner, DeepEquals, u)
	c.Assert(s.d.Group, DeepEquals, g)
	c.Assert(s.d.Recurse, Equals, args["Recurse"])
	c.Assert(s.d.Ensure, Equals, args["Ensure"])
}
Example #3
0
func (g *Group) setName(args haiconf.CommandArgs) error {
	n, err := haiconf.CheckString("Name", args)
	if err != nil {
		return err
	}

	grp, err := hacks.LookupSystemGroup(n)
	exists := err == nil && grp.Gid != ""

	g.Name = n

	if g.Ensure == haiconf.ENSURE_PRESENT {
		if !exists {
			g.action = ACTION_CREATE
		}
		// ACTION_NOOP in setDefault()
	}

	if g.Ensure == haiconf.ENSURE_ABSENT {
		if exists {
			g.action = ACTION_REMOVE
		}
		// ACTION_NOOP in setDefault()
	}

	return nil
}
Example #4
0
func CheckSystemGroup(k string, args CommandArgs) (*hacks.Group, error) {
	g, _ := args[k].(string)
	if g == "" {
		return nil, NewArgError(k+" must be defined", args)
	}

	return hacks.LookupSystemGroup(g)
}