Пример #1
0
func (s *kernelTestSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	s.bootloader = newMockBootloader(c.MkDir())
	findBootloader = func() (partition.Bootloader, error) {
		return s.bootloader, nil
	}
}
Пример #2
0
func (t *CreateTestSuite) SetUpTest(c *C) {
	t.BaseTest.SetUpTest(c)

	dirs.SetRootDir(c.MkDir())

	// mock the chroot handler
	origRunInChroot := runInChroot
	t.AddCleanup(func() { runInChroot = origRunInChroot })
	runInChroot = func(chroot string, cmd ...string) error {
		t.runInChroot = append(t.runInChroot, cmd)
		return nil
	}

	// create some content for the webserver
	r := makeMockLxdTarball(c)
	t.AddCleanup(func() { r.Close() })
	t.imageReader = r

	// ensure getgrnam is called
	getgrnamOrig := getgrnam
	getgrnam = func(name string) (osutil.Group, error) {
		t.getgrnamCalled = append(t.getgrnamCalled, name)
		return osutil.Group{}, nil
	}
	t.AddCleanup(func() { getgrnam = getgrnamOrig })
}
Пример #3
0
func (s *SnapTestSuite) SetUpTest(c *C) {
	s.secbase = policy.SecBase
	s.tempdir = c.MkDir()
	dirs.SetRootDir(s.tempdir)

	policy.SecBase = filepath.Join(s.tempdir, "security")
	os.MkdirAll(dirs.SnapServicesDir, 0755)
	os.MkdirAll(dirs.SnapSeccompDir, 0755)
	os.MkdirAll(dirs.SnapSnapsDir, 0755)

	release.Override(release.Release{Flavor: "core", Series: "15.04"})

	// create a fake systemd environment
	os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)

	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}

	// fake udevadm
	runUdevAdm = func(args ...string) error {
		return nil
	}

	// do not attempt to hit the real store servers in the tests
	nowhereURI, _ := url.Parse("")
	s.storeCfg = &store.SnapUbuntuStoreConfig{
		SearchURI: nowhereURI,
		BulkURI:   nowhereURI,
	}
	storeConfig = s.storeCfg
}
Пример #4
0
func (s *apiSuite) SetUpTest(c *check.C) {
	dirs.SetRootDir(c.MkDir())

	s.parts = nil
	s.err = nil
	s.vars = nil
}
Пример #5
0
func (s *FirstBootTestSuite) SetUpTest(c *C) {
	tempdir := c.MkDir()
	dirs.SetRootDir(tempdir)
	stampFile = filepath.Join(c.MkDir(), "stamp")

	// mock the world!
	makeMockSecurityEnv(c)
	runAppArmorParser = mockRunAppArmorParser
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}

	err := os.MkdirAll(filepath.Join(tempdir, "etc", "systemd", "system", "multi-user.target.wants"), 0755)
	c.Assert(err, IsNil)

	configMyApp := make(SystemConfig)
	configMyApp["hostname"] = "myhostname"

	s.gadgetConfig = make(SystemConfig)
	s.gadgetConfig["myapp"] = configMyApp

	s.globs = globs
	globs = nil
	s.ethdir = ethdir
	ethdir = c.MkDir()
	s.ifup = ifup
	ifup = "/bin/true"
	getGadget = s.getGadget
	newPartMap = s.newPartMap

	s.m = nil
	s.e = nil
	s.partMap = nil
	s.partMapErr = nil
}
Пример #6
0
func (s *appArmorSuite) TestUnloadRemovesCachedProfile(c *C) {
	cmd := testutil.MockCommand(c, "apparmor_parser", "")
	defer cmd.Restore()

	dirs.SetRootDir(c.MkDir())
	defer dirs.SetRootDir("")
	err := os.MkdirAll(dirs.AppArmorCacheDir, 0755)
	c.Assert(err, IsNil)

	fname := filepath.Join(dirs.AppArmorCacheDir, "profile")
	ioutil.WriteFile(fname, []byte("blob"), 0600)
	err = apparmor.UnloadProfile("profile")
	c.Assert(err, IsNil)
	_, err = os.Stat(fname)
	c.Check(os.IsNotExist(err), Equals, true)
}
Пример #7
0
func (s *ServiceActorSuite) SetUpTest(c *C) {
	// force UTC timezone, for reproducible timestamps
	os.Setenv("TZ", "")

	dirs.SetRootDir(c.MkDir())
	// TODO: this mkdir hack is so enable doesn't fail; remove when enable is the same as the rest
	c.Assert(os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "/etc/systemd/system/multi-user.target.wants"), 0755), IsNil)
	systemd.SystemctlCmd = s.myRun
	systemd.JournalctlCmd = s.myJctl
	_, err := makeInstalledMockSnap(dirs.GlobalRootDir, `name: hello-app
version: 1.09
services:
 - name: svc1
   start: bin/hello
`)
	c.Assert(err, IsNil)
	f, err := makeInstalledMockSnap(dirs.GlobalRootDir, `name: hello-app
version: 1.10
services:
 - name: svc1
   start: bin/hello
`)
	c.Assert(err, IsNil)
	c.Assert(makeSnapActive(f), IsNil)
	s.i = 0
	s.argses = nil
	s.errors = nil
	s.outs = nil
	s.j = 0
	s.jsvcs = nil
	s.jouts = nil
	s.jerrs = nil
	s.pb = &MockProgressMeter{}
}
Пример #8
0
func (s *interfaceManagerSuite) TearDownTest(c *C) {
	if s.privateMgr != nil {
		s.privateMgr.Stop()
	}
	dirs.SetRootDir("")
	s.restoreBackends()
}
Пример #9
0
func (s *PartitionTestSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	err := os.MkdirAll((&grub{}).Dir(), 0755)
	c.Assert(err, IsNil)
	err = os.MkdirAll((&uboot{}).Dir(), 0755)
	c.Assert(err, IsNil)
}
Пример #10
0
func (s *SnapfsTestSuite) SetUpTest(c *C) {
	// mocks
	aaClickHookCmd = "/bin/true"
	dirs.SetRootDir(c.MkDir())

	// ensure we use the right builder func (snapfs)
	snapBuilderFunc = BuildSnapfsSnap
}
Пример #11
0
func (s *apiSuite) SetUpTest(c *check.C) {
	dirs.SetRootDir(c.MkDir())
	c.Assert(os.MkdirAll(filepath.Dir(dirs.SnapLockFile), 0755), check.IsNil)

	s.parts = nil
	s.err = nil
	s.vars = nil
}
Пример #12
0
func (s *ServiceActorSuite) TestFindServicesNoPackagesNoPattern(c *C) {
	// tricky way of hiding the installed package ;)
	dirs.SetRootDir(c.MkDir())
	actor, err := FindServices("", "", s.pb)
	c.Check(err, IsNil)
	c.Assert(actor, NotNil)
	c.Check(actor.(*serviceActor).svcs, HasLen, 0)
}
Пример #13
0
func (s *interfaceManagerSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	state := state.New(nil)
	s.state = state
	s.privateMgr = nil
	s.extraIfaces = nil
	s.secBackend = &interfaces.TestSecurityBackend{}
	s.restoreBackends = ifacestate.MockSecurityBackends([]interfaces.SecurityBackend{s.secBackend})
}
Пример #14
0
func (s *undoTestSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	err := os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "etc", "systemd", "system", "multi-user.target.wants"), 0755)
	c.Assert(err, IsNil)

	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}
}
Пример #15
0
func (cs *clientSuite) SetUpTest(c *check.C) {
	cs.cli = client.New(nil)
	cs.cli.SetDoer(cs)
	cs.err = nil
	cs.rsp = ""
	cs.req = nil
	cs.header = nil
	cs.status = http.StatusOK

	dirs.SetRootDir(c.MkDir())
}
Пример #16
0
func init() {
	// init the global directories at startup
	root := os.Getenv("SNAPPY_GLOBAL_ROOT")
	if root == "" {
		root = "/"
	}

	dirs.SetRootDir(root)

	// we don't need to care for the error here to take into account when
	// initialized on a non snappy system
	release.Setup(dirs.GlobalRootDir)
}
Пример #17
0
func (s *BuildTestSuite) SetUpTest(c *C) {
	s.BaseTest.SetUpTest(c)

	// chdir into a tempdir
	pwd, err := os.Getwd()
	c.Assert(err, IsNil)
	s.AddCleanup(func() { os.Chdir(pwd) })
	err = os.Chdir(c.MkDir())
	c.Assert(err, IsNil)

	// use fake root
	dirs.SetRootDir(c.MkDir())
}
Пример #18
0
func (s *backendSuite) SetUpTest(c *C) {
	// Isolate this test to a temporary directory
	s.rootDir = c.MkDir()
	dirs.SetRootDir(s.rootDir)
	// Prepare a directory for DBus configuration files.
	// NOTE: Normally this is a part of the OS snap.
	err := os.MkdirAll(dirs.SnapBusPolicyDir, 0700)
	c.Assert(err, IsNil)
	// Create a fresh repository for each test
	s.repo = interfaces.NewRepository()
	s.iface = &interfaces.TestInterface{InterfaceName: "iface"}
	err = s.repo.AddInterface(s.iface)
	c.Assert(err, IsNil)
}
Пример #19
0
func (s *SnapTestSuite) SetUpTest(c *C) {
	s.secbase = policy.SecBase
	s.tempdir = c.MkDir()
	newPartition = func() (p partition.Interface) {
		return new(MockPartition)
	}

	dirs.SetRootDir(s.tempdir)
	policy.SecBase = filepath.Join(s.tempdir, "security")
	os.MkdirAll(dirs.SnapServicesDir, 0755)
	os.MkdirAll(dirs.SnapSeccompDir, 0755)

	release.Override(release.Release{Flavor: "core", Series: "15.04"})

	dirs.ClickSystemHooksDir = filepath.Join(s.tempdir, "/usr/share/click/hooks")
	os.MkdirAll(dirs.ClickSystemHooksDir, 0755)

	// create a fake systemd environment
	os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)

	// we may not have debsig-verify installed (and we don't need it
	// for the unittests)
	clickdeb.VerifyCmd = "true"
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}

	// fake "du"
	duCmd = makeFakeDuCommand(c)

	// fake udevadm
	runUdevAdm = func(args ...string) error {
		return nil
	}

	// do not attempt to hit the real store servers in the tests
	storeSearchURI, _ = url.Parse("")
	storeDetailsURI, _ = url.Parse("")
	storeBulkURI, _ = url.Parse("")

	aaExec = filepath.Join(s.tempdir, "aa-exec")
	err := ioutil.WriteFile(aaExec, []byte(mockAaExecScript), 0755)
	c.Assert(err, IsNil)

	runAppArmorParser = mockRunAppArmorParser

	makeMockSecurityEnv(c)
}
Пример #20
0
func (s *purgeSuite) SetUpTest(c *C) {
	s.tempdir = c.MkDir()
	dirs.SetRootDir(s.tempdir)
	os.MkdirAll(dirs.SnapMetaDir, 0755)
	os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}

	dirs.SnapSeccompDir = c.MkDir()
	dirs.SnapAppArmorDir = c.MkDir()

	runAppArmorParser = mockRunAppArmorParser

	makeMockSecurityEnv(c)
}
Пример #21
0
func (s *PartitionTestSuite) SetUpTest(c *C) {
	s.tempdir = c.MkDir()
	runLsblk = mockRunLsblkDualSnappy

	// custom mount target
	mountTarget = c.MkDir()

	// global roto
	dirs.SetRootDir(s.tempdir)
	err := os.MkdirAll(bootloaderGrubDir(), 0755)
	c.Assert(err, IsNil)
	err = os.MkdirAll(bootloaderUbootDir(), 0755)
	c.Assert(err, IsNil)

	c.Assert(mounts, DeepEquals, mountEntryArray(nil))
}
Пример #22
0
func (s *backendSuite) SetUpTest(c *C) {
	// Isolate this test to a temporary directory
	s.rootDir = c.MkDir()
	dirs.SetRootDir(s.rootDir)
	// Mock away any real udev interaction
	s.udevadmCmd = testutil.MockCommand(c, "udevadm", "")
	// Prepare a directory for udev rules
	// NOTE: Normally this is a part of the OS snap.
	err := os.MkdirAll(dirs.SnapUdevRulesDir, 0700)
	c.Assert(err, IsNil)
	// Create a fresh repository for each test
	s.repo = interfaces.NewRepository()
	s.iface = &interfaces.TestInterface{InterfaceName: "iface"}
	err = s.repo.AddInterface(s.iface)
	c.Assert(err, IsNil)
}
Пример #23
0
func (s *lightweightSuite) SetUpTest(c *check.C) {
	s.d = c.MkDir()
	dirs.SetRootDir(s.d)

	s.MkInstalled(c, snap.TypeApp, dirs.SnapSnapsDir, "foo", "bar", "1.0", true)
	s.MkRemoved(c, "foo.bar", "0.9")
	s.MkRemoved(c, "foo.baz", "0.8")

	s.MkInstalled(c, snap.TypeFramework, dirs.SnapSnapsDir, "fmk", "", "123", false)
	s.MkInstalled(c, snap.TypeFramework, dirs.SnapSnapsDir, "fmk", "", "120", true)
	s.MkInstalled(c, snap.TypeFramework, dirs.SnapSnapsDir, "fmk", "", "119", false)
	s.MkRemoved(c, "fmk", "12a1")

	s.MkRemoved(c, "fmk2", "4.2.0ubuntu1")

	s.MkInstalled(c, snap.TypeGadget, dirs.SnapSnapsDir, "a-gadget", "", "3", false)
}
Пример #24
0
func (s *backendSuite) SetUpTest(c *C) {
	// Isolate this test to a temporary directory
	s.rootDir = c.MkDir()
	dirs.SetRootDir(s.rootDir)
	// Prepare a directory for apparmor profiles.
	// NOTE: Normally this is a part of the OS snap.
	err := os.MkdirAll(dirs.SnapAppArmorDir, 0700)
	c.Assert(err, IsNil)
	err = os.MkdirAll(dirs.AppArmorCacheDir, 0700)
	c.Assert(err, IsNil)
	// Mock away any real apparmor interaction
	s.parserCmd = testutil.MockCommand(c, "apparmor_parser", fakeAppArmorParser)
	// Create a fresh repository for each test
	s.repo = interfaces.NewRepository()
	s.iface = &interfaces.TestInterface{InterfaceName: "iface"}
	err = s.repo.AddInterface(s.iface)
	c.Assert(err, IsNil)
}
Пример #25
0
func (s *SquashfsTestSuite) SetUpTest(c *C) {
	s.BaseTest.SetUpTest(c)

	dirs.SetRootDir(c.MkDir())
	os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)

	// ensure we do not run a real systemd
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		s.systemdCmds = append(s.systemdCmds, cmd)
		return []byte("ActiveState=inactive\n"), nil
	}

	// mock the boot variable writing for the tests
	s.bootloader = newMockBootloader(c.MkDir())
	findBootloader = func() (partition.Bootloader, error) {
		return s.bootloader, nil
	}

	s.AddCleanup(func() { findBootloader = partition.FindBootloader })
}
Пример #26
0
func ExamplePartBag() {
	d, _ := ioutil.TempDir("", "test-xyzzy-")
	defer os.RemoveAll(d)
	dirs.SetRootDir(d)
	os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.1"), 0755)
	os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.2"), 0755)
	os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.5"), 0755)
	os.MkdirAll(filepath.Join(dirs.SnapDataDir, "baz", "0.4"), 0755)
	os.MkdirAll(filepath.Join(dirs.SnapDataDir, "qux", "0.5"), 0755)

	bags := lightweight.AllPartBags()

	for _, k := range []string{"foo.bar", "baz"} {
		bag := bags[k]
		fmt.Printf("Found %d versions for %s, type %q: %s\n",
			len(bag.Versions), bag.QualifiedName(), bag.Type, bag.Versions)
	}
	// Output:
	// Found 3 versions for foo.bar, type "app": [0.5 0.2 0.1]
	// Found 1 versions for baz, type "framework": [0.4]
}
Пример #27
0
func (s *snapmgrQuerySuite) SetUpTest(c *C) {
	st := state.New(nil)
	st.Lock()
	defer st.Unlock()

	s.st = st

	dirs.SetRootDir(c.MkDir())

	// Write a snap.yaml with fake name
	dname := filepath.Join(snap.MountDir("name1", 11), "meta")
	err := os.MkdirAll(dname, 0775)
	c.Assert(err, IsNil)
	fname := filepath.Join(dname, "snap.yaml")
	err = ioutil.WriteFile(fname, []byte(`
name: name0
version: 1.1
description: |
    Lots of text`), 0644)
	c.Assert(err, IsNil)

	dname = filepath.Join(snap.MountDir("name1", 12), "meta")
	err = os.MkdirAll(dname, 0775)
	c.Assert(err, IsNil)
	fname = filepath.Join(dname, "snap.yaml")
	err = ioutil.WriteFile(fname, []byte(`
name: name0
version: 1.2
description: |
    Lots of text`), 0644)
	c.Assert(err, IsNil)

	snapstate.Set(st, "name1", &snapstate.SnapState{
		Active: true,
		Sequence: []*snap.SideInfo{
			{OfficialName: "name1", Revision: 11, EditedSummary: "s11"},
			{OfficialName: "name1", Revision: 12, EditedSummary: "s12"},
		},
	})
}
Пример #28
0
func (s *SystemdTestSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	err := os.MkdirAll(dirs.SnapServicesDir, 0755)
	c.Assert(err, IsNil)

	// force UTC timezone, for reproducible timestamps
	os.Setenv("TZ", "")

	SystemctlCmd = s.myRun
	s.i = 0
	s.argses = nil
	s.errors = nil
	s.outs = nil

	JournalctlCmd = s.myJctl
	s.j = 0
	s.jsvcs = nil
	s.jouts = nil
	s.jerrs = nil

	s.rep = new(testreporter)
}
Пример #29
0
func (s *lightweightSuite) SetUpTest(c *check.C) {
	s.d = c.MkDir()
	dirs.SetRootDir(s.d)

	s.MkInstalled(c, pkg.TypeApp, dirs.SnapAppsDir, "foo", "bar", "1.0", true)
	s.MkRemoved(c, "foo.bar", "0.9")
	s.MkRemoved(c, "foo.baz", "0.8")

	s.MkInstalled(c, pkg.TypeFramework, dirs.SnapAppsDir, "fmk", "", "123", false)
	s.MkInstalled(c, pkg.TypeFramework, dirs.SnapAppsDir, "fmk", "", "120", true)
	s.MkInstalled(c, pkg.TypeFramework, dirs.SnapAppsDir, "fmk", "", "119", false)
	s.MkRemoved(c, "fmk", "12a1")

	s.MkRemoved(c, "fmk2", "4.2.0ubuntu1")

	s.MkInstalled(c, pkg.TypeOem, dirs.SnapOemDir, "an-oem", "", "3", false)

	newCoreRepo = func() repo {
		// you can't ever have a removed systemimagepart, but for testing it'll do
		return mockrepo{removed.New(snappy.SystemImagePartName, snappy.SystemImagePartOrigin, "1", pkg.TypeCore)}
	}
}
Пример #30
0
func (s *FirstBootTestSuite) SetUpTest(c *C) {
	tempdir := c.MkDir()
	dirs.SetRootDir(tempdir)
	os.MkdirAll(dirs.SnapSnapsDir, 0755)
	stampFile = filepath.Join(c.MkDir(), "stamp")

	// mock the world!
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		return []byte("ActiveState=inactive\n"), nil
	}

	err := os.MkdirAll(filepath.Join(tempdir, "etc", "systemd", "system", "multi-user.target.wants"), 0755)
	c.Assert(err, IsNil)

	configMyApp := make(legacygadget.SystemConfig)
	configMyApp["hostname"] = "myhostname"

	s.gadgetConfig = make(legacygadget.SystemConfig)
	s.gadgetConfig["myapp"] = configMyApp

	s.globs = globs
	globs = nil
	s.ethdir = ethdir
	ethdir = c.MkDir()
	s.ifup = ifup
	ifup = "/bin/true"
	getGadget = s.getGadget
	newSnapMap = s.newSnapMap
	newOverlord = s.newOverlord
	s.fakeOverlord = &fakeOverlord{
		configs: map[string]string{},
	}

	s.m = nil
	s.e = nil
	s.snapMap = nil
	s.snapMapErr = nil
}