~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/unit/test_policy.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import urllib2
21
21
 
22
22
import mock
23
 
from oslo.config import cfg
24
 
from oslo.serialization import jsonutils
25
 
from oslo.utils import importutils
 
23
from oslo_config import cfg
 
24
from oslo_serialization import jsonutils
 
25
from oslo_utils import importutils
26
26
import six
27
27
import six.moves.urllib.request as urlrequest
28
28
 
40
40
class PolicyFileTestCase(base.BaseTestCase):
41
41
    def setUp(self):
42
42
        super(PolicyFileTestCase, self).setUp()
43
 
        self.addCleanup(policy.reset)
44
43
        self.context = context.Context('fake', 'fake', is_admin=False)
45
44
        self.target = {'tenant_id': 'fake'}
46
45
 
66
65
class PolicyTestCase(base.BaseTestCase):
67
66
    def setUp(self):
68
67
        super(PolicyTestCase, self).setUp()
69
 
        self.addCleanup(policy.reset)
70
68
        # NOTE(vish): preload rules to circumvent reloading from file
71
69
        rules = {
72
70
            "true": '@',
174
172
            jsonutils.dump(self.rules, policyfile)
175
173
        cfg.CONF.set_override('policy_file', tmpfilename)
176
174
        policy.refresh()
177
 
        self.addCleanup(policy.reset)
178
175
 
179
176
        self.context = context.Context('fake', 'fake')
180
177
 
201
198
 
202
199
class NeutronPolicyTestCase(base.BaseTestCase):
203
200
 
 
201
    def fakepolicyinit(self, **kwargs):
 
202
        enf = policy._ENFORCER
 
203
        enf.set_rules(common_policy.Rules(self.rules))
 
204
 
204
205
    def setUp(self):
205
206
        super(NeutronPolicyTestCase, self).setUp()
206
207
        policy.refresh()
207
 
        self.addCleanup(policy.reset)
208
208
        self.admin_only_legacy = "role:admin"
209
209
        self.admin_or_owner_legacy = "role:admin or tenant_id:%(tenant_id)s"
210
210
        # Add a Fake 'something' resource to RESOURCE_ATTRIBUTE_MAP
245
245
                            "rule:shared"
246
246
        }.items())
247
247
 
248
 
        def fakepolicyinit(**kwargs):
249
 
            enf = policy._ENFORCER
250
 
            enf.set_rules(common_policy.Rules(self.rules))
251
 
 
252
248
        def remove_fake_resource():
253
249
            del attributes.RESOURCE_ATTRIBUTE_MAP["%ss" % FAKE_RESOURCE_NAME]
254
250
 
255
251
        self.patcher = mock.patch.object(neutron.policy,
256
252
                                         'init',
257
 
                                         new=fakepolicyinit)
 
253
                                         new=self.fakepolicyinit)
258
254
        self.patcher.start()
259
255
        self.addCleanup(remove_fake_resource)
260
256
        self.context = context.Context('fake', 'fake', roles=['user'])
500
496
        # Trigger a policy with rule admin_or_owner
501
497
        action = "create_network"
502
498
        target = {'tenant_id': 'fake'}
503
 
        policy.init()
 
499
        self.fakepolicyinit()
504
500
        self.assertRaises(exceptions.PolicyCheckError,
505
501
                          policy.enforce,
506
502
                          self.context, action, target)