def test_non_config_policy_file(self): tmpfilename = 'nova-policy.yaml' self.flags(policy_file=tmpfilename, group='oslo_policy') selected_policy_file = policy.pick_policy_file( policy_file='non-config-file') self.assertEqual(policy.CONF.oslo_policy.policy_file, tmpfilename) self.assertEqual(selected_policy_file, 'non-config-file')
def test_only_new_default_policy_file_exist(self): tmpfilename = os.path.join(self.tmpdir.path, 'policy.yaml') with open(tmpfilename, 'w') as fh: yaml.dump(self.data, fh) selected_policy_file = policy.pick_policy_file(policy_file=None) self.assertEqual(policy.CONF.oslo_policy.policy_file, 'policy.yaml') self.assertEqual(selected_policy_file, 'policy.yaml')
def test_only_old_default_policy_file_exist(self, mock_get): mock_get.return_value = cfg.LocationInfo(cfg.Locations.set_default, 'None') tmpfilename = os.path.join(self.tmpdir.path, 'policy.json') with open(tmpfilename, 'w') as fh: jsonutils.dump(self.data, fh) selected_policy_file = policy.pick_policy_file(policy_file=None) self.assertEqual(policy.CONF.oslo_policy.policy_file, 'policy.yaml') self.assertEqual(selected_policy_file, 'policy.json')
def test_both_default_policy_file_exist(self): tmpfilename1 = os.path.join(self.tmpdir.path, 'policy.json') with open(tmpfilename1, 'w') as fh: jsonutils.dump(self.data, fh) tmpfilename2 = os.path.join(self.tmpdir.path, 'policy.yaml') with open(tmpfilename2, 'w') as fh: yaml.dump(self.data, fh) selected_policy_file = policy.pick_policy_file(policy_file=None) self.assertEqual(policy.CONF.oslo_policy.policy_file, 'policy.yaml') self.assertEqual(selected_policy_file, 'policy.yaml')
def test_overridden_policy_file(self): tmpfilename = 'nova-policy.yaml' self.flags(policy_file=tmpfilename, group='oslo_policy') selected_policy_file = policy.pick_policy_file(policy_file=None) self.assertEqual(policy.CONF.oslo_policy.policy_file, tmpfilename) self.assertEqual(selected_policy_file, tmpfilename)