def test_neutron_context_multi_vip(self, mock_is_clustered, mock_config,
                                       mock_use_local_neutron_api,
                                       _os_release):
        self.https.return_value = False
        mock_is_clustered.return_value = True
        config = {
            'vip': '10.0.0.1 10.0.1.1 10.0.2.1',
            'os-internal-network': '10.0.1.0/24',
            'os-admin-network': '10.0.0.0/24',
            'os-public-network': '10.0.2.0/24'
        }
        mock_config.side_effect = lambda key: config.get(key)

        mock_use_local_neutron_api.return_value = False
        ctxt = context.NeutronCCContext()()
        self.assertEqual(ctxt['nova_url'], 'http://10.0.1.1:8774/v2')
        self.assertFalse('neutron_url' in ctxt)

        mock_use_local_neutron_api.return_value = True
        ctxt = context.NeutronCCContext()()
        self.assertEqual(ctxt['nova_url'], 'http://10.0.1.1:8774/v2')
        self.assertEqual(ctxt['neutron_url'], 'http://10.0.1.1:9696')
def resource_map():
    '''
    Dynamically generate a map of resources that will be managed for a single
    hook execution.
    '''
    resource_map = deepcopy(BASE_RESOURCE_MAP)

    if os.path.exists('/etc/apache2/conf-available'):
        resource_map.pop(APACHE_CONF)
    else:
        resource_map.pop(APACHE_24_CONF)

    resource_map[NOVA_CONF]['contexts'].append(
        nova_cc_context.NeutronCCContext())

    if os_release('nova-common') >= 'mitaka':
        resource_map[NOVA_CONF]['contexts'].append(
            nova_cc_context.NovaAPISharedDBContext(relation_prefix='novaapi',
                                                   database='nova_api',
                                                   ssl_dir=NOVA_CONF_DIR))

    if console_attributes('services'):
        resource_map[NOVA_CONF]['services'] += \
            console_attributes('services')

    if (config('enable-serial-console')
            and os_release('nova-common') >= 'juno'):
        resource_map[NOVA_CONF]['services'] += \
            SERIAL_CONSOLE['services']

    # also manage any configs that are being updated by subordinates.
    vmware_ctxt = context.SubordinateConfigContext(interface='nova-vmware',
                                                   service='nova',
                                                   config_file=NOVA_CONF)
    vmware_ctxt = vmware_ctxt()
    if vmware_ctxt and 'services' in vmware_ctxt:
        for s in vmware_ctxt['services']:
            if s not in resource_map[NOVA_CONF]['services']:
                resource_map[NOVA_CONF]['services'].append(s)

    return resource_map
Esempio n. 3
0
def resource_map(actual_services=True):
    '''
    Dynamically generate a map of resources that will be managed for a single
    hook execution.

    :param actual_services: Whether to return the actual services that run on a
        unit (ie. apache2) or the services defined in BASE_SERVICES
        (ie.nova-placement-api).
    '''
    resource_map = deepcopy(BASE_RESOURCE_MAP)

    if os.path.exists('/etc/apache2/conf-available'):
        resource_map.pop(APACHE_CONF)
    else:
        resource_map.pop(APACHE_24_CONF)

    resource_map[NOVA_CONF]['contexts'].append(
        nova_cc_context.NeutronCCContext())

    release = os_release('nova-common')
    cmp_os_release = CompareOpenStackReleases(release)
    if cmp_os_release >= 'mitaka':
        resource_map[NOVA_CONF]['contexts'].append(
            nova_cc_context.NovaAPISharedDBContext(relation_prefix='novaapi',
                                                   database='nova_api',
                                                   ssl_dir=NOVA_CONF_DIR))

    if console_attributes('services'):
        resource_map[NOVA_CONF]['services'] += console_attributes('services')
        # nova-consoleauth will be managed by pacemaker, if
        # single-nova-consoleauth is used, then don't monitor for the
        # nova-consoleauth service to be started (LP: #1660244).
        if config('single-nova-consoleauth') and relation_ids('ha'):
            services = resource_map[NOVA_CONF]['services']
            if 'nova-consoleauth' in services:
                services.remove('nova-consoleauth')

    if (config('enable-serial-console') and cmp_os_release >= 'juno'):
        resource_map[NOVA_CONF]['services'] += SERIAL_CONSOLE['services']

    # also manage any configs that are being updated by subordinates.
    vmware_ctxt = context.SubordinateConfigContext(interface='nova-vmware',
                                                   service='nova',
                                                   config_file=NOVA_CONF)
    vmware_ctxt = vmware_ctxt()
    if vmware_ctxt and 'services' in vmware_ctxt:
        for s in vmware_ctxt['services']:
            if s not in resource_map[NOVA_CONF]['services']:
                resource_map[NOVA_CONF]['services'].append(s)

    if enable_memcache(release=release):
        resource_map[MEMCACHED_CONF] = {
            'contexts': [context.MemcacheContext()],
            'services': ['memcached']
        }

    if actual_services and placement_api_enabled():
        for cfile in resource_map:
            svcs = resource_map[cfile]['services']
            if 'nova-placement-api' in svcs:
                svcs.remove('nova-placement-api')
                if 'apache2' not in svcs:
                    svcs.append('apache2')
        wsgi_script = "/usr/bin/nova-placement-api"
        resource_map[WSGI_NOVA_PLACEMENT_API_CONF] = {
            'contexts': [
                context.WSGIWorkerConfigContext(name="nova",
                                                script=wsgi_script),
                nova_cc_context.HAProxyContext()
            ],
            'services': ['apache2']
        }
    elif not placement_api_enabled():
        for cfile in resource_map:
            svcs = resource_map[cfile]['services']
            if 'nova-placement-api' in svcs:
                svcs.remove('nova-placement-api')

    return resource_map
Esempio n. 4
0
         context.ImageServiceContext(),
         context.OSConfigFlagContext(),
         context.SubordinateConfigContext(interface='nova-vmware',
                                          service='nova',
                                          config_file=NOVA_CONF),
         nova_cc_context.NovaCellContext(),
         context.SyslogContext(),
         context.LogLevelContext(),
         nova_cc_context.HAProxyContext(),
         nova_cc_context.IdentityServiceContext(service='nova',
                                                service_user='******'),
         nova_cc_context.VolumeServiceContext(),
         context.ZeroMQContext(),
         context.NotificationDriverContext(),
         nova_cc_context.NovaIPv6Context(),
         nova_cc_context.NeutronCCContext(),
         nova_cc_context.NovaConfigContext(),
         nova_cc_context.InstanceConsoleContext(),
         nova_cc_context.ConsoleSSLContext(),
         nova_cc_context.CloudComputeContext(),
         context.InternalEndpointContext('nova-common'),
         nova_cc_context.NeutronAPIContext(),
         nova_cc_context.SerialConsoleContext(),
         context.MemcacheContext()
     ],
 }),
 (NOVA_API_PASTE, {
     'services': [s for s in resolve_services() if 'api' in s],
     'contexts': [
         nova_cc_context.IdentityServiceContext(),
         nova_cc_context.APIRateLimitingContext()
Esempio n. 5
0
def resource_map():
    '''
    Dynamically generate a map of resources that will be managed for a single
    hook execution.
    '''
    resource_map = deepcopy(BASE_RESOURCE_MAP)

    if relation_ids('nova-volume-service'):
        # if we have a relation to a nova-volume service, we're
        # also managing the nova-volume API endpoint (legacy)
        resource_map['/etc/nova/nova.conf']['services'].append(
            'nova-api-os-volume')

    net_manager = network_manager()

    if os.path.exists('/etc/apache2/conf-available'):
        resource_map.pop(APACHE_CONF)
    else:
        resource_map.pop(APACHE_24_CONF)

    resource_map[NOVA_CONF]['contexts'].append(
        nova_cc_context.NeutronCCContext())
    # pop out irrelevant resources from the OrderedDict (easier than adding
    # them late)
    if net_manager != 'quantum':
        [
            resource_map.pop(k) for k in list(resource_map.iterkeys())
            if 'quantum' in k
        ]
    if net_manager != 'neutron':
        [
            resource_map.pop(k) for k in list(resource_map.iterkeys())
            if 'neutron' in k
        ]
    # add neutron plugin requirements. nova-c-c only needs the
    # neutron-server associated with configs, not the plugin agent.
    if net_manager in ['quantum', 'neutron']:
        plugin = neutron_plugin()
        if plugin:
            conf = neutron_plugin_attribute(plugin, 'config', net_manager)
            ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager)
                     or [])
            services = neutron_plugin_attribute(plugin, 'server_services',
                                                net_manager)
            resource_map[conf] = {}
            resource_map[conf]['services'] = services
            resource_map[conf]['contexts'] = ctxts
            resource_map[conf]['contexts'].append(
                nova_cc_context.NeutronCCContext())

            # update for postgres
            resource_map[conf]['contexts'].append(
                nova_cc_context.NeutronPostgresqlDBContext())

    if is_relation_made('neutron-api'):
        for k in list(resource_map.iterkeys()):
            # neutron-api runs neutron services
            if 'quantum' in k or 'neutron' in k:
                resource_map[k]['services'] = []
        resource_map[NOVA_CONF]['contexts'].append(
            nova_cc_context.NeutronAPIContext())

    # nova-conductor for releases >= G.
    if os_release('nova-common') not in ['essex', 'folsom']:
        resource_map['/etc/nova/nova.conf']['services'] += ['nova-conductor']

    if console_attributes('services'):
        resource_map['/etc/nova/nova.conf']['services'] += \
            console_attributes('services')

    # also manage any configs that are being updated by subordinates.
    vmware_ctxt = context.SubordinateConfigContext(interface='nova-vmware',
                                                   service='nova',
                                                   config_file=NOVA_CONF)
    vmware_ctxt = vmware_ctxt()
    if vmware_ctxt and 'services' in vmware_ctxt:
        for s in vmware_ctxt['services']:
            if s not in resource_map[NOVA_CONF]['services']:
                resource_map[NOVA_CONF]['services'].append(s)

    return resource_map
Esempio n. 6
0
         context.ImageServiceContext(),
         context.OSConfigFlagContext(),
         context.SubordinateConfigContext(interface='nova-vmware',
                                          service='nova',
                                          config_file=NOVA_CONF),
         nova_cc_context.NovaCellContext(),
         context.SyslogContext(),
         context.LogLevelContext(),
         nova_cc_context.HAProxyContext(),
         nova_cc_context.IdentityServiceContext(service='nova',
                                                service_user='******'),
         nova_cc_context.VolumeServiceContext(),
         context.ZeroMQContext(),
         context.NotificationDriverContext(),
         nova_cc_context.NovaIPv6Context(),
         nova_cc_context.NeutronCCContext(),
         nova_cc_context.NovaConfigContext(),
         nova_cc_context.InstanceConsoleContext(),
         nova_cc_context.ConsoleSSLContext(),
         nova_cc_context.CloudComputeContext()
     ],
 }),
 (NOVA_API_PASTE, {
     'services': [s for s in BASE_SERVICES if 'api' in s],
     'contexts': [
         nova_cc_context.IdentityServiceContext(),
         nova_cc_context.APIRateLimitingContext()
     ],
 }),
 (QUANTUM_CONF, {
     'services': ['quantum-server'],