Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
begin process to update to astara
Browse files Browse the repository at this point in the history
This is the first step in converting the repo for Astara. This includes
changes to console scripts, new default users and packaging hooks.

Change-Id: If8e383e86cf867b8167f22b4411edf167d6cbd9a
Partially-Implements: blueprint convert-to-astara
  • Loading branch information
markmcclain committed Oct 22, 2015
1 parent 96c942e commit 8516813
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 33 deletions.
13 changes: 7 additions & 6 deletions akanda/rug/api/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
from akanda.rug.common.i18n import _LW, _LE, _LI
from akanda.rug.api import keystone
from akanda.rug.api import neutron
from akanda.rug.common import config
from akanda.rug.pez import rpcapi as pez_api

LOG = logging.getLogger(__name__)

OPTIONS = [
cfg.StrOpt(
'ssh_public_key',
help="Path to the SSH public key for the 'akanda' user within "
help="Path to the SSH public key for the 'astara' user within "
"appliance instances",
default='/etc/akanda-rug/akanda.pub'),
default='/etc/astara/astara.pub'),
cfg.StrOpt(
'instance_provider', default='on_demand',
help='Which instance provider to use (on_demand, pez)')
Expand Down Expand Up @@ -375,21 +376,21 @@ def update_instance_info(self, instance_info):
- /usr/local/bin/akanda-configure-management %(mac_address)s %(ip_address)s/64
users:
- name: akanda
gecos: Akanda
- name: astara
gecos: Astara
groups: users
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock-passwd: true
ssh-authorized-keys:
- %(ssh_public_key)s
final_message: "Akanda appliance is running"
final_message: "Astara appliance is running"
""" # noqa


def _ssh_key():
key = cfg.CONF.ssh_public_key
key = config.get_best_config_path(cfg.CONF.ssh_public_key)
if not key:
return ''
try:
Expand Down
12 changes: 5 additions & 7 deletions akanda/rug/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@

from cliff import app
from cliff import commandmanager

import pkg_resources

from oslo_config import cfg
import pkg_resources

from akanda.rug.common import config # noqa
from akanda.rug.common import config


class RugController(app.App):

log = logging.getLogger(__name__)

def __init__(self):
dist = pkg_resources.get_distribution('akanda-rug')
dist = pkg_resources.get_distribution('astara')
super(RugController, self).__init__(
description='controller for the Akanda RUG service',
version=dist.version,
Expand All @@ -45,7 +43,7 @@ def initialize_app(self, argv):

# Don't pass argv here because cfg.CONF will intercept the
# help options and exit.
cfg.CONF(['--config-file', '/etc/akanda-rug/rug.ini'],
project='akanda-rug')
cfg.CONF(['--config-file', config.get_best_config_path()],
project='astara-orchestrator')
self.rug_ini = cfg.CONF
return super(RugController, self).initialize_app(argv)
39 changes: 37 additions & 2 deletions akanda/rug/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,48 @@
# License for the specific language governing permissions and limitations
# under the License.

import os

from oslo_config import cfg
from oslo_log import log


LOG = log.getLogger(__name__)

PREFERRED_CONFIG_FILEPATH = '/etc/astara/orchestrator.ini'
SEARCH_DIRS = ['/etc/astara', '/etc/akanda-rug', '/etc/akanda']
LEGACY_FILE_MAP = {
'orchestrator.ini': 'rug.ini',
'astara.pub': 'akanda.pub'
}

DEFAULT_CONFIG_FILES = [
'/etc/akanda-rug/rug.ini'
PREFERRED_CONFIG_FILEPATH
]


def get_best_config_path(filepath=PREFERRED_CONFIG_FILEPATH):
if os.path.isfile(filepath):
return filepath

# now begin attemp to fallback for compatibility
dirname, basename = os.path.split(filepath)

if dirname and dirname not in SEARCH_DIRS:
return filepath # retain the non-standard location

for searchdir in SEARCH_DIRS:
candidate_path = os.path.join(searchdir, basename)
if os.path.isfile(candidate_path):
return candidate_path

if basename in LEGACY_FILE_MAP:
candidate_path = os.path.join(searchdir, LEGACY_FILE_MAP[basename])
if os.path.isfile(candidate_path):
return candidate_path
return filepath


def parse_config(argv, default_config_files=DEFAULT_CONFIG_FILES):
log.register_options(cfg.CONF)
# Set the logging format to include the process and thread, since
Expand Down Expand Up @@ -55,6 +86,10 @@ def parse_config(argv, default_config_files=DEFAULT_CONFIG_FILES):
]
cfg.CONF.set_default('logging_default_format_string', log_format)
log.set_defaults(default_log_levels=log_levels)

# For legacy compatibility
default_config_files = map(get_best_config_path, default_config_files)

cfg.CONF(argv,
project='akanda-rug',
project='astara-orchestrator',
default_config_files=default_config_files)
6 changes: 3 additions & 3 deletions akanda/rug/coordination.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
COORD_OPTS = [
cfg.BoolOpt('enabled', default=False,
help=_('Whether to use an external coordination service to '
'a cluster of akanda-rug nodes. This may be disabled '
'for akanda-rug node environments.')),
'a cluster of astara-orchestrator nodes. This may be '
'disabled for astara-orchestrator node environments.')),
cfg.StrOpt('url',
default='memcached://localhost:11211',
help=_('URL of suppoted coordination service')),
cfg.StrOpt('group_id', default='akanda.rug',
cfg.StrOpt('group_id', default='astara.orchestrator',
help=_('ID of coordination group to join.')),
cfg.IntOpt('heartbeat_interval', default=1,
help=_('Interval (in seconds) for cluster heartbeats')),
Expand Down
2 changes: 1 addition & 1 deletion akanda/rug/db/sqlalchemy/dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_alembic_config():


def main():
CONF(project='akanda-rug')
CONF(project='astara-orchestrator')
config = get_alembic_config()
config.akanda_config = CONF
CONF.command.func(config, CONF.command.name)
6 changes: 3 additions & 3 deletions akanda/rug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def shuffle_notifications(notification_queue, sched):


def main(argv=sys.argv[1:]):
"""Main Entry point into the akanda-rug
"""Main Entry point into the astara-orchestrator
This is the main entry point into the akanda-rug. On invocation of
This is the main entry point into the astara-orchestrator. On invocation of
this method, logging, local network connectivity setup is performed.
This information is obtained through the 'ak-config' file, passed as
arguement to this method. Worker threads are spawned for handling
Expand All @@ -111,7 +111,7 @@ def main(argv=sys.argv[1:]):
t = threading.current_thread()
t.name = 'tmain'
ak_cfg.parse_config(argv)
log.setup(cfg.CONF, 'akanda-rug')
log.setup(cfg.CONF, 'astara-orchestrator')
cfg.CONF.log_opt_values(LOG, logging.INFO)

neutron = neutron_api.Neutron(cfg.CONF)
Expand Down
2 changes: 1 addition & 1 deletion akanda/rug/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def start(self):

def main():
eventlet.monkey_patch()
cfg.CONF(sys.argv[1:], project='akanda-rug')
cfg.CONF(sys.argv[1:], project='astara-orchestrator')
log.setup('akanda')

mgr = manager.AkandaL3Manager()
Expand Down
8 changes: 4 additions & 4 deletions akanda/rug/test/unit/api/test_nova_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class FakeConf:
auth_url = 'http://127.0.0.1/'
auth_strategy = 'keystone'
auth_region = 'RegionOne'
router_image_uuid = 'akanda-image'
router_image_uuid = 'astara-image'
router_instance_flavor = 1
instance_provider = 'foo'

Expand All @@ -107,16 +107,16 @@ class FakeConf:
- /usr/local/bin/akanda-configure-management aa:aa:aa:aa:aa:aa 192.168.1.1/64
users:
- name: akanda
gecos: Akanda
- name: astara
gecos: Astara
groups: users
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock-passwd: true
ssh-authorized-keys:
- fake_key
final_message: "Akanda appliance is running"
final_message: "Astara appliance is running"
"""


Expand Down
44 changes: 44 additions & 0 deletions akanda/rug/test/unit/common/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2015 Akanda, Inc.
# All Rights Reserved.
#
# 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.

import mock

from akanda.rug.common import config
from akanda.rug.test.unit import base


class TestConfig(base.RugTestBase):
def _test_get_best_config_path(self, original, expected, files_exist=()):
def mock_isfile_f(f):
return f in files_exist

with mock.patch('os.path.isfile', side_effect=mock_isfile_f):
self.assertEqual(
config.get_best_config_path(original),
expected
)

def test_get_best_config_path_preferred(self):
self._test_get_best_config_path(
config.PREFERRED_CONFIG_FILEPATH,
config.PREFERRED_CONFIG_FILEPATH
)

def test_get_best_config_path_legacy(self):
self._test_get_best_config_path(
config.PREFERRED_CONFIG_FILEPATH,
'/etc/akanda/rug.ini',
('/etc/akanda/rug.ini',)
)
6 changes: 3 additions & 3 deletions akanda/rug/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ def report_status(self, show_config=True):

if cfg.CONF.coordination.enabled:
# NOTE(adam_g): This list could be big with a large cluster.
LOG.info(_LI(
'Peer akanda-rug hosts: %s'), self.hash_ring_mgr.hosts)
LOG.info(_LI('Peer astara-orchestrator hosts: %s'),
self.hash_ring_mgr.hosts)
else:
LOG.info(_LI(
'No peer akanda-rug hosts, coordination disabled.'))
'No peer astara-orchestrator hosts, coordination disabled.'))
11 changes: 8 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = akanda-rug
name = astara
version = 7.0.0
summary = Akanda Router Update Generator manages tenant routers
summary = Astara Network Orchestrator
description-file =
README.md
author = OpenStack
Expand Down Expand Up @@ -35,8 +35,13 @@ console_scripts =
akanda-rug-service=akanda.rug.main:main
akanda-pez-service=akanda.rug.pez.service:main
akanda-debug-router=akanda.rug.debug:debug_one_router
akanda-rug-dbsync = akanda.rug.db.sqlalchemy.dbsync:main
akanda-rug-dbsync=akanda.rug.db.sqlalchemy.dbsync:main
rug-ctl=akanda.rug.cli.main:main
astara-orchestrator=akanda.rug.main:main
astara-pez-service=akanda.rug.pez.service:main
astara-debug-router=akanda.rug.debug:debug_one_router
astara-dbsync=akanda.rug.db.sqlalchemy.dbsync:main
astara-ctl=akanda.rug.cli.main:main
akanda.rug.cli =
config reload=akanda.rug.cli.config:ConfigReload

Expand Down

0 comments on commit 8516813

Please sign in to comment.