From 516246f57d82311044dcfb606cf5f1aac8332543 Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Fri, 20 May 2016 16:52:33 +0200 Subject: [PATCH 1/2] configuring plumgrid install sources --- hooks/pg_dir_hooks.py | 5 ++++- hooks/pg_dir_utils.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 81f9013..add2a4d 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -40,7 +40,8 @@ from pg_dir_utils import ( fabric_interface_changed, load_iptables, restart_on_change, - director_cluster_ready + director_cluster_ready, + configure_pg_sources ) hooks = Hooks() @@ -135,6 +136,8 @@ def config_changed(): charm_config.changed('iovisor-build')): status_set('maintenance', 'Upgrading apt packages') stop_pg() + if charm_config.changed('install_sources'): + configure_pg_sources() configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 48f462d..4401fc7 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -42,6 +42,7 @@ from charmhelpers.contrib.openstack.utils import ( os_release, ) +SOURCES_LIST = '/etc/apt/sources.list' LXC_CONF = '/etc/libvirt/lxc.conf' TEMPLATES = 'templates/' PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data' @@ -88,6 +89,23 @@ BASE_RESOURCE_MAP = OrderedDict([ ]) +def configure_pg_sources(): + ''' + Returns true if install sources is updated in sources.list file + ''' + try: + with open(SOURCES_LIST, 'r+') as sources: + all_lines = sources.readlines() + sources.seek(0) + for i in (line for line in all_lines if "plumgrid" not in line): + sources.write(i) + sources.truncate() + sources.close() + return True + except IOError: + return False + + def determine_packages(): ''' Returns list of packages required by PLUMgrid director as specified From 80f799d1cadf781eed51b1aac8d03767f4f672fa Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Fri, 20 May 2016 16:58:24 +0200 Subject: [PATCH 2/2] logging IOError for sources.list --- hooks/pg_dir_hooks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index add2a4d..7703d6b 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -137,7 +137,8 @@ def config_changed(): status_set('maintenance', 'Upgrading apt packages') stop_pg() if charm_config.changed('install_sources'): - configure_pg_sources() + if not configure_pg_sources(): + log('IOError: sources.list couldn\'t be updated') configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: