From 938922cb07c718d6f69afaedaee4b8ea080deb61 Mon Sep 17 00:00:00 2001 From: "bbaqar@plumgrid.com" <> Date: Wed, 9 Sep 2015 15:27:57 +0500 Subject: [PATCH 01/12] Backport commit --- README.md | 10 ++ tests/files/plumgrid-director-dense.yaml | 133 +++++++++++++++++++++++ tests/files/plumgrid-director.yaml | 9 -- tests/test.yaml | 2 + 4 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 tests/files/plumgrid-director-dense.yaml create mode 100644 tests/test.yaml diff --git a/README.md b/README.md index 7be9fa1..648060d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ +# About the PLUMgrid Platform + +The [PLUMgrid Platform](http://www.plumgrid.com/technology/plumgrid-platform/) is a software-only solution that provides a rich set of distributed network functions such as routers, switches, NAT, IPAM, DHCP, and it also supports security policies, end-to-end encryption, and third party Layer 4-7 service insertion. + +## About Plumgrid Director + +The Director is the brain of the PLUMgrid Platform. It is responsible for coordinating and managing all the other platform components. Based on PLUMgrid's distributed system architecture, it provides built-in high availability and scaling. The Director allows you to create Virtual Domains on a per tenant or application basis. + + # Overview Once deployed this charm performs the configurations required for a PLUMgrid Director and starts the essential services on the node. + # Usage Instructions on using the charm: diff --git a/tests/files/plumgrid-director-dense.yaml b/tests/files/plumgrid-director-dense.yaml new file mode 100644 index 0000000..1c00fa3 --- /dev/null +++ b/tests/files/plumgrid-director-dense.yaml @@ -0,0 +1,133 @@ +test: + series: 'trusty' + relations: + - - mysql + - keystone + - - nova-cloud-controller + - mysql + - - nova-cloud-controller + - rabbitmq-server + - - nova-cloud-controller + - glance + - - nova-cloud-controller + - keystone + - - nova-compute + - nova-cloud-controller + - - nova-compute + - mysql + - - nova-compute + - rabbitmq-server + - - nova-compute + - glance + - - glance + - mysql + - - glance + - keystone + - - glance + - cinder + - - mysql + - cinder + - - cinder + - rabbitmq-server + - - cinder + - nova-cloud-controller + - - cinder + - keystone + - - openstack-dashboard + - keystone + - - neutron-api + - mysql + - - neutron-api + - keystone + - - neutron-api + - rabbitmq-server + - - neutron-api + - nova-cloud-controller + - - neutron-api + - neutron-api-plumgrid + - - neutron-api-plumgrid + - plumgrid-edge + - - plumgrid-director + - plumgrid-edge + - - nova-compute + - plumgrid-edge + - - plumgrid-director + - plumgrid-gateway + services: + mysql: + charm: cs:trusty/mysql + num_units: 1 + to: 'lxc:plumgrid-director=0' + rabbitmq-server: + charm: cs:trusty/rabbitmq-server + num_units: 1 + to: 'lxc:plumgrid-director=0' + keystone: + charm: cs:trusty/keystone + num_units: 1 + options: + admin-password: plumgrid + openstack-origin: cloud:trusty-kilo + to: 'lxc:plumgrid-director=0' + nova-cloud-controller: + charm: cs:trusty/nova-cloud-controller + num_units: 1 + options: + console-access-protocol: novnc + network-manager: Neutron + openstack-origin: cloud:trusty-kilo + quantum-security-groups: 'yes' + to: 'lxc:plumgrid-director=0' + glance: + charm: cs:trusty/glance + num_units: 1 + options: + openstack-origin: cloud:trusty-kilo + to: 'lxc:plumgrid-director=0' + openstack-dashboard: + charm: cs:trusty/openstack-dashboard + num_units: 1 + options: + openstack-origin: cloud:trusty-kilo + to: 'lxc:plumgrid-director=0' + cinder: + charm: cs:trusty/cinder + num_units: 1 + options: + openstack-origin: cloud:trusty-kilo + to: 'lxc:plumgrid-director=0' + neutron-api: + charm: cs:~plumgrid-team/trusty/neutron-api + num_units: 1 + options: + neutron-plugin: plumgrid + neutron-security-groups: false + openstack-origin: cloud:trusty-kilo + plumgrid-password: plumgrid + plumgrid-username: plumgrid + plumgrid-virtual-ip: 192.168.100.250 + to: 'lxc:plumgrid-director=0' + neutron-api-plumgrid: + charm: cs:~plumgrid-team/trusty/neutron-api-plumgrid + options: + enable-metadata: True + plumgrid-director: + charm: cs:~plumgrid-team/trusty/plumgrid-director + num_units: 1 + constraints: "root-disk=30G mem=8G cpu-cores=8" + options: + plumgrid-virtual-ip: 192.168.100.250 + nova-compute: + charm: cs:~plumgrid-team/trusty/nova-compute + num_units: 1 + options: + enable-live-migration: true + enable-resize: true + migration-auth-type: ssh + openstack-origin: cloud:trusty-kilo + to: '0' + plumgrid-edge: + charm: cs:~plumgrid-team/trusty/plumgrid-edge + plumgrid-gateway: + charm: cs:~plumgrid-team/trusty/plumgrid-gateway + num_units: 1 diff --git a/tests/files/plumgrid-director.yaml b/tests/files/plumgrid-director.yaml index a8e2245..a1a870f 100644 --- a/tests/files/plumgrid-director.yaml +++ b/tests/files/plumgrid-director.yaml @@ -57,18 +57,15 @@ test: mysql: charm: cs:trusty/mysql num_units: 1 - to: 'lxc:plumgrid-director=0' rabbitmq-server: charm: cs:trusty/rabbitmq-server num_units: 1 - to: 'lxc:plumgrid-director=0' keystone: charm: cs:trusty/keystone num_units: 1 options: admin-password: plumgrid openstack-origin: cloud:trusty-kilo - to: 'lxc:plumgrid-director=0' nova-cloud-controller: charm: cs:trusty/nova-cloud-controller num_units: 1 @@ -77,25 +74,21 @@ test: network-manager: Neutron openstack-origin: cloud:trusty-kilo quantum-security-groups: 'yes' - to: 'lxc:plumgrid-director=0' glance: charm: cs:trusty/glance num_units: 1 options: openstack-origin: cloud:trusty-kilo - to: 'lxc:plumgrid-director=0' openstack-dashboard: charm: cs:trusty/openstack-dashboard num_units: 1 options: openstack-origin: cloud:trusty-kilo - to: 'lxc:plumgrid-director=0' cinder: charm: cs:trusty/cinder num_units: 1 options: openstack-origin: cloud:trusty-kilo - to: 'lxc:plumgrid-director=0' neutron-api: charm: cs:~plumgrid-team/trusty/neutron-api num_units: 1 @@ -106,7 +99,6 @@ test: plumgrid-password: plumgrid plumgrid-username: plumgrid plumgrid-virtual-ip: 192.168.100.250 - to: 'lxc:plumgrid-director=0' neutron-api-plumgrid: charm: cs:~plumgrid-team/trusty/neutron-api-plumgrid options: @@ -124,7 +116,6 @@ test: enable-resize: true migration-auth-type: ssh openstack-origin: cloud:trusty-kilo - to: '0' plumgrid-edge: charm: cs:~plumgrid-team/trusty/plumgrid-edge plumgrid-gateway: diff --git a/tests/test.yaml b/tests/test.yaml new file mode 100644 index 0000000..15f8f66 --- /dev/null +++ b/tests/test.yaml @@ -0,0 +1,2 @@ +makefile: + - lint From b86ab1d939130cdaf4654afecdebe5753d55db1d Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Tue, 15 Sep 2015 04:26:52 -0700 Subject: [PATCH 02/12] Configurable Managment interface support --- config.yaml | 4 +++ hooks/pg_dir_context.py | 5 ++- hooks/pg_dir_utils.py | 56 +++++++++++++++++++------------ unit_tests/test_pg_dir_context.py | 6 ++-- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/config.yaml b/config.yaml index 93f1164..f12c24b 100644 --- a/config.yaml +++ b/config.yaml @@ -7,6 +7,10 @@ options: default: 'null' type: string description: Public SSH key of PLUMgrid LCM which is running PG-Tools. + mgmt-interface: + type: string + default: 'juju-br0' + description: The interface connected to PLUMgrid Managment network. network-device-mtu: type: string default: '1580' diff --git a/hooks/pg_dir_context.py b/hooks/pg_dir_context.py index 11a1900..8af93d9 100644 --- a/hooks/pg_dir_context.py +++ b/hooks/pg_dir_context.py @@ -83,9 +83,8 @@ class PGDirContext(context.NeutronContext): pg_ctxt['director_ips_string'] = pg_dir_ips_string pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] pg_ctxt['pg_hostname'] = "pg-director" - from pg_dir_utils import check_interface_type - interface_type = check_interface_type() - pg_ctxt['interface'] = interface_type + from pg_dir_utils import get_mgmt_interface + pg_ctxt['interface'] = get_mgmt_interface() pg_ctxt['label'] = get_unit_hostname() pg_ctxt['fabric_mode'] = 'host' virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip']) diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index cda7dea..8ebc314 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -7,6 +7,13 @@ from copy import deepcopy from charmhelpers.core.hookenv import ( log, config, + unit_get, +) +from charmhelpers.contrib.network.ip import ( + get_iface_from_addr, + get_bridges, + get_bridge_nics, + is_ip ) from charmhelpers.contrib.openstack import templating from charmhelpers.core.host import set_nic_mtu @@ -23,7 +30,6 @@ import pg_dir_context import subprocess import time import os -import re import json LXC_CONF = '/etc/libvirt/lxc.conf' @@ -141,36 +147,42 @@ def remove_iovisor(): error_msg='Error Loading IOVisor Kernel Module') -def check_interface_type(): +def get_mgmt_interface(): ''' - Checks the interface. Support added for AWS deployments. There are 2 - possible interfaces "juju-br0" and "eth0". The default being juju-br0 + Returns the managment interface. ''' - log("Checking Interface Type") - default_interface = "juju-br0" - AWS_interface = "eth0" - shell_output = subprocess.check_output(['brctl', 'show', 'juju-br0']) - output = re.split(' |\n|\t', shell_output) - if output[10] == '': - return AWS_interface + def interface_exists(interface): + ''' + Checks if interface exists on node. + ''' + try: + subprocess.check_call(['ip', 'link', 'show', interface], + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return False + return True + + mgmt_interface = config('mgmt-interface') + if interface_exists(mgmt_interface): + return mgmt_interface else: - return default_interface + log('Provided managment interface %s does not exist' + % mgmt_interface) + return get_iface_from_addr(unit_get('private-address')) def ensure_mtu(): ''' Ensures required MTU of the underlying networking of the node. ''' - log("Changing MTU of juju-br0 and all attached interfaces") interface_mtu = config('network-device-mtu') - interface_type = check_interface_type() - if interface_type == "juju-br0": - cmd = subprocess.check_output(["brctl", "show", interface_type]) - words = cmd.split() - for word in words: - if 'eth' in word: - set_nic_mtu(word, interface_mtu) - set_nic_mtu(interface_type, interface_mtu) + mgmt_interface = get_mgmt_interface() + if mgmt_interface in get_bridges(): + attached_interfaces = get_bridge_nics(mgmt_interface) + for interface in attached_interfaces: + set_nic_mtu(interface, interface_mtu) + set_nic_mtu(mgmt_interface, interface_mtu) def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False): @@ -229,6 +241,8 @@ def post_pg_license(): log('PLUMgrid License Key not specified') return 0 PG_VIP = config('plumgrid-virtual-ip') + if not is_ip(PG_VIP): + raise ValueError('Invalid IP Provided') LICENSE_POST_PATH = 'https://%s/0/tenant_manager/license_key' % PG_VIP LICENSE_GET_PATH = 'https://%s/0/tenant_manager/licenses' % PG_VIP PG_CURL = '%s/opt/pg/scripts/pg_curl.sh' % PG_LXC_PATH diff --git a/unit_tests/test_pg_dir_context.py b/unit_tests/test_pg_dir_context.py index 3a716eb..33019de 100644 --- a/unit_tests/test_pg_dir_context.py +++ b/unit_tests/test_pg_dir_context.py @@ -45,8 +45,8 @@ class PGDirContextTest(CharmTestCase): 'neutron_plugin_attribute') @patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip') @patch.object(context, '_pg_dir_ips') - @patch.object(utils, 'check_interface_type') - def test_neutroncc_context_api_rel(self, _int_type, _pg_dir_ips, + @patch.object(utils, 'get_mgmt_interface') + def test_neutroncc_context_api_rel(self, _mgmt_int, _pg_dir_ips, _unit_priv_ip, _npa, _ens_pkgs, _save_ff, _https, _is_clus, _unit_get, _config, _runits, _rids, @@ -73,7 +73,7 @@ class PGDirContextTest(CharmTestCase): self.get_unit_hostname.return_value = 'node0' self.get_host_ip.return_value = '192.168.100.201' _pg_dir_ips.return_value = ['192.168.100.202', '192.168.100.203'] - _int_type.return_value = 'juju-br0' + _mgmt_int.return_value = 'juju-br0' napi_ctxt = context.PGDirContext() expect = { 'config': 'neutron.randomconfig', From 97edfaac504d7358ae68b139449b479c3a37b86a Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Fri, 2 Oct 2015 08:06:23 -0700 Subject: [PATCH 03/12] Version specific install of packages enabled --- config.yaml | 10 ++++++++ .../charmhelpers/contrib/openstack/neutron.py | 4 ++-- hooks/pg_dir_utils.py | 23 ++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index f12c24b..3cd0527 100644 --- a/config.yaml +++ b/config.yaml @@ -23,6 +23,16 @@ options: default: null type: string description: Provide the respective keys of the install sources. + plumgrid-build: + default: 'latest' + type: string + description: | + Provide the build version of PLUMgrid packages that needs to be installed + iovisor-build: + default: 'latest' + type: string + description: | + Provide the build version of iovisor package that needs to be installed plumgrid-license-key: default: null type: string diff --git a/hooks/charmhelpers/contrib/openstack/neutron.py b/hooks/charmhelpers/contrib/openstack/neutron.py index 91ce1e2..c43d857 100644 --- a/hooks/charmhelpers/contrib/openstack/neutron.py +++ b/hooks/charmhelpers/contrib/openstack/neutron.py @@ -204,8 +204,8 @@ def neutron_plugins(): database=config('database'), ssl_dir=NEUTRON_CONF_DIR)], 'services': [], - 'packages': [['plumgrid-lxc'], - ['iovisor-dkms']], + 'packages': ['plumgrid-lxc', + 'iovisor-dkms'], 'server_packages': ['neutron-server', 'neutron-plugin-plumgrid'], 'server_services': ['neutron-server'] diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 8ebc314..f54b262 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -15,6 +15,9 @@ from charmhelpers.contrib.network.ip import ( get_bridge_nics, is_ip ) +from charmhelpers.fetch import ( + apt_cache +) from charmhelpers.contrib.openstack import templating from charmhelpers.core.host import set_nic_mtu from collections import OrderedDict @@ -80,7 +83,25 @@ def determine_packages(): Returns list of packages required by PLUMgrid director as specified in the neutron_plugins dictionary in charmhelpers. ''' - return neutron_plugin_attribute('plumgrid', 'packages', 'neutron') + pkgs = [] + tag = 'latest' + for pkg in neutron_plugin_attribute('plumgrid', 'packages', 'neutron'): + if 'plumgrid' in pkg: + tag = config('plumgrid-build') + elif pkg == 'iovisor-dkms': + tag = config('iovisor-build') + + if tag == 'latest': + pkgs.append(pkg) + else: + if tag in [i.ver_str for i in apt_cache()[pkg].version_list]: + pkgs.append('%s=%s' % (pkg, tag)) + else: + error_msg = \ + "Build version '%s' for package '%s' not available" \ + % (tag, pkg) + raise ValueError(error_msg) + return pkgs def register_configs(release=None): From 64215337b12e593e0909798628b7ad01099f169d Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Tue, 3 Nov 2015 23:12:31 -0800 Subject: [PATCH 04/12] Getting IP only from director relation --- hooks/pg_dir_context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/pg_dir_context.py b/hooks/pg_dir_context.py index 8af93d9..f183a4d 100644 --- a/hooks/pg_dir_context.py +++ b/hooks/pg_dir_context.py @@ -29,7 +29,7 @@ def _pg_dir_ips(): for rid in relation_ids('director'): for unit in related_units(rid): rdata = relation_get(rid=rid, unit=unit) - pg_dir_ips.append(rdata['private-address']) + pg_dir_ips.append(get_host_ip(rdata['private-address'])) return pg_dir_ips From 2497e64f42f8e710421f7450277438f63baff3d2 Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Thu, 5 Nov 2015 15:30:06 -0800 Subject: [PATCH 05/12] rmmod iovisor in config changed --- hooks/pg_dir_hooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index a0c2fc4..1b2ed3f 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -72,6 +72,7 @@ def config_changed(): log("PLUMgrid LCM Key added") return 1 stop_pg() + remove_iovisor() configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: From 1b9b10b5e14c383165ceb4fc24746015648e5750 Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Tue, 10 Nov 2015 18:04:11 -0800 Subject: [PATCH 06/12] change sequence of rmmod --- hooks/pg_dir_hooks.py | 2 +- hooks/pg_dir_utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 1b2ed3f..3e4db18 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -72,11 +72,11 @@ def config_changed(): log("PLUMgrid LCM Key added") return 1 stop_pg() - remove_iovisor() configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes'], fatal=True) + remove_iovisor() load_iovisor() ensure_mtu() add_lcm_key() diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index f54b262..63bba10 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -166,6 +166,7 @@ def remove_iovisor(): ''' _exec_cmd(cmd=['rmmod', 'iovisor'], error_msg='Error Loading IOVisor Kernel Module') + time.sleep(1) def get_mgmt_interface(): From b9a6d93d6e3d271eda90deda79bd8bc3b20bf51e Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Fri, 20 Nov 2015 20:26:17 -0800 Subject: [PATCH 07/12] Adding fabric/data network support --- config.yaml | 18 ++++++++ hooks/pg_dir_context.py | 3 +- hooks/pg_dir_utils.py | 70 +++++++++++++++++++++++-------- templates/kilo/ifcs.conf | 2 +- unit_tests/test_pg_dir_context.py | 13 +++--- 5 files changed, 82 insertions(+), 24 deletions(-) diff --git a/config.yaml b/config.yaml index 3cd0527..c450253 100644 --- a/config.yaml +++ b/config.yaml @@ -11,6 +11,24 @@ options: type: string default: 'juju-br0' description: The interface connected to PLUMgrid Managment network. + os-data-network: + type: string + default: + description: | + The IP address and netmask of the OpenStack Data network (e.g., + 192.168.0.0/24) + . + This network will be used for tenant network traffic in overlay + networks. + fabric-interfaces: + default: 'MANAGEMENT' + type: string + description: | + Interfaces that will provide fabric connectivity on the director nodes. + Provided in form of json in a string. These interfaces have to be connected + to the os-data-network specified in the config. Default value is MANAGEMENT which + will configure the management interface as the fabric interface on each + director. network-device-mtu: type: string default: '1580' diff --git a/hooks/pg_dir_context.py b/hooks/pg_dir_context.py index f183a4d..01154e8 100644 --- a/hooks/pg_dir_context.py +++ b/hooks/pg_dir_context.py @@ -83,8 +83,9 @@ class PGDirContext(context.NeutronContext): pg_ctxt['director_ips_string'] = pg_dir_ips_string pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] pg_ctxt['pg_hostname'] = "pg-director" - from pg_dir_utils import get_mgmt_interface + from pg_dir_utils import get_mgmt_interface, get_fabric_interface pg_ctxt['interface'] = get_mgmt_interface() + pg_ctxt['fabric_interface'] = get_fabric_interface() pg_ctxt['label'] = get_unit_hostname() pg_ctxt['fabric_mode'] = 'host' virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip']) diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 63bba10..abda352 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -13,7 +13,9 @@ from charmhelpers.contrib.network.ip import ( get_iface_from_addr, get_bridges, get_bridge_nics, - is_ip + is_ip, + is_address_in_network, + get_iface_addr ) from charmhelpers.fetch import ( apt_cache @@ -29,6 +31,7 @@ from charmhelpers.core.host import ( service_start, service_stop, ) +from socket import gethostname as get_unit_hostname import pg_dir_context import subprocess import time @@ -169,22 +172,23 @@ def remove_iovisor(): time.sleep(1) +def interface_exists(interface): + ''' + Checks if interface exists on node. + ''' + try: + subprocess.check_call(['ip', 'link', 'show', interface], + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return False + return True + + def get_mgmt_interface(): ''' Returns the managment interface. ''' - def interface_exists(interface): - ''' - Checks if interface exists on node. - ''' - try: - subprocess.check_call(['ip', 'link', 'show', interface], - stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError: - return False - return True - mgmt_interface = config('mgmt-interface') if interface_exists(mgmt_interface): return mgmt_interface @@ -194,17 +198,49 @@ def get_mgmt_interface(): return get_iface_from_addr(unit_get('private-address')) +def get_fabric_interface(): + ''' + Returns the fabric interface. + ''' + fabric_interfaces = config('fabric-interfaces') + if fabric_interfaces == 'MANAGEMENT': + return get_mgmt_interface() + else: + try: + all_fabric_interfaces = json.loads(fabric_interfaces) + except ValueError: + raise ValueError('Invalid json provided for fabric interfaces') + hostname = get_unit_hostname() + if hostname in all_fabric_interfaces: + node_fabric_interface = all_fabric_interfaces[hostname] + elif 'DEFAULT' in all_fabric_interfaces: + node_fabric_interface = all_fabric_interfaces['DEFAULT'] + else: + raise ValueError('No fabric interface provided for node') + if interface_exists(node_fabric_interface): + if is_address_in_network(config('os-data-network'), + get_iface_addr(node_fabric_interface)[0]): + return node_fabric_interface + else: + raise ValueError('Fabric interface not in fabric network') + else: + log('Provided fabric interface %s does not exist' + % node_fabric_interface) + raise ValueError('Provided fabric interface does not exist') + return node_fabric_interface + + def ensure_mtu(): ''' Ensures required MTU of the underlying networking of the node. ''' interface_mtu = config('network-device-mtu') - mgmt_interface = get_mgmt_interface() - if mgmt_interface in get_bridges(): - attached_interfaces = get_bridge_nics(mgmt_interface) + fabric_interface = get_fabric_interface() + if fabric_interface in get_bridges(): + attached_interfaces = get_bridge_nics(fabric_interface) for interface in attached_interfaces: set_nic_mtu(interface, interface_mtu) - set_nic_mtu(mgmt_interface, interface_mtu) + set_nic_mtu(fabric_interface, interface_mtu) def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False): diff --git a/templates/kilo/ifcs.conf b/templates/kilo/ifcs.conf index 2ac1e59..9659932 100644 --- a/templates/kilo/ifcs.conf +++ b/templates/kilo/ifcs.conf @@ -1,2 +1,2 @@ -{{ interface }} = fabric_core host +{{ fabric_interface }} = fabric_core host diff --git a/unit_tests/test_pg_dir_context.py b/unit_tests/test_pg_dir_context.py index 33019de..a82b4b5 100644 --- a/unit_tests/test_pg_dir_context.py +++ b/unit_tests/test_pg_dir_context.py @@ -46,11 +46,12 @@ class PGDirContextTest(CharmTestCase): @patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip') @patch.object(context, '_pg_dir_ips') @patch.object(utils, 'get_mgmt_interface') - def test_neutroncc_context_api_rel(self, _mgmt_int, _pg_dir_ips, - _unit_priv_ip, _npa, _ens_pkgs, - _save_ff, _https, _is_clus, - _unit_get, _config, _runits, _rids, - _rget): + @patch.object(utils, 'get_fabric_interface') + def test_neutroncc_context_api_rel(self, _fabric_int, _mgmt_int, + _pg_dir_ips, _unit_priv_ip, _npa, + _ens_pkgs, _save_ff, _https, + _is_clus, _unit_get, _config, + _runits, _rids, _rget): def mock_npa(plugin, section, manager): if section == "driver": return "neutron.randomdriver" @@ -74,6 +75,7 @@ class PGDirContextTest(CharmTestCase): self.get_host_ip.return_value = '192.168.100.201' _pg_dir_ips.return_value = ['192.168.100.202', '192.168.100.203'] _mgmt_int.return_value = 'juju-br0' + _fabric_int.return_value = 'juju-br0' napi_ctxt = context.PGDirContext() expect = { 'config': 'neutron.randomconfig', @@ -86,6 +88,7 @@ class PGDirContextTest(CharmTestCase): 'virtual_ip': '192.168.100.250', 'pg_hostname': 'pg-director', 'interface': 'juju-br0', + 'fabric_interface': 'juju-br0', 'label': 'node0', 'fabric_mode': 'host', 'virtual_router_id': '250', From da05e4864213c8df710ebdd2cb98c9e8bd40ff7a Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Sat, 21 Nov 2015 14:07:15 -0800 Subject: [PATCH 08/12] Fabric config change only applies restart to the node that has a change --- hooks/pg_dir_hooks.py | 10 ++++++++++ hooks/pg_dir_utils.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 3e4db18..1b35b9b 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -30,6 +30,7 @@ from pg_dir_utils import ( ensure_mtu, add_lcm_key, post_pg_license, + fabric_interface_changed ) hooks = Hooks() @@ -71,6 +72,15 @@ def config_changed(): if add_lcm_key(): log("PLUMgrid LCM Key added") return 1 + charm_config = config() + if charm_config.changed('fabric-interfaces'): + if not fabric_interface_changed(): + log("Fabric interface already set") + return 1 + if charm_config.changed('os-data-network'): + if charm_config['fabric-interfaces'] == 'MANAGEMENT': + log('Fabric running on managment network') + return 1 stop_pg() configure_sources(update=True) pkgs = determine_packages() diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index abda352..dacf0c7 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -198,6 +198,22 @@ def get_mgmt_interface(): return get_iface_from_addr(unit_get('private-address')) +def fabric_interface_changed(): + ''' + Returns true if interface for node changed. + ''' + fabric_interface = get_fabric_interface() + try: + with open(PG_IFCS_CONF, 'r') as ifcs: + for line in ifcs: + if 'fabric_core' in line: + if line.split()[0] == fabric_interface: + return False + except IOError: + return True + return True + + def get_fabric_interface(): ''' Returns the fabric interface. From 43492c939e86b741067f5866192d3b394b2a28cd Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Sat, 21 Nov 2015 15:44:24 -0800 Subject: [PATCH 09/12] Removing restart on license post --- hooks/pg_dir_hooks.py | 7 ++++--- unit_tests/test_pg_dir_hooks.py | 17 +---------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 1b35b9b..939f3c5 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -66,13 +66,14 @@ def config_changed(): This hook is run when a config parameter is changed. It also runs on node reboot. ''' - if post_pg_license(): - log("PLUMgrid License Posted") - return 1 if add_lcm_key(): log("PLUMgrid LCM Key added") return 1 charm_config = config() + if charm_config.changed('plumgrid-license-key'): + if post_pg_license(): + log("PLUMgrid License Posted") + return 1 if charm_config.changed('fabric-interfaces'): if not fabric_interface_changed(): log("Fabric interface already set") diff --git a/unit_tests/test_pg_dir_hooks.py b/unit_tests/test_pg_dir_hooks.py index 2fa95a4..979d9c7 100644 --- a/unit_tests/test_pg_dir_hooks.py +++ b/unit_tests/test_pg_dir_hooks.py @@ -9,7 +9,6 @@ _map = utils.restart_map utils.register_configs = MagicMock() utils.restart_map = MagicMock() - import pg_dir_hooks as hooks utils.register_configs = _reg @@ -61,22 +60,8 @@ class PGDirHooksTests(CharmTestCase): self.add_lcm_key.assert_called_with() def test_config_changed_hook(self): - _pkgs = ['plumgrid-lxc', 'iovisor-dkms'] - self.add_lcm_key.return_value = 0 - self.post_pg_license.return_value = 0 - self.determine_packages.return_value = [_pkgs] + self.add_lcm_key.return_value = 1 self._call_hook('config-changed') - self.stop_pg.assert_called_with() - self.configure_sources.assert_called_with(update=True) - self.apt_install.assert_has_calls([ - call(_pkgs, fatal=True, - options=['--force-yes']), - ]) - self.load_iovisor.assert_called_with() - self.ensure_mtu.assert_called_with() - - self.CONFIGS.write_all.assert_called_with() - self.restart_pg.assert_called_with() def test_start(self): self._call_hook('start') From 4863763c023529a4371a889d615b4bd7405393aa Mon Sep 17 00:00:00 2001 From: Abdullah Khan Date: Thu, 3 Dec 2015 12:24:26 +0500 Subject: [PATCH 10/12] Minor additions to nginx.conf --- templates/kilo/nginx.conf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/templates/kilo/nginx.conf b/templates/kilo/nginx.conf index 179bb67..00f58f1 100644 --- a/templates/kilo/nginx.conf +++ b/templates/kilo/nginx.conf @@ -12,6 +12,10 @@ upstream pgCli { server {{ virtual_ip }}:3000; } +upstream pgMW { + server 127.0.0.1:4000; +} + map $http_upgrade $connection_upgrade { default upgrade; '' close; @@ -58,6 +62,19 @@ server { proxy_set_header Host $host; } + location /mwv0 { + proxy_pass http://pgMW; + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } + + location /cloudApex/ { + index index.html; + } + location /vtap/ { alias /opt/pg/vtap; } From abdfd54ee0f36548d90bd869571eef535ca02cac Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Thu, 14 Jan 2016 04:39:52 -0800 Subject: [PATCH 11/12] Registering configs before config-changed hook --- hooks/pg_dir_hooks.py | 2 +- unit_tests/test_pg_dir_hooks.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 939f3c5..6ba6cba 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -48,7 +48,7 @@ def install(): apt_install(pkg, options=['--force-yes'], fatal=True) load_iovisor() ensure_mtu() - add_lcm_key() + CONFIGS.write_all() @hooks.hook('director-relation-joined') diff --git a/unit_tests/test_pg_dir_hooks.py b/unit_tests/test_pg_dir_hooks.py index 979d9c7..de76231 100644 --- a/unit_tests/test_pg_dir_hooks.py +++ b/unit_tests/test_pg_dir_hooks.py @@ -57,7 +57,6 @@ class PGDirHooksTests(CharmTestCase): ]) self.load_iovisor.assert_called_with() self.ensure_mtu.assert_called_with() - self.add_lcm_key.assert_called_with() def test_config_changed_hook(self): self.add_lcm_key.return_value = 1 From b31bec9f6e80ac66eebee6ebde2140df7563dfad Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Tue, 26 Jan 2016 10:44:19 -0800 Subject: [PATCH 12/12] Changing hostname in plumgrid director config --- hooks/pg_dir_context.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hooks/pg_dir_context.py b/hooks/pg_dir_context.py index 01154e8..94b6834 100644 --- a/hooks/pg_dir_context.py +++ b/hooks/pg_dir_context.py @@ -82,11 +82,12 @@ class PGDirContext(context.NeutronContext): pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip) pg_ctxt['director_ips_string'] = pg_dir_ips_string pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] - pg_ctxt['pg_hostname'] = "pg-director" + unit_hostname = get_unit_hostname() + pg_ctxt['pg_hostname'] = unit_hostname from pg_dir_utils import get_mgmt_interface, get_fabric_interface pg_ctxt['interface'] = get_mgmt_interface() pg_ctxt['fabric_interface'] = get_fabric_interface() - pg_ctxt['label'] = get_unit_hostname() + pg_ctxt['label'] = unit_hostname pg_ctxt['fabric_mode'] = 'host' virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip']) pg_ctxt['virtual_router_id'] = virtual_ip_array[3]