~ubuntu-branches/ubuntu/precise/nova/precise

« back to all changes in this revision

Viewing changes to nova/tests/test_policy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandleman, Chuck Short
  • Date: 2012-03-02 11:04:04 UTC
  • mfrom: (1.1.47)
  • Revision ID: package-import@ubuntu.com-20120302110404-fr230yakr8hov3dj
Tags: 2012.1~e4-0ubuntu1
[ Adam Gandleman ]
* debian/patches/libvirt-use-console-pipe.patch: Refreshed. 
* debain/nova-volume.upstart.in: Ensure lock directory is created
  (LP: #940780)
* debain/control: Fix nova-compute-$flavor Depends
* debian/control: Add python-iso8601 to python-nova Depends

[ Chuck Short ]
* debian/rules: Fix FTBFS.
* Merge Ubuntu/Debian packaging:
  - Thanks to Julien Danjou, Ghe Rivero, and Thomas Goirand
  - debian/copyright: Update copyright file.
  - debian/nova-api.init, debian/nova-compute.init,
    debian/nova-network.init, debian/nova-objectstore,
    debian/nova-scheduler, debian/nova-volume.init:
    Synchronize init scripts.
  - nova-common.install, debian/rules: Install policy.json
  - debian/rules, debian/nova-xcp-network.install,
    debian/nova-xcp-plugins.install, nova-xcp-plugins.postrm,
    debian/nova-xcp-plugins.doc, debian/nova-xcp-plugins.postinst,
    debian/README.xcp_and_openstack, debian/control,
    debian/ubuntu_xen-openvswitch-nova.rules,
    debian/patches/path-to-the-xenhost.conf-fixup.patch:
    Add Xen XCP support.
  - debian/control,
    debian/nova-compute-{kvm,lxc,qemu,xen,uml}.postinst: Make
    nova-compute a virtual package.
  - Dropped ubuntu_ubuntu_control_vars: We dont use it
* New upstream release.
* Dropped python-babel, it will be handled by langpacks.
* debian/patches/ec2-fixes.patch: Backport turnk fix for ec2
  permissions.
* debian/patches/path-to-the-xenhost.conf-fixup.patch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Test of Policy Engine For Nova"""
19
19
 
 
20
import os.path
20
21
import StringIO
21
 
import tempfile
22
22
import urllib2
23
23
 
24
24
from nova.common import policy as common_policy
28
28
import nova.common.policy
29
29
from nova import policy
30
30
from nova import test
 
31
from nova import utils
31
32
 
32
33
FLAGS = flags.FLAGS
33
34
 
36
37
    def setUp(self):
37
38
        super(PolicyFileTestCase, self).setUp()
38
39
        policy.reset()
39
 
        _, self.tmpfilename = tempfile.mkstemp()
40
 
        self.flags(policy_file=self.tmpfilename)
41
40
        self.context = context.RequestContext('fake', 'fake')
42
41
        self.target = {}
43
42
 
46
45
        policy.reset()
47
46
 
48
47
    def test_modified_policy_reloads(self):
49
 
        action = "example:test"
50
 
        with open(self.tmpfilename, "w") as policyfile:
51
 
            policyfile.write("""{"example:test": []}""")
52
 
        policy.enforce(self.context, action, self.target)
53
 
        with open(self.tmpfilename, "w") as policyfile:
54
 
            policyfile.write("""{"example:test": ["false:false"]}""")
55
 
        # NOTE(vish): reset stored policy cache so we don't have to sleep(1)
56
 
        policy._POLICY_CACHE = {}
57
 
        self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
58
 
                          self.context, action, self.target)
 
48
        with utils.tempdir() as tmpdir:
 
49
            tmpfilename = os.path.join(tmpdir, 'policy')
 
50
            self.flags(policy_file=tmpfilename)
 
51
 
 
52
            action = "example:test"
 
53
            with open(tmpfilename, "w") as policyfile:
 
54
                policyfile.write("""{"example:test": []}""")
 
55
            policy.enforce(self.context, action, self.target)
 
56
            with open(tmpfilename, "w") as policyfile:
 
57
                policyfile.write("""{"example:test": ["false:false"]}""")
 
58
            # NOTE(vish): reset stored policy cache so we don't have to
 
59
            # sleep(1)
 
60
            policy._POLICY_CACHE = {}
 
61
            self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
 
62
                              self.context, action, self.target)
59
63
 
60
64
 
61
65
class PolicyTestCase(test.TestCase):