Ejemplo n.º 1
0
def test_parse_events(good_events):
    events = [Dep(parent='service1', parent_action='run',
                  child='config1', child_action='run',
                  state='success'),
              React(parent='config1', parent_action='run',
                    child='service1', child_action='apply_config',
                    state='success')]
    parsed = cr.parse_events(good_events)
    assert events == parsed
Ejemplo n.º 2
0
Archivo: api.py Proyecto: cvieri/solar
def create_event(event_dict):
    etype = event_dict['etype']
    kwargs = {'child': event_dict['child'],
              'parent': event_dict['parent'],
              'child_action': event_dict['child_action'],
              'parent_action': event_dict['parent_action'],
              'state': event_dict['state']}
    if etype == React.etype:
        return React(**kwargs)
    elif etype == Dep.etype:
        return Dep(**kwargs)
    else:
        raise Exception('No support for type %s', etype)
Ejemplo n.º 3
0
def parse_events(template_events):
    parsed_events = []
    events = extend_events(template_events)
    for event in events:
        event_type = event['type']
        parent, parent_action = event['parent_action'].split('.')
        child, child_action = event['depend_action'].split('.')
        state = event['state']
        if event_type == Dep.etype:
            event = Dep(parent, parent_action, state, child, child_action)
        elif event_type == React.etype:
            event = React(parent, parent_action, state, child, child_action)
        else:
            raise Exception('Invalid event type: {0}'.format(event_type))
        parsed_events.append(event)
    return parsed_events
Ejemplo n.º 4
0
def add_react(parent, dep, actions, state='success'):
    for act in actions:
        r = React(parent, act, state=state, child=dep, child_action=act)
        add_event(r)
        log.debug('Added event: %s', r)
Ejemplo n.º 5
0
def setup_riak(nodes_num=None, hosts_mapping=False):

    if nodes_num is None:
        nodes_num = NODES
    db.clear()

    resources = vr.create('nodes', 'templates/nodes.yaml',
                          {'count': nodes_num})
    nodes = [x for x in resources if x.name.startswith('node')]
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]

    riak_services = []
    ips = '10.0.0.%d'
    for i in xrange(nodes_num):
        num = i + 1
        r = vr.create(
            'riak_service%d' % num, 'resources/riak_node', {
                'riak_self_name': 'riak%d' % num,
                'riak_hostname': 'riak_server%d.solar' % num,
                'riak_name': 'riak%d@riak_server%d.solar' % (num, num)
            })[0]
        riak_services.append(r)

    for i, riak in enumerate(riak_services):
        nodes[i].connect(riak)

    for i, riak in enumerate(riak_services[1:]):
        riak_services[0].connect(riak, {'riak_name': 'join_to'})

    if hosts_mapping:
        for riak in riak_services:
            for hosts_file in hosts_services:
                riak.connect_with_events(hosts_file, {
                    'riak_hostname': 'hosts:name',
                    'ip': 'hosts:ip'
                })

    res_errors = resource.validate_resources()
    for r, error in res_errors:
        click.echo('ERROR: %s: %s' % (r.name, error))
    has_errors = False

    if has_errors:
        click.echo("ERRORS")
        sys.exit(1)

    events = []
    for x in xrange(nodes_num):
        i = x + 1
        if hosts_mapping:
            events.append(
                Dep('hosts_file%d' % i, 'run', 'success', 'riak_service%d' % i,
                    'run'))
        if i >= 2:
            events.append(
                React('riak_service%d' % i, 'run', 'success',
                      'riak_service%d' % i, 'join'))
        events.append(
            React('riak_service%d' % i, 'join', 'success', 'riak_service1',
                  'commit'))

    for event in events:
        add_event(event)

    click.echo('Use solar changes process & orch')
    sys.exit(0)
Ejemplo n.º 6
0
with open('/vagrant/tmp/keys/ssh_public') as fp:
    master_key = fp.read().strip()

# Dnsmasq resources
for node in nodes_list:
    node = NodeAdapter(node)
    node_resource = next(n for n in node_resources
                         if n.name.endswith('node_{0}'.format(node.node_id)))

    node_resource.update({
        'partitioning': node.partitioning,
        'master_key': master_key,
        'repos': node.repos,
    })

    dnsmasq = vr.create('dnsmasq_{0}'.format(node.node_id),
                        'resources/dnsmasq', {})[0]
    master_node.connect(dnsmasq)
    node_resource.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'})

    event = React(node_resource.name, 'run', 'success', node_resource.name,
                  'provision')
    add_event(event)
    event = React(node_resource.name, 'provision', 'success', dnsmasq.name,
                  'exclude_mac_pxe')
    add_event(event)
    event = React(dnsmasq.name, 'exclude_mac_pxe', 'success',
                  node_resource.name, 'reboot')
    add_event(event)
Ejemplo n.º 7
0
def setup_riak():

    ModelMeta.remove_all()
    resources = vr.create('nodes', 'templates/nodes.yaml', {'count': 3})
    nodes = [x for x in resources if x.name.startswith('node')]
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]
    node1, node2, node3 = nodes
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]

    riak_services = []
    ips = '10.0.0.%d'
    for i in xrange(3):
        num = i + 1
        r = vr.create('riak_service%d' % num,
                      'resources/riak_node',
                      {'riak_self_name': 'riak%d' % num,
                       'storage_backend': 'leveldb',
                       'riak_hostname': 'riak_server%d.solar' % num,
                       'riak_name': 'riak%d@riak_server%d.solar' % (num, num)})[0]
        riak_services.append(r)

    for i, riak in enumerate(riak_services):
        nodes[i].connect(riak)

    for i, riak in enumerate(riak_services[1:]):
        riak_services[0].connect(riak, {'riak_name': 'join_to'})

    for riak in riak_services:
        for hosts_file in hosts_services:
            riak.connect_with_events(hosts_file,
                {'riak_hostname': 'hosts:name',
                 'ip': 'hosts:ip'})

    Resource.save_all_lazy()
    errors = resource.validate_resources()
    for r, error in errors:
        click.echo('ERROR: %s: %s' % (r.name, error))
    has_errors = False

    if errors:
        click.echo("ERRORS")
        sys.exit(1)

    events = [
        Dep('hosts_file1', 'run', 'success', 'riak_service1', 'run'),
        Dep('hosts_file2', 'run', 'success', 'riak_service2', 'run'),
        Dep('hosts_file3', 'run', 'success', 'riak_service3', 'run'),

        React('riak_service2', 'run', 'success', 'riak_service2', 'join'),
        React('riak_service3', 'run', 'success', 'riak_service3', 'join'),

        # Dep('riak_service1', 'run', 'success', 'riak_service2', 'join'),
        # Dep('riak_service1', 'run', 'success', 'riak_service3', 'join'),

        # React('riak_service2', 'join', 'error', 'riak_service2', 'leave'),
        # React('riak_service3', 'join', 'error', 'riak_service3', 'leave'),

        React('riak_service2', 'leave', 'success', 'riak_service2', 'join'),
        React('riak_service3', 'leave', 'success', 'riak_service3', 'join'),

        # React('riak_service2', 'leave', 'success', 'riak_service1', 'commit_leave'),
        # React('riak_service3', 'leave', 'success', 'riak_service1', 'commit_leave'),

        # Dep('riak_service1', 'commit_leave', 'success', 'riak_service2', 'join'),
        # Dep('riak_service1', 'commit_leave', 'success', 'riak_service3', 'join'),

        React('riak_service3', 'join', 'success', 'riak_service1', 'commit'),
        React('riak_service2', 'join', 'success', 'riak_service1', 'commit')
    ]

    for event in events:
        add_event(event)

    click.echo('Use solar changes process & orch')
    sys.exit(0)
Ejemplo n.º 8
0
def setup_haproxies():
    hps = []
    hpc = []
    hpsc_http = []
    hpsc_pb = []
    for i in xrange(3):
        num = i + 1
        hps.append(vr.create('haproxy_service%d' % num,
                             'resources/haproxy_service',
                             {})[0])
        hpc.append(vr.create('haproxy_config%d' % num,
                             'resources/haproxy_config',
                             {})[0])
        hpsc_http.append(vr.create('haproxy_service_config_http%d' % num,
                                   'resources/haproxy_service_config',
                                   {'listen_port': 8098,
                                    'protocol': 'http',
                                    'name': 'riak_haproxy_http%d' % num})[0])
        hpsc_pb.append(vr.create('haproxy_service_config_pb%d' % num,
                                 'resources/haproxy_service_config',
                                 {'listen_port': 8087,
                                  'protocol': 'tcp',
                                  'name': 'riak_haproxy_pb%d' % num})[0])

    riak1 = resource.load('riak_service1')
    riak2 = resource.load('riak_service2')
    riak3 = resource.load('riak_service3')
    riaks = [riak1, riak2, riak3]

    for single_hpsc in hpsc_http:
        for riak in riaks:
            riak.connect(single_hpsc, {
                'riak_hostname': 'backends:server',
                'riak_port_http': 'backends:port'})

    for single_hpsc in hpsc_pb:
        for riak in riaks:
            riak.connect(single_hpsc,
                {'riak_hostname': 'backends:server',
                 'riak_port_pb': 'backends:port'})

    # haproxy config to haproxy service

    for single_hpc, single_hpsc in zip(hpc, hpsc_http):
        single_hpsc.connect(single_hpc, {"backends": "config:backends",
                                                  "listen_port": "config:listen_port",
                                                  "protocol": "config:protocol",
                                                  "name": "config:name"})

    for single_hpc, single_hpsc in zip(hpc, hpsc_pb):
        single_hpsc.connect(single_hpc, {"backends": "config:backends",
                                                  "listen_port": "config:listen_port",
                                                  "protocol": "config:protocol",
                                                  "name": "config:name"})


    # assign haproxy services to each node

    node1 = resource.load('node1')
    node2 = resource.load('node2')
    node3 = resource.load('node3')
    nodes = [node1, node2, node3]

    for single_node, single_hps in zip(nodes, hps):
        single_node.connect(single_hps)

    for single_node, single_hpc in zip(nodes, hpc):
        single_node.connect(single_hpc)

    has_errors = False
    for r in locals().values():

        # TODO: handle list
        if not isinstance(r, resource.Resource):
            continue

        # print 'Validating {}'.format(r.name)
        local_errors = validation.validate_resource(r)
        if local_errors:
            has_errors = True
            print 'ERROR: %s: %s' % (r.name, local_errors)

    if has_errors:
        print "ERRORS"
        sys.exit(1)

    events = []
    for node, single_hps, single_hpc in zip(nodes, hps, hpc):
        # r = React(node.name, 'run', 'success', single_hps.name, 'install')
        d = Dep(single_hps.name, 'run', 'success', single_hpc.name, 'run')
        e1 = React(single_hpc.name, 'run', 'success', single_hps.name, 'apply_config')
        e2 = React(single_hpc.name, 'update', 'success', single_hps.name, 'apply_config')
        # events.extend([r, d, e1, e2])
        events.extend([d, e1, e2])

    for event in events:
        add_event(event)