aboutsummaryrefslogtreecommitdiffstats
path: root/manifests/profile/base/rabbitmq.pp
blob: d90805a7d5a27ec2d967dbd65ffc6134b4d5b2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Copyright 2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: tripleo::profile::base::rabbitmq
#
# RabbitMQ profile for tripleo
#
# === Parameters
#
# [*config_variables*]
#   (Optional) RabbitMQ environment.
#   Defaults to hiera('rabbitmq_config_variables').
#
# [*environment*]
#   (Optional) RabbitMQ environment.
#   Defaults to hiera('rabbitmq_environment').
#
# [*ipv6*]
#   (Optional) Whether to deploy RabbitMQ on IPv6 network.
#   Defaults to str2bool(hiera('rabbit_ipv6', false)).
#
# [*kernel_variables*]
#   (Optional) RabbitMQ environment.
#   Defaults to hiera('rabbitmq_environment').
#
# [*nodes*]
#   (Optional) Array of host(s) for RabbitMQ nodes.
#   Defaults to hiera('rabbitmq_node_ips', []).
#
# [*step*]
#   (Optional) The current step in deployment. See tripleo-heat-templates
#   for more details.
#   Defaults to hiera('step')
#
class tripleo::profile::base::rabbitmq (
  $config_variables = hiera('rabbitmq_config_variables'),
  $environment      = hiera('rabbitmq_environment'),
  $ipv6             = str2bool(hiera('rabbit_ipv6', false)),
  $kernel_variables = hiera('rabbitmq_kernel_variables'),
  $nodes            = hiera('rabbitmq_node_ips', []),
  $step             = hiera('step'),
) {
  # IPv6 environment, necessary for RabbitMQ.
  if $ipv6 {
    $rabbit_env = merge($environment, {
      'RABBITMQ_SERVER_START_ARGS' => '"-proto_dist inet6_tcp"',
      'RABBITMQ_CTL_ERL_ARGS' => '"-proto_dist inet6_tcp"'
    })
  } else {
    $rabbit_env = $environment
  }

  $manage_service = hiera('rabbitmq::service_manage', true)
  if $step >= 1 {
    # Specific configuration for multi-nodes or when running with Pacemaker.
    if count($nodes) > 1 or ! $manage_service {
      class { '::rabbitmq':
        config_cluster          => $manage_service,
        cluster_nodes           => $nodes,
        config_kernel_variables => $kernel_variables,
        config_variables        => $config_variables,
        environment_variables   => $rabbit_env,
      }
      # when running multi-nodes without Pacemaker
      if $manage_service {
        rabbitmq_policy { 'ha-all@/':
          pattern    => '^(?!amq\.).*',
          definition => {
            'ha-mode' => 'all',
          },
        }
      }
    } else {
      # Standard configuration
      class { '::rabbitmq':
        config_kernel_variables => $kernel_variables,
        config_variables        => $config_variables,
        environment_variables   => $rabbit_env,
      }
    }
  }

}
class="n">strip().startswith(pattern): continue return line.strip().rstrip('\n') return None except OSError: return None def get_os(): """Get distro name. :returns: Return distro name as a string """ return ' '.join(platform.dist()) def get_kernel(): """Get kernel version. :returns: Return kernel version as a string """ return platform.release() def get_cpu(): """Get CPU information. :returns: Return CPU information as a string """ cpu = match_line('/proc/cpuinfo', 'model name') return cpu.split(':')[1] if cpu else cpu def get_nic(): """Get NIC(s) information. :returns: Return NIC(s) information as a list """ nics = [] output = subprocess.check_output('lspci', shell=True) output = output.decode(locale.getdefaultlocale()[1]) for line in output.split('\n'): for nic in S.getValue('NICS'): # lspci shows PCI addresses without domain part, i.e. last 7 chars if line.startswith(nic['pci'][-7:]): nics.append(''.join(line.split(':')[2:]).strip()) return nics def get_platform(): """Get platform information. Currently this is the motherboard vendor, name and socket count. :returns: Return platform information as a string """ output = [] with open('/sys/class/dmi/id/board_vendor', 'r') as file_: output.append(file_.readline().rstrip()) with open('/sys/class/dmi/id/board_name', 'r') as file_: output.append(file_.readline().rstrip()) num_nodes = len([name for name in os.listdir( '/sys/devices/system/node/') if name.startswith('node')]) output.append(''.join(['[', str(num_nodes), ' sockets]'])) return ' '.join(output).strip() def get_cpu_cores(): """Get number of CPU cores. :returns: Return number of CPU cores """ cores = 0 with open('/proc/cpuinfo') as file_: for line in file_: if line.rstrip('\n').startswith('processor'): cores += 1 continue # this code must be executed by at leat one core... if cores < 1: cores = 1 return cores def get_memory(): """Get memory information. :returns: amount of system memory as string together with unit """ memory = match_line('/proc/meminfo', 'MemTotal') return memory.split(':')[1].strip() if memory else memory def get_memory_bytes(): """Get memory information in bytes :returns: amount of system memory """ mem_list = get_memory().split(' ') mem = float(mem_list[0].strip()) if mem_list.__len__() > 1: unit = mem_list[1].strip().lower() if unit == 'kb': mem *= 1024 elif unit == 'mb': mem *= 1024 ** 2 elif unit == 'gb': mem *= 1024 ** 3 elif unit == 'tb': mem *= 1024 ** 4 return int(mem) def get_pids(proc_names_list): """ Get pid(s) of process(es) with given name(s) :returns: list with pid(s) of given processes or None if processes with given names are not running """ try: pids = subprocess.check_output(['sudo', 'LC_ALL=' + S.getValue('DEFAULT_CMD_LOCALE'), 'pidof'] + proc_names_list) except subprocess.CalledProcessError: # such process isn't running return None return list(map(str, map(int, pids.split()))) def get_pid(proc_name_str): """ Get pid(s) of process with given name :returns: list with pid(s) of given process or None if process with given name is not running """ return get_pids([proc_name_str]) def pid_isalive(pid): """ Checks if given PID is alive :param pid: PID of the process :returns: True if given process is running, False otherwise """ return os.path.isdir('/proc/' + str(pid)) # This function uses long switch per purpose, so let us suppress pylint warning too-many-branches # pylint: disable=R0912 def get_version(app_name): """ Get version of given application and its git tag :returns: dictionary {'name' : app_name, 'version' : app_version, 'git_tag' : app_git_tag) in case that version or git tag are not known or not applicaple, than None is returned for any unknown value """ app_version_file = { 'ovs' : os.path.join(S.getValue('OVS_DIR'), 'include/openvswitch/version.h'), 'dpdk' : os.path.join(S.getValue('RTE_SDK'), 'lib/librte_eal/common/include/rte_version.h'), 'qemu' : os.path.join(S.getValue('QEMU_DIR'), 'VERSION'), 'l2fwd' : os.path.join(S.getValue('ROOT_DIR'), 'src/l2fwd/l2fwd.c'), 'ixnet' : os.path.join(S.getValue('TRAFFICGEN_IXNET_LIB_PATH'), 'pkgIndex.tcl'), } def get_git_tag(path): """ get tag of recent commit from repository located at 'path' :returns: git tag in form of string with commit hash or None if there isn't any git repository at given path """ try: if os.path.isdir(path): return subprocess.check_output('cd {}; git rev-parse HEAD'.format(path), shell=True, stderr=subprocess.DEVNULL).decode().rstrip('\n') elif os.path.isfile(path): return subprocess.check_output('cd $(dirname {}); git log -1 --pretty="%H" {}'.format(path, path), shell=True, stderr=subprocess.DEVNULL).decode().rstrip('\n') else: return None except subprocess.CalledProcessError: return None app_version = None app_git_tag = None if app_name.lower().startswith('ovs'): app_version = match_line(app_version_file['ovs'], '#define OVS_PACKAGE_VERSION') if app_version: app_version = app_version.split('"')[1] app_git_tag = get_git_tag(S.getValue('OVS_DIR')) elif app_name.lower() in ['dpdk', 'testpmd']: tmp_ver = ['', '', ''] dpdk_16 = False with open(app_version_file['dpdk']) as file_: for line in file_: if not line.strip(): continue # DPDK version < 16 if line.startswith('#define RTE_VER_MAJOR'): tmp_ver[0] = line.rstrip('\n').split(' ')[2] # DPDK version < 16 elif line.startswith('#define RTE_VER_PATCH_LEVEL'): tmp_ver[2] = line.rstrip('\n').split(' ')[2] # DPDK version < 16 elif line.startswith('#define RTE_VER_PATCH_RELEASE'): release = line.rstrip('\n').split(' ')[2] if not '16' in release: tmp_ver[2] += line.rstrip('\n').split(' ')[2] # DPDK all versions elif line.startswith('#define RTE_VER_MINOR'): if dpdk_16: tmp_ver[2] = line.rstrip('\n').split(' ')[2] else: tmp_ver[1] = line.rstrip('\n').split(' ')[2] # DPDK all versions elif line.startswith('#define RTE_VER_SUFFIX'): tmp_ver[2] += line.rstrip('\n').split('"')[1] # DPDK version >= 16 elif line.startswith('#define RTE_VER_YEAR'): dpdk_16 = True tmp_ver[0] = line.rstrip('\n').split(' ')[2] # DPDK version >= 16 elif line.startswith('#define RTE_VER_MONTH'): tmp_ver[1] = '{:0>2}'.format(line.rstrip('\n').split(' ')[2]) # DPDK version >= 16 elif line.startswith('#define RTE_VER_RELEASE'): release = line.rstrip('\n').split(' ')[2] if not '16' in release: tmp_ver[2] += line.rstrip('\n').split(' ')[2] if len(tmp_ver[0]): app_version = '.'.join(tmp_ver) app_git_tag = get_git_tag(S.getValue('RTE_SDK')) elif app_name.lower().startswith('qemu'): app_version = match_line(app_version_file['qemu'], '') app_git_tag = get_git_tag(S.getValue('QEMU_DIR')) elif app_name.lower() == 'ixnet': app_version = match_line(app_version_file['ixnet'], 'package provide IxTclNetwork') if app_version: app_version = app_version.split(' ')[3] elif app_name.lower() == 'xena': try: app_version = S.getValue('XENA_VERSION') except AttributeError: # setting was not available after execution app_version = 'N/A' elif app_name.lower() == 'dummy': # get git tag of file with Dummy implementation app_git_tag = get_git_tag(os.path.join(S.getValue('ROOT_DIR'), 'tools/pkt_gen/dummy/dummy.py')) elif app_name.lower() == 'vswitchperf': app_git_tag = get_git_tag(S.getValue('ROOT_DIR')) elif app_name.lower() == 'l2fwd': app_version = match_line(app_version_file[app_name], 'MODULE_VERSION') if app_version: app_version = app_version.split('"')[1] app_git_tag = get_git_tag(app_version_file[app_name]) elif app_name.lower() in ['linux_bridge', 'buildin']: # without login into running VM, it is not possible to check bridge_utils version app_version = 'NA' app_git_tag = 'NA' return {'name' : app_name, 'version' : app_version, 'git_tag' : app_git_tag}