def memcache(self): ctxt = {} ctxt['use_memcache'] = False if self.charm_instance: if (ch_utils.OPENSTACK_RELEASES.index(self.charm_instance.release) >= ch_utils.OPENSTACK_RELEASES.index('mitaka')): ctxt['use_memcache'] = True if ctxt['use_memcache']: # Trusty version of memcached does not support ::1 as a listen # address so use host file entry instead release = ch_host.lsb_release()['DISTRIB_CODENAME'].lower() if ch_ip.is_ipv6_disabled(): if ch_host.CompareHostReleases(release) > 'trusty': ctxt['memcache_server'] = '127.0.0.1' else: ctxt['memcache_server'] = 'localhost' ctxt['memcache_server_formatted'] = '127.0.0.1' ctxt['memcache_port'] = '11211' ctxt['memcache_url'] = '{}:{}'.format( ctxt['memcache_server_formatted'], ctxt['memcache_port']) else: if ch_host.CompareHostReleases(release) > 'trusty': ctxt['memcache_server'] = '::1' else: ctxt['memcache_server'] = 'ip6-localhost' ctxt['memcache_server_formatted'] = '[::1]' ctxt['memcache_port'] = '11211' ctxt['memcache_url'] = 'inet6:{}:{}'.format( ctxt['memcache_server_formatted'], ctxt['memcache_port']) return ctxt
def memcache(self): ctxt = {} ctxt['use_memcache'] = False if self.charm_instance: if (ch_utils.OPENSTACK_RELEASES.index( self.charm_instance.release) >= ch_utils.OPENSTACK_RELEASES.index('mitaka')): ctxt['use_memcache'] = True if ctxt['use_memcache']: # Trusty version of memcached does not support ::1 as a listen # address so use host file entry instead release = ch_host.lsb_release()['DISTRIB_CODENAME'].lower() if ch_ip.is_ipv6_disabled(): if ch_host.CompareHostReleases(release) > 'trusty': ctxt['memcache_server'] = '127.0.0.1' else: ctxt['memcache_server'] = 'localhost' ctxt['memcache_server_formatted'] = '127.0.0.1' ctxt['memcache_port'] = '11211' ctxt['memcache_url'] = '{}:{}'.format( ctxt['memcache_server_formatted'], ctxt['memcache_port']) else: if ch_host.CompareHostReleases(release) > 'trusty': ctxt['memcache_server'] = '::1' else: ctxt['memcache_server'] = 'ip6-localhost' ctxt['memcache_server_formatted'] = '[::1]' ctxt['memcache_port'] = '11211' ctxt['memcache_url'] = 'inet6:{}:{}'.format( ctxt['memcache_server_formatted'], ctxt['memcache_port']) return ctxt
def test_is_ipv6_disabled(self, mock_check_output): # verify that the function does look for the right thing mock_check_output.return_value = """ Some lines before net.ipv6.conf.all.disable_ipv6 = 1 Some lines afterward """ self.assertTrue(net_ip.is_ipv6_disabled()) mock_check_output.assert_called_once_with( ['sysctl', 'net.ipv6.conf.all.disable_ipv6'], stderr=subprocess.STDOUT, universal_newlines=True) # if it isn't there, it must return false mock_check_output.return_value = "" self.assertFalse(net_ip.is_ipv6_disabled()) # If the syscall returns an error, then return True def fake_check_call(*args, **kwargs): raise subprocess.CalledProcessError(['called'], 1) mock_check_output.side_effect = fake_check_call self.assertTrue(net_ip.is_ipv6_disabled())
def ipv6_enabled(self): """ @return True if IPv6 is enabled """ return not ch_ip.is_ipv6_disabled()