예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
파일: utils.py 프로젝트: openstack/manila
    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
예제 #6
0
파일: utils.py 프로젝트: vponomaryov/manila
    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
예제 #7
0
 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,
         )
예제 #8
0
 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,
         )