def test_build_agent_config_with_interfaces_file(self): ajc = agent_jinja_cfg.AgentJinjaTemplater() self.conf.config(group="amphora_agent", agent_server_network_file='/etc/network/interfaces') self.conf.config(group="haproxy_amphora", use_upstart='False') expected_config = ('\n[DEFAULT]\n' 'debug = False\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' 'bind_host = 0.0.0.0\n' 'bind_port = 9443\n' 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' 'use_upstart = False\n' 'user_group = nogroup\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' 'heartbeat_key = TEST\n\n' '[amphora_agent]\n' 'agent_server_ca = ' '/etc/octavia/certs/client_ca.pem\n' 'agent_server_cert = ' '/etc/octavia/certs/server.pem\n' 'agent_server_network_dir = ' '/etc/network/interfaces.d/\n' 'agent_server_network_file = ' '/etc/network/interfaces\n' 'agent_request_read_timeout = 120\n' 'amphora_id = ' + AMP_ID) agent_cfg = ajc.build_agent_config(AMP_ID) self.assertEqual(expected_config, agent_cfg)
def test_build_agent_config(self): ajc = agent_jinja_cfg.AgentJinjaTemplater() # Test execution order could influence this with the test below self.conf.config(group='amphora_agent', agent_server_network_file=None) expected_config = ('\n[DEFAULT]\n' 'debug = False\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' 'bind_host = 0.0.0.0\n' 'bind_port = 9443\n' 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' 'use_upstart = True\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' 'heartbeat_key = TEST\n\n' '[amphora_agent]\n' 'agent_server_ca = ' '/etc/octavia/certs/client_ca.pem\n' 'agent_server_cert = ' '/etc/octavia/certs/server.pem\n' 'agent_server_network_dir = ' '/etc/network/interfaces.d/\n' 'agent_request_read_timeout = 180\n' 'amphora_id = ' + AMP_ID + '\n' 'amphora_udp_driver = keepalived_lvs\n\n' '[controller_worker]\n' 'loadbalancer_topology = ' + constants.TOPOLOGY_SINGLE) agent_cfg = ajc.build_agent_config(AMP_ID, constants.TOPOLOGY_SINGLE) self.assertEqual(expected_config, agent_cfg)
def execute(self, amphora_id, build_type_priority=constants.LB_CREATE_NORMAL_PRIORITY, ports=None, config_drive_files=None, server_group_id=None): """Create an amphora :returns: an amphora """ ports = ports or [] network_ids = CONF.controller_worker.amp_boot_network_list[:] config_drive_files = config_drive_files or {} user_data = None LOG.debug("Compute create execute for amphora with id %s", amphora_id) user_data_config_drive = CONF.controller_worker.user_data_config_drive key_name = CONF.controller_worker.amp_ssh_key_name # TODO(rm_work): amp_ssh_access_allowed is deprecated in Pike. # Remove the following two lines in the S release. ssh_access = CONF.controller_worker.amp_ssh_access_allowed key_name = None if not ssh_access else key_name try: if CONF.haproxy_amphora.build_rate_limit != -1: self.rate_limit.add_to_build_request_queue( amphora_id, build_type_priority) agent_cfg = agent_jinja_cfg.AgentJinjaTemplater() config_drive_files['/etc/octavia/amphora-agent.conf'] = ( agent_cfg.build_agent_config(amphora_id)) if user_data_config_drive: udtemplater = user_data_jinja_cfg.UserDataJinjaCfg() user_data = udtemplater.build_user_data_config( config_drive_files) config_drive_files = None compute_id = self.compute.build( name="amphora-" + amphora_id, amphora_flavor=CONF.controller_worker.amp_flavor_id, image_id=CONF.controller_worker.amp_image_id, image_tag=CONF.controller_worker.amp_image_tag, image_owner=CONF.controller_worker.amp_image_owner_id, key_name=key_name, sec_groups=CONF.controller_worker.amp_secgroup_list, network_ids=network_ids, port_ids=[port.id for port in ports], config_drive_files=config_drive_files, user_data=user_data, server_group_id=server_group_id) LOG.debug("Server created with id: %s for amphora id: %s", compute_id, amphora_id) return compute_id except Exception: LOG.exception("Compute create for amphora id: %s failed", amphora_id) raise
def execute(self, amphora_id, ports=None, config_drive_files=None): """Create an amphora :returns: an amphora """ ports = ports or [] config_drive_files = config_drive_files or {} LOG.debug("Compute create execute for amphora with id %s", amphora_id) try: agent_cfg = agent_jinja_cfg.AgentJinjaTemplater() config_drive_files['/etc/octavia/amphora-agent.conf'] = ( agent_cfg.build_agent_config(amphora_id)) compute_id = self.compute.build( name="amphora-" + amphora_id, amphora_flavor=CONF.controller_worker.amp_flavor_id, image_id=CONF.controller_worker.amp_image_id, key_name=CONF.controller_worker.amp_ssh_key_name, sec_groups=CONF.controller_worker.amp_secgroup_list, network_ids=[CONF.controller_worker.amp_network], port_ids=[port.id for port in ports], config_drive_files=config_drive_files) LOG.debug("Server created with id: %s for amphora id: %s", (compute_id, amphora_id)) return compute_id except Exception: LOG.exception(_LE("Compute create for amphora id: %s failed"), amphora_id) raise
def execute(self, amphora_id, ports=None, config_drive_files=None, server_group_id=None): """Create an amphora :returns: an amphora """ ports = ports or [] network_ids = CONF.controller_worker.amp_boot_network_list[:] config_drive_files = config_drive_files or {} user_data = None LOG.debug("Compute create execute for amphora with id %s", amphora_id) user_data_config_drive = CONF.controller_worker.user_data_config_drive ssh_access = CONF.controller_worker.amp_ssh_access_allowed ssh_key = CONF.controller_worker.amp_ssh_key_name key_name = None if not ssh_access else ssh_key try: agent_cfg = agent_jinja_cfg.AgentJinjaTemplater() config_drive_files['/etc/octavia/amphora-agent.conf'] = ( agent_cfg.build_agent_config(amphora_id)) if user_data_config_drive: udtemplater = user_data_jinja_cfg.UserDataJinjaCfg() user_data = udtemplater.build_user_data_config( config_drive_files) config_drive_files = None compute_id = self.compute.build( name="amphora-" + amphora_id, amphora_flavor=CONF.controller_worker.amp_flavor_id, image_id=CONF.controller_worker.amp_image_id, image_tag=CONF.controller_worker.amp_image_tag, image_owner=CONF.controller_worker.amp_image_owner_id, key_name=key_name, sec_groups=CONF.controller_worker.amp_secgroup_list, network_ids=network_ids, port_ids=[port.id for port in ports], config_drive_files=config_drive_files, user_data=user_data, server_group_id=server_group_id) LOG.debug("Server created with id: %s for amphora id: %s", compute_id, amphora_id) return compute_id except Exception: LOG.exception(_LE("Compute create for amphora id: %s failed"), amphora_id) raise
def test_build_agent_config_with_interfaces_file(self): ajc = agent_jinja_cfg.AgentJinjaTemplater() self.conf.config(group="amphora_agent", agent_server_network_file='/etc/network/interfaces') self.conf.config(group="haproxy_amphora", use_upstart='False') self.conf.config(group="amphora_agent", administrative_log_facility=1) self.conf.config(group="amphora_agent", user_log_facility=0) expected_config = ('\n[DEFAULT]\n' 'debug = False\n' 'use_syslog = True\n' 'syslog_log_facility = LOG_LOCAL1\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' 'bind_host = 0.0.0.0\n' 'bind_port = 9443\n' 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' 'use_upstart = False\n' 'user_log_facility = 0\n' 'administrative_log_facility = 1\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' 'heartbeat_key = TEST\n\n' '[amphora_agent]\n' 'agent_server_ca = ' '/etc/octavia/certs/client_ca.pem\n' 'agent_server_cert = ' '/etc/octavia/certs/server.pem\n' 'agent_server_network_dir = ' '/etc/network/interfaces.d/\n' 'agent_server_network_file = ' '/etc/network/interfaces\n' 'agent_request_read_timeout = 180\n' 'amphora_id = ' + AMP_ID + '\n' 'amphora_udp_driver = keepalived_lvs\n' 'agent_tls_protocol = TLSv1.2\n\n' '[controller_worker]\n' 'loadbalancer_topology = ' + constants.TOPOLOGY_ACTIVE_STANDBY) agent_cfg = ajc.build_agent_config(AMP_ID, constants.TOPOLOGY_ACTIVE_STANDBY) self.assertEqual(expected_config, agent_cfg)
def execute(self, amphora, flavor): # Extract any flavor based settings if flavor: topology = flavor.get(constants.LOADBALANCER_TOPOLOGY, CONF.controller_worker.loadbalancer_topology) else: topology = CONF.controller_worker.loadbalancer_topology # Build the amphora agent config agent_cfg_tmpl = agent_jinja_cfg.AgentJinjaTemplater() agent_config = agent_cfg_tmpl.build_agent_config(amphora.id, topology) # Push the new configuration to the amphroa try: self.amphora_driver.update_amphora_agent_config( amphora, agent_config) except driver_except.AmpDriverNotImplementedError: LOG.error('Amphora {} does not support agent configuration ' 'update. Please update the amphora image for this ' 'amphora. Skipping.'.format(amphora.id))
def execute(self, amphora_id, config_drive_files=None, build_type_priority=constants.LB_CREATE_NORMAL_PRIORITY, server_group_id=None, ports=None, flavor=None, availability_zone=None): """Create an amphora :returns: an amphora """ ports = ports or [] network_ids = CONF.controller_worker.amp_boot_network_list[:] config_drive_files = config_drive_files or {} user_data = None LOG.debug("Compute create execute for amphora with id %s", amphora_id) user_data_config_drive = CONF.controller_worker.user_data_config_drive key_name = CONF.controller_worker.amp_ssh_key_name # Apply an Octavia flavor customizations if flavor: topology = flavor.get(constants.LOADBALANCER_TOPOLOGY, CONF.controller_worker.loadbalancer_topology) amp_compute_flavor = flavor.get( constants.COMPUTE_FLAVOR, CONF.controller_worker.amp_flavor_id) else: topology = CONF.controller_worker.loadbalancer_topology amp_compute_flavor = CONF.controller_worker.amp_flavor_id if availability_zone: amp_availability_zone = availability_zone.get( constants.COMPUTE_ZONE) amp_network = availability_zone.get(constants.MANAGEMENT_NETWORK) if amp_network: network_ids = [amp_network] else: amp_availability_zone = None try: if CONF.haproxy_amphora.build_rate_limit != -1: self.rate_limit.add_to_build_request_queue( amphora_id, build_type_priority) agent_cfg = agent_jinja_cfg.AgentJinjaTemplater() config_drive_files['/etc/octavia/amphora-agent.conf'] = ( agent_cfg.build_agent_config(amphora_id, topology)) logging_cfg = logging_jinja_cfg.LoggingJinjaTemplater( CONF.amphora_agent.logging_template_override) config_drive_files['/etc/rsyslog.d/10-rsyslog.conf'] = ( logging_cfg.build_logging_config()) if user_data_config_drive: udtemplater = user_data_jinja_cfg.UserDataJinjaCfg() user_data = udtemplater.build_user_data_config( config_drive_files) config_drive_files = None compute_id = self.compute.build( name="amphora-" + amphora_id, amphora_flavor=amp_compute_flavor, image_id=CONF.controller_worker.amp_image_id, image_tag=CONF.controller_worker.amp_image_tag, image_owner=CONF.controller_worker.amp_image_owner_id, key_name=key_name, sec_groups=CONF.controller_worker.amp_secgroup_list, network_ids=network_ids, port_ids=[port.id for port in ports], config_drive_files=config_drive_files, user_data=user_data, server_group_id=server_group_id, availability_zone=amp_availability_zone) LOG.debug("Server created with id: %s for amphora id: %s", compute_id, amphora_id) return compute_id except Exception: LOG.exception("Compute create for amphora id: %s failed", amphora_id) raise
def test_build_agent_config(self): ajc = agent_jinja_cfg.AgentJinjaTemplater() agent_cfg = ajc.build_agent_config(AMP_ID) self.assertEqual(self.expected_config, agent_cfg)