コード例 #1
0
    def __init__(self, api_server_ip, api_server_port, conf_sections, sandesh,
                 api_server_obj=None):
        if api_server_ip == '0.0.0.0':
            self._vnc_api_ip = '127.0.0.1'
        else:
            self._vnc_api_ip = api_server_ip
        self._vnc_api_port = api_server_port
        self._config_sections = conf_sections
        self._auth_user = conf_sections.get('KEYSTONE', 'admin_user')
        self._auth_passwd = conf_sections.get('KEYSTONE', 'admin_password')
        self._auth_tenant = conf_sections.get('KEYSTONE', 'admin_tenant_name')
        self._api_server_obj = api_server_obj

        try:
            exts_enabled = conf_sections.getboolean(
                'NEUTRON', 'contrail_extensions_enabled')
        except (configparser.NoSectionError, configparser.NoOptionError):
            exts_enabled = True
        self._contrail_extensions_enabled = exts_enabled

        try:
            strict = conf_sections.getboolean('NEUTRON',
                                              'strict_compliance')
        except (configparser.NoSectionError, configparser.NoOptionError):
            strict = False
        self._strict_compliance = strict

        try:
            _vnc_connection_cache_size = int(
                conf_sections.get("DEFAULTS", "vnc_connection_cache_size"))
        except configparser.NoOptionError:
            _vnc_connection_cache_size = 0

        try:
            self._multi_tenancy = conf_sections.get(
                'DEFAULTS', 'multi_tenancy')
        except configparser.NoOptionError:
            self._multi_tenancy = True

        try:
            self._list_optimization_enabled = \
                conf_sections.get('DEFAULTS', 'list_optimization_enabled')
        except configparser.NoOptionError:
            self._list_optimization_enabled = False

        try:
            self._sn_host_route = conf_sections.get('DEFAULTS',
                                                    'apply_subnet_host_routes')
        except configparser.NoOptionError:
            self._sn_host_route = False

        self._cfgdb = None
        self._cfgdb_map = CacheContainer(_vnc_connection_cache_size) \
            if _vnc_connection_cache_size > 0 else dict()

        global LOG
        LOG = sandesh.logger()
        self.logger = LOG
コード例 #2
0
    def test_cache_container_trimming(self):
        c = CacheContainer(5)
        l = ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm']

        for index, value in enumerate(l):
            c[value] = index + 1

        self.assertEqual(len(c.dictionary.keys()), 5)
        self.assertEqual(set(l[-5:]), set(c.dictionary.keys()))
コード例 #3
0
    def test_cache_container_fetch(self):
        c = CacheContainer(5)
        l = ['a', 'b', 'c', 'd', 'e']

        for index, value in enumerate(l):
            c[value] = index + 1

        self.assertEqual(set(l), set(c.dictionary.keys()))

        # get the oldest value and check on the next set its not lost
        _ = c['a']
        c['f'] = 6
        self.assertEqual(set(['c', 'd', 'e', 'f', 'a']),
                         set(c.dictionary.keys()))

        # put a value for the oldest key and check its not lost
        c['c'] = 'x'
        self.assertEqual(c['c'], 'x')
        self.assertEqual(set(['d', 'e', 'f', 'a', 'c']),
                         set(c.dictionary.keys()))

        c['g'] = 7
        self.assertEqual(set(['e', 'f', 'a', 'c', 'g']),
                         set(c.dictionary.keys()))