def test_allows_path(self):
     allows = {
         '/1': config_filter.AllowRule(),
         '2/22': config_filter.AllowRule(),
         '5': config_filter.AllowRule()
     }
     expected_config = {'1': '1', '2': {'22': '22'}}
     configfilter = config_filter.ConfigFilter(allows)
     filtered_config = configfilter.filter(self.config_)
     self.assertEqual(filtered_config, expected_config)
 def test_allows_asterisks(self):
     """test allows rules."""
     # keys in allows will be copied to dest.
     # if '*' in allows, all keys will be copied to dest.
     allows = {
         '*': config_filter.AllowRule(),
         '3': config_filter.AllowRule(),
         '5': config_filter.AllowRule()
     }
     configfilter = config_filter.ConfigFilter(allows)
     filtered_config = configfilter.filter(self.config_)
     self.assertEqual(filtered_config, self.config_)
 def test_init(self):
     config_filter.ConfigFilter(allows={
         'abc': config_filter.AllowRule(),
         'def': config_filter.AllowRule()
     },
                                denies={
                                    'def': config_filter.DenyRule(),
                                    'ghi': config_filter.DenyRule()
                                })
     config_filter.ConfigFilter(allows={
         u'abc': config_filter.AllowRule(),
         u'def': config_filter.AllowRule()
     },
                                denies={
                                    u'def': config_filter.DenyRule(),
                                    u'ghi': config_filter.DenyRule()
                                })
 def test_allows_asterrisks_in_path(self):
     allows = {'*/33': config_filter.AllowRule()}
     expected_config = {
         '2': {
             '33': {
                 '333': '333',
                 '44': '444'
             }
         },
         '3': {
             '33': '44'
         }
     }
     configfilter = config_filter.ConfigFilter(allows)
     filtered_config = configfilter.filter(self.config_)
     self.assertEqual(filtered_config, expected_config)
Esempio n. 5
0
from compass.config_management.utils import config_filter
from compass.config_management.utils import config_filter_callbacks
from compass.db import database
from compass.db.model import Adapter
from compass.db.model import Cluster
from compass.db.model import ClusterHost
from compass.db.model import ClusterState
from compass.db.model import HostState
from compass.db.model import LogProgressingHistory
from compass.db.model import Machine
from compass.db.model import Role
from compass.db.model import Switch
from compass.db.model import SwitchConfig
from compass.utils import setting_wrapper as setting

GET_CLUSTER_ALLOWS = {'*': config_filter.AllowRule()}
GET_CLUSTER_DENIES = {
    '/networking/global/ha_vip':
    config_filter.DenyRule(check=config_filter_callbacks.deny_if_empty)
}
GET_HOST_ALLOWS = {'*': config_filter.AllowRule()}
GET_HOST_DENIES = {
    '/roles':
    config_filter.DenyRule(check=config_filter_callbacks.deny_if_empty),
    '/dashboard_roles':
    config_filter.DenyRule(check=config_filter_callbacks.deny_if_empty),
    '/haproxy_roles':
    config_filter.DenyRule(check=config_filter_callbacks.deny_if_empty),
}
UPDATE_CLUSTER_ALLOWS = {
    '/security': config_filter.AllowRule(),