def _prepare_policy(self): policy = jsonutils.load(open(CONF.policy_file)) # Convert all actions to require specified role for action, rule in policy.iteritems(): policy[action] = 'role:%s' % self.role self.policy_dir = self.useFixture(fixtures.TempDir()) self.policy_file = os.path.join(self.policy_dir.path, 'policy.json') with open(self.policy_file, 'w') as f: jsonutils.dump(policy, f)
def setUp(self): """Copy live policy.json file and convert all actions to allow users of the specified role only """ super(RoleBasedPolicyFixture, self).setUp() policy = jsonutils.load(open(CONF.policy_file)) # Convert all actions to require specified role for action, rule in policy.iteritems(): policy[action] = "role:%s" % self.role self.policy_dir = self.useFixture(fixtures.TempDir()) self.policy_file_name = os.path.join(self.policy_dir.path, "policy.json") with open(self.policy_file_name, "w") as policy_file: jsonutils.dump(policy, policy_file) CONF.set_override("policy_file", self.policy_file_name) nova.policy.reset() nova.policy.init() self.addCleanup(nova.policy.reset)
def setUp(self): """Copy live policy.json file and convert all actions to allow users of the specified role only """ super(RoleBasedPolicyFixture, self).setUp() policy = jsonutils.load(open(CONF.policy_file)) # Convert all actions to require specified role for action, rule in policy.iteritems(): policy[action] = 'role:%s' % self.role self.policy_dir = self.useFixture(fixtures.TempDir()) self.policy_file_name = os.path.join(self.policy_dir.path, 'policy.json') with open(self.policy_file_name, 'w') as policy_file: jsonutils.dump(policy, policy_file) CONF.set_override('policy_file', self.policy_file_name) nova.policy.reset() nova.policy.init() self.addCleanup(nova.policy.reset)