def test_verify_share_driver_mode_option_type(self): with utils.tempdir() as tmpdir: tmpfilename = os.path.join(tmpdir, 'share_driver_mode.conf') with open(tmpfilename, "w") as configfile: configfile.write("""[DEFAULT]\nshare_driver_mode = fake""") # Add config file with updated opt driver.CONF.default_config_files = [configfile.name] # Reload config instance to use redefined opt driver.CONF.reload_config_files() share_driver = driver.ShareDriver() self.assertEqual('fake', share_driver.mode)
def test_modified_policy_reloads(self): with utils.tempdir() as tmpdir: tmpfilename = os.path.join(tmpdir, 'policy') self.flags(policy_file=tmpfilename) action = "example:test" with open(tmpfilename, "w") as policyfile: policyfile.write("""{"example:test": []}""") policy.enforce(self.context, action, self.target) with open(tmpfilename, "w") as policyfile: policyfile.write("""{"example:test": ["false:false"]}""") # NOTE(vish): reset stored policy cache so we don't have to # sleep(1) policy._POLICY_CACHE = {} self.assertRaises(exception.PolicyNotAuthorized, policy.enforce, self.context, action, self.target)
def __enter__(self): config_filename = 'fake_config' with utils.tempdir() as tmpdir: tmpfilename = os.path.join(tmpdir, '%s.conf' % config_filename) with open(tmpfilename, "w") as configfile: for group, opts in self.data.items(): configfile.write("""[%s]\n""" % group) for opt, value in opts.items(): configfile.write( """%(k)s = %(v)s\n""" % {'k': opt, 'v': value}) configfile.write("""\n""") # Add config file with updated opts CONF.default_config_files = [configfile.name] # Reload config instance to use redefined opts CONF.reload_config_files() return CONF
def test_modified_policy_reloads(self): with utils.tempdir() as tmpdir: tmpfilename = os.path.join(tmpdir, 'policy') CONF.set_override('policy_file', tmpfilename, group='oslo_policy') action = "example:test" with open(tmpfilename, "w") as policyfile: policyfile.write("""{"example:test": []}""") policy.init(tmpfilename) policy.enforce(self.context, action, self.target) with open(tmpfilename, "w") as policyfile: policyfile.write("""{"example:test": ["false:false"]}""") # NOTE(vish): reset stored policy cache so we don't have to # sleep(1) policy._ENFORCER.load_rules(True) self.assertRaises( exception.PolicyNotAuthorized, policy.enforce, self.context, action, self.target, )