Commit a3dc8e7e authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

deploy: Fix context issues in fabfile

Ensure that the context that each component is setup with, is
the correct one and does not include stale entries.

Use fabric's execute() method with hosts argument the proper
target nodes derived from current context. Introduce three
new decorators for this purpose:

 - with_ctx gets the current context
 - with_node updates the context's node with env.host
 - with_cluster updates the context's cluster with env.host
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent 86bf9c6a
......@@ -46,29 +46,29 @@ class Context(object):
def update(self, node=None, role=None, cluster=None, setup=None):
if node:
self.node = node
context.node = self.node = node
if role:
self.role = role
context.role = self.role = role
if cluster:
self.cluster = cluster
context.cluster = self.cluster = cluster
if setup:
self.setup = setup
context.setup = self.setup = setup
self.update_info()
def update_info(self):
self.ns = self.get(constants.NS)
self.nfs = self.get(constants.NFS)
self.mq = self.get(constants.MQ)
self.db = self.get(constants.DB)
self.astakos = self.get(constants.ASTAKOS)
self.cyclades = self.get(constants.CYCLADES)
self.pithos = self.get(constants.PITHOS)
self.stats = self.get(constants.STATS)
self.cms = self.get(constants.CMS)
self.router = self.get(constants.ROUTER)
self.client = self.get(constants.CLIENT)
def get(self, role):
self.ns = self._get(constants.NS)
self.nfs = self._get(constants.NFS)
self.mq = self._get(constants.MQ)
self.db = self._get(constants.DB)
self.astakos = self._get(constants.ASTAKOS)
self.cyclades = self._get(constants.CYCLADES)
self.pithos = self._get(constants.PITHOS)
self.stats = self._get(constants.STATS)
self.cms = self._get(constants.CMS)
self.router = self._get(constants.ROUTER)
self.client = self._get(constants.CLIENT)
def _get(self, role):
return config.get_single_node_role_info(self.setup, role)
@property
......@@ -101,9 +101,12 @@ class Context(object):
def nodes(self):
return list(set(self.masters + self.vmcs))
def get(self, role):
try:
return config.get(self.setup, role)
except:
return config.get(self.cluster, role)
def get(role):
return config.get(context.setup, role)
def backup():
context.node_backup = context.node
......
......@@ -26,41 +26,77 @@ from fabric.api import env, execute, parallel
from snfdeploy import context
from snfdeploy import constants
from snfdeploy import roles
import copy
def with_ctx(fn):
def wrapper(*args):
ctx = context.Context()
return fn(*args, ctx=ctx)
return wrapper
def with_cluster(fn):
def wrapper(old_ctx, *args):
ctx = copy.deepcopy(old_ctx)
ctx.update(cluster=env.host)
return fn(ctx, *args)
return wrapper
def with_node(fn):
def wrapper(old_ctx, *args):
ctx = copy.deepcopy(old_ctx)
ctx.update(node=env.host)
return fn(ctx, *args)
return wrapper
def setup_env(args):
env.component = args.component
env.method = args.method
env.ctx = context.Context()
env.role = args.role
# Helper methods that are invoked via fabric's execute
@parallel
def setup_vmc():
env.ctx.update(node=env.host)
VMC = roles.get(constants.VMC, env.ctx)
@with_node
def _setup_vmc(ctx):
VMC = roles.get(constants.VMC, ctx)
VMC.setup()
def setup_master():
env.ctx.update(node=env.host)
_setup_role(constants.MASTER)
@with_node
def _setup_master(ctx):
MASTER = roles.get(constants.MASTER, ctx)
MASTER.setup()
@with_node
def _setup_role(ctx, role):
ROLE = roles.get(role, ctx)
ROLE.setup()
@parallel
def setup_cluster():
env.ctx.update(cluster=env.host)
execute(setup_master, hosts=env.ctx.masters)
execute(setup_vmc, hosts=env.ctx.vmcs)
@with_cluster
def _setup_cluster(ctx):
execute(_setup_master, ctx, hosts=ctx.masters)
execute(_setup_vmc, ctx, hosts=ctx.vmcs)
def _setup_role(role):
env.ctx.update(node=env.host)
ROLE = roles.get(role, env.ctx)
ROLE.setup()
# Helper method that get a context snapshot and
# invoke fabric's execute with proper host argument
@with_ctx
def setup_role(role, ctx=None):
execute(_setup_role, ctx, role, hosts=ctx.get(role))
def setup_role(role):
execute(_setup_role, role, hosts=context.get(role))
@with_ctx
def setup_cluster(ctx=None):
execute(_setup_cluster, ctx, hosts=ctx.clusters)
def setup_synnefo():
......@@ -74,7 +110,7 @@ def setup_synnefo():
setup_role(constants.CYCLADES)
setup_role(constants.CMS)
execute(setup_cluster, hosts=env.ctx.clusters)
setup_cluster()
setup_role(constants.STATS)
setup_role(constants.CLIENT)
......@@ -83,27 +119,29 @@ def setup_synnefo():
def setup_ganeti():
setup_role(constants.NS)
setup_role(constants.NFS)
execute(setup_cluster, hosts=env.ctx.clusters)
setup_cluster()
def _setup_qa():
env.ctx.update(cluster=env.host)
@with_cluster
def _setup_qa(ctx):
setup_role(constants.NS)
setup_role(constants.NFS)
setup_cluster()
setup_role(constants.DEV)
def setup_qa():
execute(_setup_qa, hosts=env.ctx.clusters)
@with_ctx
def setup_qa(ctx=None):
execute(_setup_qa, ctx, hosts=ctx.clusters)
def setup():
@with_ctx
def setup(ctx=None):
if env.component:
target = env.component
else:
target = env.ctx.role
C = roles.get(target, env.ctx)
target = env.role
C = roles.get(target, ctx)
if env.method:
fn = getattr(C, env.method)
fn()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment