Beispiel #1
0
func (s *systemtestSuite) TestVolCLIPolicy(c *C) {
	policy1, err := s.readIntent(fmt.Sprintf("testdata/%s/policy1.json", getDriver()))
	c.Assert(err, IsNil)

	policy2, err := s.readIntent(fmt.Sprintf("testdata/%s/policy2.json", getDriver()))
	c.Assert(err, IsNil)

	_, err = s.uploadIntent("test1", "policy1")
	c.Assert(err, IsNil)

	defer func() {
		_, err := s.volcli("policy delete test1")
		c.Assert(err, IsNil)

		_, err = s.volcli("policy get test1")
		c.Assert(err, NotNil)
	}()

	_, err = s.uploadIntent("test2", "policy2")
	c.Assert(err, IsNil)

	defer func() {
		_, err := s.volcli("policy delete test2")
		c.Assert(err, IsNil)

		_, err = s.volcli("policy get test2")
		c.Assert(err, NotNil)
	}()

	out, err := s.volcli("policy get test1")
	c.Assert(err, IsNil)

	intentTarget := config.NewPolicy()
	c.Assert(json.Unmarshal([]byte(out), intentTarget), IsNil)
	policy1.FileSystems = map[string]string{"ext4": "mkfs.ext4 -m0 %"}

	policy1.Name = "test1"
	c.Assert(policy1, DeepEquals, intentTarget)
	c.Assert(err, IsNil)

	out, err = s.volcli("policy get test2")
	c.Assert(err, IsNil)

	intentTarget = config.NewPolicy()
	c.Assert(json.Unmarshal([]byte(out), intentTarget), IsNil)
	policy2.FileSystems = map[string]string{"ext4": "mkfs.ext4 -m0 %"}
	policy2.Name = "test2"
	c.Assert(policy2, DeepEquals, intentTarget)

	out, err = s.volcli("policy list")
	c.Assert(err, IsNil)

	// matches assertion below doesn't handle newlines too well
	out = strings.Replace(out, "\n", " ", -1)

	c.Assert(out, Matches, ".*test1.*")
	c.Assert(out, Matches, ".*test2.*")
}
Beispiel #2
0
func (s *systemtestSuite) readIntent(fn string) (*config.Policy, error) {
	content, err := ioutil.ReadFile(fn)
	if err != nil {
		return nil, err
	}

	cfg := config.NewPolicy()

	if err := json.Unmarshal(content, cfg); err != nil {
		return nil, err
	}

	return cfg, nil
}
Beispiel #3
0
func (d *DaemonConfig) handlePolicyUpload(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	policyName := vars["policy"]

	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		api.RESTHTTPError(w, errors.ReadBody.Combine(err))
		return
	}

	policy := config.NewPolicy()
	if err := json.Unmarshal(data, policy); err != nil {
		api.RESTHTTPError(w, errors.UnmarshalPolicy.Combine(err))
		return
	}

	if err := d.Config.PublishPolicy(policyName, policy); err != nil {
		api.RESTHTTPError(w, errors.PublishPolicy.Combine(err))
		return
	}
}
Beispiel #4
0
func (s *systemtestSuite) TestVolCLIPolicyNullDriver(c *C) {
	testDriverIntent, err := s.readIntent(fmt.Sprintf("testdata/%s/testdriver.json", getDriver()))
	c.Assert(err, IsNil)
	out, err := s.uploadIntent("test", "testdriver")
	c.Assert(err, IsNil, Commentf("output: %s", out))

	defer func() {
		out, err := s.volcli("policy delete test")
		c.Assert(err, IsNil, Commentf("output: %s", out))

		out, err = s.volcli("policy get test")
		c.Assert(err, NotNil, Commentf("output: %s", out))
	}()

	out, err = s.volcli("policy get test")
	c.Assert(err, IsNil, Commentf("output: %s", out))
	intentTarget := config.NewPolicy()
	c.Assert(json.Unmarshal([]byte(out), intentTarget), IsNil)
	testDriverIntent.Name = "test"
	testDriverIntent.FileSystems = map[string]string{"ext4": "mkfs.ext4 -m0 %"}
	c.Assert(testDriverIntent, DeepEquals, intentTarget)
}