diff --git a/config.yaml b/config.yaml index 8a9e76eb..2860510e 100644 --- a/config.yaml +++ b/config.yaml @@ -21,6 +21,11 @@ options: description: | Key ID to import to the apt keyring to support use with arbitary source configuration from outside of Launchpad archives or PPA's. + port: + type: int + default: 80 + description: | + The port that the RADOS Gateway will listen on. # Keystone integration operator-roles: default: "Member,Admin" diff --git a/hooks/ceph_radosgw_context.py b/hooks/ceph_radosgw_context.py index 1e079904..6adac61d 100644 --- a/hooks/ceph_radosgw_context.py +++ b/hooks/ceph_radosgw_context.py @@ -21,18 +21,17 @@ class HAProxyContext(context.HAProxyContext): def __call__(self): ctxt = super(HAProxyContext, self).__call__() + port = config('port') # Apache ports - a_cephradosgw_api = determine_apache_port(80, - singlenode_mode=True) + a_cephradosgw_api = determine_apache_port(port, singlenode_mode=True) port_mapping = { - 'cephradosgw-server': [ - 80, a_cephradosgw_api] + 'cephradosgw-server': [port, a_cephradosgw_api] } ctxt['cephradosgw_bind_port'] = determine_api_port( - 80, + port, singlenode_mode=True, ) @@ -99,6 +98,8 @@ class MonContext(context.OSContextGenerator): 'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0, 'use_syslog': str(config('use-syslog')).lower(), 'embedded_webserver': config('use-embedded-webserver'), + 'port': determine_apache_port(config('port'), + singlenode_mode=True) } if self.context_complete(ctxt): diff --git a/hooks/hooks.py b/hooks/hooks.py index 8898706b..18b8a95b 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -34,6 +34,9 @@ from charmhelpers.core.host import ( lsb_release, restart_on_change, ) +from charmhelpers.contrib.hahelpers.cluster import ( + determine_apache_port, +) from utils import ( render_template, enable_pocket, @@ -58,6 +61,9 @@ from charmhelpers.contrib.openstack.ip import ( from charmhelpers.contrib.openstack.utils import ( set_os_workload_status, ) + +APACHE_PORTS_CONF = '/etc/apache2/ports.conf' + hooks = Hooks() CONFIGS = register_configs() @@ -125,7 +131,8 @@ def install(): def emit_apacheconf(): apachecontext = { - "hostname": unit_get('private-address') + "hostname": unit_get('private-address'), + "port": determine_apache_port(config('port'), singlenode_mode=True) } site_conf = '/etc/apache2/sites-available/rgw' if is_apache_24(): @@ -152,7 +159,11 @@ def apache_reload(): def apache_ports(): - shutil.copy('files/ports.conf', '/etc/apache2/ports.conf') + portscontext = { + "port": determine_apache_port(config('port'), singlenode_mode=True) + } + with open(APACHE_PORTS_CONF, 'w') as portsconf: + portsconf.write(render_template('ports.conf', portscontext)) @hooks.hook('upgrade-charm', @@ -188,22 +199,22 @@ def mon_relation(): @hooks.hook('gateway-relation-joined') def gateway_relation(): relation_set(hostname=unit_get('private-address'), - port=80) + port=config('port')) def start(): subprocess.call(['service', 'radosgw', 'start']) - open_port(port=80) + open_port(port=config('port')) def stop(): subprocess.call(['service', 'radosgw', 'stop']) - open_port(port=80) + open_port(port=config('port')) def restart(): subprocess.call(['service', 'radosgw', 'restart']) - open_port(port=80) + open_port(port=config('port')) @hooks.hook('identity-service-relation-joined') @@ -212,7 +223,7 @@ def identity_joined(relid=None): log('Integration with keystone requires ceph >= 0.55') sys.exit(1) - port = 80 + port = config('port') admin_url = '%s:%i/swift' % (canonical_url(None, ADMIN), port) internal_url = '%s:%s/swift/v1' % \ (canonical_url(None, INTERNAL), port) diff --git a/templates/ceph.conf b/templates/ceph.conf index e1c95fce..4213d324 100644 --- a/templates/ceph.conf +++ b/templates/ceph.conf @@ -17,7 +17,7 @@ keyring = /etc/ceph/keyring.rados.gateway rgw socket path = /tmp/radosgw.sock log file = /var/log/ceph/radosgw.log {% if embedded_webserver %} -rgw frontends = civetweb port=70 +rgw frontends = civetweb port={{ port }} {% else %} # Turn off 100-continue optimization as stock mod_fastcgi # does not support it diff --git a/files/ports.conf b/templates/ports.conf similarity index 88% rename from files/ports.conf rename to templates/ports.conf index 83a775fe..9b011ec1 100644 --- a/files/ports.conf +++ b/templates/ports.conf @@ -1,4 +1,4 @@ -Listen 70 +Listen {{ port }} Listen 443 diff --git a/templates/rgw b/templates/rgw index 6101e1bc..7a3e4724 100644 --- a/templates/rgw +++ b/templates/rgw @@ -2,7 +2,7 @@ FastCgiExternalServer /var/www/s3gw.fcgi -socket /tmp/radosgw.sock - + ServerName {{ hostname }} ServerAdmin ceph@ubuntu.com DocumentRoot /var/www diff --git a/unit_tests/test_ceph_radosgw_context.py b/unit_tests/test_ceph_radosgw_context.py index 4394f683..4a043418 100644 --- a/unit_tests/test_ceph_radosgw_context.py +++ b/unit_tests/test_ceph_radosgw_context.py @@ -165,7 +165,8 @@ class MonContextTest(CharmTestCase): 'hostname': '10.0.0.10', 'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789', 'old_auth': False, - 'use_syslog': 'false' + 'use_syslog': 'false', + 'port': 70 } self.assertEqual(expect, mon_ctxt()) @@ -197,7 +198,8 @@ class MonContextTest(CharmTestCase): 'hostname': '10.0.0.10', 'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789', 'old_auth': False, - 'use_syslog': 'false' + 'use_syslog': 'false', + 'port': 70 } self.assertEqual(expect, mon_ctxt()) @@ -221,6 +223,7 @@ class MonContextTest(CharmTestCase): 'hostname': '10.0.0.10', 'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789', 'old_auth': False, - 'use_syslog': 'false' + 'use_syslog': 'false', + 'port': 70 } self.assertEqual(expect, mon_ctxt()) diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 9b17cd10..0f428ef3 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -127,6 +127,7 @@ class CephRadosGWTests(CharmTestCase): self.unit_get.return_value = '10.0.0.1' apachecontext = { "hostname": '10.0.0.1', + "port": 70, } vhost_file = '/etc/apache2/sites-available/rgw.conf' with patch_open() as (_open, _file): @@ -167,6 +168,7 @@ class CephRadosGWTests(CharmTestCase): ] self.subprocess.call.assert_has_calls(calls) + @patch.object(ceph_hooks, 'apache_ports', lambda *args: True) def test_config_changed(self): _install_packages = self.patch('install_packages') _emit_apacheconf = self.patch('emit_apacheconf')